2323import org .objectweb .asm .Opcodes ;
2424
2525import java .io .File ;
26+ import java .io .FileInputStream ;
2627import java .io .IOException ;
2728import java .io .InputStream ;
2829import java .nio .charset .StandardCharsets ;
2930import java .nio .file .Files ;
3031import java .nio .file .Path ;
3132import java .util .ArrayList ;
33+ import java .util .Arrays ;
3234import java .util .HashMap ;
3335import java .util .List ;
3436import java .util .Map ;
@@ -126,24 +128,23 @@ private void extractFromJar(File file, Map<String, String> classesToModules) thr
126128 private String extractClassNameFromJar (JarFile jarFile ) {
127129 return jarFile .stream ()
128130 .filter (
129- je -> je .getName ().startsWith ("META-INF" ) == false
130- && je .getName ().equals ("module-info.class" ) == false
131- && je .getName ().endsWith (".class" )
131+ je -> je .getName ().startsWith ("META-INF" ) == false
132+ && je .getName ().equals ("module-info.class" ) == false
133+ && je .getName ().endsWith (".class" )
132134 )
133- .findFirst ().map (ZipEntry ::getName ).orElse (null );
135+ .findFirst ()
136+ .map (ZipEntry ::getName )
137+ .orElse (null );
134138 }
135139
136140 private String extractModuleNameFromJar (File file , JarFile jarFile ) throws IOException {
137141 String moduleName = null ;
138142
139143 if (jarFile .isMultiRelease ()) {
140144 List <Integer > versions = jarFile .stream ()
141- .filter (
142- je -> je .getName ().startsWith ("META-INF/versions/" )
143- && je .getName ().endsWith ("/module-info.class" )
144- )
145- .map (je -> Integer .parseInt (je .getName ().substring (18 , je .getName ().length () - 18 )))
146- .toList ();
145+ .filter (je -> je .getName ().startsWith ("META-INF/versions/" ) && je .getName ().endsWith ("/module-info.class" ))
146+ .map (je -> Integer .parseInt (je .getName ().substring (18 , je .getName ().length () - 18 )))
147+ .toList ();
147148 versions = new ArrayList <>(versions );
148149 versions .sort (Integer ::compareTo );
149150 versions = versions .reversed ();
@@ -201,10 +202,10 @@ private String extractModuleNameFromJar(File file, JarFile jarFile) throws IOExc
201202 return moduleName ;
202203 }
203204
204- private void extractFromDirectory (File file , Map <String , String > classesToModules ) {
205+ private void extractFromDirectory (File file , Map <String , String > classesToModules ) throws IOException {
205206 String className = extractClassNameFromDirectory (file );
206- String moduleName = null ;
207-
207+ String moduleName = extractModuleNameFromDirectory ( file ) ;
208+ getLogger (). lifecycle ( "DIRECTORY: " + className + " -> " + moduleName );
208209 if (className != null && moduleName != null ) {
209210 classesToModules .put (className , moduleName );
210211 }
@@ -214,9 +215,33 @@ private String extractClassNameFromDirectory(File file) {
214215 List <File > files = new ArrayList <>(List .of (file ));
215216 while (files .isEmpty () == false ) {
216217 File find = files .removeFirst ();
218+ getLogger ().lifecycle ("FIND: " + find .getAbsolutePath ());
217219 if (find .exists ()) {
218- if (find .getName ().endsWith (".class" ) && find .getName ().equals ("module-info.class" ) == false && find .getName ().contains ("$" ) == false ) {
220+ if (find .getName ().endsWith (".class" )
221+ && find .getName ().equals ("module-info.class" ) == false
222+ && find .getName ().contains ("$" ) == false ) {
219223 return find .getAbsolutePath ().substring (file .getAbsolutePath ().length () + 1 );
224+ } else if (find .isDirectory ()) {
225+ files .addAll (Arrays .asList (find .listFiles ()));
226+ }
227+ }
228+
229+ }
230+ return null ;
231+ }
232+
233+ private String extractModuleNameFromDirectory (File file ) throws IOException {
234+ List <File > files = new ArrayList <>(List .of (file ));
235+ while (files .isEmpty () == false ) {
236+ File find = files .removeFirst ();
237+ getLogger ().lifecycle ("FIND: " + find .getAbsolutePath ());
238+ if (find .exists ()) {
239+ if (find .getName ().equals ("module-info.class" )) {
240+ try (InputStream inputStream = new FileInputStream (find )) {
241+ return extractModuleNameFromModuleInfo (inputStream );
242+ }
243+ } else if (find .isDirectory ()) {
244+ files .addAll (Arrays .asList (find .listFiles ()));
220245 }
221246 }
222247 }
0 commit comments