Skip to content

Commit 2d96def

Browse files
author
jantje
committed
#555 this should do it.
1 parent 162d56b commit 2d96def

File tree

1 file changed

+58
-48
lines changed

1 file changed

+58
-48
lines changed

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

+58-48
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373

7474
/**
7575
* ArduinoHelpers is a static class containing general purpose functions
76-
*
76+
*
7777
* @author Jan Baeyens
78-
*
78+
*
7979
*/
8080
public class Helpers extends Common {
8181
private static final String ARDUINO_CORE_FOLDER_NAME = "cores"; //$NON-NLS-1$
@@ -115,7 +115,7 @@ public class Helpers extends Common {
115115
/**
116116
* This method is the internal working class that adds the provided include
117117
* path to all configurations and languages.
118-
*
118+
*
119119
* @param configurationDescription
120120
* The configuration description of the project to add it to
121121
* @param IncludePath
@@ -150,7 +150,7 @@ private static void addIncludeFolder(ICConfigurationDescription configurationDes
150150
/**
151151
* Removes include folders that are not valid. This method does not save the
152152
* configurationDescription description
153-
*
153+
*
154154
* @param configurationDescription
155155
* the configuration that is checked
156156
* @return true is a include path has been removed. False if the include
@@ -200,7 +200,7 @@ public static boolean removeInvalidIncludeFolders(ICConfigurationDescription con
200200
/**
201201
* This method adds the provided path to the include path of all
202202
* configurations and languages.
203-
*
203+
*
204204
* @param project
205205
* The project to add it to
206206
* @param IncludePath
@@ -238,7 +238,7 @@ public static void addCodeFolder(IProject project, Path toLinkFolder, String Lin
238238
* Creates a folder and links the folder to an existing folder Parent
239239
* folders of the target folder are created if needed. In case this method
240240
* fails an error is logged.
241-
*
241+
*
242242
* @param project
243243
* the project the newly created folder will belong to
244244
* @param target
@@ -276,19 +276,19 @@ public static void LinkFolderToFolder(IProject project, IPath source, IPath targ
276276
* Forget about this. Arduino made this all so complicated I don't know
277277
* anymore what needs to be added to what<br/>
278278
* <br/>
279-
*
279+
*
280280
* note Arduino has these subfolders in the libraries that need to be
281281
* include.<br/>
282282
* <br/>
283-
*
283+
*
284284
* note that in the current eclipse version, there is no need to add the
285285
* subfolder as a code folder. This may change in the future as it looks
286286
* like a bug to me.<br/>
287-
*
287+
*
288288
* @param project
289289
* @param Path
290290
* @throws CoreException
291-
*
291+
*
292292
* @see addLibraryDependency
293293
* {@link #addLibraryDependency(IProject, IProject)}
294294
*/
@@ -322,26 +322,33 @@ public static void addCodeFolder(IProject project, IPath toLinkFolder, String Li
322322
}
323323
}
324324

325+
public static void removeCodeFolder(IProject project, String LinkName) throws CoreException {
326+
IFolder link = project.getFolder(LinkName);
327+
if (link.exists()) {
328+
link.delete(true, null);
329+
}
330+
}
331+
325332
/**
326333
* This method creates a link folder in the project and adds the folder as a
327334
* source path to the project it also adds the path to the include folder if
328335
* the include path parameter points to a path that contains a subfolder
329336
* named "utility" this subfolder will be added to the include path as well
330337
* <br/>
331338
* <br/>
332-
*
339+
*
333340
* note Arduino has these subfolders in the libraries that need to be
334341
* include.<br/>
335342
* <br/>
336-
*
343+
*
337344
* note that in the current eclipse version, there is no need to add the
338345
* subfolder as a code folder. This may change in the future as it looks
339346
* like a bug to me.<br/>
340-
*
347+
*
341348
* @param project
342349
* @param Path
343350
* @throws CoreException
344-
*
351+
*
345352
* @see addLibraryDependency
346353
* {@link #addLibraryDependency(IProject, IProject)}
347354
*/
@@ -355,7 +362,7 @@ public static void addCodeFolder(IProject project, Path Path, ICConfigurationDes
355362
/**
356363
* addTheNatures replaces all existing natures by the natures needed for a
357364
* arduino project
358-
*
365+
*
359366
* @param project
360367
* The project where the natures need to be added to
361368
* @throws CoreException
@@ -375,7 +382,7 @@ public static void addTheNatures(IProjectDescription description) throws CoreExc
375382
/**
376383
* This method adds the content of a content stream to a file If the file
377384
* already exist the file remains untouched
378-
*
385+
*
379386
* @param container
380387
* used as a reference to the file
381388
* @param path
@@ -416,7 +423,7 @@ public static MessageConsole findConsole(String name) {
416423
/**
417424
* This method adds the Arduino code in a subfolder named Arduino. 2 linked
418425
* subfolders named core and variant link to the real Arduino code note
419-
*
426+
*
420427
* @param project
421428
* The project to add the arduino code to
422429
* @param configurationDescription
@@ -438,7 +445,10 @@ public static void addArduinoCodeToProject(IProject project, ICConfigurationDesc
438445

439446
addCodeFolder(project, corePath, ARDUINO_CODE_FOLDER_NAME + '/' + ARDUINO_CORE_BUILD_FOLDER_NAME,
440447
configurationDescription);
441-
if (!boardVariant.isEmpty()) {
448+
if (boardVariant.isEmpty()) {
449+
// remove the existing link
450+
Helpers.removeCodeFolder(project, ARDUINO_CODE_FOLDER_NAME + "/variant"); //$NON-NLS-1$
451+
} else {
442452
String redirectVariantPath = getBuildEnvironmentVariable(configurationDescription,
443453
ENV_KEY_JANTJE_REFERENCED_VARIANT_PATH, EMPTY_STRING);
444454
IPath VariantFile;
@@ -456,7 +466,7 @@ public static void addArduinoCodeToProject(IProject project, ICConfigurationDesc
456466

457467
/**
458468
* Creates a new folder resource as a link or local
459-
*
469+
*
460470
* @param Project
461471
* the project the folder is added to
462472
* @param newFolderName
@@ -465,7 +475,7 @@ public static void addArduinoCodeToProject(IProject project, ICConfigurationDesc
465475
* if null a local folder is created using newFolderName if not
466476
* null a link folder is created with the name newFolderName and
467477
* pointing to linklocation
468-
*
478+
*
469479
* @return nothing
470480
* @throws CoreException
471481
*/
@@ -482,7 +492,7 @@ public static void createNewFolder(IProject Project, String newFolderName, URI l
482492

483493
/**
484494
* Remove all the arduino environment variables.
485-
*
495+
*
486496
* @param contribEnv
487497
* @param confDesc
488498
*/
@@ -502,7 +512,7 @@ private static void removeAllEraseEnvironmentVariables(IContributedEnvironment c
502512
* platform.txt file. Here I set these values. This method should be called
503513
* as first. This way the values in platform.txt and boards.txt will take
504514
* precedence of the default values declared here
505-
*
515+
*
506516
* @param contribEnv
507517
* @param confDesc
508518
* @param platformFile
@@ -589,7 +599,7 @@ private static void setTheEnvironmentVariablesAddAFile(IContributedEnvironment c
589599
/**
590600
* This method parses a file with environment variables like the
591601
* platform.txt file for values to be added to the environment variables
592-
*
602+
*
593603
* @param contribEnv
594604
* @param confDesc
595605
* @param envVarFile
@@ -638,7 +648,7 @@ private static void setTheEnvironmentVariablesAddAFile(String prefix, IContribut
638648
* the modifiers) Then it parses for the menu variables
639649
* menu.[menuID].[boardID].[selectionID].[key]=[value] results in
640650
* [key]=[value] (taking in account the modifiers)
641-
*
651+
*
642652
* @param contribEnv
643653
* @param confDesc
644654
* @param platformFilename
@@ -761,14 +771,14 @@ private static void setTheEnvironmentVariablesAddThePlatformInfo(IContributedEnv
761771
* The project properties are used to identify the boards.txt and
762772
* platform.txt as well as the board id to select the settings in the
763773
* board.txt file At the end also the path variable is set
764-
*
774+
*
765775
* from arduino IDE 1.6.5 an additional file generated by the arduino ide is
766776
* processed. This is the first file processed.
767-
*
777+
*
768778
* To be able to quickly fix boards.txt and platform.txt problems I also
769779
* added a pre and post platform and boards files that are processed before
770780
* and after the arduino delivered boards.txt file.
771-
*
781+
*
772782
* @param project
773783
* the project for which the environment variables are set
774784
* @param arduinoProperties
@@ -856,20 +866,20 @@ public static void setTheEnvironmentVariables(IProject project, ICConfigurationD
856866
* Hardware-specification This method parses the boards.txt file for
857867
* myboard.build.core myboard.build.variant currently not supported
858868
* myboard.upload.tool myboard.bootloader.tool
859-
*
869+
*
860870
* in case myboard.build.core is of type [vendor]:[value]
861871
* PATH_VARIABLE_NAME_ARDUINO_PLATFORM is changed to the correct value in
862872
* case myboard.build.variant is of type [vendor]:[value]
863873
* PATH_VARIABLE_NAME_ARDUINO_PINS is changed to the correct value
864-
*
874+
*
865875
* this method also sets ENV_KEY_JANTJE_BUILD_CORE and
866876
* ENV_KEY_JANTJE_BUILD_VARIANT to [value] of respectively
867877
* myboard.build.core and myboard.build.variant
868-
*
878+
*
869879
* This method relies on the post processing to set
870880
* A.BUILD.CORE=${ENV_KEY_JANTJE_BUILD_CORE}
871881
* A.BUILD.VARIANT=${ENV_KEY_JANTJE_BUILD_VARIANT}
872-
*
882+
*
873883
* @param contribEnv
874884
* @param confDesc
875885
* @param boardsFile
@@ -929,10 +939,10 @@ private static void setTheEnvironmentVariablesRedirectToOtherVendors(IContribute
929939
/**
930940
* This method looks for a referenced platformFile. Ask the boards manager
931941
* to find the latest installed vendor/architecture platform file
932-
*
942+
*
933943
* If this is not found there is still sme old code that probably can be
934944
* deleted.
935-
*
945+
*
936946
* @param vendor
937947
* @param architecture
938948
* @return
@@ -946,21 +956,21 @@ private static IPath findReferencedPlatformFile(String vendor, String architectu
946956

947957
/**
948958
* Following post processing is done
949-
*
959+
*
950960
* the macro expansion resolves the "file tag" Therefore I split the
951961
* "recipe" patterns in 2 parts (before and after the "file tag") the
952962
* pattern in the toolchain is then ${first part} ${files} ${second part}
953-
*
963+
*
954964
* The handling of the upload variables is done differently in arduino than
955965
* here. This is taken care of here. for example the output of this input
956966
* tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}"
957967
* {upload.verbose} is changed as if it were the output of this input
958968
* tools.avrdude.upload.pattern="{tools.avrdude.cmd.path}"
959969
* "-C{tools.avrdude.config.path}" {tools.avrdude.upload.verbose}
960-
*
970+
*
961971
* if a programmer is selected different from default some extra actions are
962972
* done here so no special code is needed to handle programmers
963-
*
973+
*
964974
* @param contribEnv
965975
* @param confDesc
966976
*/
@@ -1116,7 +1126,7 @@ private static void setTheEnvironmentVariablesPostProcessing(IContributedEnviron
11161126
* Converts the CPP and C compiler flags to not optimize for space/size and
11171127
* to leave symbols in. These changes allow step through debugging with JTAG
11181128
* and Dragon AVR
1119-
*
1129+
*
11201130
* @param confDesc
11211131
* @param envManager
11221132
* @param contribEnv
@@ -1157,7 +1167,7 @@ private static void setTheEnvironmentVariablesModifyDebugCompilerSettings(ICConf
11571167
* When parsing boards.txt and platform.txt some processing needs to be done
11581168
* to get "acceptable environment variable values" This method does the
11591169
* parsing
1160-
*
1170+
*
11611171
* @param inputString
11621172
* the value string as read from the file
11631173
* @return the string to be stored as value for the environment variable
@@ -1184,11 +1194,11 @@ public static String MakeEnvironmentString(String inputString, String keyPrefix)
11841194
* to get "acceptable environment variable keys" This method does the
11851195
* parsing some examples on windows "test.windows" becomes "A.TEST"
11861196
* "test.linux" becomes "A.TEST.LINUX"
1187-
*
1197+
*
11881198
* on Linux "test.windows" becomes "A.TEST.WINDOWS" "test.linux" becomes
11891199
* "A.TEST"
1190-
*
1191-
*
1200+
*
1201+
*
11921202
* @param inputString
11931203
* the key string as read from the file
11941204
* @return the string to be used as key for the environment variable
@@ -1214,7 +1224,7 @@ private static String MakeKeyString(String prefix, String string) {
12141224
* this to work is by deleting the build folder Still then the "indexer
12151225
* needs to recheck his includes from the language provider which still is
12161226
* not working
1217-
*
1227+
*
12181228
* @param project
12191229
*/
12201230
public static void setDirtyFlag(IProject project, ICConfigurationDescription cfgDescription) {
@@ -1257,7 +1267,7 @@ public static void setDirtyFlag(IProject project, ICConfigurationDescription cfg
12571267
* So I keep it for now and we'll see how it goes The eclipse default
12581268
* behavior is (starting from the project folder [configuration]/Source The
12591269
* Arduino default behavior is all in 1 location (so no subfolders)
1260-
*
1270+
*
12611271
* @param Source
12621272
* The source file to find the
12631273
* @return The base file name for the ouput if Source is "file.cpp" the
@@ -1276,7 +1286,7 @@ public static IPath GetOutputName(IPath Source) {
12761286
/**
12771287
* Converts a name to a tagged environment variable if variableName ="this"
12781288
* the output is "${this}"
1279-
*
1289+
*
12801290
* @param variableName
12811291
* @return
12821292
*/
@@ -1288,7 +1298,7 @@ private static String makeEnvironmentVar(String variableName) {
12881298
* Give the string entered in the com port try to extract a host. If no host
12891299
* is found return null yun.local at xxx.yyy.zzz (arduino yun) returns
12901300
* yun.local
1291-
*
1301+
*
12921302
* @param mComPort
12931303
* @return
12941304
*/
@@ -1301,7 +1311,7 @@ public static String getHostFromComPort(String mComPort) {
13011311

13021312
/**
13031313
* creates links to the root files and folders of the source location
1304-
*
1314+
*
13051315
* @param source
13061316
* the location where the files are that need to be linked to
13071317
* @param target
@@ -1334,7 +1344,7 @@ public static void linkDirectory(IProject project, IPath source, IPath target) {
13341344
/**
13351345
* given a action and a tool return the environment key that matches it's
13361346
* recipe
1337-
*
1347+
*
13381348
* @param action
13391349
* @return he environment variable key to find the recipe
13401350
*/

0 commit comments

Comments
 (0)