diff options
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java | 25 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java | 2 |
2 files changed, 24 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java index cba5c479e6..2771da6e2d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java @@ -103,7 +103,7 @@ public class JavaCommon { private final ImmutableMap<ClasspathType, ImmutableList<TransitiveInfoCollection>> targetsTreatedAsDeps; - private ImmutableList<Artifact> sources = ImmutableList.of(); + private final ImmutableList<Artifact> sources; private ImmutableList<JavaPluginInfoProvider> activePlugins = ImmutableList.of(); private final RuleContext ruleContext; @@ -112,18 +112,40 @@ public class JavaCommon { public JavaCommon(RuleContext ruleContext, JavaSemantics semantics) { this(ruleContext, semantics, + ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list(), collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.COMPILE_ONLY), collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.RUNTIME_ONLY), collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.BOTH)); } + public JavaCommon(RuleContext ruleContext, JavaSemantics semantics, + ImmutableList<Artifact> sources) { + this(ruleContext, semantics, + sources, + collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.COMPILE_ONLY), + collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.RUNTIME_ONLY), + collectTargetsTreatedAsDeps(ruleContext, semantics, ClasspathType.BOTH)); + } + + public JavaCommon(RuleContext ruleContext, + JavaSemantics semantics, + ImmutableList<TransitiveInfoCollection> compileDeps, + ImmutableList<TransitiveInfoCollection> runtimeDeps, + ImmutableList<TransitiveInfoCollection> bothDeps) { + this(ruleContext, semantics, + ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list(), + compileDeps, runtimeDeps, bothDeps); + } + public JavaCommon(RuleContext ruleContext, JavaSemantics semantics, + ImmutableList<Artifact> sources, ImmutableList<TransitiveInfoCollection> compileDeps, ImmutableList<TransitiveInfoCollection> runtimeDeps, ImmutableList<TransitiveInfoCollection> bothDeps) { this.ruleContext = ruleContext; this.semantics = semantics; + this.sources = sources; this.targetsTreatedAsDeps = ImmutableMap.of( ClasspathType.COMPILE_ONLY, compileDeps, ClasspathType.RUNTIME_ONLY, runtimeDeps, @@ -504,7 +526,6 @@ public class JavaCommon { */ public JavaTargetAttributes.Builder initCommon(Collection<Artifact> extraSrcs) { Preconditions.checkState(javacOpts != null); - sources = ruleContext.getPrerequisiteArtifacts("srcs", Mode.TARGET).list(); activePlugins = collectPlugins(); JavaTargetAttributes.Builder javaTargetAttributes = new JavaTargetAttributes.Builder(semantics); diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java index fa3805b9dd..46e4d815e2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java @@ -63,7 +63,7 @@ public class JavaImport implements RuleConfiguredTargetFactory { .addAll(ruleContext.getPrerequisites("exports", Mode.TARGET)) .build(); final JavaCommon common = new JavaCommon( - ruleContext, semantics, targets, targets, targets); + ruleContext, semantics, /*srcs=*/ImmutableList.<Artifact>of(), targets, targets, targets); semantics.checkRule(ruleContext, common); // No need for javac options - no compilation happening here. |