diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java b/src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java index e24266db5f..edecece6aa 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/Jvm.java @@ -39,6 +39,10 @@ public final class Jvm extends BuildConfiguration.Fragment { private final PathFragment jar; private final PathFragment java; + private static final String BIN_JAVAC = "bin/javac" + OsUtils.executableExtension(); + private static final String BIN_JAR = "bin/jar" + OsUtils.executableExtension(); + private static final String BIN_JAVA = "bin/java" + OsUtils.executableExtension(); + /** * Creates a Jvm instance. Either the {@code javaHome} parameter is absolute, * or the {@code jvmLabel} parameter must be non-null. This restriction might @@ -48,9 +52,9 @@ public final class Jvm extends BuildConfiguration.Fragment { Preconditions.checkArgument(javaHome.isAbsolute() ^ (jvmLabel != null)); this.javaHome = javaHome; this.jvmLabel = jvmLabel; - this.javac = getJavaHome().getRelative("bin/javac" + OsUtils.executableExtension()); - this.jar = getJavaHome().getRelative("bin/jar" + OsUtils.executableExtension()); - this.java = getJavaHome().getRelative("bin/java" + OsUtils.executableExtension()); + this.javac = getJavaHome().getRelative(BIN_JAVAC); + this.jar = getJavaHome().getRelative(BIN_JAR); + this.java = getJavaHome().getRelative(BIN_JAVA); } /** @@ -95,6 +99,17 @@ public final class Jvm extends BuildConfiguration.Fragment { return jvmLabel; } + /** + * If possible, resolves java relative to the jvmLabel's repository. Otherwise, returns the + * same thing as getJavaExecutable(). + */ + public PathFragment getRunfilesJavaExecutable() { + if (jvmLabel == null || jvmLabel.getPackageIdentifier().getRepository().isMain()) { + return getJavaExecutable(); + } + return jvmLabel.getPackageIdentifier().getRepository().getRunfilesPath().getRelative(BIN_JAVA); + } + @Override public void addGlobalMakeVariables(Builder<String, String> globalMakeEnvBuilder) { globalMakeEnvBuilder.put("JAVABASE", getJavaHome().getPathString()); |