Add support for --system to JavaBuilder
PiperOrigin-RevId: 294771352
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
index c039836..e124dd2 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/JavaLibraryBuildRequest.java
@@ -54,6 +54,7 @@
private final ImmutableList<Path> sourcePath;
private final ImmutableList<Path> classPath;
private final ImmutableList<Path> bootClassPath;
+ private final Path system;
private final ImmutableList<Path> processorPath;
private final List<String> processorNames;
@@ -155,6 +156,7 @@
this.classPath = asPaths(optionsParser.getClassPath());
this.sourcePath = asPaths(optionsParser.getSourcePath());
this.bootClassPath = asPaths(optionsParser.getBootClassPath());
+ this.system = asPath(optionsParser.getSystem());
this.processorPath = asPaths(optionsParser.getProcessorPath());
this.processorNames = optionsParser.getProcessorNames();
this.builtinProcessorNames = ImmutableSet.copyOf(optionsParser.getBuiltinProcessorNames());
@@ -232,6 +234,10 @@
return bootClassPath;
}
+ public Path getSystem() {
+ return system;
+ }
+
public ImmutableList<Path> getProcessorPath() {
return processorPath;
}
@@ -310,6 +316,7 @@
.classPath(classPath)
.classOutput(getClassDir())
.bootClassPath(getBootClassPath())
+ .system(getSystem())
.javacOptions(makeJavacArguments())
.sourceFiles(ImmutableList.copyOf(getSourceFiles()))
.processors(null)
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
index 736e159..b88221c 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java
@@ -79,6 +79,7 @@
private final List<String> classPath = new ArrayList<>();
private final List<String> sourcePath = new ArrayList<>();
private final List<String> bootClassPath = new ArrayList<>();
+ private String system;
private final List<String> processorPath = new ArrayList<>();
private final List<String> processorNames = new ArrayList<>();
@@ -174,6 +175,9 @@
case "--bootclasspath":
collectFlagArguments(bootClassPath, argQueue, "-");
break;
+ case "--system":
+ system = getArgument(argQueue, arg);
+ break;
case "--processorpath":
collectFlagArguments(processorPath, argQueue, "-");
break;
@@ -416,6 +420,10 @@
return bootClassPath;
}
+ public String getSystem() {
+ return system;
+ }
+
public List<String> getSourcePath() {
return sourcePath;
}
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacArguments.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacArguments.java
index d7831fb..be40f45 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacArguments.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacArguments.java
@@ -43,6 +43,9 @@
/** The compilation bootclasspath. */
public abstract ImmutableList<Path> bootClassPath();
+ @Nullable
+ public abstract Path system();
+
/** The compilation source path. */
public abstract ImmutableList<Path> sourcePath();
@@ -101,6 +104,8 @@
Builder bootClassPath(ImmutableList<Path> bootClassPath);
+ Builder system(Path system);
+
Builder javacOptions(ImmutableList<String> javacOptions);
Builder sourcePath(ImmutableList<Path> sourcePath);
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
index e99d78c..18b34b3 100644
--- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
+++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/BlazeJavacMain.java
@@ -231,10 +231,16 @@
}
fileManager.setLocationFromPaths(StandardLocation.SOURCE_PATH, sourcePath);
- // The bootclasspath may legitimately be empty if --release is being used.
- Collection<Path> bootClassPath = arguments.bootClassPath();
- if (!bootClassPath.isEmpty()) {
- fileManager.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
+ Path system = arguments.system();
+ if (system != null) {
+ fileManager.setLocationFromPaths(
+ StandardLocation.locationFor("SYSTEM_MODULES"), ImmutableList.of(system));
+ } else {
+ // The bootclasspath may legitimately be empty if --release is being used.
+ Collection<Path> bootClassPath = arguments.bootClassPath();
+ if (!bootClassPath.isEmpty()) {
+ fileManager.setLocationFromPaths(StandardLocation.PLATFORM_CLASS_PATH, bootClassPath);
+ }
}
fileManager.setLocationFromPaths(
StandardLocation.ANNOTATION_PROCESSOR_PATH, arguments.processorPath());