Skip to content

Commit 4184d28

Browse files
author
jantje
committed
#1411 take the packager into account when installing a platform
1 parent 1da8e7a commit 4184d28

File tree

2 files changed

+80
-54
lines changed

2 files changed

+80
-54
lines changed

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

+64-53
Original file line numberDiff line numberDiff line change
@@ -212,20 +212,63 @@ public static void installLatestPlatform(String JasonName, String packageName, S
212212

213213
@SuppressWarnings("nls")
214214
private static IStatus install(ArduinoPlatformVersion platformVersion, IProgressMonitor monitor) {
215+
boolean forceDownload = false;
215216
String name = platformVersion.getName();
216217
String architecture = platformVersion.getArchitecture();
217218
String version = platformVersion.getVersion().toString();
218219
// Check if we're installed already
219220
if (platformVersion.isInstalled()) {
220-
System.out.println("reusing platform " + name + " " + architecture + "(" + version + ")");
221+
System.out.println("reusing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
221222
return Status.OK_STATUS;
222223
}
223224

224225
// Download platform archive
225-
System.out.println("start installing platform " + name + " " + architecture + "(" + version + ")");
226-
IStatus ret = BoardsManager.downloadAndInstall(platformVersion, false, monitor);
227-
System.out.println("done installing platform " + name + " " + architecture + "(" + version + ")");
228-
return ret;
226+
System.out.println("start installing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
227+
228+
MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platformVersion.getName()); //$NON-NLS-1$
229+
mstatus.addErrors(PackageManager.downloadAndInstall(platformVersion, forceDownload, monitor));
230+
if (!mstatus.isOK()) {
231+
// no use installing tools when the boards failed installing
232+
return mstatus;
233+
}
234+
235+
//keep a copy of the json file used at install
236+
File packageFile = platformVersion.getParent().getParent().getPackageIndex().getJsonFile();
237+
File copyToFile = platformVersion.getInstallPath().append(packageFile.getName()).toFile();
238+
try {
239+
Files.copy(packageFile.toPath(), copyToFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
240+
} catch (IOException e) {
241+
e.printStackTrace();
242+
}
243+
244+
ArduinoPackage referencingPkg = platformVersion.getParent().getParent();
245+
for (ArduinoPlatformTooldDependency toolDependency : platformVersion.getToolsDependencies()) {
246+
//TODO make sure that tools from other providers are installed
247+
ArduinoPackage pkg = referencingPkg;
248+
ArduinoPlatformToolVersion tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
249+
if (tool == null) {
250+
//maybe these are referenced tools
251+
pkg = getPackageByProvider(toolDependency.getPackager());
252+
if (pkg != null) {
253+
tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
254+
}
255+
}
256+
if (tool == null) {
257+
mstatus.add(new Status(IStatus.ERROR, Activator.getId(),
258+
Messages.Tool_no_valid_system.replace(Messages.KEY_TAG, toolDependency.getName())));
259+
} else if (!tool.isInstalled()) {
260+
ArduinoInstallable installable = tool.getInstallable();
261+
if (installable != null) {
262+
monitor.setTaskName(InstallProgress.getRandomMessage());
263+
mstatus.addErrors(PackageManager.downloadAndInstall(installable, forceDownload, monitor));
264+
}
265+
}
266+
}
267+
268+
WorkAround.applyKnownWorkArounds(platformVersion);
269+
270+
System.out.println("done installing platform " + name + " " + architecture + "(" + version + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
271+
return mstatus;
229272
}
230273

231274
public static void addPrivateHardwarePath(String newHardwarePath) {
@@ -590,11 +633,10 @@ private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVer
590633
ArduinoPackage pkg = platformVersion.getParent().getParent();
591634
for (ArduinoPlatformTooldDependency tool : platformVersion.getToolsDependencies()) {
592635
ArduinoPlatformTool theTool = pkg.getTool(tool.getName());
593-
for (ArduinoPlatformToolVersion curToolVersion : theTool.getVersions()) {
594-
if (curToolVersion.isInstalled()) {
595-
vars.putAll(curToolVersion.getEnvVars(true));
596-
597-
}
636+
if (theTool == null) {
637+
System.err.println("Did not find " + tool.getName() + " in package with ID " + pkg.getID()); //$NON-NLS-1$ //$NON-NLS-2$
638+
} else {
639+
vars.putAll(theTool.getEnvVars(null));
598640
}
599641
}
600642
return vars;
@@ -660,7 +702,7 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
660702
if (platform == null) {
661703
status = new Status(IStatus.ERROR, Activator.getId(), Messages.No_Platform_available);
662704
} else {
663-
status = downloadAndInstall(platform.getNewestVersion(), false, monitor);
705+
status = install(platform.getNewestVersion(), monitor);
664706
}
665707

666708
if (!status.isOK()) {
@@ -673,48 +715,6 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
673715

674716
}
675717

676-
private static IStatus downloadAndInstall(ArduinoPlatformVersion platformVersion, boolean forceDownload,
677-
IProgressMonitor monitor) {
678-
MyMultiStatus mstatus = new MyMultiStatus("Failed to install " + platformVersion.getName()); //$NON-NLS-1$
679-
mstatus.addErrors(PackageManager.downloadAndInstall(platformVersion, forceDownload, monitor));
680-
if (!mstatus.isOK()) {
681-
// no use going on installing tools if the boards failed installing
682-
return mstatus;
683-
}
684-
685-
//keep a copy of the json file used at install
686-
File packageFile = platformVersion.getParent().getParent().getPackageIndex().getJsonFile();
687-
File copyToFile = platformVersion.getInstallPath().append(packageFile.getName()).toFile();
688-
try {
689-
Files.copy(packageFile.toPath(), copyToFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
690-
} catch (IOException e) {
691-
e.printStackTrace();
692-
}
693-
694-
if (platformVersion.getToolsDependencies() != null) {
695-
ArduinoPackage pkg = platformVersion.getParent().getParent();
696-
if (pkg == null) {
697-
return null;
698-
}
699-
for (ArduinoPlatformTooldDependency toolDependency : platformVersion.getToolsDependencies()) {
700-
ArduinoPlatformToolVersion tool = pkg.getTool(toolDependency.getName(), toolDependency.getVersion());
701-
if (tool == null) {
702-
mstatus.add(new Status(IStatus.ERROR, Activator.getId(),
703-
Messages.Tool_no_valid_system.replace(Messages.KEY_TAG, toolDependency.getName())));
704-
} else if (!tool.isInstalled()) {
705-
ArduinoInstallable installable = tool.getInstallable();
706-
if (installable != null) {
707-
monitor.setTaskName(InstallProgress.getRandomMessage());
708-
mstatus.addErrors(PackageManager.downloadAndInstall(installable, forceDownload, monitor));
709-
}
710-
}
711-
}
712-
}
713-
714-
WorkAround.applyKnownWorkArounds(platformVersion);
715-
return mstatus;
716-
}
717-
718718
synchronized static public List<ArduinoPlatformPackageIndex> getPackageIndices() {
719719
if (packageIndices == null) {
720720
loadJsons(false);
@@ -878,4 +878,15 @@ public static ArduinoPlatformVersion getPlatform(String vendor, String architect
878878
return null;
879879
}
880880

881+
public static ArduinoPackage getPackageByProvider(String packager) {
882+
for (ArduinoPlatformPackageIndex index : getPackageIndices()) {
883+
for (ArduinoPackage pkg : index.getPackages()) {
884+
if (packager.equals(pkg.getID())) {
885+
return pkg;
886+
}
887+
}
888+
}
889+
return null;
890+
}
891+
881892
}

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

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package io.sloeber.core.api.Json;
22

33
import static io.sloeber.core.Gson.GsonConverter.*;
4+
import static io.sloeber.core.common.Const.*;
5+
6+
import org.eclipse.core.runtime.IPath;
47

58
import com.google.gson.JsonElement;
69
import com.google.gson.JsonObject;
710
import com.google.gson.JsonParseException;
811

912
import io.sloeber.core.api.VersionNumber;
13+
import io.sloeber.core.common.ConfigurationPreferences;
1014

1115
public class ArduinoPlatformTooldDependency {
1216

1317
private String myName;
18+
private String myPackager;
1419
private VersionNumber myVersion;
1520

1621
private transient ArduinoPlatformVersion myParentPlatform;
@@ -22,18 +27,28 @@ public ArduinoPlatformTooldDependency(JsonElement json, ArduinoPlatformVersion a
2227
try {
2328

2429
myName = getSafeString(jsonObject, "name");
30+
myPackager = getSafeString(jsonObject, "packager");
2531
myVersion = getSafeVersion(jsonObject, "version");
2632
} catch (Exception e) {
2733
throw new JsonParseException("failed to parse json " + e.getMessage());
2834
}
2935
}
3036

3137
public String getName() {
32-
return this.myName;
38+
return myName;
3339
}
3440

3541
public VersionNumber getVersion() {
3642
return myVersion;
3743
}
3844

45+
public String getPackager() {
46+
return myPackager;
47+
}
48+
49+
public IPath getInstallPath() {
50+
return ConfigurationPreferences.getInstallationPathPackages().append(myPackager).append(TOOLS).append(myName)
51+
.append(myVersion.toString());
52+
53+
}
3954
}

0 commit comments

Comments
 (0)