1
1
package io .sloeber .core .api ;
2
2
3
+ import static io .sloeber .core .common .Common .*;
4
+ import static io .sloeber .core .common .Const .*;
5
+
3
6
import java .io .File ;
4
7
import java .util .ArrayList ;
5
8
import java .util .Collections ;
23
26
import io .sloeber .core .Messages ;
24
27
import io .sloeber .core .common .Common ;
25
28
import io .sloeber .core .common .ConfigurationPreferences ;
26
- import io .sloeber .core .common .Const ;
27
29
import io .sloeber .core .managers .ArduinoPlatform ;
28
30
import io .sloeber .core .managers .InternalPackageManager ;
29
31
import io .sloeber .core .tools .Helpers ;
34
36
import io .sloeber .core .txt .Programmers ;
35
37
import io .sloeber .core .txt .TxtFile ;
36
38
37
- public class BoardDescription extends Common {
39
+ public class BoardDescription {
38
40
// Important constants to avoid having to add the class
39
41
private static final String TOOL_ID = Messages .TOOL ;
40
42
private static final String BOARD_ID = Messages .BOARD ;
41
43
private static final String FILE_ID = Messages .FILE ;
42
- private static final String VendorArduino = Const . ARDUINO ;
44
+ private static final String VendorArduino = ARDUINO ;
43
45
44
46
/*
45
47
* Some constants
@@ -50,8 +52,8 @@ public class BoardDescription extends Common {
50
52
private static final String KEY_LAST_USED_UPLOAD_PROTOCOL = "last Used upload Protocol" ; //$NON-NLS-1$
51
53
private static final String KEY_LAST_USED_BOARDS_FILE = "Last used Boards file" ; //$NON-NLS-1$
52
54
private static final String KEY_LAST_USED_BOARD_MENU_OPTIONS = "last used Board custom option selections" ; //$NON-NLS-1$
53
- private static final String ENV_KEY_JANTJE_MENU_SELECTION = ENV_KEY_JANTJE_START + Const . MENU ;
54
- private static final String ENV_KEY_JANTJE_UPLOAD_PORT = ENV_KEY_JANTJE_START + Const . COM_PORT ;
55
+ private static final String ENV_KEY_JANTJE_MENU_SELECTION = ENV_KEY_JANTJE_START + MENU ;
56
+ private static final String ENV_KEY_JANTJE_UPLOAD_PORT = ENV_KEY_JANTJE_START + COM_PORT ;
55
57
private static final String ENV_KEY_JANTJE_BOARD_NAME = ENV_KEY_JANTJE_START + "board_name" ; //$NON-NLS-1$
56
58
private static final String ENV_KEY_JANTJE_BOARDS_FILE = ENV_KEY_JANTJE_START + "boards_file" ; //$NON-NLS-1$
57
59
private static final String ENV_KEY_JANTJE_PACKAGE_ID = ENV_KEY_JANTJE_START + "package_ID" ; //$NON-NLS-1$
@@ -210,7 +212,7 @@ private void ParseSection() {
210
212
myBoardsCore = actualValue ;
211
213
myReferencedCorePlatformPath = InternalPackageManager .getPlatformInstallPath (refVendor , architecture );
212
214
if (this .myReferencedCorePlatformPath == null ) {
213
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
215
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
214
216
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , core )
215
217
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
216
218
.replace (BOARD_ID , getBoardID ())));
@@ -225,7 +227,7 @@ private void ParseSection() {
225
227
myReferencedCorePlatformPath = InternalPackageManager .getPlatformInstallPath (refVendor , refArchitecture ,
226
228
refVersion );
227
229
if (this .myReferencedCorePlatformPath == null ) {
228
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
230
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
229
231
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , core )
230
232
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
231
233
.replace (BOARD_ID , getBoardID ())));
@@ -244,7 +246,7 @@ private void ParseSection() {
244
246
this .myReferencedBoardVariantPlatformPath = InternalPackageManager .getPlatformInstallPath (refVendor ,
245
247
architecture );
246
248
if (this .myReferencedBoardVariantPlatformPath == null ) {
247
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
249
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
248
250
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , variant )
249
251
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
250
252
.replace (BOARD_ID , getBoardID ())));
@@ -264,7 +266,7 @@ private void ParseSection() {
264
266
refArchitecture , refVersion );
265
267
}
266
268
if (this .myReferencedBoardVariantPlatformPath == null ) {
267
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
269
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
268
270
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , variant )
269
271
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
270
272
.replace (BOARD_ID , getBoardID ())));
@@ -283,7 +285,7 @@ private void ParseSection() {
283
285
this .myReferencedUploadToolPlatformPath = InternalPackageManager .getPlatformInstallPath (refVendor ,
284
286
architecture );
285
287
if (this .myReferencedUploadToolPlatformPath == null ) {
286
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
288
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
287
289
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , upload )
288
290
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
289
291
.replace (BOARD_ID , getBoardID ())));
@@ -298,7 +300,7 @@ private void ParseSection() {
298
300
this .myReferencedUploadToolPlatformPath = InternalPackageManager .getPlatformInstallPath (refVendor ,
299
301
refArchitecture , refVersion );
300
302
if (this .myReferencedUploadToolPlatformPath == null ) {
301
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID ,
303
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID ,
302
304
Messages .Helpers_tool_reference_missing .replace (TOOL_ID , upload )
303
305
.replace (FILE_ID , getReferencingBoardsFile ().toString ())
304
306
.replace (BOARD_ID , getBoardID ())));
@@ -408,7 +410,7 @@ private void setDefaultOptions() {
408
410
* project
409
411
*/
410
412
public void saveUserSelection () {
411
- myStorageNode .put (KEY_LAST_USED_BOARDS_FILE , getReferencingBoardsFile ().toString ());
413
+ myStorageNode .put (KEY_LAST_USED_BOARDS_FILE , makePathEnvironmentString ( getReferencingBoardsFile ().toString () ));
412
414
myStorageNode .put (KEY_LAST_USED_BOARD , this .myBoardID );
413
415
myStorageNode .put (KEY_LAST_USED_UPLOAD_PORT , this .myUploadPort );
414
416
myStorageNode .put (KEY_LAST_USED_UPLOAD_PROTOCOL , this .myProgrammer );
@@ -580,7 +582,7 @@ public IPath getActualVariantPath() {
580
582
if (retPath == null ) {
581
583
retPath = getreferencingPlatformPath ();
582
584
}
583
- return retPath .append (Const . VARIANTS_FOLDER_NAME ).append (getBoardVariant ());
585
+ return retPath .append (VARIANTS_FOLDER_NAME ).append (getBoardVariant ());
584
586
}
585
587
586
588
private String getBoardVariant () {
@@ -597,7 +599,7 @@ public IPath getActualCoreCodePath() {
597
599
if (this .myBoardsCore == null ) {
598
600
return null ;
599
601
}
600
- return retPath .append (Const . CORES ).append (this .myBoardsCore );
602
+ return retPath .append (CORES ).append (this .myBoardsCore );
601
603
}
602
604
603
605
/**
@@ -632,7 +634,7 @@ public IPath getReferencedVariantPlatformPath() {
632
634
633
635
public PlatformTxtFile getReferencingPlatformFile () {
634
636
updateWhenDirty ();
635
- File platformFile = getreferencingPlatformPath ().append (Const . PLATFORM_FILE_NAME ).toFile ();
637
+ File platformFile = getreferencingPlatformPath ().append (PLATFORM_FILE_NAME ).toFile ();
636
638
if (platformFile != null && platformFile .exists ()) {
637
639
return new PlatformTxtFile (platformFile );
638
640
}
@@ -652,7 +654,7 @@ public PlatformTxtFile getreferencedPlatformFile() {
652
654
if (this .myReferencedCorePlatformPath == null ) {
653
655
return null ;
654
656
}
655
- File platformFile = myReferencedCorePlatformPath .append (Const . PLATFORM_FILE_NAME ).toFile ();
657
+ File platformFile = myReferencedCorePlatformPath .append (PLATFORM_FILE_NAME ).toFile ();
656
658
if (platformFile != null && platformFile .exists ()) {
657
659
return new PlatformTxtFile (platformFile );
658
660
}
@@ -675,36 +677,36 @@ public IPath getReferencingLibraryPath() {
675
677
public String getUploadCommand (ICConfigurationDescription confdesc ) {
676
678
updateWhenDirty ();
677
679
String upLoadTool = getActualUploadTool ();
678
- String action = Const . UPLOAD ;
680
+ String action = UPLOAD ;
679
681
if (usesProgrammer ()) {
680
- action = Const . PROGRAM ;
682
+ action = PROGRAM ;
681
683
}
682
684
String networkPrefix = EMPTY ;
683
685
if (isNetworkUpload ()) {
684
- networkPrefix = DOT + Const . NETWORK_PREFIX ;
686
+ networkPrefix = DOT + NETWORK_PREFIX ;
685
687
}
686
- String key = Const . A_TOOLS + upLoadTool + DOT + action + networkPrefix + DOT + Const . PATTERN ;
688
+ String key = A_TOOLS + upLoadTool + DOT + action + networkPrefix + DOT + PATTERN ;
687
689
String ret = Common .getBuildEnvironmentVariable (confdesc , key , EMPTY );
688
690
if (ret .isEmpty ()) {
689
- Common .log (new Status (IStatus .ERROR , Const . CORE_PLUGIN_ID , key + " : not found in the platform.txt file" )); //$NON-NLS-1$
691
+ Common .log (new Status (IStatus .ERROR , CORE_PLUGIN_ID , key + " : not found in the platform.txt file" )); //$NON-NLS-1$
690
692
}
691
693
return ret ;
692
694
}
693
695
694
696
public String getActualUploadTool () {
695
697
updateWhenDirty ();
696
698
// if (confdesc == null) {
697
- // Common.log(new Status(IStatus.ERROR, Const .CORE_PLUGIN_ID, "Confdesc null is
699
+ // Common.log(new Status(IStatus.ERROR, .CORE_PLUGIN_ID, "Confdesc null is
698
700
// not alowed here")); //$NON-NLS-1$
699
701
// return this.myUploadTool;
700
702
// }
701
703
// if (usesProgrammer()) {
702
- // return Common.getBuildEnvironmentVariable(confdesc, Const. PROGRAM_TOOL,
704
+ // return Common.getBuildEnvironmentVariable(confdesc, PROGRAM_TOOL,
703
705
// "Program tool not properly configured"); //$NON-NLS-1$
704
706
// }
705
707
//
706
708
// if (this.myUploadTool == null) {
707
- // return Common.getBuildEnvironmentVariable(confdesc, Const. UPLOAD_TOOL,
709
+ // return Common.getBuildEnvironmentVariable(confdesc, UPLOAD_TOOL,
708
710
// "upload tool not properly configured"); //$NON-NLS-1$
709
711
// }
710
712
return myUploadTool ;
@@ -1032,12 +1034,12 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
1032
1034
for (Entry <String , String > curVariable : vars .entrySet ()) {
1033
1035
String name = curVariable .getKey ();
1034
1036
String value = curVariable .getValue ();
1035
- if (name .startsWith (Const . RECIPE_OBJCOPY ) && name .endsWith (".pattern" ) && !value .isEmpty ()) { //$NON-NLS-1$
1037
+ if (name .startsWith (RECIPE_OBJCOPY ) && name .endsWith (".pattern" ) && !value .isEmpty ()) { //$NON-NLS-1$
1036
1038
objcopyCommand .add (makeEnvironmentVar (name ));
1037
1039
}
1038
1040
}
1039
1041
Collections .sort (objcopyCommand );
1040
- extraVars .put (Const . JANTJE_OBJCOPY , StringUtil .join (objcopyCommand , "\n \t " )); //$NON-NLS-1$
1042
+ extraVars .put (JANTJE_OBJCOPY , StringUtil .join (objcopyCommand , "\n \t " )); //$NON-NLS-1$
1041
1043
1042
1044
// handle the hooks
1043
1045
extraVars .putAll (getEnvVarsHookBuild (vars , "A.JANTJE.pre.link" , //$NON-NLS-1$
@@ -1052,10 +1054,10 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
1052
1054
"A.recipe.hooks.sketch.postbuild.XX.pattern" , false )); //$NON-NLS-1$
1053
1055
1054
1056
// add -relax for mega boards; the arduino ide way
1055
- String buildMCU = vars .get (Const . ENV_KEY_BUILD_MCU );
1057
+ String buildMCU = vars .get (ENV_KEY_BUILD_MCU );
1056
1058
if ("atmega2560" .equalsIgnoreCase (buildMCU )) { //$NON-NLS-1$
1057
- String c_elf_flags = vars .get (Const . ENV_KEY_BUILD_COMPILER_C_ELF_FLAGS );
1058
- extraVars .put (Const . ENV_KEY_BUILD_COMPILER_C_ELF_FLAGS , c_elf_flags + ",--relax" ); //$NON-NLS-1$
1059
+ String c_elf_flags = vars .get (ENV_KEY_BUILD_COMPILER_C_ELF_FLAGS );
1060
+ extraVars .put (ENV_KEY_BUILD_COMPILER_C_ELF_FLAGS , c_elf_flags + ",--relax" ); //$NON-NLS-1$
1059
1061
}
1060
1062
return extraVars ;
1061
1063
}
@@ -1097,11 +1099,21 @@ public static BoardDescription getFromCDT(ICConfigurationDescription confDesc) {
1097
1099
BoardDescription ret = new BoardDescription ();
1098
1100
ret .myUploadPort = getOldWayEnvVar (confDesc , "JANTJE.com_port" );
1099
1101
ret .myProgrammer = getOldWayEnvVar (confDesc , "JANTJE.upload" );
1100
- ret .myreferencingBoardsFile = new File (getOldWayEnvVar (confDesc , "JANTJE.boards_file" ));
1101
1102
ret .myBoardID = getOldWayEnvVar (confDesc , "JANTJE.board_ID" );
1102
- ret .myTxtFile = new BoardTxtFile (ret .myreferencingBoardsFile );
1103
1103
String optinconcat = getOldWayEnvVar (confDesc , "JANTJE.menu" );
1104
1104
ret .myOptions = KeyValue .makeMap (optinconcat );
1105
+
1106
+ String referencingBoardsFile = getOldWayEnvVar (confDesc , "JANTJE.boards_file" );
1107
+ int packagesIndex =referencingBoardsFile .indexOf ( "\\ arduinoPlugin\\ packages\\ " );
1108
+ if (packagesIndex ==-1 ) {
1109
+ packagesIndex =referencingBoardsFile .indexOf ( "/arduinoPlugin/packages/" );
1110
+ }
1111
+ if (packagesIndex !=-1 ) {
1112
+ referencingBoardsFile = eclipseHomePath .append (referencingBoardsFile .substring (packagesIndex )).toString ();
1113
+ }
1114
+ ret .myreferencingBoardsFile = new File (referencingBoardsFile );
1115
+ ret .myTxtFile = new BoardTxtFile (ret .myreferencingBoardsFile );
1116
+
1105
1117
return ret ;
1106
1118
}
1107
1119
0 commit comments