aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-10-31 12:54:26 -0400
committerGravatar John Cater <jcater@google.com>2017-11-01 09:58:45 -0400
commit18462d516727ce3b43773506bca4b2e4424d43b2 (patch)
treed67d36a8f88d75afb7812126adcf806118c16c5b /src/main/java/com/google/devtools
parent1bd4aafd1b15851da7929d279ff4dce78a9bd928 (diff)
Rename ResourceFilter to ResourceFilterFactory
In the next review, to handle issues around density filtering, ResourceFilterFactory will return another object that actually handles filtering. To ensure stuff is named properly, rename ResourceFilter to ResourceFilterFactory now so that the new class can be called ResourceFilter. This is a straightforward automated refactor, followed with some automated reformatting to make linting happy. I used the name ResourceFilterFactory, rather than the more concise ResourceFilters, as this class actually contains state (both around what filtering should currently do and about what resources were filtered out) and isn't just a helper class. RELNOTES: none PiperOrigin-RevId: 174049618
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java4
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java25
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java50
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java3
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactory.java (renamed from src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java)64
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java15
11 files changed, 109 insertions, 96 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
index 38882e3c91..6cd81e2065 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java
@@ -244,7 +244,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_RESOURCES_APK),
resourceDeps,
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.ANDROID_R_TXT),
- ResourceFilter.fromRuleContext(ruleContext),
+ ResourceFilterFactory.fromRuleContext(ruleContext),
ruleContext.getExpander().withDataLocations().tokenized("nocompress_extensions"),
ruleContext.attributes().get("crunch_png", Type.BOOLEAN),
ProguardHelper.getProguardConfigArtifact(ruleContext, ""),
@@ -907,7 +907,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
.withPrimary(resourceApk.getPrimaryResource())
.withDependencies(resourceApk.getResourceDependencies())
.setTargetAaptVersion(AndroidAaptVersion.chooseTargetAaptVersion(ruleContext))
- .setResourceFilter(ResourceFilter.fromRuleContext(ruleContext))
+ .setResourceFilterFactory(ResourceFilterFactory.fromRuleContext(ruleContext))
.setUncompressedExtensions(
ruleContext.getExpander().withDataLocations().tokenized("nocompress_extensions"))
.build();
@@ -1502,7 +1502,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory {
public static boolean shouldRegenerate(RuleContext ruleContext,
ResourceDependencies resourceDeps) {
return Iterables.size(resourceDeps.getResourceContainers()) > 1
- || ResourceFilter.hasFilters(ruleContext)
+ || ResourceFilterFactory.hasFilters(ruleContext)
|| ruleContext.attributes().isAttributeValueExplicitlySpecified("nocompress_extensions");
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
index 5f31cc2791..54b632bcbd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinaryOnlyRule.java
@@ -46,7 +46,7 @@ public final class AndroidBinaryOnlyRule implements RuleDefinition {
A list of resource configuration filters, such 'en' that will limit the resources in the
apk to only the ones in the 'en' configuration.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME, STRING_LIST))
+ .add(attr(ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME, STRING_LIST))
/* <!-- #BLAZE_RULE(android_binary).ATTRIBUTE(shrink_resources) -->
Whether to perform resource shrinking. Resources that are not used by the binary will be
removed from the APK. This is only supported for rules using local resources (i.e. the
@@ -78,7 +78,7 @@ public final class AndroidBinaryOnlyRule implements RuleDefinition {
section will also be added to the manifest if it does not already contain a superset
listing.
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */
- .add(attr(ResourceFilter.DENSITIES_NAME, STRING_LIST))
+ .add(attr(ResourceFilterFactory.DENSITIES_NAME, STRING_LIST))
.add(attr("$android_manifest_merge_tool", LABEL)
.cfg(HOST)
.exec()
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
index ddca5e41eb..0e7f3d85ac 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java
@@ -560,7 +560,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
@Option(
name = "experimental_android_resource_filtering_method",
- converter = ResourceFilter.Converter.class,
+ converter = ResourceFilterFactory.Converter.class,
defaultValue = "filter_in_execution",
documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
effectTags = {OptionEffectTag.UNKNOWN},
@@ -575,10 +575,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
+ "in analysis, possibly making the build even faster (especially in systems that "
+ "do not cache the results of those dependencies)."
)
- // The ResourceFilter object holds the filtering behavior as well as settings for which
+ // The ResourceFilterFactory object holds the filtering behavior as well as settings for which
// resources should be filtered. The filtering behavior is set from the command line, but the
// other settings default to empty and are set or modified via dynamic configuration.
- public ResourceFilter resourceFilter;
+ public ResourceFilterFactory resourceFilterFactory;
@Option(
name = "experimental_android_compress_java_resources",
@@ -732,7 +732,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
private final AndroidManifestMerger manifestMerger;
private final ApkSigningMethod apkSigningMethod;
private final boolean useSingleJarApkBuilder;
- private final ResourceFilter resourceFilter;
+ private final ResourceFilterFactory resourceFilterFactory;
private final boolean compressJavaResources;
private final boolean includeLibraryResourceJars;
private final boolean exportsManifestDefault;
@@ -769,7 +769,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
this.apkSigningMethod = options.apkSigningMethod;
this.useSingleJarApkBuilder = options.useSingleJarApkBuilder;
this.useRexToCompressDexFiles = options.useRexToCompressDexFiles;
- this.resourceFilter = options.resourceFilter;
+ this.resourceFilterFactory = options.resourceFilterFactory;
this.compressJavaResources = options.compressJavaResources;
this.includeLibraryResourceJars = options.includeLibraryResourceJars;
this.exportsManifestDefault = options.exportsManifestDefault;
@@ -894,8 +894,8 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
return useSingleJarApkBuilder;
}
- public ResourceFilter getResourceFilter() {
- return resourceFilter;
+ public ResourceFilterFactory getResourceFilterFactory() {
+ return resourceFilterFactory;
}
public boolean useParallelDex2Oat() {
@@ -943,7 +943,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
public String getOutputDirectoryName() {
// We expect this value to be null most of the time - it will only become non-null when a
// dynamically configured transition changes the configuration's resource filter object.
- String resourceFilterSuffix = resourceFilter.getOutputDirectorySuffix();
+ String resourceFilterSuffix = resourceFilterFactory.getOutputDirectorySuffix();
if (configurationDistinguisher.suffix == null) {
return resourceFilterSuffix;
@@ -959,7 +959,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment {
@Nullable
@Override
public PatchTransition topLevelConfigurationHook(Target toTarget) {
- return resourceFilter.getTopLevelPatchTransition(
+ return resourceFilterFactory.getTopLevelPatchTransition(
toTarget.getAssociatedRule().getRuleClass(),
AggregatingAttributeMapper.of(toTarget.getAssociatedRule()));
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
index d5d05cc0ae..c9228d3079 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidResourcesProcessorBuilder.java
@@ -71,7 +71,7 @@ public class AndroidResourcesProcessorBuilder {
private Artifact rTxtOut;
private Artifact sourceJarOut;
private boolean debug = false;
- private ResourceFilter resourceFilter;
+ private ResourceFilterFactory resourceFilterFactory;
private List<String> uncompressedExtensions = Collections.emptyList();
private Artifact apkOut;
private final AndroidSdkProvider sdk;
@@ -101,7 +101,7 @@ public class AndroidResourcesProcessorBuilder {
this.sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
this.ruleContext = ruleContext;
this.spawnActionBuilder = new SpawnAction.Builder();
- this.resourceFilter = ResourceFilter.empty(ruleContext);
+ this.resourceFilterFactory = ResourceFilterFactory.empty(ruleContext);
}
/**
@@ -139,9 +139,9 @@ public class AndroidResourcesProcessorBuilder {
return this;
}
- public AndroidResourcesProcessorBuilder setResourceFilter(
- ResourceFilter resourceFilter) {
- this.resourceFilter = resourceFilter;
+ public AndroidResourcesProcessorBuilder setResourceFilterFactory(
+ ResourceFilterFactory resourceFilterFactory) {
+ this.resourceFilterFactory = resourceFilterFactory;
return this;
}
@@ -439,21 +439,22 @@ public class AndroidResourcesProcessorBuilder {
builder.addExecPath("--packagePath", apkOut);
outs.add(apkOut);
}
- if (resourceFilter.hasConfigurationFilters()) {
+ if (resourceFilterFactory.hasConfigurationFilters()) {
// Always pass filters to aapt, even if we filtered in analysis, since aapt is stricter and
// might remove resources that we previously accepted.
- builder.add("--resourceConfigs", resourceFilter.getConfigurationFilterString());
+ builder.add("--resourceConfigs", resourceFilterFactory.getConfigurationFilterString());
}
- if (resourceFilter.hasDensities()) {
+ if (resourceFilterFactory.hasDensities()) {
// If we did not filter by density in analysis, filter in execution. Otherwise, don't filter
// in execution, but still pass the densities so they can be added to the manifest.
- if (resourceFilter.isPrefiltering()) {
- builder.add("--densitiesForManifest", resourceFilter.getDensityString());
+ if (resourceFilterFactory.isPrefiltering()) {
+ builder.add("--densitiesForManifest", resourceFilterFactory.getDensityString());
} else {
- builder.add("--densities", resourceFilter.getDensityString());
+ builder.add("--densities", resourceFilterFactory.getDensityString());
}
}
- ImmutableList<String> filteredResources = resourceFilter.getResourcesToIgnoreInExecution();
+ ImmutableList<String> filteredResources =
+ resourceFilterFactory.getResourcesToIgnoreInExecution();
if (!filteredResources.isEmpty()) {
builder.addAll("--prefilteredResources", VectorArg.join(",").each(filteredResources));
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
index c832717eb5..d0bac081e9 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidRuleClasses.java
@@ -289,10 +289,9 @@ public final class AndroidRuleClasses {
}
/**
- * Turns off dynamic resource filtering for non-Android targets. This prevents unnecessary
- * build graph bloat. For example, there's no point analyzing distinct cc_library targets for
- * different resource filter configurations because cc_library semantics doesn't care about
- * filters.
+ * Turns off dynamic resource filtering for non-Android targets. This prevents unnecessary build
+ * graph bloat. For example, there's no point analyzing distinct cc_library targets for different
+ * resource filter configurations because cc_library semantics doesn't care about filters.
*/
public static final RuleTransitionFactory REMOVE_DYNAMIC_RESOURCE_FILTERING =
new RuleTransitionFactory() {
@@ -303,7 +302,8 @@ public final class AndroidRuleClasses {
@Override
public Attribute.Transition buildTransitionFor(Rule depRule) {
return keepFilterRuleClasses.contains(depRule.getRuleClass())
- ? null : ResourceFilter.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION;
+ ? null
+ : ResourceFilterFactory.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION;
}
};
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
index e7b338e8bb..079cc6c496 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java
@@ -345,8 +345,9 @@ public final class ApplicationManifest {
throws InterruptedException, RuleErrorException {
// Filter the resources during analysis to prevent processing of dependencies on unwanted
// resources during execution.
- ResourceFilter resourceFilter = ResourceFilter.fromRuleContext(ruleContext);
- resourceDeps = resourceDeps.filter(ruleContext, resourceFilter);
+ ResourceFilterFactory resourceFilterFactory =
+ ResourceFilterFactory.fromRuleContext(ruleContext);
+ resourceDeps = resourceDeps.filter(ruleContext, resourceFilterFactory);
LocalResourceContainer data =
LocalResourceContainer.forAssetsAndResources(
@@ -354,7 +355,7 @@ public final class ApplicationManifest {
"assets",
AndroidCommon.getAssetDir(ruleContext),
"local_resource_files")
- .filter(ruleContext, resourceFilter);
+ .filter(ruleContext, resourceFilterFactory);
// Now that the LocalResourceContainer has been filtered, we can build a filtered resource
// container from it.
@@ -377,7 +378,7 @@ public final class ApplicationManifest {
new AndroidResourcesProcessorBuilder(ruleContext)
.setLibrary(false)
.setApkOut(resourceContainer.getApk())
- .setResourceFilter(resourceFilter)
+ .setResourceFilterFactory(resourceFilterFactory)
.setUncompressedExtensions(ImmutableList.of())
.setCrunchPng(true)
.setJavaPackage(resourceContainer.getJavaPackage())
@@ -427,9 +428,10 @@ public final class ApplicationManifest {
throws InterruptedException, RuleErrorException {
// Filter the resources during analysis to prevent processing of dependencies on unwanted
// resources during execution.
- ResourceFilter resourceFilter = ResourceFilter.fromRuleContext(ruleContext);
- data = data.filter(ruleContext, resourceFilter);
- resourceDeps = resourceDeps.filter(ruleContext, resourceFilter);
+ ResourceFilterFactory resourceFilterFactory =
+ ResourceFilterFactory.fromRuleContext(ruleContext);
+ data = data.filter(ruleContext, resourceFilterFactory);
+ resourceDeps = resourceDeps.filter(ruleContext, resourceFilterFactory);
// Now that the LocalResourceContainer has been filtered, we can build a filtered resource
// container from it.
@@ -524,9 +526,10 @@ public final class ApplicationManifest {
// Filter the resources during analysis to prevent processing of dependencies on unwanted
// resources during execution.
- ResourceFilter resourceFilter = ResourceFilter.fromRuleContext(ruleContext);
- data = data.filter(ruleContext, resourceFilter);
- resourceDeps = resourceDeps.filter(ruleContext, resourceFilter);
+ ResourceFilterFactory resourceFilterFactory =
+ ResourceFilterFactory.fromRuleContext(ruleContext);
+ data = data.filter(ruleContext, resourceFilterFactory);
+ resourceDeps = resourceDeps.filter(ruleContext, resourceFilterFactory);
// Now that the LocalResourceContainer has been filtered, we can build a filtered resource
// container from it.
@@ -548,7 +551,7 @@ public final class ApplicationManifest {
new AndroidResourcesProcessorBuilder(ruleContext)
.setLibrary(false)
.setApkOut(resourceContainer.getApk())
- .setResourceFilter(resourceFilter)
+ .setResourceFilterFactory(resourceFilterFactory)
.setUncompressedExtensions(uncompressedExtensions)
.setCrunchPng(crunchPng)
.setJavaPackage(resourceContainer.getJavaPackage())
@@ -586,7 +589,7 @@ public final class ApplicationManifest {
Artifact resourceApk,
ResourceDependencies resourceDeps,
@Nullable Artifact rTxt,
- ResourceFilter resourceFilter,
+ ResourceFilterFactory resourceFilterFactory,
List<String> uncompressedExtensions,
boolean crunchPng,
Artifact proguardCfg,
@@ -600,9 +603,9 @@ public final class ApplicationManifest {
LocalResourceContainer data =
LocalResourceContainer.forAssetsAndResources(
ruleContext, "assets", AndroidCommon.getAssetDir(ruleContext), "resource_files")
- .filter(ruleContext, resourceFilter);
+ .filter(ruleContext, resourceFilterFactory);
- resourceDeps = resourceDeps.filter(ruleContext, resourceFilter);
+ resourceDeps = resourceDeps.filter(ruleContext, resourceFilterFactory);
// Now that the LocalResourceContainer has been filtered, we can build a filtered resource
// container from it.
@@ -625,7 +628,7 @@ public final class ApplicationManifest {
new AndroidResourcesProcessorBuilder(ruleContext)
.setLibrary(false)
.setApkOut(resourceContainer.getApk())
- .setResourceFilter(resourceFilter)
+ .setResourceFilterFactory(resourceFilterFactory)
.setUncompressedExtensions(uncompressedExtensions)
.setCrunchPng(crunchPng)
.setJavaPackage(resourceContainer.getJavaPackage())
@@ -676,12 +679,13 @@ public final class ApplicationManifest {
throws InterruptedException, RuleErrorException {
// Filter the resources during analysis to prevent processing of dependencies on unwanted
// resources during execution.
- ResourceFilter resourceFilter = ResourceFilter.fromRuleContext(ruleContext);
+ ResourceFilterFactory resourceFilterFactory =
+ ResourceFilterFactory.fromRuleContext(ruleContext);
LocalResourceContainer data =
LocalResourceContainer.forAssetsAndResources(
ruleContext, "assets", AndroidCommon.getAssetDir(ruleContext), "resource_files")
- .filter(ruleContext, resourceFilter);
- resourceDeps = resourceDeps.filter(ruleContext, resourceFilter);
+ .filter(ruleContext, resourceFilterFactory);
+ resourceDeps = resourceDeps.filter(ruleContext, resourceFilterFactory);
ResourceContainer.Builder builder =
ResourceContainer.builderFromRule(ruleContext)
.setAssetsAndResourcesFrom(data)
@@ -884,7 +888,8 @@ public final class ApplicationManifest {
new AndroidAaptActionHelper(
ruleContext, getManifest(), Lists.newArrayList(resourceContainers));
- ResourceFilter resourceFilter = ResourceFilter.fromRuleContext(ruleContext);
+ ResourceFilterFactory resourceFilterFactory =
+ ResourceFilterFactory.fromRuleContext(ruleContext);
List<String> uncompressedExtensions;
if (ruleContext.getRule().isAttrDefined(
@@ -904,8 +909,9 @@ public final class ApplicationManifest {
for (String extension : uncompressedExtensions) {
additionalAaptOpts.add("-0").add(extension);
}
- if (resourceFilter.hasConfigurationFilters() && !resourceFilter.isPrefiltering()) {
- additionalAaptOpts.add("-c").add(resourceFilter.getConfigurationFilterString());
+ if (resourceFilterFactory.hasConfigurationFilters()
+ && !resourceFilterFactory.isPrefiltering()) {
+ additionalAaptOpts.add("-c").add(resourceFilterFactory.getConfigurationFilterString());
}
Artifact javaSourcesJar = null;
@@ -921,7 +927,7 @@ public final class ApplicationManifest {
resourceApk,
resourceContainer.getRenameManifestPackage(),
additionalAaptOpts.build(),
- resourceFilter.getDensities());
+ resourceFilterFactory.getDensities());
ResourceContainer updatedResources =
resourceContainer
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java
index 53dd15100e..89f38bbeee 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/LocalResourceContainer.java
@@ -378,12 +378,13 @@ public final class LocalResourceContainer {
* Filters this object.
*
* @return a new {@link LocalResourceContainer} with resources filtered by the passed {@link
- * ResourceFilter}, or this object if no resources should be filtered.
+ * ResourceFilterFactory}, or this object if no resources should be filtered.
*/
public LocalResourceContainer filter(
- RuleErrorConsumer ruleErrorConsumer, ResourceFilter resourceFilter)
+ RuleErrorConsumer ruleErrorConsumer, ResourceFilterFactory resourceFilterFactory)
throws RuleErrorException {
- ImmutableList<Artifact> filteredResources = resourceFilter.filter(ruleErrorConsumer, resources);
+ ImmutableList<Artifact> filteredResources = resourceFilterFactory
+ .filter(ruleErrorConsumer, resources);
if (filteredResources.size() == resources.size()) {
// Nothing was filtered out
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java
index ab6004415d..ce218c3236 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceContainer.java
@@ -177,7 +177,8 @@ public abstract class ResourceContainer {
* Returns a copy of this container with filtered resources, or the original if no resources
* should be filtered. The original container is unchanged.
*/
- public ResourceContainer filter(RuleErrorConsumer ruleErrorConsumer, ResourceFilter filter) {
+ public ResourceContainer filter(
+ RuleErrorConsumer ruleErrorConsumer, ResourceFilterFactory filter) {
ImmutableList<Artifact> filteredResources = filter.filter(ruleErrorConsumer, getResources());
if (filteredResources.size() == getResources().size()) {
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
index 009d7c2fa8..cb9a3dd971 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceDependencies.java
@@ -356,7 +356,8 @@ public final class ResourceDependencies {
* Returns a copy of this instance with filtered resources. The original object is unchanged, and
* may be returned if no filtering should be done.
*/
- public ResourceDependencies filter(RuleErrorConsumer ruleErrorConsumer, ResourceFilter filter) {
+ public ResourceDependencies filter(
+ RuleErrorConsumer ruleErrorConsumer, ResourceFilterFactory filter) {
NestedSet<Artifact> filteredResources =
filter.filterDependencies(ruleErrorConsumer, transitiveResources);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactory.java
index 93e15c5735..c252c94204 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilter.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactory.java
@@ -56,7 +56,7 @@ import javax.annotation.Nullable;
* and {@link #hashCode()} methods. Failure to do so isn't just bad practice; it could seriously
* interfere with Bazel's caching performance.
*/
-public class ResourceFilter {
+public class ResourceFilterFactory {
public static final String RESOURCE_CONFIGURATION_FILTERS_NAME = "resource_configuration_filters";
public static final String DENSITIES_NAME = "densities";
@@ -127,7 +127,7 @@ public class ResourceFilter {
* @param filterBehavior the behavior of this filter.
*/
@VisibleForTesting
- ResourceFilter(
+ ResourceFilterFactory(
ImmutableList<String> configFilters,
ImmutableList<String> densities,
FilterBehavior filterBehavior) {
@@ -194,12 +194,12 @@ public class ResourceFilter {
}
}
- // Create a sorted copy so that ResourceFilter objects with the same filters are treated the
+ // Create a sorted copy so that ResourceFilterFactory objects with the same filters are treated
// the same regardless of the ordering of those filters.
return ImmutableList.sortedCopyOf(builder.build());
}
- static ResourceFilter fromRuleContext(RuleContext ruleContext) {
+ static ResourceFilterFactory fromRuleContext(RuleContext ruleContext) {
Preconditions.checkNotNull(ruleContext);
if (!ruleContext.isLegalFragment(AndroidConfiguration.class)) {
@@ -207,35 +207,35 @@ public class ResourceFilter {
}
return forBaseAndAttrs(
- ruleContext.getFragment(AndroidConfiguration.class).getResourceFilter(),
+ ruleContext.getFragment(AndroidConfiguration.class).getResourceFilterFactory(),
ruleContext.attributes());
}
@VisibleForTesting
- static ResourceFilter forBaseAndAttrs(ResourceFilter base, AttributeMap attrs) {
+ static ResourceFilterFactory forBaseAndAttrs(ResourceFilterFactory base, AttributeMap attrs) {
return base.withAttrsFrom(attrs);
}
/**
- * Creates a new {@link ResourceFilter} based on this object's properties, overridden by any
- * filters specified in the passed {@link AttributeMap}.
+ * Creates a new {@link ResourceFilterFactory} based on this object's properties, overridden by
+ * any filters specified in the passed {@link AttributeMap}.
*
* <p>A new object will always be returned, as returning the same object across multiple rules (as
* would be done with {@link FilterBehavior#FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION}) causes
* problems.
*/
- ResourceFilter withAttrsFrom(AttributeMap attrs) {
+ ResourceFilterFactory withAttrsFrom(AttributeMap attrs) {
if (!hasFilters(attrs)) {
- return new ResourceFilter(configFilters, densities, filterBehavior);
+ return new ResourceFilterFactory(configFilters, densities, filterBehavior);
}
- return new ResourceFilter(
+ return new ResourceFilterFactory(
extractFilters(attrs, RESOURCE_CONFIGURATION_FILTERS_NAME),
extractFilters(attrs, DENSITIES_NAME),
filterBehavior);
}
- ResourceFilter withoutDynamicConfiguration() {
+ ResourceFilterFactory withoutDynamicConfiguration() {
if (!usesDynamicConfiguration()) {
return this;
}
@@ -384,13 +384,13 @@ public class ResourceFilter {
}
}
- static ResourceFilter empty(RuleContext ruleContext) {
+ static ResourceFilterFactory empty(RuleContext ruleContext) {
return empty(fromRuleContext(ruleContext).filterBehavior);
}
@VisibleForTesting
- static ResourceFilter empty(FilterBehavior filterBehavior) {
- return new ResourceFilter(
+ static ResourceFilterFactory empty(FilterBehavior filterBehavior) {
+ return new ResourceFilterFactory(
ImmutableList.<String>of(), ImmutableList.<String>of(), filterBehavior);
}
@@ -753,16 +753,16 @@ public class ResourceFilter {
/**
* {@inheritDoc}
*
- * <p>ResourceFilter requires an accurately overridden equals() method to work correctly with
- * Bazel's caching and dynamic configuration.
+ * <p>ResourceFilterFactory requires an accurately overridden equals() method to work correctly
+ * with Bazel's caching and dynamic configuration.
*/
@Override
public boolean equals(Object object) {
- if (!(object instanceof ResourceFilter)) {
+ if (!(object instanceof ResourceFilterFactory)) {
return false;
}
- ResourceFilter other = (ResourceFilter) object;
+ ResourceFilterFactory other = (ResourceFilterFactory) object;
return filterBehavior == other.filterBehavior
&& configFilters.equals(other.configFilters)
@@ -776,17 +776,17 @@ public class ResourceFilter {
}
/**
- * Converts command line settings for the filter behavior into an empty {@link ResourceFilter}
- * object.
+ * Converts command line settings for the filter behavior into an empty {@link
+ * ResourceFilterFactory} object.
*/
public static final class Converter
- implements com.google.devtools.common.options.Converter<ResourceFilter> {
+ implements com.google.devtools.common.options.Converter<ResourceFilterFactory> {
private final FilterBehavior.Converter filterEnumConverter = new FilterBehavior.Converter();
@Override
- public ResourceFilter convert(String input) throws OptionsParsingException {
+ public ResourceFilterFactory convert(String input) throws OptionsParsingException {
- return ResourceFilter.empty(filterEnumConverter.convert(input));
+ return empty(filterEnumConverter.convert(input));
}
@Override
@@ -804,7 +804,7 @@ public class ResourceFilter {
return null;
}
- if (!ruleClass.equals("android_binary") || !ResourceFilter.hasFilters(attrs)) {
+ if (!ruleClass.equals("android_binary") || !hasFilters(attrs)) {
// This target doesn't specify any filtering settings, so dynamically configured resource
// filtering would be a waste of time.
// If the target's dependencies include android_binary targets, those dependencies might
@@ -825,8 +825,8 @@ public class ResourceFilter {
private static final class RemoveDynamicallyConfiguredResourceFilteringTransition
extends BaseDynamicallyConfiguredResourceFilteringTransition {
@Override
- ResourceFilter getNewResourceFilter(ResourceFilter oldResourceFilter) {
- return oldResourceFilter.withoutDynamicConfiguration();
+ ResourceFilterFactory getNewResourceFilter(ResourceFilterFactory oldResourceFilterFactory) {
+ return oldResourceFilterFactory.withoutDynamicConfiguration();
}
}
@@ -840,8 +840,8 @@ public class ResourceFilter {
}
@Override
- ResourceFilter getNewResourceFilter(ResourceFilter oldResourceFilter) {
- return oldResourceFilter.withAttrsFrom(attrs);
+ ResourceFilterFactory getNewResourceFilter(ResourceFilterFactory oldResourceFilterFactory) {
+ return oldResourceFilterFactory.withAttrsFrom(attrs);
}
@VisibleForTesting
@@ -858,11 +858,13 @@ public class ResourceFilter {
AndroidConfiguration.Options androidOptions =
newOptions.get(AndroidConfiguration.Options.class);
- androidOptions.resourceFilter = getNewResourceFilter(androidOptions.resourceFilter);
+ androidOptions.resourceFilterFactory =
+ getNewResourceFilter(androidOptions.resourceFilterFactory);
return newOptions;
}
- abstract ResourceFilter getNewResourceFilter(ResourceFilter oldResourceFilter);
+ abstract ResourceFilterFactory getNewResourceFilter(
+ ResourceFilterFactory oldResourceFilterFactory);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
index 4b7eaf48f5..8844451581 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ResourceShrinkerActionBuilder.java
@@ -51,14 +51,14 @@ public class ResourceShrinkerActionBuilder {
private final AndroidSdkProvider sdk;
private List<String> uncompressedExtensions = Collections.emptyList();
- private ResourceFilter resourceFilter;
+ private ResourceFilterFactory resourceFilterFactory;
/** @param ruleContext The RuleContext of the owning rule. */
public ResourceShrinkerActionBuilder(RuleContext ruleContext) throws RuleErrorException {
this.ruleContext = ruleContext;
this.spawnActionBuilder = new SpawnAction.Builder();
this.sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
- this.resourceFilter = ResourceFilter.empty(ruleContext);
+ this.resourceFilterFactory = ResourceFilterFactory.empty(ruleContext);
}
public ResourceShrinkerActionBuilder setUncompressedExtensions(
@@ -67,9 +67,10 @@ public class ResourceShrinkerActionBuilder {
return this;
}
- /** @param resourceFilter The filters to apply to the resources. */
- public ResourceShrinkerActionBuilder setResourceFilter(ResourceFilter resourceFilter) {
- this.resourceFilter = resourceFilter;
+ /** @param resourceFilterFactory The filters to apply to the resources. */
+ public ResourceShrinkerActionBuilder setResourceFilterFactory(
+ ResourceFilterFactory resourceFilterFactory) {
+ this.resourceFilterFactory = resourceFilterFactory;
return this;
}
@@ -181,8 +182,8 @@ public class ResourceShrinkerActionBuilder {
if (ruleContext.getConfiguration().getCompilationMode() != CompilationMode.OPT) {
commandLine.add("--debug");
}
- if (resourceFilter.hasConfigurationFilters()) {
- commandLine.add("--resourceConfigs", resourceFilter.getConfigurationFilterString());
+ if (resourceFilterFactory.hasConfigurationFilters()) {
+ commandLine.add("--resourceConfigs", resourceFilterFactory.getConfigurationFilterString());
}
checkNotNull(resourceFilesZip);