@@ -96,7 +96,8 @@ public class DependencyLoaderImpl {
9696 private static final String [] CHECKSUM_TYPES = new String []{"sha512" , "sha256" , "sha1" , "md5" };
9797 private static final Map <String , Version > loadedLibraries = new ConcurrentHashMap <>();
9898 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 <>();
100101 private static final Logger LOG = LogManager .getLogger (Tags .MODNAME + " Library Loader" );
101102
102103 private static final AtomicLong counter = new AtomicLong (0 );
@@ -176,7 +177,7 @@ private static void ensureExists(Path directory) {
176177 }
177178
178179 public static void addMavenRepo (String url ) {
179- mavenRepositories .add (url );
180+ remoteMavenRepositories .add (url );
180181 }
181182
182183 private static String bytesToHex (byte [] hash ) {
@@ -262,7 +263,7 @@ public static CompletableFuture<Void> loadLibrariesAsync(Library... libraries) {
262263 return CompletableFuture .allOf (futures .toArray (new CompletableFuture [0 ]));
263264 }
264265
265- private static boolean scanForDepSpecs (URL source , List <URL > output ) {
266+ private static boolean scanForDepSpecs (URL source , List <URL > output , List < URL > jijURLs ) {
266267 if (!source .getProtocol ().equals ("file" )) {
267268 return false ;
268269 }
@@ -274,14 +275,22 @@ private static boolean scanForDepSpecs(URL source, List<URL> output) {
274275 val jarFile = new JarInputStream (inputStream , false )) {
275276 ZipEntry entry ;
276277 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/" ))
278280 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+ }
285294 }
286295 }
287296 } catch (IOException e ) {
@@ -306,14 +315,22 @@ private static boolean scanForDepSpecs(URL source, List<URL> output) {
306315 }
307316 try (val files = Files .list (metaInf )) {
308317 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+ }
317334 }
318335 return prev ;
319336 }, (a ,b ) -> a || b );
@@ -420,8 +437,9 @@ private static void scanDeps() {
420437 .filter ((url ) -> !urlsWithoutDeps .contains (url .toString ()))
421438 .collect (Collectors .toList ());
422439 val urls = new ArrayList <URL >();
440+ val jijURLs = new ArrayList <URL >();
423441 for (val candidate : candidates ) {
424- if (!scanForDepSpecs (candidate , urls )) {
442+ if (!scanForDepSpecs (candidate , urls , jijURLs )) {
425443 urlsWithoutDeps .add (candidate .toString ());
426444 }
427445 }
@@ -459,9 +477,11 @@ private static void scanDeps() {
459477 }).filter (Objects ::nonNull ).collect (Collectors .toSet ());
460478 long end = System .currentTimeMillis ();
461479 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 ()));
465485 val artifacts = dependencySpecs .stream ()
466486 .map ((root ) -> new Pair <>(root .source (), root .dependencies ()))
467487 .flatMap (pair -> flatMap (pair ,
@@ -706,8 +726,13 @@ private void load() {
706726 if (tryLoadingExistingFile ()) {
707727 return ;
708728 }
729+ for (val repo : localMavenRepositories ) {
730+ if (tryDownloadFromMaven (repo )) {
731+ return ;
732+ }
733+ }
709734 validateDownloadsAllowed ();
710- for (var repo : mavenRepositories ) {
735+ for (var repo : remoteMavenRepositories ) {
711736 if (tryDownloadFromMaven (repo )) {
712737 return ;
713738 }
0 commit comments