Skip to content

Commit

Permalink
#1339 tools(versions) wer not yet in a tree
Browse files Browse the repository at this point in the history
follow up on this chage is lots of problems with tool versions in the
environment variables.
  • Loading branch information
jantje committed Nov 25, 2021
1 parent 4d3e9e0 commit 23ac555
Show file tree
Hide file tree
Showing 9 changed files with 289 additions and 138 deletions.
57 changes: 48 additions & 9 deletions io.sloeber.core/src/io/sloeber/core/api/BoardDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;

import io.sloeber.core.api.Json.ArduinoPackage;
import io.sloeber.core.api.Json.ArduinoPlatform;
import io.sloeber.core.api.Json.ArduinoPlatformTool;
import io.sloeber.core.api.Json.ArduinoPlatformToolVersion;
import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency;
import io.sloeber.core.api.Json.ArduinoPlatformVersion;
import io.sloeber.core.common.Common;
import io.sloeber.core.common.ConfigurationPreferences;
import io.sloeber.core.tools.Helpers;
import io.sloeber.core.common.Const;
import io.sloeber.core.tools.KeyValue;
import io.sloeber.core.txt.BoardTxtFile;
import io.sloeber.core.txt.KeyValueTree;
Expand Down Expand Up @@ -838,29 +842,64 @@ public Map<String, String> getEnvVars() {
}

private Map<String, String> getEnVarPlatformInfo() {
Map<String, String> ret = new HashMap<>();
IPath referencingPlatformPath = getreferencingPlatformPath();
ArduinoPlatformVersion referencingPlatform = BoardsManager.getPlatform(referencingPlatformPath);

if ((referencingPlatformPath == null) || (myReferencedPlatformCore == null)) {
// something is seriously wrong -->shoot
return new HashMap<>();
if (referencingPlatform == null) {
// This is the case for private hardware
//there is no need to specidy tool path as they do not use them
return ret;
}
ArduinoPlatformVersion latestArduinoPlatform = BoardsManager.getNewestInstalledPlatform(Const.ARDUINO,
referencingPlatform.getArchitecture());
if (latestArduinoPlatform != null) {
ret.putAll(getEnvVarPlatformFileTools(latestArduinoPlatform));
}

ArduinoPlatformVersion referencingPlatform = BoardsManager.getPlatform(referencingPlatformPath);
if (myReferencedPlatformCore == null) {
//there is no referenced core so no need to do smart stuff
return getEnvVarPlatformFileTools(referencingPlatform);
}

boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
if (jsonBasedPlatformManagement) {
// overrule the Arduino IDE way of working and use the json refereced tools
Map<String, String> ret = Helpers.getEnvVarPlatformFileTools(myReferencedPlatformCore, true);
ret.putAll(Helpers.getEnvVarPlatformFileTools(referencingPlatform, false));
ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore));
ret.putAll(getEnvVarPlatformFileTools(referencingPlatform));
return ret;
}
// standard arduino IDE way
Map<String, String> ret = Helpers.getEnvVarPlatformFileTools(referencingPlatform, false);
ret.putAll(Helpers.getEnvVarPlatformFileTools(myReferencedPlatformCore, true));
ret.putAll(getEnvVarPlatformFileTools(referencingPlatform));
ret.putAll(getEnvVarPlatformFileTools(myReferencedPlatformCore));
return ret;

}

/**
* This method only returns environment variables without the version number
* The environment variables with version number are "global" and as sutch are
* understood to exists
*
* @param platformVersion
* @return environment variables pointing to the tools used by the platform
*/
private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) {
HashMap<String, String> vars = new HashMap<>();
if (platformVersion.getToolsDependencies() == null) {
return vars;
}
ArduinoPackage pkg = platformVersion.getParent().getParent();
for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) {
ArduinoPlatformTool theTool = pkg.getTool(tool.getName());
ArduinoPlatformToolVersion theNewestTool = theTool.getNewestInstalled();
if (theNewestTool != null) {
vars.putAll(theNewestTool.getEnvVars(false));
}
}
return vars;
}

/**
* Following post processing is done
*
Expand Down
25 changes: 20 additions & 5 deletions io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
import io.sloeber.core.api.Json.ArduinoPlatform;
import io.sloeber.core.api.Json.ArduinoPlatformPackageIndex;
import io.sloeber.core.api.Json.ArduinoPlatformTool;
import io.sloeber.core.api.Json.ArduinoPlatformToolVersion;
import io.sloeber.core.api.Json.ArduinoPlatformTooldDependency;
import io.sloeber.core.api.Json.ArduinoPlatformVersion;
import io.sloeber.core.common.Common;
import io.sloeber.core.common.ConfigurationPreferences;
import io.sloeber.core.common.Const;
import io.sloeber.core.common.InstancePreferences;
import io.sloeber.core.managers.InstallProgress;
import io.sloeber.core.tools.Helpers;
import io.sloeber.core.tools.MyMultiStatus;
import io.sloeber.core.tools.PackageManager;
import io.sloeber.core.txt.BoardTxtFile;
Expand Down Expand Up @@ -573,18 +573,33 @@ public static Map<String, String> getEnvironmentVariables() {
ArduinoPlatformVersion latestSamPlatform = getNewestInstalledPlatform(Const.ARDUINO, Const.SAM);

if (latestSamdPlatform != null) {
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamdPlatform, false));
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamdPlatform));
}
if (latestSamPlatform != null) {
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestSamPlatform, false));
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestSamPlatform));
}
if (latestAvrPlatform != null) {
myWorkbenchEnvironmentVariables.putAll(Helpers.getEnvVarPlatformFileTools(latestAvrPlatform, false));
myWorkbenchEnvironmentVariables.putAll(getEnvVarPlatformFileTools(latestAvrPlatform));
}
envVarsNeedUpdating = false;
return myWorkbenchEnvironmentVariables;
}

private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVersion platformVersion) {
HashMap<String, String> vars = new HashMap<>();
ArduinoPackage pkg = platformVersion.getParent().getParent();
for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) {
ArduinoPlatformTool theTool = pkg.getTool(tool.getName());
for (ArduinoPlatformToolVersion curToolVersion : theTool.getVersions()) {
if (curToolVersion.isInstalled()) {
vars.putAll(curToolVersion.getEnvVars(true));

}
}
}
return vars;
}

/**
* given a vendor and a architecture provide the newest installed platform
* version
Expand Down Expand Up @@ -682,7 +697,7 @@ private static IStatus downloadAndInstall(ArduinoPlatformVersion platformVersion
return null;
}
for (ArduinoPlatformTooldDependency toolDependency : platformVersion.getToolsDependencies()) {
ArduinoPlatformTool tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
ArduinoPlatformToolVersion tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
if (tool == null) {
mstatus.add(new Status(IStatus.ERROR, Activator.getId(),
Messages.Tool_no_valid_system.replace(Messages.KEY_TAG, toolDependency.getName())));
Expand Down
48 changes: 28 additions & 20 deletions io.sloeber.core/src/io/sloeber/core/api/Json/ArduinoPackage.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -22,6 +21,7 @@
import com.google.gson.JsonParseException;

import io.sloeber.core.api.BoardsManager;
import io.sloeber.core.api.VersionNumber;
import io.sloeber.core.common.ConfigurationPreferences;

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

@SuppressWarnings("nls")
Expand All @@ -59,7 +59,16 @@ public ArduinoPackage(JsonElement json, ArduinoPlatformPackageIndex packageIndex
}
}
for (JsonElement curElement : jsonObject.get("tools").getAsJsonArray()) {
tools.add(new ArduinoPlatformTool(curElement, this));
JsonObject jsonObject2 = curElement.getAsJsonObject();
// architecture is the id for a platform
String toolName = getSafeString(jsonObject2, "name");
ArduinoPlatformTool tool = tools.get(toolName);
if (tool == null) {
ArduinoPlatformTool newTool = new ArduinoPlatformTool(curElement, this);
tools.put(newTool.getID(), newTool);
} else {
tool.addVersion(curElement);
}
}
} catch (Exception e) {
throw new JsonParseException("failed to parse Package json " + e.getMessage());
Expand Down Expand Up @@ -124,29 +133,28 @@ public ArduinoPlatform getPlatform(String platformID) {
return platforms.get(platformID);
}

public List<ArduinoPlatformTool> getTools() {
return tools;
public Collection<ArduinoPlatformTool> getTools() {
return tools.values();
}

public ArduinoPlatformTool getTool(String toolName, String version) {
for (ArduinoPlatformTool tool : tools) {
if (tool.getName().trim().equals(toolName) && tool.getVersion().equals(version)) {
return tool;
}
public ArduinoPlatformToolVersion getTool(String toolName, VersionNumber version) {
ArduinoPlatformTool tool = tools.get(toolName);
if (tool == null) {
return null;
}
return null;
return tool.getVersion(version);
}

public ArduinoPlatformTool getLatestTool(String toolName) {
ArduinoPlatformTool latestTool = null;
for (ArduinoPlatformTool tool : this.tools) {
if (tool.getName().equals(toolName)) {
if (latestTool == null || tool.getVersion().compareTo(latestTool.getVersion()) > 0) {
latestTool = tool;
}
}
public ArduinoPlatformTool getTool(String toolName) {
return tools.get(toolName);
}

public ArduinoPlatformToolVersion getNewestInstalled(String toolName) {
ArduinoPlatformTool tool = tools.get(toolName);
if (tool == null) {
return null;
}
return latestTool;
return tool.getNewestInstalled();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public int compareTo(ArduinoPlatform o) {
}

/**
* Get the newest version of this library
* Get the newest version of this platform
*
* @return the newest version of this library
* @return the newest version of this platform
*/
public ArduinoPlatformVersion getNewestVersion() {
return myVersions.firstEntry().getValue();
Expand All @@ -101,7 +101,7 @@ public ArduinoPlatformVersion getVersion(VersionNumber refVersion) {
}

/**
* return the installed version with the biggest version number
* return the installed version with the newest version number
* Null if no version is installed
*
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,103 @@

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

import java.util.ArrayList;
import java.util.List;
import java.util.Collection;
import java.util.Collections;
import java.util.TreeMap;

import org.eclipse.core.runtime.IPath;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import io.sloeber.core.common.ConfigurationPreferences;
import io.sloeber.core.api.VersionNumber;

public class ArduinoPlatformTool {
public class ArduinoPlatformTool extends Node {

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

private transient ArduinoPackage pkg;
private transient ArduinoPackage myParentPackage;

@SuppressWarnings("nls")
public ArduinoPlatformTool(JsonElement json, ArduinoPackage pkg) {
this.pkg = pkg;
myParentPackage = pkg;
JsonObject jsonObject = json.getAsJsonObject();

try {
name = getSafeString(jsonObject, "name");
version = getSafeString(jsonObject, "version");
if (jsonObject.get("systems") != null) {
for (JsonElement curElement : jsonObject.get("systems").getAsJsonArray()) {
systems.add(new ArduinpPlatformToolSystem(curElement, this));
}
}
myName = getSafeString(jsonObject, "name");
addVersion(jsonObject);
} catch (Exception e) {
throw new JsonParseException("failed to parse Tool json " + e.getMessage());
}
}

protected void addVersion(JsonElement json) {
ArduinoPlatformToolVersion version = new ArduinoPlatformToolVersion(json, this);
myVersions.put(version.getVersion(), version);
}

public ArduinoPackage getPackage() {
return this.pkg;
return myParentPackage;
}

@Override
public String getName() {
return this.name;
return myName;
}

public String getVersion() {
return this.version;
public ArduinoPlatformToolVersion getVersion(VersionNumber version) {
return myVersions.get(version);
}

public List<ArduinpPlatformToolSystem> getSystems() {
return this.systems;
public IPath getInstallPath() {
return myParentPackage.getInstallPath().append(TOOLS).append(getID());

}

public IPath getInstallPath() {
return ConfigurationPreferences.getInstallationPathPackages().append(this.pkg.getName()).append(TOOLS)
.append(this.name).append(this.version);
@Override
public Node[] getChildren() {
return myVersions.values().toArray(new Node[myVersions.size()]);
}

@Override
public Node getParent() {
return myParentPackage;
}

public boolean isInstalled() {
return getInstallPath().toFile().exists();
@Override
public String getID() {
return getName();
}

/*
* Get the installable for this tool on this system
* May return null if none is found
/**
* Get the newest version of this tool
*
* @return the newest version of this tool
*/
public ArduinoInstallable getInstallable() {
for (ArduinpPlatformToolSystem system : this.systems) {
if (system.isApplicable()) {
return system;
public ArduinoPlatformToolVersion getNewest() {
return myVersions.firstEntry().getValue();
}

/**
* return the installed version with the newest version number
* Null if no version is installed
*
* @return
*/
public ArduinoPlatformToolVersion getNewestInstalled() {
for (ArduinoPlatformToolVersion curVersion : myVersions.values()) {
if (curVersion.isInstalled()) {
return curVersion;
}
}
return null;
}

public Collection<ArduinoPlatformToolVersion> getVersions() {
return myVersions.values();
}

}
Loading

0 comments on commit 23ac555

Please sign in to comment.