@@ -212,20 +212,63 @@ public static void installLatestPlatform(String JasonName, String packageName, S
212
212
213
213
@ SuppressWarnings ("nls" )
214
214
private static IStatus install (ArduinoPlatformVersion platformVersion , IProgressMonitor monitor ) {
215
+ boolean forceDownload = false ;
215
216
String name = platformVersion .getName ();
216
217
String architecture = platformVersion .getArchitecture ();
217
218
String version = platformVersion .getVersion ().toString ();
218
219
// Check if we're installed already
219
220
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$
221
222
return Status .OK_STATUS ;
222
223
}
223
224
224
225
// 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 ;
229
272
}
230
273
231
274
public static void addPrivateHardwarePath (String newHardwarePath ) {
@@ -590,11 +633,10 @@ private static Map<String, String> getEnvVarPlatformFileTools(ArduinoPlatformVer
590
633
ArduinoPackage pkg = platformVersion .getParent ().getParent ();
591
634
for (ArduinoPlatformTooldDependency tool : platformVersion .getToolsDependencies ()) {
592
635
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 ));
598
640
}
599
641
}
600
642
return vars ;
@@ -660,7 +702,7 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
660
702
if (platform == null ) {
661
703
status = new Status (IStatus .ERROR , Activator .getId (), Messages .No_Platform_available );
662
704
} else {
663
- status = downloadAndInstall (platform .getNewestVersion (), false , monitor );
705
+ status = install (platform .getNewestVersion (), monitor );
664
706
}
665
707
666
708
if (!status .isOK ()) {
@@ -673,48 +715,6 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
673
715
674
716
}
675
717
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
-
718
718
synchronized static public List <ArduinoPlatformPackageIndex > getPackageIndices () {
719
719
if (packageIndices == null ) {
720
720
loadJsons (false );
@@ -878,4 +878,15 @@ public static ArduinoPlatformVersion getPlatform(String vendor, String architect
878
878
return null ;
879
879
}
880
880
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
+
881
892
}
0 commit comments