aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Liam Miller-Cushon <cushon@google.com>2016-04-21 15:03:46 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-04-22 11:48:46 +0000
commit342a14ee77b7ae007423da52d88780f385db2c47 (patch)
tree137da332a27b023221cf3ae8ef13b6f484fbb795
parentad8678fea1fdd995641dfe0aceb69bc4584b5228 (diff)
Don't write empty Main-Class manifest entries
When java_binary.create_executable=0, omit the Main-Class entry in the deploy jar's manifest instead of writing an empty main class name. -- MOS_MIGRATED_REVID=120443936
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java27
1 files changed, 11 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
index 4e8513a1e1..980691f957 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/java/BazelJavaSemantics.java
@@ -80,24 +80,19 @@ public class BazelJavaSemantics implements JavaSemantics {
@Override
public void checkRule(RuleContext ruleContext, JavaCommon javaCommon) {
}
-
+
private String getMainClassInternal(RuleContext ruleContext, ImmutableList<Artifact> sources) {
- String mainClass = ruleContext.getRule().isAttrDefined("main_class", Type.STRING)
- ? ruleContext.attributes().get("main_class", Type.STRING) : "";
- boolean createExecutable = ruleContext.attributes().get("create_executable", Type.BOOLEAN);
- boolean useTestrunner = ruleContext.attributes().get("use_testrunner", Type.BOOLEAN)
- && !useLegacyJavaTest(ruleContext);
-
- if (createExecutable) {
- if (useTestrunner) {
- mainClass = "com.google.testing.junit.runner.BazelTestRunner";
- } else { /* java_binary or non-Junit java_test */
- if (mainClass.isEmpty()) {
- mainClass = JavaCommon.determinePrimaryClass(ruleContext, sources);
- }
- }
+ if (!ruleContext.attributes().get("create_executable", Type.BOOLEAN)) {
+ return null;
+ }
+ if (ruleContext.attributes().get("use_testrunner", Type.BOOLEAN)
+ && !useLegacyJavaTest(ruleContext)) {
+ return "com.google.testing.junit.runner.BazelTestRunner";
+ }
+ String mainClass = ruleContext.attributes().get("main_class", Type.STRING);
+ if (mainClass.isEmpty()) {
+ mainClass = JavaCommon.determinePrimaryClass(ruleContext, sources);
}
-
return mainClass;
}