21
21
import java .nio .file .StandardCopyOption ;
22
22
import java .util .ArrayList ;
23
23
import java .util .Arrays ;
24
+ import java .util .Collection ;
24
25
import java .util .HashMap ;
25
26
import java .util .HashSet ;
26
27
import java .util .List ;
53
54
54
55
public class InternalPackageManager extends PackageManager {
55
56
56
- private static final String FILE = Messages .FILE ;
57
+ private static final String FILE = Messages .FILE ;
57
58
private static final String FOLDER = Messages .FOLDER ;
58
59
private static boolean myIsReady = false ;
59
60
@@ -76,31 +77,38 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
76
77
if (!LibraryManager .libsAreInstalled ()) {
77
78
LibraryManager .InstallDefaultLibraries (monitor );
78
79
}
79
- IPath examplesPath = ConfigurationPreferences .getInstallationPathExamples ();
80
- if (!examplesPath .toFile ().exists ()) {//examples are not installed
80
+ IPath examplesPath = ConfigurationPreferences .getInstallationPathExamples ();
81
+ if (!examplesPath .toFile ().exists ()) {// examples are not installed
81
82
// Download arduino IDE example programs
82
- Common .log (downloadAndInstall ( Defaults . EXAMPLES_URL , Defaults . EXAMPLE_PACKAGE ,
83
- examplesPath , false , monitor ));
83
+ Common .log (
84
+ downloadAndInstall ( Defaults . EXAMPLES_URL , Defaults . EXAMPLE_PACKAGE , examplesPath , false , monitor ));
84
85
}
85
86
if (allBoards .isEmpty ()) { // If no boards are installed
86
87
87
88
MyMultiStatus mstatus = new MyMultiStatus ("Failed to configer Sloeber" ); //$NON-NLS-1$
88
89
89
90
if (mstatus .isOK ()) {
90
91
// if successfully installed the examples: add the boards
91
-
92
- Package pkg = getPackageIndices ().get (0 ).getPackages ().get (0 );
93
- if (pkg != null ) {
94
- ArduinoPlatform platform = pkg .getLatestPlatform (Defaults .DEFAULT_INSTALL_PLATFORM_NAME , false );
95
- if (platform == null ) {
96
- ArduinoPlatform [] platformList = new ArduinoPlatform [pkg .getLatestPlatforms ().size ()];
97
- pkg .getLatestPlatforms ().toArray (platformList );
98
- platform = platformList [0 ];
99
- }
100
- if (platform != null ) {
101
- mstatus .addErrors (downloadAndInstall (platform , false , monitor ));
92
+ ArduinoPlatform platform = null ;
93
+ Collection <ArduinoPlatform > latestsPlatforms = PackageManager .getLatestPlatforms ();
94
+ if (!latestsPlatforms .isEmpty ()) {
95
+ platform = latestsPlatforms .iterator ().next ();
96
+ for (ArduinoPlatform curPlatform : latestsPlatforms ) {
97
+
98
+ if (Defaults .DEFAULT_INSTALL_PLATFORM_NAME .equalsIgnoreCase (curPlatform .getName ())
99
+ && Defaults .DEFAULT_INSTALL_ARCHITECTURE .equalsIgnoreCase (curPlatform .getArchitecture ())
100
+ && Defaults .DEFAULT_INSTALL_MAINTAINER
101
+ .equalsIgnoreCase (curPlatform .getParent ().getMaintainer ())) {
102
+ platform = curPlatform ;
103
+ }
102
104
}
103
105
}
106
+ if (platform == null ) {
107
+ mstatus .add (new Status (IStatus .ERROR , Activator .getId (), Messages .No_Platform_available ));
108
+ } else {
109
+ mstatus .addErrors (downloadAndInstall (platform , false , monitor ));
110
+ }
111
+
104
112
}
105
113
if (!mstatus .isOK ()) {
106
114
StatusManager stMan = StatusManager .getManager ();
@@ -125,20 +133,17 @@ public static synchronized void startup_Pluging(IProgressMonitor monitor) {
125
133
static public synchronized IStatus downloadAndInstall (ArduinoPlatform platform , boolean forceDownload ,
126
134
IProgressMonitor monitor ) {
127
135
128
-
129
136
MyMultiStatus mstatus = new MyMultiStatus ("Failed to install " + platform .getName ()); //$NON-NLS-1$
130
137
mstatus .addErrors (downloadAndInstall (platform .getUrl (), platform .getArchiveFileName (),
131
138
platform .getInstallPath (), forceDownload , monitor ));
132
139
if (!mstatus .isOK ()) {
133
140
// no use going on installing tools if the boards failed installing
134
141
return mstatus ;
135
142
}
136
- File packageFile = platform .getParent ().getParent ().getJsonFile ();
137
- File copyToFile = platform .getInstallPath ().append ( packageFile .getName ()).toFile ();
143
+ File packageFile = platform .getParent ().getParent ().getJsonFile ();
144
+ File copyToFile = platform .getInstallPath ().append (packageFile .getName ()).toFile ();
138
145
try {
139
- Files .copy (packageFile .toPath (),
140
- copyToFile .toPath (),
141
- StandardCopyOption .REPLACE_EXISTING );
146
+ Files .copy (packageFile .toPath (), copyToFile .toPath (), StandardCopyOption .REPLACE_EXISTING );
142
147
} catch (IOException e ) {
143
148
// TODO Auto-generated catch block
144
149
e .printStackTrace ();
@@ -160,7 +165,7 @@ static public synchronized IStatus downloadAndInstall(ArduinoPlatform platform,
160
165
}
161
166
}
162
167
163
- WorkAround .applyKnownWorkArounds ( platform );
168
+ WorkAround .applyKnownWorkArounds (platform );
164
169
return mstatus ;
165
170
166
171
}
@@ -172,7 +177,6 @@ static public List<PackageIndex> getPackageIndices() {
172
177
return packageIndices ;
173
178
}
174
179
175
-
176
180
static public List <Board > getBoards () {
177
181
List <Board > boards = new ArrayList <>();
178
182
for (PackageIndex index : getPackageIndices ()) {
@@ -330,10 +334,8 @@ static public Tool getTool(String packageName, String toolName, String version)
330
334
* done with processArchive so only files types supported by this method will be
331
335
* properly extracted
332
336
*
333
- * @param pURL
334
- * the url of the file to download
335
- * @param pArchiveFileName
336
- * the name of the file in the download folder
337
+ * @param pURL the url of the file to download
338
+ * @param pArchiveFileName the name of the file in the download folder
337
339
* @param pInstallPath
338
340
* @param pForceDownload
339
341
* @param pMonitor
@@ -351,7 +353,8 @@ public static IStatus downloadAndInstall(String pURL, String pArchiveFileName, I
351
353
myCopy (dl , archivePath .toFile (), true );
352
354
}
353
355
} catch (IOException e ) {
354
- return new Status (IStatus .ERROR , Activator .getId (), Messages .Manager_Failed_to_download .replace (FILE , pURL ), e );
356
+ return new Status (IStatus .ERROR , Activator .getId (), Messages .Manager_Failed_to_download .replace (FILE , pURL ),
357
+ e );
355
358
}
356
359
return processArchive (pArchiveFileName , pInstallPath , pForceDownload , archivePath .toString (), pMonitor );
357
360
}
@@ -398,7 +401,7 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
398
401
// (because creating a file in a folder alters the folder's timestamp)
399
402
Map <File , Long > foldersTimestamps = new HashMap <>();
400
403
401
- String pathPrefix = new String ();
404
+ String pathPrefix = new String ();
402
405
403
406
Map <File , File > hardLinks = new HashMap <>();
404
407
Map <File , Integer > hardLinksMode = new HashMap <>();
@@ -471,8 +474,9 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
471
474
472
475
// Strip the common path prefix when requested
473
476
if (!name .startsWith (pathPrefix )) {
474
- throw new IOException (Messages .Manager_archive_error_root_folder_name_mismatch .replace (FILE , name ).replace (FOLDER , pathPrefix ));
475
-
477
+ throw new IOException (Messages .Manager_archive_error_root_folder_name_mismatch .replace (FILE , name )
478
+ .replace (FOLDER , pathPrefix ));
479
+
476
480
}
477
481
name = name .substring (pathPrefix .length ());
478
482
if (name .isEmpty ()) {
@@ -483,7 +487,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
483
487
File outputLinkedFile = null ;
484
488
if (isLink && linkName != null ) {
485
489
if (!linkName .startsWith (pathPrefix )) {
486
- throw new IOException (Messages .Manager_archive_error_root_folder_name_mismatch .replace (FILE , name ).replace (FOLDER , pathPrefix ));
490
+ throw new IOException (Messages .Manager_archive_error_root_folder_name_mismatch .replace (FILE , name )
491
+ .replace (FOLDER , pathPrefix ));
487
492
}
488
493
linkName = linkName .substring (pathPrefix .length ());
489
494
outputLinkedFile = new File (destFolder , linkName );
@@ -492,7 +497,8 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
492
497
// Symbolic links are referenced with relative paths
493
498
outputLinkedFile = new File (linkName );
494
499
if (outputLinkedFile .isAbsolute ()) {
495
- System .err .println (Messages .Manager_archive_error_symbolic_link_to_absolute_path .replace (FILE , outputFile .toString ()).replace (FOLDER , outputLinkedFile .toString ()));
500
+ System .err .println (Messages .Manager_archive_error_symbolic_link_to_absolute_path
501
+ .replace (FILE , outputFile .toString ()).replace (FOLDER , outputLinkedFile .toString ()));
496
502
System .err .println ();
497
503
}
498
504
}
@@ -501,15 +507,14 @@ public static IStatus extract(ArchiveInputStream in, File destFolder, int stripP
501
507
if (isDirectory ) {
502
508
if (outputFile .isFile () && !overwrite ) {
503
509
throw new IOException (
504
- Messages .Manager_Cant_create_folder_exists .replace (FILE , outputFile .getPath ()) );
510
+ Messages .Manager_Cant_create_folder_exists .replace (FILE , outputFile .getPath ()));
505
511
}
506
512
} else {
507
513
// - isLink
508
514
// - isSymLink
509
515
// - anything else
510
516
if (outputFile .exists () && !overwrite ) {
511
- throw new IOException (
512
- Messages .Manager_Cant_extract_file_exist .replace (FILE , outputFile .getPath ()));
517
+ throw new IOException (Messages .Manager_Cant_extract_file_exist .replace (FILE , outputFile .getPath ()));
513
518
}
514
519
}
515
520
@@ -585,14 +590,15 @@ private static void symlink(String from, File to) throws IOException, Interrupte
585
590
}
586
591
587
592
/*
588
- * create a link file at the level of the os
589
- * using mklink /H on windows makes that no admin rights are needed
593
+ * create a link file at the level of the os using mklink /H on windows makes
594
+ * that no admin rights are needed
590
595
*/
591
596
@ SuppressWarnings ("nls" )
592
597
private static void link (File actualFile , File linkName ) throws IOException , InterruptedException {
593
- String [] command = new String [] { "ln" , actualFile .getAbsolutePath (), linkName .getAbsolutePath () };
598
+ String [] command = new String [] { "ln" , actualFile .getAbsolutePath (), linkName .getAbsolutePath () };
594
599
if (SystemUtils .IS_OS_WINDOWS ) {
595
- command = new String [] { "cmd" ,"/c" ,"mklink" , "/H" ,linkName .getAbsolutePath (), actualFile .getAbsolutePath () };
600
+ command = new String [] { "cmd" , "/c" , "mklink" , "/H" , linkName .getAbsolutePath (),
601
+ actualFile .getAbsolutePath () };
596
602
}
597
603
Process process = Runtime .getRuntime ().exec (command , null , null );
598
604
process .waitFor ();
@@ -637,7 +643,8 @@ private static void copyStreamToFile(InputStream in, long size, File outputFile)
637
643
while (leftToWrite > 0 ) {
638
644
int length = in .read (buffer );
639
645
if (length <= 0 ) {
640
- throw new IOException (Messages .Manager_Failed_to_extract .replace (FILE , outputFile .getAbsolutePath ()));
646
+ throw new IOException (
647
+ Messages .Manager_Failed_to_extract .replace (FILE , outputFile .getAbsolutePath ()));
641
648
}
642
649
fos .write (buffer , 0 , length );
643
650
leftToWrite -= length ;
@@ -657,7 +664,7 @@ public static void removePackageURLs(Set<String> packageUrlsToRemove) {
657
664
658
665
activeUrls .removeAll (packageUrlsToRemove );
659
666
660
- ConfigurationPreferences .setJsonURLs (activeUrls .toArray ((String [])null ));
667
+ ConfigurationPreferences .setJsonURLs (activeUrls .toArray ((String []) null ));
661
668
662
669
// remove the files from disk
663
670
for (String curJson : packageUrlsToRemove ) {
0 commit comments