Skip to content

Commit 23ac555

Browse files
author
jantje
committed
#1339 tools(versions) wer not yet in a tree
follow up on this chage is lots of problems with tool versions in the environment variables.
1 parent 4d3e9e0 commit 23ac555

9 files changed

+289
-138
lines changed

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

+48-9
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,15 @@
2222
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
2323
import org.eclipse.core.runtime.preferences.InstanceScope;
2424

25+
import io.sloeber.core.api.Json.ArduinoPackage;
2526
import io.sloeber.core.api.Json.ArduinoPlatform;
27+
import io.sloeber.core.api.Json.ArduinoPlatformTool;
28+
import io.sloeber.core.api.Json.ArduinoPlatformToolVersion;
29+
import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency;
2630
import io.sloeber.core.api.Json.ArduinoPlatformVersion;
2731
import io.sloeber.core.common.Common;
2832
import io.sloeber.core.common.ConfigurationPreferences;
29-
import io.sloeber.core.tools.Helpers;
33+
import io.sloeber.core.common.Const;
3034
import io.sloeber.core.tools.KeyValue;
3135
import io.sloeber.core.txt.BoardTxtFile;
3236
import io.sloeber.core.txt.KeyValueTree;
@@ -838,29 +842,64 @@ public Map<String, String> getEnvVars() {
838842
}
839843

840844
private Map<String, String> getEnVarPlatformInfo() {
845+
Map<String, String> ret = new HashMap<>();
841846
IPath referencingPlatformPath = getreferencingPlatformPath();
847+
ArduinoPlatformVersion referencingPlatform = BoardsManager.getPlatform(referencingPlatformPath);
842848

843-
if ((referencingPlatformPath == null) || (myReferencedPlatformCore == null)) {
844-
// something is seriously wrong -->shoot
845-
return new HashMap<>();
849+
if (referencingPlatform == null) {
850+
// This is the case for private hardware
851+
//there is no need to specidy tool path as they do not use them
852+
return ret;
853+
}
854+
ArduinoPlatformVersion latestArduinoPlatform = BoardsManager.getNewestInstalledPlatform(Const.ARDUINO,
855+
referencingPlatform.getArchitecture());
856+
if (latestArduinoPlatform != null) {
857+
ret.putAll(getEnvVarPlatformFileTools(latestArduinoPlatform));
846858
}
847859

848-
ArduinoPlatformVersion referencingPlatform = BoardsManager.getPlatform(referencingPlatformPath);
860+
if (myReferencedPlatformCore == null) {
861+
//there is no referenced core so no need to do smart stuff
862+
return getEnvVarPlatformFileTools(referencingPlatform);
863+
}
849864

850865
boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
851866
if (jsonBasedPlatformManagement) {
852867
// overrule the Arduino IDE way of working and use the json refereced tools
853-
Map<String, String> ret = Helpers.getEnvVarPlatformFileTools(myReferencedPlatformCore, true);
854-
ret.putAll(Helpers.getEnvVarPlatformFileTools(referencingPlatform, false));
868+
ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore));
869+
ret.putAll(getEnvVarPlatformFileTools(referencingPlatform));
855870
return ret;
856871
}
857872
// standard arduino IDE way
858-
Map<String, String> ret = Helpers.getEnvVarPlatformFileTools(referencingPlatform, false);
859-
ret.putAll(Helpers.getEnvVarPlatformFileTools(myReferencedPlatformCore, true));
873+
ret.putAll(getEnvVarPlatformFileTools(referencingPlatform));
874+
ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore));
860875
return ret;
861876

862877
}
863878

879+
/**
880+
* This method only returns environment variables without the version number
881+
* The environment variables with version number are "global" and as sutch are
882+
* understood to exists
883+
*
884+
* @param platformVersion
885+
* @return environment variables pointing to the tools used by the platform
886+
*/
887+
private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) {
888+
HashMap<String, String> vars = new HashMap<>();
889+
if (platformVersion.getToolsDependencies() == null) {
890+
return vars;
891+
}
892+
ArduinoPackage pkg = platformVersion.getParent().getParent();
893+
for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) {
894+
ArduinoPlatformTool theTool = pkg.getTool(tool.getName());
895+
ArduinoPlatformToolVersion theNewestTool = theTool.getNewestInstalled();
896+
if (theNewestTool != null) {
897+
vars.putAll(theNewestTool.getEnvVars(false));
898+
}
899+
}
900+
return vars;
901+
}
902+
864903
/**
865904
* Following post processing is done
866905
*

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

+20-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
import io.sloeber.core.api.Json.ArduinoPlatform;
4444
import io.sloeber.core.api.Json.ArduinoPlatformPackageIndex;
4545
import io.sloeber.core.api.Json.ArduinoPlatformTool;
46+
import io.sloeber.core.api.Json.ArduinoPlatformToolVersion;
4647
import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency;
4748
import io.sloeber.core.api.Json.ArduinoPlatformVersion;
4849
import io.sloeber.core.common.Common;
4950
import io.sloeber.core.common.ConfigurationPreferences;
5051
import io.sloeber.core.common.Const;
5152
import io.sloeber.core.common.InstancePreferences;
5253
import io.sloeber.core.managers.InstallProgress;
53-
import io.sloeber.core.tools.Helpers;
5454
import io.sloeber.core.tools.MyMultiStatus;
5555
import io.sloeber.core.tools.PackageManager;
5656
import io.sloeber.core.txt.BoardTxtFile;
@@ -573,18 +573,33 @@ public static Map<String, String> getEnvironmentVariables() {
573573
ArduinoPlatformVersion latestSamPlatform = getNewestInstalledPlatform(Const.ARDUINO, Const.SAM);
574574

575575
if (latestSamdPlatform != null) {
576-
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamdPlatform, false));
576+
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamdPlatform));
577577
}
578578
if (latestSamPlatform != null) {
579-
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamPlatform, false));
579+
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamPlatform));
580580
}
581581
if (latestAvrPlatform != null) {
582-
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestAvrPlatform, false));
582+
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestAvrPlatform));
583583
}
584584
envVarsNeedUpdating = false;
585585
return myWorkbenchEnvironmentVariables;
586586
}
587587

588+
private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) {
589+
HashMap<String, String> vars = new HashMap<>();
590+
ArduinoPackage pkg = platformVersion.getParent().getParent();
591+
for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) {
592+
ArduinoPlatformTool theTool = pkg.getTool(tool.getName());
593+
for (ArduinoPlatformToolVersion curToolVersion : theTool.getVersions()) {
594+
if (curToolVersion.isInstalled()) {
595+
vars.putAll(curToolVersion.getEnvVars(true));
596+
597+
}
598+
}
599+
}
600+
return vars;
601+
}
602+
588603
/**
589604
* given a vendor and a architecture provide the newest installed platform
590605
* version
@@ -682,7 +697,7 @@ private static IStatus downloadAndInstall(ArduinoPlatformVersion platformVersion
682697
return null;
683698
}
684699
for (ArduinoPlatformTooldDependency toolDependency : platformVersion.getToolsDependencies()) {
685-
ArduinoPlatformTool tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
700+
ArduinoPlatformToolVersion tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
686701
if (tool == null) {
687702
mstatus.add(new Status(IStatus.ERROR, Activator.getId(),
688703
Messages.Tool_no_valid_system.replace(Messages.KEY_TAG, toolDependency.getName())));

io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPackage.java

+28-20
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import static io.sloeber.core.Gson.GsonConverter.*;
1111

12-
import java.util.ArrayList;
1312
import java.util.Collection;
1413
import java.util.LinkedList;
1514
import java.util.List;
@@ -22,6 +21,7 @@
2221
import com.google.gson.JsonParseException;
2322

2423
import io.sloeber.core.api.BoardsManager;
24+
import io.sloeber.core.api.VersionNumber;
2525
import io.sloeber.core.common.ConfigurationPreferences;
2626

2727
public class ArduinoPackage extends Node implements Comparable<ArduinoPackage> {
@@ -32,7 +32,7 @@ public class ArduinoPackage extends Node implements Comparable<ArduinoPackage> {
3232
private String email;
3333
private String helpOnline;
3434
private TreeMap<String, ArduinoPlatform> platforms = new TreeMap<>();
35-
private List<ArduinoPlatformTool> tools = new ArrayList<>();
35+
private TreeMap<String, ArduinoPlatformTool> tools = new TreeMap<>();
3636
private transient ArduinoPlatformPackageIndex myParent = null;
3737

3838
@SuppressWarnings("nls")
@@ -59,7 +59,16 @@ public ArduinoPackage(JsonElement json, ArduinoPlatformPackageIndex packageIndex
5959
}
6060
}
6161
for (JsonElement curElement : jsonObject.get("tools").getAsJsonArray()) {
62-
tools.add(new ArduinoPlatformTool(curElement, this));
62+
JsonObject jsonObject2 = curElement.getAsJsonObject();
63+
// architecture is the id for a platform
64+
String toolName = getSafeString(jsonObject2, "name");
65+
ArduinoPlatformTool tool = tools.get(toolName);
66+
if (tool == null) {
67+
ArduinoPlatformTool newTool = new ArduinoPlatformTool(curElement, this);
68+
tools.put(newTool.getID(), newTool);
69+
} else {
70+
tool.addVersion(curElement);
71+
}
6372
}
6473
} catch (Exception e) {
6574
throw new JsonParseException("failed to parse Package json " + e.getMessage());
@@ -124,29 +133,28 @@ public ArduinoPlatform getPlatform(String platformID) {
124133
return platforms.get(platformID);
125134
}
126135

127-
public List<ArduinoPlatformTool> getTools() {
128-
return tools;
136+
public Collection<ArduinoPlatformTool> getTools() {
137+
return tools.values();
129138
}
130139

131-
public ArduinoPlatformTool getTool(String toolName, String version) {
132-
for (ArduinoPlatformTool tool : tools) {
133-
if (tool.getName().trim().equals(toolName) && tool.getVersion().equals(version)) {
134-
return tool;
135-
}
140+
public ArduinoPlatformToolVersion getTool(String toolName, VersionNumber version) {
141+
ArduinoPlatformTool tool = tools.get(toolName);
142+
if (tool == null) {
143+
return null;
136144
}
137-
return null;
145+
return tool.getVersion(version);
138146
}
139147

140-
public ArduinoPlatformTool getLatestTool(String toolName) {
141-
ArduinoPlatformTool latestTool = null;
142-
for (ArduinoPlatformTool tool : this.tools) {
143-
if (tool.getName().equals(toolName)) {
144-
if (latestTool == null || tool.getVersion().compareTo(latestTool.getVersion()) > 0) {
145-
latestTool = tool;
146-
}
147-
}
148+
public ArduinoPlatformTool getTool(String toolName) {
149+
return tools.get(toolName);
150+
}
151+
152+
public ArduinoPlatformToolVersion getNewestInstalled(String toolName) {
153+
ArduinoPlatformTool tool = tools.get(toolName);
154+
if (tool == null) {
155+
return null;
148156
}
149-
return latestTool;
157+
return tool.getNewestInstalled();
150158
}
151159

152160
@Override

io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatform.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public int compareTo(ArduinoPlatform o) {
8484
}
8585

8686
/**
87-
* Get the newest version of this library
87+
* Get the newest version of this platform
8888
*
89-
* @return the newest version of this library
89+
* @return the newest version of this platform
9090
*/
9191
public ArduinoPlatformVersion getNewestVersion() {
9292
return myVersions.firstEntry().getValue();
@@ -101,7 +101,7 @@ public ArduinoPlatformVersion getVersion(VersionNumber refVersion) {
101101
}
102102

103103
/**
104-
* return the installed version with the biggest version number
104+
* return the installed version with the newest version number
105105
* Null if no version is installed
106106
*
107107
* @return

io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPlatformTool.java

+55-34
Original file line numberDiff line numberDiff line change
@@ -9,82 +9,103 @@
99

1010
import static io.sloeber.core.Gson.GsonConverter.*;
1111

12-
import java.util.ArrayList;
13-
import java.util.List;
12+
import java.util.Collection;
13+
import java.util.Collections;
14+
import java.util.TreeMap;
1415

1516
import org.eclipse.core.runtime.IPath;
1617

1718
import com.google.gson.JsonElement;
1819
import com.google.gson.JsonObject;
1920
import com.google.gson.JsonParseException;
2021

21-
import io.sloeber.core.common.ConfigurationPreferences;
22+
import io.sloeber.core.api.VersionNumber;
2223

23-
public class ArduinoPlatformTool {
24+
public class ArduinoPlatformTool extends Node {
2425

2526
private static final String TOOLS = "tools"; //$NON-NLS-1$
26-
private String name;
27-
private String version;
28-
private List<ArduinpPlatformToolSystem> systems = new ArrayList<>();
27+
private String myName;
28+
private TreeMap<VersionNumber, ArduinoPlatformToolVersion> myVersions = new TreeMap<>(Collections.reverseOrder());
2929

30-
private transient ArduinoPackage pkg;
30+
private transient ArduinoPackage myParentPackage;
3131

3232
@SuppressWarnings("nls")
3333
public ArduinoPlatformTool(JsonElement json, ArduinoPackage pkg) {
34-
this.pkg = pkg;
34+
myParentPackage = pkg;
3535
JsonObject jsonObject = json.getAsJsonObject();
3636

3737
try {
38-
name = getSafeString(jsonObject, "name");
39-
version = getSafeString(jsonObject, "version");
40-
if (jsonObject.get("systems") != null) {
41-
for (JsonElement curElement : jsonObject.get("systems").getAsJsonArray()) {
42-
systems.add(new ArduinpPlatformToolSystem(curElement, this));
43-
}
44-
}
38+
myName = getSafeString(jsonObject, "name");
39+
addVersion(jsonObject);
4540
} catch (Exception e) {
4641
throw new JsonParseException("failed to parse Tool json " + e.getMessage());
4742
}
43+
}
4844

45+
protected void addVersion(JsonElement json) {
46+
ArduinoPlatformToolVersion version = new ArduinoPlatformToolVersion(json, this);
47+
myVersions.put(version.getVersion(), version);
4948
}
5049

5150
public ArduinoPackage getPackage() {
52-
return this.pkg;
51+
return myParentPackage;
5352
}
5453

54+
@Override
5555
public String getName() {
56-
return this.name;
56+
return myName;
5757
}
5858

59-
public String getVersion() {
60-
return this.version;
59+
public ArduinoPlatformToolVersion getVersion(VersionNumber version) {
60+
return myVersions.get(version);
6161
}
6262

63-
public List<ArduinpPlatformToolSystem> getSystems() {
64-
return this.systems;
63+
public IPath getInstallPath() {
64+
return myParentPackage.getInstallPath().append(TOOLS).append(getID());
65+
6566
}
6667

67-
public IPath getInstallPath() {
68-
return ConfigurationPreferences.getInstallationPathPackages().append(this.pkg.getName()).append(TOOLS)
69-
.append(this.name).append(this.version);
68+
@Override
69+
public Node[] getChildren() {
70+
return myVersions.values().toArray(new Node[myVersions.size()]);
71+
}
7072

73+
@Override
74+
public Node getParent() {
75+
return myParentPackage;
7176
}
7277

73-
public boolean isInstalled() {
74-
return getInstallPath().toFile().exists();
78+
@Override
79+
public String getID() {
80+
return getName();
7581
}
7682

77-
/*
78-
* Get the installable for this tool on this system
79-
* May return null if none is found
83+
/**
84+
* Get the newest version of this tool
85+
*
86+
* @return the newest version of this tool
8087
*/
81-
public ArduinoInstallable getInstallable() {
82-
for (ArduinpPlatformToolSystem system : this.systems) {
83-
if (system.isApplicable()) {
84-
return system;
88+
public ArduinoPlatformToolVersion getNewest() {
89+
return myVersions.firstEntry().getValue();
90+
}
91+
92+
/**
93+
* return the installed version with the newest version number
94+
* Null if no version is installed
95+
*
96+
* @return
97+
*/
98+
public ArduinoPlatformToolVersion getNewestInstalled() {
99+
for (ArduinoPlatformToolVersion curVersion : myVersions.values()) {
100+
if (curVersion.isInstalled()) {
101+
return curVersion;
85102
}
86103
}
87104
return null;
88105
}
89106

107+
public Collection<ArduinoPlatformToolVersion> getVersions() {
108+
return myVersions.values();
109+
}
110+
90111
}

0 commit comments

Comments
 (0)