41
41
import org .apache .commons .exec .DefaultExecutor ;
42
42
import org .apache .commons .exec .Executor ;
43
43
import org .apache .commons .exec .PumpStreamHandler ;
44
+ import org .slf4j .Logger ;
45
+ import org .slf4j .LoggerFactory ;
44
46
import processing .app .BaseNoGui ;
45
47
import processing .app .I18n ;
46
48
import processing .app .Platform ;
51
53
import java .io .ByteArrayOutputStream ;
52
54
import java .io .File ;
53
55
import java .io .IOException ;
54
- import java .net .URL ;
55
56
import java .nio .file .Files ;
56
57
import java .nio .file .Path ;
57
58
import java .nio .file .Paths ;
62
63
import static processing .app .I18n .tr ;
63
64
64
65
public class ContributionInstaller {
66
+ private static Logger log = LoggerFactory .getLogger (ContributionInstaller .class );
65
67
66
68
private final Platform platform ;
67
69
private final SignatureVerifier signatureVerifier ;
@@ -122,10 +124,10 @@ public synchronized List<String> install(ContributedPlatform contributedPlatform
122
124
// all the temporary folders and abort installation.
123
125
124
126
List <Map .Entry <ContributedToolReference , ContributedTool >> resolvedToolReferences = contributedPlatform
125
- .getResolvedToolReferences ().entrySet ().stream ()
126
- .filter ((entry ) -> !entry .getValue ().isInstalled ()
127
- || entry .getValue ().isBuiltIn ())
128
- .collect (Collectors .toList ());
127
+ .getResolvedToolReferences ().entrySet ().stream ()
128
+ .filter ((entry ) -> !entry .getValue ().isInstalled ()
129
+ || entry .getValue ().isBuiltIn ())
130
+ .collect (Collectors .toList ());
129
131
130
132
int i = 1 ;
131
133
for (Map .Entry <ContributedToolReference , ContributedTool > entry : resolvedToolReferences ) {
@@ -265,9 +267,10 @@ public synchronized List<String> remove(ContributedPlatform contributedPlatform)
265
267
// now try to remove the containing TOOL_NAME folder
266
268
// (and silently fail if another version of the tool is installed)
267
269
try {
268
- Files .delete (destFolder .getParentFile ().toPath ());
270
+ Files .deleteIfExists (destFolder .getParentFile ().toPath ());
269
271
} catch (Exception e ) {
270
272
// ignore
273
+ log .error (e .getMessage (), e );
271
274
}
272
275
}
273
276
@@ -282,7 +285,8 @@ public synchronized List<String> updateIndex(ProgressListener progressListener)
282
285
MultiStepProgress progress = new MultiStepProgress (1 );
283
286
284
287
List <String > downloadedPackageIndexFilesAccumulator = new LinkedList <>();
285
- downloadIndexAndSignature (progress , downloadedPackageIndexFilesAccumulator , Constants .PACKAGE_INDEX_URL , progressListener );
288
+ final DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader (BaseNoGui .indexer .getStagingFolder ());
289
+ downloader .downloadIndexAndSignature (progress , downloadedPackageIndexFilesAccumulator , Constants .PACKAGE_INDEX_URL , progressListener , signatureVerifier );
286
290
287
291
Set <String > packageIndexURLs = new HashSet <>();
288
292
String additionalURLs = PreferencesData .get (Constants .PREF_BOARDS_MANAGER_ADDITIONAL_URLS , "" );
@@ -292,8 +296,9 @@ public synchronized List<String> updateIndex(ProgressListener progressListener)
292
296
293
297
for (String packageIndexURL : packageIndexURLs ) {
294
298
try {
295
- downloadIndexAndSignature (progress , downloadedPackageIndexFilesAccumulator , packageIndexURL , progressListener );
299
+ downloader . downloadIndexAndSignature (progress , downloadedPackageIndexFilesAccumulator , packageIndexURL , progressListener , signatureVerifier );
296
300
} catch (Exception e ) {
301
+ log .error (e .getMessage (), e );
297
302
System .err .println (e .getMessage ());
298
303
}
299
304
}
@@ -303,41 +308,6 @@ public synchronized List<String> updateIndex(ProgressListener progressListener)
303
308
return downloadedPackageIndexFilesAccumulator ;
304
309
}
305
310
306
- private void downloadIndexAndSignature (MultiStepProgress progress , List <String > downloadedPackagedIndexFilesAccumulator , String packageIndexUrl , ProgressListener progressListener ) throws Exception {
307
- File packageIndex = download (progress , packageIndexUrl , progressListener );
308
- downloadedPackagedIndexFilesAccumulator .add (packageIndex .getName ());
309
- try {
310
- File packageIndexSignature = download (progress , packageIndexUrl + ".sig" , progressListener );
311
- boolean signatureVerified = signatureVerifier .isSigned (packageIndex );
312
- if (signatureVerified ) {
313
- downloadedPackagedIndexFilesAccumulator .add (packageIndexSignature .getName ());
314
- } else {
315
- downloadedPackagedIndexFilesAccumulator .remove (packageIndex .getName ());
316
- Files .delete (packageIndex .toPath ());
317
- Files .delete (packageIndexSignature .toPath ());
318
- System .err .println (I18n .format (tr ("{0} file signature verification failed. File ignored." ), packageIndexUrl ));
319
- }
320
- } catch (Exception e ) {
321
- //ignore errors
322
- }
323
- }
324
-
325
- private File download (MultiStepProgress progress , String packageIndexUrl , ProgressListener progressListener ) throws Exception {
326
- String statusText = tr ("Downloading platforms index..." );
327
- URL url = new URL (packageIndexUrl );
328
- String [] urlPathParts = url .getFile ().split ("/" );
329
- File outputFile = BaseNoGui .indexer .getIndexFile (urlPathParts [urlPathParts .length - 1 ]);
330
- File tmpFile = new File (outputFile .getAbsolutePath () + ".tmp" );
331
- DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader (BaseNoGui .indexer .getStagingFolder ());
332
- boolean noResume = true ;
333
- downloader .download (url , tmpFile , progress , statusText , progressListener , noResume );
334
-
335
- Files .deleteIfExists (outputFile .toPath ());
336
- Files .move (tmpFile .toPath (), outputFile .toPath ());
337
-
338
- return outputFile ;
339
- }
340
-
341
311
public synchronized void deleteUnknownFiles (List <String > downloadedPackageIndexFiles ) throws IOException {
342
312
File preferencesFolder = BaseNoGui .indexer .getIndexFile ("." ).getParentFile ();
343
313
File [] additionalPackageIndexFiles = preferencesFolder .listFiles (new PackageIndexFilenameFilter (Constants .DEFAULT_INDEX_FILE_NAME ));
0 commit comments