Skip to content

Commit ea99d21

Browse files
committed
Mark automatic modules in module path analysis with [AUTO]
1 parent 9577b7c commit ea99d21

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/main/java/org/gradlex/javamodule/dependencies/tasks/ModulePathAnalysis.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ private void collect(Configuration configuration, Set<String> usedMappings, Set<
192192
boolean isModuleForReal = getJavaModuleDetector().isModule(true, resultFile);
193193

194194
if (moduleName != null && isModuleForReal) {
195-
usedMappings.add(moduleName + " -> " + ga + version);
195+
if (isRealModule(resultFile)) {
196+
usedMappings.add(moduleName + " -> " + ga + version);
197+
} else {
198+
usedMappings.add("[AUTO] " + moduleName + " -> " + ga + version);
199+
}
196200
}
197201
if (moduleName == null && !isModuleForReal) {
198202
nonModules.add(ga + version);
@@ -228,6 +232,24 @@ private String readNameFromModuleFromJarFile(File jarFile) throws IOException {
228232
return null;
229233
}
230234

235+
private boolean isRealModule(File jarFile) throws IOException {
236+
try (JarInputStream jarStream = new JarInputStream(Files.newInputStream(jarFile.toPath()))) {
237+
boolean isMultiReleaseJar = containsMultiReleaseJarEntry(jarStream);
238+
ZipEntry next = jarStream.getNextEntry();
239+
while (next != null) {
240+
if (MODULE_INFO_CLASS_FILE.equals(next.getName())) {
241+
return true;
242+
}
243+
if (isMultiReleaseJar && MODULE_INFO_CLASS_MRJAR_PATH.matcher(next.getName()).matches()) {
244+
return true;
245+
}
246+
next = jarStream.getNextEntry();
247+
}
248+
}
249+
return false;
250+
}
251+
252+
231253
private String getAutomaticModuleName(Manifest manifest) {
232254
if (manifest == null) {
233255
return null;

0 commit comments

Comments
 (0)