Skip to content

Commit f8c536b

Browse files
author
jantje
committed
#1268 upgrade single config works
Single config is a project wit 1 single config using extra compile paratmeter's a nd no libraries
1 parent f6ca3d9 commit f8c536b

File tree

3 files changed

+76
-94
lines changed

3 files changed

+76
-94
lines changed

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

+43-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package io.sloeber.core.api;
22

3+
import static io.sloeber.core.common.Common.*;
4+
import static io.sloeber.core.common.Const.*;
5+
36
import java.io.File;
47
import java.util.ArrayList;
58
import java.util.Collections;
@@ -23,7 +26,6 @@
2326
import io.sloeber.core.Messages;
2427
import io.sloeber.core.common.Common;
2528
import io.sloeber.core.common.ConfigurationPreferences;
26-
import io.sloeber.core.common.Const;
2729
import io.sloeber.core.managers.ArduinoPlatform;
2830
import io.sloeber.core.managers.InternalPackageManager;
2931
import io.sloeber.core.tools.Helpers;
@@ -34,12 +36,12 @@
3436
import io.sloeber.core.txt.Programmers;
3537
import io.sloeber.core.txt.TxtFile;
3638

37-
public class BoardDescription extends Common {
39+
public class BoardDescription {
3840
// Important constants to avoid having to add the class
3941
private static final String TOOL_ID = Messages.TOOL;
4042
private static final String BOARD_ID = Messages.BOARD;
4143
private static final String FILE_ID = Messages.FILE;
42-
private static final String VendorArduino = Const.ARDUINO;
44+
private static final String VendorArduino = ARDUINO;
4345

4446
/*
4547
* Some constants
@@ -50,8 +52,8 @@ public class BoardDescription extends Common {
5052
private static final String KEY_LAST_USED_UPLOAD_PROTOCOL = "last Used upload Protocol"; //$NON-NLS-1$
5153
private static final String KEY_LAST_USED_BOARDS_FILE = "Last used Boards file"; //$NON-NLS-1$
5254
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;
5557
private static final String ENV_KEY_JANTJE_BOARD_NAME = ENV_KEY_JANTJE_START + "board_name"; //$NON-NLS-1$
5658
private static final String ENV_KEY_JANTJE_BOARDS_FILE = ENV_KEY_JANTJE_START + "boards_file"; //$NON-NLS-1$
5759
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() {
210212
myBoardsCore = actualValue;
211213
myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, architecture);
212214
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,
214216
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, core)
215217
.replace(FILE_ID, getReferencingBoardsFile().toString())
216218
.replace(BOARD_ID, getBoardID())));
@@ -225,7 +227,7 @@ private void ParseSection() {
225227
myReferencedCorePlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor, refArchitecture,
226228
refVersion);
227229
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,
229231
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, core)
230232
.replace(FILE_ID, getReferencingBoardsFile().toString())
231233
.replace(BOARD_ID, getBoardID())));
@@ -244,7 +246,7 @@ private void ParseSection() {
244246
this.myReferencedBoardVariantPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor,
245247
architecture);
246248
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,
248250
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, variant)
249251
.replace(FILE_ID, getReferencingBoardsFile().toString())
250252
.replace(BOARD_ID, getBoardID())));
@@ -264,7 +266,7 @@ private void ParseSection() {
264266
refArchitecture, refVersion);
265267
}
266268
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,
268270
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, variant)
269271
.replace(FILE_ID, getReferencingBoardsFile().toString())
270272
.replace(BOARD_ID, getBoardID())));
@@ -283,7 +285,7 @@ private void ParseSection() {
283285
this.myReferencedUploadToolPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor,
284286
architecture);
285287
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,
287289
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, upload)
288290
.replace(FILE_ID, getReferencingBoardsFile().toString())
289291
.replace(BOARD_ID, getBoardID())));
@@ -298,7 +300,7 @@ private void ParseSection() {
298300
this.myReferencedUploadToolPlatformPath = InternalPackageManager.getPlatformInstallPath(refVendor,
299301
refArchitecture, refVersion);
300302
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,
302304
Messages.Helpers_tool_reference_missing.replace(TOOL_ID, upload)
303305
.replace(FILE_ID, getReferencingBoardsFile().toString())
304306
.replace(BOARD_ID, getBoardID())));
@@ -408,7 +410,7 @@ private void setDefaultOptions() {
408410
* project
409411
*/
410412
public void saveUserSelection() {
411-
myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, getReferencingBoardsFile().toString());
413+
myStorageNode.put(KEY_LAST_USED_BOARDS_FILE, makePathEnvironmentString(getReferencingBoardsFile().toString()));
412414
myStorageNode.put(KEY_LAST_USED_BOARD, this.myBoardID);
413415
myStorageNode.put(KEY_LAST_USED_UPLOAD_PORT, this.myUploadPort);
414416
myStorageNode.put(KEY_LAST_USED_UPLOAD_PROTOCOL, this.myProgrammer);
@@ -580,7 +582,7 @@ public IPath getActualVariantPath() {
580582
if (retPath == null) {
581583
retPath = getreferencingPlatformPath();
582584
}
583-
return retPath.append(Const.VARIANTS_FOLDER_NAME).append(getBoardVariant());
585+
return retPath.append(VARIANTS_FOLDER_NAME).append(getBoardVariant());
584586
}
585587

586588
private String getBoardVariant() {
@@ -597,7 +599,7 @@ public IPath getActualCoreCodePath() {
597599
if (this.myBoardsCore == null) {
598600
return null;
599601
}
600-
return retPath.append(Const.CORES).append(this.myBoardsCore);
602+
return retPath.append(CORES).append(this.myBoardsCore);
601603
}
602604

603605
/**
@@ -632,7 +634,7 @@ public IPath getReferencedVariantPlatformPath() {
632634

633635
public PlatformTxtFile getReferencingPlatformFile() {
634636
updateWhenDirty();
635-
File platformFile = getreferencingPlatformPath().append(Const.PLATFORM_FILE_NAME).toFile();
637+
File platformFile = getreferencingPlatformPath().append(PLATFORM_FILE_NAME).toFile();
636638
if (platformFile != null && platformFile.exists()) {
637639
return new PlatformTxtFile(platformFile);
638640
}
@@ -652,7 +654,7 @@ public PlatformTxtFile getreferencedPlatformFile() {
652654
if (this.myReferencedCorePlatformPath == null) {
653655
return null;
654656
}
655-
File platformFile = myReferencedCorePlatformPath.append(Const.PLATFORM_FILE_NAME).toFile();
657+
File platformFile = myReferencedCorePlatformPath.append(PLATFORM_FILE_NAME).toFile();
656658
if (platformFile != null && platformFile.exists()) {
657659
return new PlatformTxtFile(platformFile);
658660
}
@@ -675,36 +677,36 @@ public IPath getReferencingLibraryPath() {
675677
public String getUploadCommand(ICConfigurationDescription confdesc) {
676678
updateWhenDirty();
677679
String upLoadTool = getActualUploadTool();
678-
String action = Const.UPLOAD;
680+
String action = UPLOAD;
679681
if (usesProgrammer()) {
680-
action = Const.PROGRAM;
682+
action = PROGRAM;
681683
}
682684
String networkPrefix = EMPTY;
683685
if (isNetworkUpload()) {
684-
networkPrefix = DOT + Const.NETWORK_PREFIX;
686+
networkPrefix = DOT + NETWORK_PREFIX;
685687
}
686-
String key = Const.A_TOOLS + upLoadTool + DOT + action + networkPrefix + DOT + Const.PATTERN;
688+
String key = A_TOOLS + upLoadTool + DOT + action + networkPrefix + DOT + PATTERN;
687689
String ret = Common.getBuildEnvironmentVariable(confdesc, key, EMPTY);
688690
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$
690692
}
691693
return ret;
692694
}
693695

694696
public String getActualUploadTool() {
695697
updateWhenDirty();
696698
// 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
698700
// not alowed here")); //$NON-NLS-1$
699701
// return this.myUploadTool;
700702
// }
701703
// if (usesProgrammer()) {
702-
// return Common.getBuildEnvironmentVariable(confdesc, Const.PROGRAM_TOOL,
704+
// return Common.getBuildEnvironmentVariable(confdesc, PROGRAM_TOOL,
703705
// "Program tool not properly configured"); //$NON-NLS-1$
704706
// }
705707
//
706708
// if (this.myUploadTool == null) {
707-
// return Common.getBuildEnvironmentVariable(confdesc, Const.UPLOAD_TOOL,
709+
// return Common.getBuildEnvironmentVariable(confdesc, UPLOAD_TOOL,
708710
// "upload tool not properly configured"); //$NON-NLS-1$
709711
// }
710712
return myUploadTool;
@@ -1032,12 +1034,12 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
10321034
for (Entry<String, String> curVariable : vars.entrySet()) {
10331035
String name = curVariable.getKey();
10341036
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$
10361038
objcopyCommand.add(makeEnvironmentVar(name));
10371039
}
10381040
}
10391041
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$
10411043

10421044
// handle the hooks
10431045
extraVars.putAll(getEnvVarsHookBuild(vars, "A.JANTJE.pre.link", //$NON-NLS-1$
@@ -1052,10 +1054,10 @@ private Map<String, String> getEnvVarsPostProcessing(Map<String, String> vars) {
10521054
"A.recipe.hooks.sketch.postbuild.XX.pattern", false)); //$NON-NLS-1$
10531055

10541056
// 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);
10561058
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$
10591061
}
10601062
return extraVars;
10611063
}
@@ -1097,11 +1099,21 @@ public static BoardDescription getFromCDT(ICConfigurationDescription confDesc) {
10971099
BoardDescription ret = new BoardDescription();
10981100
ret.myUploadPort = getOldWayEnvVar(confDesc, "JANTJE.com_port");
10991101
ret.myProgrammer = getOldWayEnvVar(confDesc, "JANTJE.upload");
1100-
ret.myreferencingBoardsFile = new File(getOldWayEnvVar(confDesc, "JANTJE.boards_file"));
11011102
ret.myBoardID = getOldWayEnvVar(confDesc, "JANTJE.board_ID");
1102-
ret.myTxtFile = new BoardTxtFile(ret.myreferencingBoardsFile);
11031103
String optinconcat = getOldWayEnvVar(confDesc, "JANTJE.menu");
11041104
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+
11051117
return ret;
11061118
}
11071119

io.sloeber.core/src/io/sloeber/core/common/Common.java

+31-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package io.sloeber.core.common;
22

3+
import java.net.URI;
4+
import java.net.URISyntaxException;
5+
import java.net.URL;
6+
import java.nio.file.Paths;
7+
38
import org.eclipse.cdt.core.CCorePlugin;
4-
import org.eclipse.cdt.core.cdtvariables.ICdtVariable;
5-
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
69
import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager;
710
import org.eclipse.cdt.core.model.CoreModel;
811
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
@@ -12,24 +15,40 @@
1215
import org.eclipse.core.resources.ResourcesPlugin;
1316
import org.eclipse.core.runtime.IPath;
1417
import org.eclipse.core.runtime.IStatus;
18+
import org.eclipse.core.runtime.Path;
1519
import org.eclipse.core.runtime.Platform;
20+
import org.eclipse.core.runtime.Status;
1621
import org.eclipse.ui.statushandlers.StatusManager;
1722

1823
import io.sloeber.core.Activator;
1924

2025
public class Common extends Const {
2126

22-
private static String eclipseHomeValue = null;
23-
static {
27+
public final static String eclipseHome = getEclipseHome();
28+
public final static IPath eclipseHomePath = new Path(eclipseHome);
29+
30+
private static String getEclipseHome() {
31+
2432
try {
25-
ICdtVariableManager manager = CCorePlugin.getDefault().getCdtVariableManager();
26-
ICdtVariable var = manager.getVariable(ECLIPSE_HOME, null);
27-
eclipseHomeValue = var.getStringValue();
28-
} catch (Exception e) {
29-
// nobody cares
33+
String sloeber_HomeValue = System.getenv(Const.SLOEBER_HOME);
34+
if (sloeber_HomeValue != null) {
35+
if (!sloeber_HomeValue.isEmpty()) {
36+
return sloeber_HomeValue;
37+
}
38+
}
39+
40+
URL resolvedUrl = Platform.getInstallLocation().getURL();
41+
URI resolvedUri = new URI(resolvedUrl.getProtocol(), resolvedUrl.getPath(), null);
42+
return Paths.get(resolvedUri).toString();
43+
} catch (URISyntaxException e) {
44+
// this should not happen
45+
// but it seems a space in the path makes it happen
46+
Common.log(new Status(IStatus.ERROR, Const.CORE_PLUGIN_ID,
47+
"Eclipse fails to provide its own installation folder :-(. \nThis is known to happen when you have a space ! # or other wierd characters in your eclipse installation path", //$NON-NLS-1$
48+
e));
49+
}
50+
return null;
3051
}
31-
}
32-
3352

3453

3554

@@ -189,17 +208,7 @@ public static IPath getWorkspaceRoot() {
189208
return myWorkspaceRoot.getLocation();
190209
}
191210

192-
static {
193211

194-
try {
195-
ICdtVariableManager manager = CCorePlugin.getDefault().getCdtVariableManager();
196-
ICdtVariable var = manager.getVariable(ECLIPSE_HOME, null);
197-
eclipseHomeValue = var.getStringValue();
198-
} catch (Exception e) {
199-
// nobody cares
200-
}
201-
202-
}
203212

204213
/**
205214
* Check whether the string starts with the eclipse path If it does replace with
@@ -209,10 +218,7 @@ public static IPath getWorkspaceRoot() {
209218
* @return modified string or the original
210219
*/
211220
public static String makePathEnvironmentString(String path) {
212-
if (eclipseHomeValue == null) {
213-
return path;
214-
}
215-
return path.replace(eclipseHomeValue, makeEnvironmentVar(ECLIPSE_HOME));
221+
return path.replace(eclipseHome, makeEnvironmentVar(ECLIPSE_HOME));
216222
}
217223

218224

0 commit comments

Comments
 (0)