@@ -96,7 +96,8 @@ public class DependencyLoaderImpl {
96
96
private static final String [] CHECKSUM_TYPES = new String []{"sha512" , "sha256" , "sha1" , "md5" };
97
97
private static final Map <String , Version > loadedLibraries = new ConcurrentHashMap <>();
98
98
private static final Map <String , String > loadedLibraryMods = new ConcurrentHashMap <>();
99
- private static final Set <String > mavenRepositories = new ConcurrentSet <>();
99
+ private static final Set <String > remoteMavenRepositories = new ConcurrentSet <>();
100
+ private static final Set <String > localMavenRepositories = new ConcurrentSet <>();
100
101
private static final Logger LOG = LogManager .getLogger (Tags .MODNAME + " Library Loader" );
101
102
102
103
private static final AtomicLong counter = new AtomicLong (0 );
@@ -176,7 +177,7 @@ private static void ensureExists(Path directory) {
176
177
}
177
178
178
179
public static void addMavenRepo (String url ) {
179
- mavenRepositories .add (url );
180
+ remoteMavenRepositories .add (url );
180
181
}
181
182
182
183
private static String bytesToHex (byte [] hash ) {
@@ -262,7 +263,7 @@ public static CompletableFuture<Void> loadLibrariesAsync(Library... libraries) {
262
263
return CompletableFuture .allOf (futures .toArray (new CompletableFuture [0 ]));
263
264
}
264
265
265
- private static boolean scanForDepSpecs (URL source , List <URL > output ) {
266
+ private static boolean scanForDepSpecs (URL source , List <URL > output , List < URL > jijURLs ) {
266
267
if (!source .getProtocol ().equals ("file" )) {
267
268
return false ;
268
269
}
@@ -274,14 +275,22 @@ private static boolean scanForDepSpecs(URL source, List<URL> output) {
274
275
val jarFile = new JarInputStream (inputStream , false )) {
275
276
ZipEntry entry ;
276
277
while ((entry = jarFile .getNextEntry ()) != null ) {
277
- if (!entry .getName ().startsWith ("META-INF" ) || !entry .getName ().endsWith (".json" )) {
278
+ val name = entry .getName ();
279
+ if (!name .startsWith ("META-INF/" ))
278
280
continue ;
279
- }
280
- try {
281
- output .add (new URL ("jar:" + source + "!/" + entry .getName ()));
282
- found = true ;
283
- } catch (MalformedURLException e ) {
284
- LOG .error ("Failed to add json source {} to dependency source list: {}" , entry .getName (), e );
281
+ if (name .endsWith (".json" ) && name .matches ("META-INF/\\ w+.json" )) {
282
+ try {
283
+ output .add (new URL ("jar:" + source + "!/" + entry .getName ()));
284
+ found = true ;
285
+ } catch (MalformedURLException e ) {
286
+ LOG .error ("Failed to add json source {} to dependency source list: {}" , entry .getName (), e );
287
+ }
288
+ } else if (name .equals ("META-INF/falsepatternlib_repo/" )) {
289
+ try {
290
+ jijURLs .add (new URL ("jar:" + source + "!/" + entry .getName ()));
291
+ } catch (MalformedURLException e ) {
292
+ LOG .error ("Failed to add jar-in-jar repo {}: {}" , entry .getName (), e );
293
+ }
285
294
}
286
295
}
287
296
} catch (IOException e ) {
@@ -306,14 +315,22 @@ private static boolean scanForDepSpecs(URL source, List<URL> output) {
306
315
}
307
316
try (val files = Files .list (metaInf )) {
308
317
found = files .reduce (false , (prev ,file ) -> {
309
- if (!file .endsWith (".json" )) {
310
- return prev ;
311
- }
312
- try {
313
- output .add (file .toUri ().toURL ());
314
- return true ;
315
- } catch (MalformedURLException e ) {
316
- LOG .error ("Failed to add json source {} to dependency source list: {}" , file .getFileName (), e );
318
+ val entryFileName = file .getFileName ().toString ();
319
+ if (entryFileName .endsWith (".json" )) {
320
+ try {
321
+ output .add (file .toUri ().toURL ());
322
+ return true ;
323
+ } catch (MalformedURLException e ) {
324
+ LOG .error ("Failed to add json source {} to dependency source list: {}" ,
325
+ file .toString (),
326
+ e );
327
+ }
328
+ } else if (entryFileName .equals ("falsepatternlib_repo" )) {
329
+ try {
330
+ jijURLs .add (file .toUri ().toURL ());
331
+ } catch (MalformedURLException e ) {
332
+ LOG .error ("Failed to add jar-in-jar repo {}: {}" , file .toString (), e );
333
+ }
317
334
}
318
335
return prev ;
319
336
}, (a ,b ) -> a || b );
@@ -420,8 +437,9 @@ private static void scanDeps() {
420
437
.filter ((url ) -> !urlsWithoutDeps .contains (url .toString ()))
421
438
.collect (Collectors .toList ());
422
439
val urls = new ArrayList <URL >();
440
+ val jijURLs = new ArrayList <URL >();
423
441
for (val candidate : candidates ) {
424
- if (!scanForDepSpecs (candidate , urls )) {
442
+ if (!scanForDepSpecs (candidate , urls , jijURLs )) {
425
443
urlsWithoutDeps .add (candidate .toString ());
426
444
}
427
445
}
@@ -459,9 +477,11 @@ private static void scanDeps() {
459
477
}).filter (Objects ::nonNull ).collect (Collectors .toSet ());
460
478
long end = System .currentTimeMillis ();
461
479
LOG .debug ("Discovered {} dependency source candidates in {}ms" , dependencySpecs .size (), end - start );
462
- mavenRepositories .addAll (dependencySpecs .stream ()
463
- .flatMap ((dep ) -> dep .repositories ().stream ())
464
- .collect (Collectors .toSet ()));
480
+ remoteMavenRepositories .addAll (dependencySpecs .stream ()
481
+ .flatMap ((dep ) -> dep .repositories ().stream ())
482
+ .map (repo -> repo .endsWith ("/" ) ? repo : repo + "/" )
483
+ .collect (Collectors .toSet ()));
484
+ localMavenRepositories .addAll (jijURLs .stream ().map (URL ::toString ).map (repo -> repo .endsWith ("/" ) ? repo : repo + "/" ).collect (Collectors .toSet ()));
465
485
val artifacts = dependencySpecs .stream ()
466
486
.map ((root ) -> new Pair <>(root .source (), root .dependencies ()))
467
487
.flatMap (pair -> flatMap (pair ,
@@ -706,8 +726,13 @@ private void load() {
706
726
if (tryLoadingExistingFile ()) {
707
727
return ;
708
728
}
729
+ for (val repo : localMavenRepositories ) {
730
+ if (tryDownloadFromMaven (repo )) {
731
+ return ;
732
+ }
733
+ }
709
734
validateDownloadsAllowed ();
710
- for (var repo : mavenRepositories ) {
735
+ for (var repo : remoteMavenRepositories ) {
711
736
if (tryDownloadFromMaven (repo )) {
712
737
return ;
713
738
}
0 commit comments