33import java .io .File ;
44import java .io .IOException ;
55import java .lang .module .Configuration ;
6+ import java .lang .module .ModuleDescriptor ;
67import java .lang .module .ModuleFinder ;
8+ import java .lang .module .ModuleReference ;
79import java .lang .reflect .Method ;
810import java .net .URLClassLoader ;
11+ import java .nio .file .Files ;
912import java .nio .file .Path ;
10- import java .nio .file .Paths ;
13+ import java .util .HashSet ;
14+ import java .util .Optional ;
1115import java .util .Set ;
16+ import java .util .stream .Collectors ;
1217
1318import static org .mangorage .bootstrap .Bootstrap .fetchJars ;
1419
1520public final class Test {
1621 public static void main (String [] args ) throws IOException {
1722 try {
1823 System .out .println ("you have 15 seconds!" );
19- Thread . sleep ( 15_000 );
24+
2025
2126 } catch (Throwable ignored ) {}
2227
23- LibraryHandler .handle ();
28+ final var list = LibraryHandler .handle ();
2429
2530 Path libsPath = Path .of ("sortedLibraries" );
2631 Path pluginsPath = Path .of ("plugins" );
2732
33+ Files .deleteIfExists (libsPath .resolve ("okio-jvm-3.6.0.jar" ));
34+
2835 ModuleFinder plugins = ModuleFinder .of (pluginsPath );
2936
3037 ModuleFinder finder = ModuleFinder .of (libsPath , pluginsPath );
@@ -34,7 +41,7 @@ public static void main(String[] args) throws IOException {
3441 .resolveAndBind (
3542 finder ,
3643 ModuleFinder .of (),
37- Set . of ( )
44+ getModuleNames ( pluginsPath )
3845 );
3946
4047
@@ -46,6 +53,33 @@ public static void main(String[] args) throws IOException {
4653 callMain ("org.mangorage.entrypoint.MangoBotCore" , args , cl , layer );
4754 }
4855
56+ public static Set <String > getModuleNames (Path folder ) {
57+ Set <String > moduleNames = new HashSet <>();
58+
59+ if (folder == null || !folder .toFile ().isDirectory ()) {
60+ throw new IllegalArgumentException ("That's not a valid folder, genius: " + folder );
61+ }
62+
63+ File [] jarFiles = folder .toFile ().listFiles ((dir , name ) -> name .endsWith (".jar" ));
64+ if (jarFiles == null ) return moduleNames ;
65+
66+ for (File jar : jarFiles ) {
67+ try {
68+ ModuleFinder finder = ModuleFinder .of (jar .toPath ());
69+ Set <ModuleReference > modules = finder .findAll ();
70+
71+ for (ModuleReference moduleRef : modules ) {
72+ var descriptor = moduleRef .descriptor ();
73+ moduleNames .add (descriptor .name ());
74+ }
75+ } catch (Exception e ) {
76+ System .err .println ("Couldn't process " + jar .getName () + ": " + e .getMessage ());
77+ }
78+ }
79+
80+ return moduleNames ;
81+ }
82+
4983 public static void callMain (String className , String [] args , ClassLoader classLoader , ModuleLayer moduleLayer ) {
5084 try {
5185 Class <?> clazz = Class .forName (moduleLayer .findModule ("org.mangorage.mangobotcore" ).get (), className );
0 commit comments