Delete the interface NativeAspectFactory and make native aspects extend from NativeAspectClass.
This a large refactoring of the aspects, currently we have the following:
- AspectClasses: The interface AspectClass is a implemented by either
SkylarkAspectClass or NativeAspectClass<NativeAspectFactory>.
They are wrappers for the AspectFactories and they hold the information about
the Class<> of the factory.
- AspectFactories (FooAspect.java): Represented by the interfaces
ConfiguredAspectFactory and NativeAspectFactory, also by
the interface ConfiguredNativeAspectFactory which is the union of the two
aforementioned interfaces.
All aspects implement ConfiguredNativeAspectFactory except Skylark aspects
which implement only ConfiguredAspectFactory.
After this CL the distinction between NativeAspectFactories and NativeAspectClasses
dissappear, namely aspect that extends NativeAspectClass is considered native
and if it implements ConfiguredAspectFactory it is configured.
Therefore the interfaces NativeAspectFactory and ConfiguredNativeAspectFactory
both disappear.
With this refactoring the aspectFactoryMap in the ConfiguredRuleClassProvider
changes its type from (String -> Class<? extends NativeAspectClass>)
to (String -> NativeAspectClass) which means it is now able to have an instance
of the aspect instead of its Class only.
By doing this, it is now possible to pass parameters when creating an
aspect in the ConfiguredRuleClassProvider.
--
MOS_MIGRATED_REVID=120819647
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
index e4a4a2c..bfc8b5b 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/ConfiguredRuleClassProvider.java
@@ -36,7 +36,7 @@
import com.google.devtools.build.lib.graph.Digraph;
import com.google.devtools.build.lib.graph.Node;
import com.google.devtools.build.lib.packages.Attribute;
-import com.google.devtools.build.lib.packages.NativeAspectClass.NativeAspectFactory;
+import com.google.devtools.build.lib.packages.NativeAspectClass;
import com.google.devtools.build.lib.packages.RuleClass;
import com.google.devtools.build.lib.packages.RuleClassProvider;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
@@ -93,7 +93,7 @@
private final Map<String, RuleClass> ruleClassMap = new HashMap<>();
private final Map<String, RuleDefinition> ruleDefinitionMap = new HashMap<>();
- private final Map<String, Class<? extends NativeAspectFactory>> aspectFactoryMap =
+ private final Map<String, NativeAspectClass> nativeAspectClassMap =
new HashMap<>();
private final Map<Class<? extends RuleDefinition>, RuleClass> ruleMap = new HashMap<>();
private final Digraph<Class<? extends RuleDefinition>> dependencyGraph =
@@ -161,10 +161,8 @@
return this;
}
- public Builder addAspectFactory(
- String name, Class<? extends ConfiguredNativeAspectFactory> configuredAspectFactoryClass) {
- aspectFactoryMap.put(name, configuredAspectFactoryClass);
-
+ public Builder addNativeAspectClass(NativeAspectClass aspectFactoryClass) {
+ nativeAspectClassMap.put(aspectFactoryClass.getName(), aspectFactoryClass);
return this;
}
@@ -264,7 +262,7 @@
toolsRepository,
ImmutableMap.copyOf(ruleClassMap),
ImmutableMap.copyOf(ruleDefinitionMap),
- ImmutableMap.copyOf(aspectFactoryMap),
+ ImmutableMap.copyOf(nativeAspectClassMap),
defaultWorkspaceFilePrefix.toString(),
defaultWorkspaceFileSuffix.toString(),
ImmutableList.copyOf(buildInfoFactories),
@@ -344,7 +342,7 @@
/**
* Maps aspect name to the aspect factory meta class.
*/
- private final ImmutableMap<String, Class<? extends NativeAspectFactory>> aspectFactoryMap;
+ private final ImmutableMap<String, NativeAspectClass> nativeAspectClassMap;
/**
* The configuration options that affect the behavior of the rules.
@@ -381,7 +379,7 @@
String toolsRepository,
ImmutableMap<String, RuleClass> ruleClassMap,
ImmutableMap<String, RuleDefinition> ruleDefinitionMap,
- ImmutableMap<String, Class<? extends NativeAspectFactory>> aspectFactoryMap,
+ ImmutableMap<String, NativeAspectClass> nativeAspectClassMap,
String defaultWorkspaceFilePrefix,
String defaultWorkspaceFileSuffix,
ImmutableList<BuildInfoFactory> buildInfoFactories,
@@ -398,7 +396,7 @@
this.toolsRepository = toolsRepository;
this.ruleClassMap = ruleClassMap;
this.ruleDefinitionMap = ruleDefinitionMap;
- this.aspectFactoryMap = aspectFactoryMap;
+ this.nativeAspectClassMap = nativeAspectClassMap;
this.defaultWorkspaceFilePrefix = defaultWorkspaceFilePrefix;
this.defaultWorkspaceFileSuffix = defaultWorkspaceFileSuffix;
this.buildInfoFactories = buildInfoFactories;
@@ -436,8 +434,13 @@
}
@Override
- public Map<String, Class<? extends NativeAspectFactory>> getAspectFactoryMap() {
- return aspectFactoryMap;
+ public Map<String, NativeAspectClass> getNativeAspectClassMap() {
+ return nativeAspectClassMap;
+ }
+
+ @Override
+ public NativeAspectClass getNativeAspectClass(String key) {
+ return nativeAspectClassMap.get(key);
}
/**