Skip to content

Commit 2e658d1

Browse files
committed
moditect#67 Putting module-info.class to JAR root by default;
See the discussion in moditect#68 and related JDK bug https://bugs.openjdk.java.net/browse/JDK-8207162.
1 parent 0be0b57 commit 2e658d1

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

core/src/main/java/org/moditect/commands/AddModuleInfo.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
public class AddModuleInfo {
4242

43+
private static final String NO_JVM_VERSION = "base";
44+
4345
private final String moduleInfoSource;
4446
private final String mainClass;
4547
private final String version;
@@ -54,11 +56,11 @@ public AddModuleInfo(String moduleInfoSource, String mainClass, String version,
5456
this.version = version;
5557
this.inputJar = inputJar;
5658
this.outputDirectory = outputDirectory;
57-
if (jvmVersion == null) {
58-
// By default, put module descriptor in "META-INF/versions/9" for maximum backwards compatibility
59-
this.jvmVersion = Integer.valueOf(9);
60-
}
61-
else if (jvmVersion.equals("base")) {
59+
60+
// #67 It'd be nice to use META-INF/services/9 by default to avoid conflicts with legacy
61+
// classpath scanners, but this causes isses with subsequent jdeps invocations if there
62+
// are MR-JARs and non-MR JARs passed to it due to https://bugs.openjdk.java.net/browse/JDK-8207162
63+
if (jvmVersion == null || jvmVersion.equals(NO_JVM_VERSION)) {
6264
this.jvmVersion = null;
6365
}
6466
else {
@@ -69,7 +71,7 @@ else if (jvmVersion.equals("base")) {
6971
}
7072
}
7173
catch (NumberFormatException e) {
72-
throw new IllegalArgumentException("Invalid JVM Version: " + jvmVersion);
74+
throw new IllegalArgumentException("Invalid JVM Version: " + jvmVersion + ". Allowed values are 'base' and integer values >= 9." );
7375
}
7476
}
7577
this.overwriteExistingFiles = overwriteExistingFiles;

core/src/main/java/org/moditect/commands/GenerateModuleInfo.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,17 @@ private Map<String, Boolean> generateModuleInfo() throws AssertionError {
376376
command.add( modules.toString() );
377377
command.add( "--module-path" );
378378
command.add( modulePath.toString() );
379-
380-
command.addAll( jdepsExtraArgs );
381379
}
382380

381+
command.addAll( jdepsExtraArgs );
383382
command.add( inputJar.toString() );
384383

385384
log.debug( "Running jdeps " + String.join( " ", command ) );
386-
jdeps.run( System.out, System.err, command.toArray( new String[0] ) );
385+
int result = jdeps.run( System.out, System.err, command.toArray( new String[0] ) );
386+
387+
if (result != 0) {
388+
throw new IllegalStateException("Invocation of jdeps failed: jdeps " + String.join( " ", command ) );
389+
}
387390

388391
return optionalityPerModule;
389392
}

0 commit comments

Comments
 (0)