@@ -275,6 +275,19 @@ private boolean tryLoadingExistingFile() {
275
275
if (!file .exists ()) {
276
276
return false ;
277
277
}
278
+ try {
279
+ val status = validateChecksum (file );
280
+ if (status == ChecksumStatus .FAILED ) {
281
+ return false ;
282
+ } else if (status == ChecksumStatus .MISSING ) {
283
+ log .debug ("Library {} is missing checksum data! Either it was manually deleted, " +
284
+ "or the source repo didn't have it in the first place" , artifactLogName );
285
+ }
286
+ } catch (IOException e ) {
287
+ log .error ("Failed to execute validation check for " + artifactLogName , e );
288
+ checkedDelete (file );
289
+ return false ;
290
+ }
278
291
try {
279
292
addToClasspath (file );
280
293
loadedLibraries .put (artifact , preferredVersion );
@@ -360,22 +373,36 @@ private ChecksumStatus validateChecksum(String url) throws IOException {
360
373
success .set (true );
361
374
});
362
375
if (success .get ()) {
363
- val fileHash = hash (checksumType , file );
364
- val referenceHash = new String (Files .readAllBytes (checksumFile .toPath ()));
365
- if (!fileHash .equals (referenceHash )) {
366
- log .error ("Failed {} checksum validation for {}. Retrying download..." , checksumType ,
367
- artifactLogName );
368
- checkedDelete (file );
369
- checkedDelete (checksumFile );
370
- return ChecksumStatus .FAILED ;
371
- }
372
- log .debug ("Successfully validated {} checksum for {}" , checksumType , artifactLogName );
373
- return ChecksumStatus .OK ;
376
+ return getChecksumStatus (file , checksumType , checksumFile );
374
377
}
375
378
}
376
379
return ChecksumStatus .MISSING ;
377
380
}
378
381
382
+ private ChecksumStatus validateChecksum (File file ) throws IOException {
383
+ for (val checksumType : CHECKSUM_TYPES ) {
384
+ val checksumFile = new File (libDir , jarName + "." + checksumType );
385
+ log .debug ("Attempting to read {} checksum from file..." , checksumType );
386
+ if (checksumFile .exists ()) {
387
+ return getChecksumStatus (file , checksumType , checksumFile );
388
+ }
389
+ }
390
+ return ChecksumStatus .MISSING ;
391
+ }
392
+
393
+ private ChecksumStatus getChecksumStatus (File file , String checksumType , File checksumFile ) throws IOException {
394
+ val fileHash = hash (checksumType , file );
395
+ val referenceHash = new String (Files .readAllBytes (checksumFile .toPath ()));
396
+ if (!fileHash .equals (referenceHash )) {
397
+ log .error ("Failed {} checksum validation for {}." , checksumType , artifactLogName );
398
+ checkedDelete (file );
399
+ checkedDelete (checksumFile );
400
+ return ChecksumStatus .FAILED ;
401
+ }
402
+ log .debug ("Successfully validated {} checksum for {}." , checksumType , artifactLogName );
403
+ return ChecksumStatus .OK ;
404
+ }
405
+
379
406
private enum ChecksumStatus {
380
407
OK ,
381
408
FAILED ,
0 commit comments