Skip to content

Commit

Permalink
[batch compiler] Unrecognized option : --patch-module
Browse files Browse the repository at this point in the history
  • Loading branch information
stephan-herrmann committed Jun 9, 2024
1 parent 7a95d70 commit 235fcd8
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ public static synchronized ResourceBundle getBundle(Locale locale) {
private List<String> addonReads = Collections.EMPTY_LIST;
public Set<String> rootModules = Collections.EMPTY_SET;
public Set<String> limitedModules;
private Map<String,String> patchModules; // <module>=<file>(<pathsep><file>)*

public Locale compilerLocale;
public CompilerOptions compilerOptions; // read-only
Expand Down Expand Up @@ -1840,6 +1841,7 @@ public void configure(String[] argv) {
final int INSIDE_RELEASE = 30;
final int INSIDE_LIMIT_MODULES = 31;
final int INSIDE_MODULE_VERSION = 32;
final int INSIDE_PATCH_MODULE = 33;

final int DEFAULT = 0;
ArrayList<String> bootclasspaths = new ArrayList<>(DEFAULT_SIZE_CLASSPATH);
Expand Down Expand Up @@ -2149,6 +2151,10 @@ public void configure(String[] argv) {
mode = INSIDE_LIMIT_MODULES;
continue;
}
if (currentArg.equals("--patch-module")) { //$NON-NLS-1$
mode = INSIDE_PATCH_MODULE;
continue;
}
if (currentArg.equals("--module-version")) { //$NON-NLS-1$
mode = INSIDE_MODULE_VERSION;
continue;
Expand Down Expand Up @@ -2785,6 +2791,20 @@ public void configure(String[] argv) {
this.limitedModules.add(tokenizer.nextToken().trim());
}
continue;
case INSIDE_PATCH_MODULE:
mode = DEFAULT;
String[] toks = currentArg.split("="); //$NON-NLS-1$
if (toks.length == 2) {
if (this.patchModules == null) {
this.patchModules = new HashMap<>();
}
if (this.patchModules.put(toks[0].trim(), toks[1].trim()) != null) {
throw new IllegalArgumentException(this.bind("configure.duplicatePatchModule", toks[0].trim())); //$NON-NLS-1$
}
} else {
throw new IllegalArgumentException(this.bind("configure.invalidSyntaxPatchModule", currentArg)); //$NON-NLS-1$
}
continue;
case INSIDE_MODULE_VERSION:
mode = DEFAULT;
this.moduleVersion = validateModuleVersion(currentArg);
Expand Down Expand Up @@ -3402,9 +3422,22 @@ public CompilationUnit[] getCompilationUnits() {
return null;
};
}
String modName = this.modNames[i];
if (modName == null && this.patchModules != null) {
// does this source file patch an existing module?
patchEntries: for (Entry<String, String> entry : this.patchModules.entrySet()) {
StringTokenizer tokenizer = new StringTokenizer(entry.getValue(), File.pathSeparator);
while (tokenizer.hasMoreTokens()) {
if (fileName.startsWith(tokenizer.nextToken()+File.separator)) {
modName = entry.getKey();
break patchEntries;
}
}
}
}
units[i] = new CompilationUnit(null, fileName, encoding, this.destinationPaths[i],
shouldIgnoreOptionalProblems(this.ignoreOptionalProblemsFromFolders, fileName.toCharArray()),
this.modNames[i], annotationPathProvider);
modName, annotationPathProvider);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ configure.duplicateModuleSourcepath = duplicate source module path specification
configure.invalidModuleDescriptor = cannot open the module descriptor from {0}
configure.invalidModuleOption = incorrectly formatted option: {0}
configure.duplicateExport = can specify a package in a module only once with --add-export
configure.duplicatePatchModule = duplicate module in --patch-module: {0}
configure.invalidSyntaxPatchModule = invalid syntax for --patch-module: {0}
configure.OneOfModuleOrSourcePath = cannot specify both -source-path and --module-source-path
configure.duplicateBootClasspath = duplicate bootclasspath specification: {0}
configure.duplicateExtDirs = duplicate extdirs specification: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5968,4 +5968,58 @@ public void testIssue2357_001() throws Exception {
"}";
checkDisassembledClassFile(OUTPUT_DIR + File.separator + out + File.separator + "module-info.class", "module-info", expectedOutput);
}

public void testPatchModuleSingle() {
File outputDirectory = new File(OUTPUT_DIR);
Util.flushDirectoryContent(outputDirectory);
String out1 = OUTPUT_DIR + File.separator + "bin1";
String src1 = OUTPUT_DIR + File.separator + "src1";
List<String> files = new ArrayList<>();
writeFileCollecting(files, src1,
"module-info.java",
"module mod.one { \n" + // no exports!
"}");
writeFileCollecting(files, src1 + File.separator + "test1",
"A.java",
"package test1;\n" +
"public class A {}");
StringBuilder buffer = new StringBuilder();
buffer.append("-d " + out1 )
.append(" -9 ")
.append(" -proc:none ")
.append(" -classpath \"")
.append(Util.getJavaClassLibsAsString())
.append("\" ");
runConformModuleTest(
files,
buffer,
"",
"",
false);

files.clear();
String out2 = "bin2";
String src2 = OUTPUT_DIR + File.separator + "src2";
writeFileCollecting(files, src2 + File.separator + "test2",
"B.java",
"package test2;\n" +
"import test1.A;\n" +
"class B extends A {}");
buffer = new StringBuilder();
buffer.append("-d " + OUTPUT_DIR + File.separator + out2 )
.append(" -9 ")
.append(" -proc:none ")
.append(" --patch-module mod.one=\"").append(src2).append("\" ")
.append(" --module-path \"")
.append(Util.getJavaClassLibsAsString())
.append(File.pathSeparatorChar)
.append(out1)
.append("\" ");
runConformModuleTest(
files,
buffer,
"",
"",
false);
}
}

0 comments on commit 235fcd8

Please sign in to comment.