Skip to content

Commit 3da109b

Browse files
author
jantje
committed
Support for referencing other versions
Arduino supports arduino:arduino to reference variants,cores and upload. I added referencedplatform:referenced architecture:referenced version:value Only 2 fields or 4 fields are supported
1 parent 82f62ef commit 3da109b

File tree

2 files changed

+85
-41
lines changed

2 files changed

+85
-41
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardDescriptor.java

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ public boolean equals(BoardDescriptor otherBoardDescriptor) {
160160
*/
161161
public boolean needsSettingDirty(BoardDescriptor otherBoardDescriptor) {
162162

163-
164163
if (!this.getBoardID().equals(otherBoardDescriptor.getBoardID())) {
165164
return true;
166165
}
@@ -180,8 +179,8 @@ public boolean needsSettingDirty(BoardDescriptor otherBoardDescriptor) {
180179
return true;
181180
}
182181
if (!this.getMyWorkSpaceLocation().equals(otherBoardDescriptor.getMyWorkSpaceLocation())) {
183-
return true;
184-
}
182+
return true;
183+
}
185184
return false;
186185
}
187186

@@ -244,14 +243,29 @@ private void ParseSection(Map<String, String> boardInfo) {
244243
upload = uploadOption;
245244
}
246245
}
247-
246+
String architecture = getArchitecture();
248247
if (core != null) {
249248
String valueSplit[] = core.split(":");
250249
if (valueSplit.length == 2) {
251250
String refVendor = valueSplit[0];
252251
String actualValue = valueSplit[1];
253252
this.myBoardsCore = actualValue;
254-
this.myReferencedCorePlatformPath = findReferencedPlatform(refVendor);
253+
this.myReferencedCorePlatformPath = Manager.getPlatformInstallPath(refVendor, architecture);
254+
if (this.myReferencedCorePlatformPath == null) {
255+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
256+
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, core)
257+
.replaceAll(FILE_KEY, getReferencingBoardsFile().toString())
258+
.replaceAll(BOARD_KEY, getBoardID())));
259+
return;
260+
}
261+
} else if (valueSplit.length == 4) {
262+
String refVendor = valueSplit[0];
263+
String refArchitecture = valueSplit[1];
264+
String refVersion = valueSplit[2];
265+
String actualValue = valueSplit[3];
266+
this.myUploadTool = actualValue;
267+
this.myReferencedCorePlatformPath = Manager.getPlatformInstallPath(refVendor, refArchitecture,
268+
refVersion);
255269
if (this.myReferencedCorePlatformPath == null) {
256270
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
257271
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, core)
@@ -269,7 +283,22 @@ private void ParseSection(Map<String, String> boardInfo) {
269283
String refVendor = valueSplit[0];
270284
String actualValue = valueSplit[1];
271285
this.myBoardsVariant = actualValue;
272-
this.myReferencedBoardVariantPlatformPath = findReferencedPlatform(refVendor);
286+
this.myReferencedBoardVariantPlatformPath = Manager.getPlatformInstallPath(refVendor, architecture);
287+
if (this.myReferencedBoardVariantPlatformPath == null) {
288+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
289+
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, variant)
290+
.replaceAll(FILE_KEY, getReferencingBoardsFile().toString())
291+
.replaceAll(BOARD_KEY, getBoardID())));
292+
return;
293+
}
294+
} else if (valueSplit.length == 4) {
295+
String refVendor = valueSplit[0];
296+
String refArchitecture = valueSplit[1];
297+
String refVersion = valueSplit[2];
298+
String actualValue = valueSplit[3];
299+
this.myUploadTool = actualValue;
300+
this.myReferencedBoardVariantPlatformPath = Manager.getPlatformInstallPath(refVendor, refArchitecture,
301+
refVersion);
273302
if (this.myReferencedBoardVariantPlatformPath == null) {
274303
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
275304
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, variant)
@@ -287,7 +316,22 @@ private void ParseSection(Map<String, String> boardInfo) {
287316
String refVendor = valueSplit[0];
288317
String actualValue = valueSplit[1];
289318
this.myUploadTool = actualValue;
290-
this.myReferencedUploadToolPlatformPath = findReferencedPlatform(refVendor);
319+
this.myReferencedUploadToolPlatformPath = Manager.getPlatformInstallPath(refVendor, architecture);
320+
if (this.myReferencedUploadToolPlatformPath == null) {
321+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
322+
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, upload)
323+
.replaceAll(FILE_KEY, getReferencingBoardsFile().toString())
324+
.replaceAll(BOARD_KEY, getBoardID())));
325+
return;
326+
}
327+
} else if (valueSplit.length == 4) {
328+
String refVendor = valueSplit[0];
329+
String refArchitecture = valueSplit[1];
330+
String refVersion = valueSplit[2];
331+
String actualValue = valueSplit[3];
332+
this.myUploadTool = actualValue;
333+
this.myReferencedUploadToolPlatformPath = Manager.getPlatformInstallPath(refVendor, refArchitecture,
334+
refVersion);
291335
if (this.myReferencedUploadToolPlatformPath == null) {
292336
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
293337
Messages.Helpers_tool_reference_missing.replaceAll(TOOL_KEY, upload)
@@ -324,8 +368,7 @@ protected BoardDescriptor(ICConfigurationDescription confdesc) {
324368
"");
325369
this.myWorkEclipseLocation = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION,
326370
"");
327-
String optinconcat= Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_MENU_SELECTION,
328-
"");
371+
String optinconcat = Common.getBuildEnvironmentVariable(confdesc, ENV_KEY_JANTJE_MENU_SELECTION, "");
329372
this.myOptions = KeyValue.makeMap(optinconcat);
330373
}
331374
calculateDerivedFields();
@@ -595,8 +638,8 @@ public boolean saveConfiguration(ICConfigurationDescription confDesc, IContribut
595638
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_ECLIPSE_LOCATION,
596639
this.myWorkEclipseLocation);
597640
Common.setBuildEnvironmentVariable(confDesc, JANTJE_ACTION_UPLOAD, this.myProgrammer);
598-
String value=KeyValue.makeString(this.myOptions);
599-
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MENU_SELECTION ,value);
641+
String value = KeyValue.makeString(this.myOptions);
642+
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_JANTJE_MENU_SELECTION, value);
600643

601644
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT, this.myUploadPort);
602645
Common.setBuildEnvironmentVariable(contribEnv, confDesc, ENV_KEY_SERIAL_PORT_FILE,
@@ -702,7 +745,7 @@ public String[] getCompatibleBoards() {
702745

703746
public String[] getUploadProtocols() {
704747

705-
return Programmers.getUploadProtocols(this);
748+
return Programmers.getUploadProtocols(this);
706749

707750
}
708751

@@ -769,24 +812,6 @@ public String getProjectName() {
769812
return this.myProjectName;
770813
}
771814

772-
/**
773-
* This method looks for a referenced platform. Ask the boards manager to find
774-
* the latest installed vendor/architecture platform file
775-
*
776-
* If this is not found there is still sme old code that probably can be
777-
* deleted.
778-
*
779-
* @param vendor
780-
* @param architecture
781-
* @return
782-
*/
783-
private IPath findReferencedPlatform(String vendor) {
784-
// ask the boardsmanager for the platform file
785-
IPath ret = Manager.getPlatformInstallPath(vendor, getArchitecture());
786-
return ret;
787-
788-
}
789-
790815
/**
791816
* provide the actual path to the variant. Use this method if you want to know
792817
* where the variant is
@@ -871,24 +896,25 @@ public IPath getReferencingLibraryPath() {
871896

872897
public String getUploadCommand(ICConfigurationDescription confdesc) {
873898
String upLoadTool = getActualUploadTool(confdesc);
874-
String action="UPLOAD";
899+
String action = "UPLOAD";
875900
if (usesProgrammer()) {
876-
action="PROGRAM";
901+
action = "PROGRAM";
877902
}
878-
return Common.getBuildEnvironmentVariable(confdesc, "A.TOOLS." + upLoadTool.toUpperCase() + "."+action+".PATTERN",
879-
upLoadTool.toUpperCase());
903+
return Common.getBuildEnvironmentVariable(confdesc,
904+
"A.TOOLS." + upLoadTool.toUpperCase() + "." + action + ".PATTERN", upLoadTool.toUpperCase());
880905
}
881906

882907
public String getActualUploadTool(ICConfigurationDescription confdesc) {
883-
if(confdesc == null) {
884-
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,"Confdesc null is not alowed here"));
908+
if (confdesc == null) {
909+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID, "Confdesc null is not alowed here"));
885910
return this.myUploadTool;
886911
}
887-
if(usesProgrammer()) {
888-
return Common.getBuildEnvironmentVariable(confdesc, "A.PROGRAM.TOOL", "Program tool not properly configured");
912+
if (usesProgrammer()) {
913+
return Common.getBuildEnvironmentVariable(confdesc, "A.PROGRAM.TOOL",
914+
"Program tool not properly configured");
889915
}
890-
if (this.myUploadTool == null ) {
891-
return Common.getBuildEnvironmentVariable(confdesc, "A.UPLOAD.TOOL", "upload tool not properly configured");
916+
if (this.myUploadTool == null) {
917+
return Common.getBuildEnvironmentVariable(confdesc, "A.UPLOAD.TOOL", "upload tool not properly configured");
892918
}
893919
return this.myUploadTool;
894920
}

io.sloeber.core/src/io/sloeber/core/managers/Manager.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static File getLocalFileName(String url) {
222222
* already available locally
223223
*/
224224
static private void loadJson(String url, boolean forceDownload) {
225-
System.out.println("loadJson "+url+" forced= "+forceDownload);
225+
//System.out.println("loadJson "+url+" forced= "+forceDownload); //$NON-NLS-1$ //$NON-NLS-2$
226226
File jsonFile = getLocalFileName(url);
227227
if (jsonFile == null) {
228228
return;
@@ -322,6 +322,22 @@ public static IPath getPlatformInstallPath(String vendor, String architecture) {
322322
return null;
323323
}
324324

325+
public static IPath getPlatformInstallPath(String refVendor, String refArchitecture, String refVersion) {
326+
for (PackageIndex index : getPackageIndices()) {
327+
for (Package pkg : index.getPackages()) {
328+
if (refVendor.equalsIgnoreCase(pkg.getName())) {
329+
for (ArduinoPlatform curPlatform : pkg.getInstalledPlatforms()) {
330+
if (refArchitecture.equalsIgnoreCase(curPlatform.getArchitecture())
331+
&& refVersion.equalsIgnoreCase(curPlatform.getVersion())) {
332+
return new org.eclipse.core.runtime.Path(curPlatform.getInstallPath().toString());
333+
}
334+
}
335+
}
336+
}
337+
}
338+
return null;
339+
}
340+
325341
/**
326342
* Given a platform.txt file find the platform in the platform manager
327343
*
@@ -854,4 +870,6 @@ public static void onlyKeepLatestPlatforms() {
854870
}
855871
}
856872

873+
874+
857875
}

0 commit comments

Comments
 (0)