aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Ulf Adams <ulfjack@google.com>2016-02-24 10:26:23 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2016-02-24 17:58:58 +0000
commit0a6ac84594f4dfc558730c7c6c4807a7d86330ab (patch)
treeb9b38b2348408068c81a1c6a19449d6945a439f1
parent7de6655f583641d3074d50a361ac870310a0d7a5 (diff)
Initialize JavaCommon.sources eagerly, rather than in initCommon().
This allows us to make the field final, and guarantees that it can't be mutated after construction. -- MOS_MIGRATED_REVID=115430793
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java25
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java2
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.