diff options
author | 2017-04-24 18:07:42 +0200 | |
---|---|---|
committer | 2017-04-25 14:45:43 +0200 | |
commit | 3e25d209504b8cd2fa03dfb6dee42e10e31b7c49 (patch) | |
tree | 1c0c8788ae1febce56156dac477b5e9b36617670 /src/main/java | |
parent | c3aee5a2f279a96f917ef4674eb047c1c27ee4a8 (diff) |
Cleanup SingleJarActionBuilder
Avoiding duplicating code between the branches for handling
the Java and c++ implementations, and skip the
--resources flag if there are no resources. Both of these
changes should be no-ops.
PiperOrigin-RevId: 154055528
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java | 58 |
1 files changed, 23 insertions, 35 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java index 8f488ea4d7..3942ba2e33 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java @@ -22,7 +22,6 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.actions.CommandLine; import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.actions.SpawnAction; -import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.Collection; @@ -54,44 +53,31 @@ public final class SingleJarActionBuilder { Map<PathFragment, Artifact> resources, Collection<Artifact> resourceJars, Artifact outputJar) { - PathFragment javaPath = - ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable(); - NestedSet<Artifact> hostJavabaseInputs = JavaHelper.getHostJavabaseInputs(ruleContext); Artifact singleJar = getSingleJar(ruleContext); - + SpawnAction.Builder builder = new SpawnAction.Builder(); // If singlejar's name ends with .jar, it is Java application, otherwise it is native. // TODO(asmundak): once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is, // the native singlejar is used on windows) remove support for the Java implementation if (singleJar.getFilename().endsWith(".jar")) { - ruleContext.registerAction( - new SpawnAction.Builder() - .addOutput(outputJar) - .addInputs(resources.values()) - .addInputs(resourceJars) - .addTransitiveInputs(hostJavabaseInputs) - .setJarExecutable( - javaPath, - singleJar, - JavaToolchainProvider.fromRuleContext(ruleContext).getJvmOptions()) - .setCommandLine(sourceJarCommandLine(outputJar, resources, resourceJars)) - .alwaysUseParameterFile(ParameterFileType.SHELL_QUOTED) - .setProgressMessage("Building source jar " + outputJar.prettyPrint()) - .setMnemonic("JavaSourceJar") - .setExecutionInfo(ImmutableMap.of("supports-workers", "1")) - .build(ruleContext)); + builder + .addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext)) + .setJarExecutable( + ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable(), + singleJar, + JavaToolchainProvider.fromRuleContext(ruleContext).getJvmOptions()) + .setExecutionInfo(ImmutableMap.of("supports-workers", "1")); } else { - ruleContext.registerAction( - new SpawnAction.Builder() - .addOutput(outputJar) - .addInputs(resources.values()) - .addInputs(resourceJars) - .setExecutable(singleJar) - .setCommandLine(sourceJarCommandLine(outputJar, resources, resourceJars)) - .alwaysUseParameterFile(ParameterFileType.SHELL_QUOTED) - .setProgressMessage("Building source jar " + outputJar.prettyPrint()) - .setMnemonic("JavaSourceJar") - .build(ruleContext)); + builder.setExecutable(singleJar); } + builder + .addOutput(outputJar) + .addInputs(resources.values()) + .addInputs(resourceJars) + .setCommandLine(sourceJarCommandLine(outputJar, resources, resourceJars)) + .alwaysUseParameterFile(ParameterFileType.SHELL_QUOTED) + .setProgressMessage("Building source jar " + outputJar.prettyPrint()) + .setMnemonic("JavaSourceJar"); + ruleContext.registerAction(builder.build(ruleContext)); } /** Returns the SingleJar deploy jar Artifact. */ @@ -109,9 +95,11 @@ public final class SingleJarActionBuilder { args.addExecPath("--output", outputJar); args.add(SOURCE_JAR_COMMAND_LINE_ARGS); args.addExecPaths("--sources", resourceJars); - args.add("--resources"); - for (Map.Entry<PathFragment, Artifact> resource : resources.entrySet()) { - args.addPaths("%s:%s", resource.getValue().getExecPath(), resource.getKey()); + if (!resources.isEmpty()) { + args.add("--resources"); + for (Map.Entry<PathFragment, Artifact> resource : resources.entrySet()) { + args.addPaths("%s:%s", resource.getValue().getExecPath(), resource.getKey()); + } } return args.build(); } |