diff options
author | Googler <noreply@google.com> | 2016-08-31 03:33:28 +0000 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2016-08-31 08:14:57 +0000 |
commit | c79b921670ae39a281f58cfca4e343fbae8c853e (patch) | |
tree | 6947de6f7152693c295af52f3425701ff2a34777 /src/main/java/com/google/devtools/build/lib/rules | |
parent | 5dd852cc4438e9d768910f86457bd2bca1362233 (diff) |
Migrate classes to @AutoValue. Mostly created by
--
MOS_MIGRATED_REVID=131787166
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
4 files changed, 102 insertions, 174 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationArgs.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationArgs.java index c19f0f5217..a12b01b7dc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationArgs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationArgs.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.rules.java; +import com.google.auto.value.AutoValue; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.FileProvider; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; @@ -23,10 +24,9 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.util.FileType; import java.util.Collection; -/** - * A container of Java compilation artifacts. - */ -public final class JavaCompilationArgs { +/** A container of Java compilation artifacts. */ +@AutoValue +public abstract class JavaCompilationArgs { // TODO(bazel-team): It would be desirable to use LinkOrderNestedSet here so that // parents-before-deps is preserved for graphs that are not trees. However, the legacy // JavaLibraryCollector implemented naive link ordering and many targets in the @@ -38,43 +38,28 @@ public final class JavaCompilationArgs { // decided by the rightmost branch in such cases. For example, if A depends on {junit4, // B}, B depends on {C, D}, C depends on {junit3}, and D depends on {junit4}, // the classpath of A will have junit3 before junit4. - private final NestedSet<Artifact> runtimeJars; - private final NestedSet<Artifact> compileTimeJars; - private final NestedSet<Artifact> instrumentationMetadata; - public static final JavaCompilationArgs EMPTY_ARGS = new JavaCompilationArgs( - NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER), - NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER), - NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER)); + public static final JavaCompilationArgs EMPTY_ARGS = + JavaCompilationArgs.create( + NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER), + NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER), + NestedSetBuilder.<Artifact>create(Order.NAIVE_LINK_ORDER)); - private JavaCompilationArgs(NestedSet<Artifact> runtimeJars, + private static JavaCompilationArgs create( + NestedSet<Artifact> runtimeJars, NestedSet<Artifact> compileTimeJars, NestedSet<Artifact> instrumentationMetadata) { - this.runtimeJars = runtimeJars; - this.compileTimeJars = compileTimeJars; - this.instrumentationMetadata = instrumentationMetadata; + return new AutoValue_JavaCompilationArgs(runtimeJars, compileTimeJars, instrumentationMetadata); } - /** - * Returns transitive runtime jars. - */ - public NestedSet<Artifact> getRuntimeJars() { - return runtimeJars; - } + /** Returns transitive runtime jars. */ + public abstract NestedSet<Artifact> getRuntimeJars(); - /** - * Returns transitive compile-time jars. - */ - public NestedSet<Artifact> getCompileTimeJars() { - return compileTimeJars; - } + /** Returns transitive compile-time jars. */ + public abstract NestedSet<Artifact> getCompileTimeJars(); - /** - * Returns transitive instrumentation metadata jars. - */ - public NestedSet<Artifact> getInstrumentationMetadata() { - return instrumentationMetadata; - } + /** Returns transitive instrumentation metadata jars. */ + public abstract NestedSet<Artifact> getInstrumentationMetadata(); /** * Returns a new builder instance. @@ -252,7 +237,7 @@ public final class JavaCompilationArgs { * Builds a {@link JavaCompilationArgs} object. */ public JavaCompilationArgs build() { - return new JavaCompilationArgs( + return JavaCompilationArgs.create( runtimeJarsBuilder.build(), compileTimeJarsBuilder.build(), instrumentationMetadataBuilder.build()); @@ -272,4 +257,6 @@ public final class JavaCompilationArgs { /* Only include on runtime classpath */ RUNTIME_ONLY; } + + JavaCompilationArgs() {} } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java index 7030f81855..ebc87e4bd7 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchain.java @@ -13,8 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.rules.java; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Iterables; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.ConfiguredTarget; @@ -32,7 +31,6 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.java.JavaToolchainData.SupportsWorkers; import com.google.devtools.build.lib.syntax.Type; - import java.util.List; import java.util.Map; @@ -59,7 +57,7 @@ public final class JavaToolchain implements RuleConfiguredTargetFactory { Artifact singleJar = getArtifact("singlejar", ruleContext); Artifact genClass = getArtifact("genclass", ruleContext); FilesToRunProvider ijar = ruleContext.getExecutablePrerequisite("ijar", Mode.HOST); - ImmutableMap<String, ImmutableList<String>> compatibleJavacOptions = + ImmutableListMultimap<String, String> compatibleJavacOptions = getCompatibleJavacOptions(ruleContext); final JavaToolchainData toolchainData = @@ -74,19 +72,18 @@ public final class JavaToolchain implements RuleConfiguredTargetFactory { jvmOpts, javacSupportsWorkers ? SupportsWorkers.YES : SupportsWorkers.NO); final JavaConfiguration configuration = ruleContext.getFragment(JavaConfiguration.class); - JavaToolchainProvider provider = - new JavaToolchainProvider( - toolchainData, - bootclasspath, - extclasspath, - configuration.getDefaultJavacFlags(), - javac, - javabuilder, - headerCompiler, - singleJar, - genClass, - ijar, - compatibleJavacOptions); + JavaToolchainProvider provider = JavaToolchainProvider.create( + toolchainData, + bootclasspath, + extclasspath, + configuration.getDefaultJavacFlags(), + javac, + javabuilder, + headerCompiler, + singleJar, + genClass, + ijar, + compatibleJavacOptions); RuleConfiguredTargetBuilder builder = new RuleConfiguredTargetBuilder(ruleContext) .addSkylarkTransitiveInfo(JavaToolchainSkylarkApiProvider.NAME, new JavaToolchainSkylarkApiProvider()) @@ -97,18 +94,17 @@ public final class JavaToolchain implements RuleConfiguredTargetFactory { return builder.build(); } - private ImmutableMap<String, ImmutableList<String>> getCompatibleJavacOptions( + private static ImmutableListMultimap<String, String> getCompatibleJavacOptions( RuleContext ruleContext) { - ImmutableMap.Builder<String, ImmutableList<String>> result = ImmutableMap.builder(); + ImmutableListMultimap.Builder<String, String> result = ImmutableListMultimap.builder(); for (Map.Entry<String, List<String>> entry : ruleContext.attributes().get("compatible_javacopts", Type.STRING_LIST_DICT).entrySet()) { - result.put( - entry.getKey(), ImmutableList.copyOf(JavaHelper.tokenizeJavaOptions(entry.getValue()))); + result.putAll(entry.getKey(), JavaHelper.tokenizeJavaOptions(entry.getValue())); } return result.build(); } - private Artifact getArtifact(String attributeName, RuleContext ruleContext) { + private static Artifact getArtifact(String attributeName, RuleContext ruleContext) { TransitiveInfoCollection prerequisite = ruleContext.getPrerequisite(attributeName, Mode.HOST); if (prerequisite == null) { return null; @@ -122,7 +118,8 @@ public final class JavaToolchain implements RuleConfiguredTargetFactory { return Iterables.getOnlyElement(artifacts); } - private NestedSet<Artifact> getArtifactList(String attributeName, RuleContext ruleContext) { + private static NestedSet<Artifact> getArtifactList( + String attributeName, RuleContext ruleContext) { TransitiveInfoCollection prerequisite = ruleContext.getPrerequisite(attributeName, Mode.HOST); if (prerequisite == null) { return null; diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java index 3190fe7e5b..600a8edd61 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaToolchainProvider.java @@ -13,10 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.rules.java; -import static com.google.devtools.build.lib.util.Preconditions.checkNotNull; - +import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableListMultimap; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.FilesToRunProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; @@ -30,31 +29,16 @@ import javax.annotation.Nullable; /** * Information about the JDK used by the <code>java_*</code> rules. */ +@AutoValue @Immutable -public final class JavaToolchainProvider implements TransitiveInfoProvider { +public abstract class JavaToolchainProvider implements TransitiveInfoProvider { /** Returns the Java Toolchain associated with the rule being analyzed or {@code null}. */ public static JavaToolchainProvider fromRuleContext(RuleContext ruleContext) { return ruleContext.getPrerequisite(":java_toolchain", Mode.TARGET, JavaToolchainProvider.class); } - private final String sourceVersion; - private final String targetVersion; - private final NestedSet<Artifact> bootclasspath; - private final NestedSet<Artifact> extclasspath; - private final String encoding; - private final ImmutableList<String> javacOptions; - private final ImmutableList<String> jvmOptions; - private final boolean javacSupportsWorkers; - private final Artifact javac; - private final Artifact javaBuilder; - private final Artifact headerCompiler; - @Nullable private final Artifact singleJar; - private final Artifact genClass; - private final FilesToRunProvider ijar; - private final ImmutableMap<String, ImmutableList<String>> compatibleJavacOptions; - - public JavaToolchainProvider( + public static JavaToolchainProvider create( JavaToolchainData data, NestedSet<Artifact> bootclasspath, NestedSet<Artifact> extclasspath, @@ -65,115 +49,80 @@ public final class JavaToolchainProvider implements TransitiveInfoProvider { Artifact singleJar, Artifact genClass, FilesToRunProvider ijar, - ImmutableMap<String, ImmutableList<String>> compatibleJavacOptions) { - this.sourceVersion = checkNotNull(data.getSourceVersion(), "sourceVersion must not be null"); - this.targetVersion = checkNotNull(data.getTargetVersion(), "targetVersion must not be null"); - this.bootclasspath = checkNotNull(bootclasspath, "bootclasspath must not be null"); - this.extclasspath = checkNotNull(extclasspath, "extclasspath must not be null"); - this.encoding = checkNotNull(data.getEncoding(), "encoding must not be null"); - this.javac = checkNotNull(javac, "javac must not be null"); - this.javaBuilder = checkNotNull(javaBuilder, "javaBuilder must not be null"); - this.headerCompiler = headerCompiler; - this.singleJar = checkNotNull(singleJar, "singleJar must not be null"); - this.genClass = checkNotNull(genClass, "genClass must not be null"); - this.ijar = checkNotNull(ijar, "ijar must not be null"); - this.compatibleJavacOptions = - checkNotNull(compatibleJavacOptions, "compatible javac options must not be null"); - - // merges the defaultJavacFlags from - // {@link JavaConfiguration} with the flags from the {@code java_toolchain} rule. - this.javacOptions = + ImmutableListMultimap<String, String> compatibleJavacOptions) { + return new AutoValue_JavaToolchainProvider( + data.getSourceVersion(), + data.getTargetVersion(), + bootclasspath, + extclasspath, + data.getEncoding(), + javac, + javaBuilder, + headerCompiler, + singleJar, + genClass, + ijar, + compatibleJavacOptions, + // merges the defaultJavacFlags from + // {@link JavaConfiguration} with the flags from the {@code java_toolchain} rule. ImmutableList.<String>builder() .addAll(data.getJavacOptions()) .addAll(defaultJavacFlags) - .build(); - this.jvmOptions = data.getJvmOptions(); - this.javacSupportsWorkers = data.getJavacSupportsWorkers(); - } - - /** @return the list of default options for the java compiler */ - public ImmutableList<String> getJavacOptions() { - return javacOptions; - } - - /** - * @return the list of default options for the JVM running the java compiler and associated tools. - */ - public ImmutableList<String> getJvmOptions() { - return jvmOptions; - } - - /** @return whether JavaBuilders supports running as a persistent worker or not */ - public boolean getJavacSupportsWorkers() { - return javacSupportsWorkers; + .build(), + data.getJvmOptions(), + data.getJavacSupportsWorkers()); } /** @return the input Java language level */ - public String getSourceVersion() { - return sourceVersion; - } + public abstract String getSourceVersion(); /** @return the target Java language level */ - public String getTargetVersion() { - return targetVersion; - } + public abstract String getTargetVersion(); /** @return the target Java bootclasspath */ - public NestedSet<Artifact> getBootclasspath() { - return bootclasspath; - } + public abstract NestedSet<Artifact> getBootclasspath(); /** @return the target Java extclasspath */ - public NestedSet<Artifact> getExtclasspath() { - return extclasspath; - } + public abstract NestedSet<Artifact> getExtclasspath(); /** @return the encoding for Java source files */ - @Nullable - public String getEncoding() { - return encoding; - } + public abstract String getEncoding(); /** Returns the {@link Artifact} of the javac jar */ - @Nullable - public Artifact getJavac() { - return javac; - } + public abstract Artifact getJavac(); /** Returns the {@link Artifact} of the JavaBuilder deploy jar */ - @Nullable - public Artifact getJavaBuilder() { - return javaBuilder; - } + public abstract Artifact getJavaBuilder(); /** @return the {@link Artifact} of the Header Compiler deploy jar */ - @Nullable - public Artifact getHeaderCompiler() { - return headerCompiler; - } + @Nullable public abstract Artifact getHeaderCompiler(); /** Returns the {@link Artifact} of the SingleJar deploy jar */ - @Nullable - public Artifact getSingleJar() { - return singleJar; - } + public abstract Artifact getSingleJar(); /** Returns the {@link Artifact} of the GenClass deploy jar */ - @Nullable - public Artifact getGenClass() { - return genClass; - } + public abstract Artifact getGenClass(); /** Returns the ijar executable */ - @Nullable - public FilesToRunProvider getIjar() { - return ijar; - } + public abstract FilesToRunProvider getIjar(); + + abstract ImmutableListMultimap<String, String> getCompatibleJavacOptions(); /** @return the map of target environment-specific javacopts. */ public ImmutableList<String> getCompatibleJavacOptions(String key) { - return compatibleJavacOptions.containsKey(key) - ? compatibleJavacOptions.get(key) - : ImmutableList.<String>of(); + return getCompatibleJavacOptions().get(key); } + + /** @return the list of default options for the java compiler */ + public abstract ImmutableList<String> getJavacOptions(); + + /** + * @return the list of default options for the JVM running the java compiler and associated tools. + */ + public abstract ImmutableList<String> getJvmOptions(); + + /** @return whether JavaBuilders supports running as a persistent worker or not */ + public abstract boolean getJavacSupportsWorkers(); + + JavaToolchainProvider() {} } diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java index dd1ec34d43..0f679ae116 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/MessageBundleProvider.java @@ -14,28 +14,23 @@ package com.google.devtools.build.lib.rules.java; +import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.analysis.TransitiveInfoProvider; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; -/** - * Marks configured targets that are able to supply message bundles to their - * dependents. - */ +/** Marks configured targets that are able to supply message bundles to their dependents. */ +@AutoValue @Immutable -public final class MessageBundleProvider implements TransitiveInfoProvider { +public abstract class MessageBundleProvider implements TransitiveInfoProvider { - private final ImmutableList<Artifact> messages; - - public MessageBundleProvider(ImmutableList<Artifact> messages) { - this.messages = messages; + public static MessageBundleProvider create(ImmutableList<Artifact> messages) { + return new AutoValue_MessageBundleProvider(messages); } - /** - * The set of XML source files containing the message definitions. - */ - public ImmutableList<Artifact> getMessages() { - return messages; - } + /** The set of XML source files containing the message definitions. */ + public abstract ImmutableList<Artifact> getMessages(); + + MessageBundleProvider() {} } |