diff options
author | lberki <lberki@google.com> | 2018-07-12 01:14:46 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-12 01:16:14 -0700 |
commit | ce8f52060e2cf1e5a49a522039f0cba2a340f7e3 (patch) | |
tree | 7f76f467b308f06a80fc81a1467f41f39a48fec1 /src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java | |
parent | f814454ff5477418ca44696efb5c71339368efa4 (diff) |
Automated rollback of commit f4a3dd9b8124dc7b2795f89e6700881b66371e4f.
*** Reason for rollback ***
Breaks //devtools/blaze/integration:{[]_test_test,gdp_validation_test} and at leats //contentads/supermixer/server:supermixer .
*** Original change description ***
Refactor handling of API generation in JavaPluginInfoProvider
Instead of keeping two copies of state for the API-generating and
non-API-generating cases, create a 'JavaPluginInfo' abstraction to contain all
state for each case, and then keep two copies in the top-level
JavaPluginInfoProvider provider.
This will make it easier and less error-prone to add additional state to the
provider.
PiperOrigin-RevId: 204258844
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java | 48 |
1 files changed, 35 insertions, 13 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 c68bd76547..e88782951d 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 @@ -50,7 +50,6 @@ import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.rules.cpp.LinkerInput; import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType; -import com.google.devtools.build.lib.rules.java.JavaPluginInfoProvider.JavaPluginInfo; import com.google.devtools.build.lib.syntax.Type; import com.google.devtools.build.lib.util.FileTypeSet; import com.google.devtools.build.lib.util.Pair; @@ -103,7 +102,7 @@ public class JavaCommon { targetsTreatedAsDeps; private final ImmutableList<Artifact> sources; - private JavaPluginInfoProvider activePlugins = JavaPluginInfoProvider.empty(); + private ImmutableList<JavaPluginInfoProvider> activePlugins = ImmutableList.of(); private final RuleContext ruleContext; private final JavaSemantics semantics; @@ -763,21 +762,33 @@ public class JavaCommon { * Adds information about the annotation processors that should be run for this java target * retrieved from the given plugins to the target attributes. * - * <p>In particular, the processor names/paths and the API generating processor names/paths are - * added to the given attributes. Plugins having repetitive names/paths will be added only once. + * In particular, the processor names/paths and the API generating processor names/paths are added + * to the given attributes. Plugins having repetitive names/paths will be added only once. */ public static void addPlugins( - JavaTargetAttributes.Builder attributes, JavaPluginInfoProvider activePlugins) { - attributes.addPlugin(activePlugins); + JavaTargetAttributes.Builder attributes, Iterable<JavaPluginInfoProvider> activePlugins) { + for (JavaPluginInfoProvider plugin : activePlugins) { + for (String name : plugin.getProcessorClasses()) { + attributes.addProcessorName(name); + } + // Now get the plugin-libraries runtime classpath. + attributes.addProcessorPath(plugin.getProcessorClasspath()); + + // Add api-generating plugins + for (String name : plugin.getApiGeneratingProcessorClasses()) { + attributes.addApiGeneratingProcessorName(name); + } + attributes.addApiGeneratingProcessorPath(plugin.getApiGeneratingProcessorClasspath()); + } } - private JavaPluginInfoProvider collectPlugins() { + private ImmutableList<JavaPluginInfoProvider> collectPlugins() { List<JavaPluginInfoProvider> result = new ArrayList<>(); Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, ":java_plugins", Mode.HOST)); Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, "plugins", Mode.HOST)); Iterables.addAll(result, getPluginInfoProvidersForAttribute(ruleContext, "deps", Mode.TARGET)); - return JavaPluginInfoProvider.merge(result); + return ImmutableList.copyOf(result); } private static Iterable<JavaPluginInfoProvider> getPluginInfoProvidersForAttribute( @@ -790,12 +801,23 @@ public class JavaCommon { } JavaPluginInfoProvider getJavaPluginInfoProvider(RuleContext ruleContext) { - NestedSet<String> processorClasses = - NestedSetBuilder.wrap(Order.NAIVE_LINK_ORDER, getProcessorClasses(ruleContext)); + ImmutableSet<String> processorClasses = getProcessorClasses(ruleContext); NestedSet<Artifact> processorClasspath = getRuntimeClasspath(); - return JavaPluginInfoProvider.create( - JavaPluginInfo.create(processorClasses, processorClasspath), - ruleContext.attributes().get("generates_api", Type.BOOLEAN)); + ImmutableSet<String> apiGeneratingProcessorClasses; + NestedSet<Artifact> apiGeneratingProcessorClasspath; + if (ruleContext.attributes().get("generates_api", Type.BOOLEAN)) { + apiGeneratingProcessorClasses = processorClasses; + apiGeneratingProcessorClasspath = processorClasspath; + } else { + apiGeneratingProcessorClasses = ImmutableSet.of(); + apiGeneratingProcessorClasspath = NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER); + } + + return new JavaPluginInfoProvider( + processorClasses, + processorClasspath, + apiGeneratingProcessorClasses, + apiGeneratingProcessorClasspath); } /** |