aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java4
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/BUILD4
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/LocalResourceContainerTest.java8
-rw-r--r--src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java (renamed from src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterTest.java)136
15 files changed, 192 insertions, 165 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);
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
index 712de1084b..0960797488 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java
@@ -1444,8 +1444,8 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase {
// Validate resource filters are not passed to execution, since they were applied in analysis
List<String> args = resourceArguments(directResources);
assertThat(args)
- .doesNotContain(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
- assertThat(args).doesNotContain(ResourceFilter.DENSITIES_NAME);
+ .doesNotContain(ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ assertThat(args).doesNotContain(ResourceFilterFactory.DENSITIES_NAME);
if (densities.isEmpty()) {
assertThat(args).doesNotContain("--densitiesForManifest");
} else {
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
index 8549fcbc81..2678afa39f 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/BUILD
@@ -86,8 +86,8 @@ java_test(
)
java_test(
- name = "ResourceFilterTest",
- srcs = ["ResourceFilterTest.java"],
+ name = "ResourceFilterFactoryTest",
+ srcs = ["ResourceFilterFactoryTest.java"],
deps = [
":ResourceTestBase",
"//src/main/java/com/google/devtools/build/lib:android-rules",
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/LocalResourceContainerTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/LocalResourceContainerTest.java
index 302ff4afdc..f6306cb3fd 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/LocalResourceContainerTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/LocalResourceContainerTest.java
@@ -117,8 +117,8 @@ public class LocalResourceContainerTest extends ResourceTestBase {
private void assertFilter(
ImmutableList<Artifact> unfilteredResources, ImmutableList<Artifact> filteredResources)
throws Exception {
- ResourceFilter filter =
- new FakeResourceFilter(ImmutableMap.of(unfilteredResources, filteredResources));
+ ResourceFilterFactory filter =
+ new FakeResourceFilterFactory(ImmutableMap.of(unfilteredResources, filteredResources));
ImmutableList<PathFragment> unfilteredResourcesRoots = getResourceRoots(unfilteredResources);
LocalResourceContainer unfiltered =
new LocalResourceContainer(
@@ -146,10 +146,10 @@ public class LocalResourceContainerTest extends ResourceTestBase {
}
}
- private static class FakeResourceFilter extends ResourceFilter {
+ private static class FakeResourceFilterFactory extends ResourceFilterFactory {
private final Map<ImmutableList<Artifact>, ImmutableList<Artifact>> filterInputToOutputMap;
- FakeResourceFilter(
+ FakeResourceFilterFactory(
Map<ImmutableList<Artifact>, ImmutableList<Artifact>> filterInputToOutputMap) {
super(
ImmutableList.<String>of(),
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java
index aff6556fae..67ec77a7b5 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceFilterFactoryTest.java
@@ -25,8 +25,8 @@ import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.packages.AttributeMap;
-import com.google.devtools.build.lib.rules.android.ResourceFilter.AddDynamicallyConfiguredResourceFilteringTransition;
-import com.google.devtools.build.lib.rules.android.ResourceFilter.FilterBehavior;
+import com.google.devtools.build.lib.rules.android.ResourceFilterFactory.AddDynamicallyConfiguredResourceFilteringTransition;
+import com.google.devtools.build.lib.rules.android.ResourceFilterFactory.FilterBehavior;
import com.google.devtools.build.lib.testutil.FakeAttributeMapper;
import java.util.ArrayList;
import java.util.List;
@@ -34,11 +34,11 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
-/** Tests {@link ResourceFilter}. */
+/** Tests {@link ResourceFilterFactory}. */
// TODO(asteinb): Test behavior not already covered in this test, and, when practical, move unit
// tests currently located in {@link AndroidBinaryTest} to this class instead.
@RunWith(JUnit4.class)
-public class ResourceFilterTest extends ResourceTestBase {
+public class ResourceFilterFactoryTest extends ResourceTestBase {
/**
* Tests that, when filtering with dynamic configuration, dependencies are not filtered (since
@@ -145,7 +145,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -160,7 +160,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -175,7 +175,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -190,7 +190,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -210,7 +210,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -227,7 +227,8 @@ public class ResourceFilterTest extends ResourceTestBase {
"values-sr-Latn/foo.xml",
"values-sr-rLatn/foo.xml"));
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
}
@Test
@@ -242,7 +243,7 @@ public class ResourceFilterTest extends ResourceTestBase {
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.hasSize(1);
}
@@ -258,7 +259,8 @@ public class ResourceFilterTest extends ResourceTestBase {
"values-es-rUS/foo.xml",
"values-es-419/foo.xml"));
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
}
/**
@@ -279,29 +281,32 @@ public class ResourceFilterTest extends ResourceTestBase {
"When referring to locale qualifiers with regions, use of qualifier 'en_US' is"
+ " deprecated. Use 'en-rUS' instead.");
- ResourceFilter filter =
- new ResourceFilter(badQualifiers, ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
+ ResourceFilterFactory filter =
+ new ResourceFilterFactory(
+ badQualifiers, ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
filter.filter(errorConsumer, ImmutableList.of());
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.containsExactlyElementsIn(expectedWarnings);
errorConsumer.assertNoRuleWarnings();
// Filtering again with this filter should not produce additional warnings
filter.filter(errorConsumer, ImmutableList.of());
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
errorConsumer.assertNoRuleWarnings();
// Filtering with a new filter should produce warnings again, since it is working on a different
// target
filter =
- new ResourceFilter(badQualifiers, ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
+ new ResourceFilterFactory(
+ badQualifiers, ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
filter.filter(errorConsumer, ImmutableList.of());
assertThat(
errorConsumer.getAndClearAttributeWarnings(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME))
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME))
.containsExactlyElementsIn(expectedWarnings);
errorConsumer.assertNoRuleWarnings();
}
@@ -326,27 +331,30 @@ public class ResourceFilterTest extends ResourceTestBase {
"For resource folder values-es_US, when referring to locale qualifiers with regions, "
+ "use of qualifier 'es_US' is deprecated. Use 'es-rUS' instead.");
- ResourceFilter filter =
- new ResourceFilter(
+ ResourceFilterFactory filter =
+ new ResourceFilterFactory(
ImmutableList.of("en"), ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
filter.filter(errorConsumer, badResources);
assertThat(errorConsumer.getAndClearRuleWarnings()).containsExactlyElementsIn(expectedWarnings);
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
// Filtering again with this filter should not produce additional warnings
filter.filter(errorConsumer, badResources);
errorConsumer.assertNoRuleWarnings();
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
// Filtering with a new filter should produce warnings again, since it is working on a different
// target
filter =
- new ResourceFilter(
+ new ResourceFilterFactory(
ImmutableList.of("en"), ImmutableList.of(), FilterBehavior.FILTER_IN_ANALYSIS);
filter.filter(errorConsumer, badResources);
assertThat(errorConsumer.getAndClearRuleWarnings()).containsExactlyElementsIn(expectedWarnings);
- errorConsumer.assertNoAttributeWarnings(ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME);
+ errorConsumer.assertNoAttributeWarnings(
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME);
}
@Test
@@ -403,19 +411,19 @@ public class ResourceFilterTest extends ResourceTestBase {
ImmutableList<Artifact> allArtifacts =
ImmutableList.copyOf(Iterables.concat(expectedResources, unexpectedResources));
- ResourceFilter resourceFilter =
+ ResourceFilterFactory resourceFilterFactory =
makeResourceFilter(resourceConfigurationFilters, densities, filterBehavior);
- ImmutableList<Artifact> filtered = resourceFilter.filter(errorConsumer, allArtifacts);
+ ImmutableList<Artifact> filtered = resourceFilterFactory.filter(errorConsumer, allArtifacts);
assertThat(filtered).containsExactlyElementsIn(expectedResources).inOrder();
if (filterBehavior == FilterBehavior.FILTER_IN_ANALYSIS) {
- assertThat(resourceFilter.getResourcesToIgnoreInExecution())
+ assertThat(resourceFilterFactory.getResourcesToIgnoreInExecution())
.containsExactlyElementsIn(resourcesToDiscard);
} else {
// Either we are not filtering in analysis, or this target's dependencies were also filtered.
// In both cases, no resources should be ignored in execution.
- assertThat(resourceFilter.getResourcesToIgnoreInExecution()).isEmpty();
+ assertThat(resourceFilterFactory.getResourcesToIgnoreInExecution()).isEmpty();
}
}
@@ -487,9 +495,9 @@ public class ResourceFilterTest extends ResourceTestBase {
@Test
public void testGetOutputDirectoryDensitiesAreDifferentFromDensityConfigurationFilters()
throws Exception {
- ResourceFilter configurationFilter =
+ ResourceFilterFactory configurationFilter =
makeResourceFilter("hdpi", "", FilterBehavior.FILTER_IN_ANALYSIS);
- ResourceFilter densityFilter =
+ ResourceFilterFactory densityFilter =
makeResourceFilter("", "hdpi", FilterBehavior.FILTER_IN_ANALYSIS);
assertThat(configurationFilter.getOutputDirectorySuffix())
@@ -510,53 +518,55 @@ public class ResourceFilterTest extends ResourceTestBase {
*/
@Test
public void testGetOutputDirectoryDifferentlyOrdered() throws Exception {
- ResourceFilter first =
+ ResourceFilterFactory first =
makeResourceFilter("en,fr", "hdpi,ldpi", FilterBehavior.FILTER_IN_ANALYSIS);
- ResourceFilter second =
+ ResourceFilterFactory second =
makeResourceFilter("fr,en", "ldpi,hdpi", FilterBehavior.FILTER_IN_ANALYSIS);
assertThat(first.getOutputDirectorySuffix()).isEqualTo(second.getOutputDirectorySuffix());
}
@Test
public void testGetOutputDirectoryDuplicated() throws Exception {
- ResourceFilter duplicated =
+ ResourceFilterFactory duplicated =
makeResourceFilter("en,en", "hdpi,hdpi", FilterBehavior.FILTER_IN_ANALYSIS);
- ResourceFilter normal = makeResourceFilter("en", "hdpi", FilterBehavior.FILTER_IN_ANALYSIS);
+ ResourceFilterFactory normal =
+ makeResourceFilter("en", "hdpi", FilterBehavior.FILTER_IN_ANALYSIS);
assertThat(duplicated.getOutputDirectorySuffix()).isEqualTo(normal.getOutputDirectorySuffix());
}
- private ResourceFilter makeResourceFilter(
+ private ResourceFilterFactory makeResourceFilter(
String resourceConfigurationFilters, String densities, FilterBehavior behavior)
throws Exception {
return makeResourceFilter(
ImmutableList.of(resourceConfigurationFilters), ImmutableList.of(densities), behavior);
}
- private ResourceFilter makeResourceFilter(
+ private ResourceFilterFactory makeResourceFilter(
ImmutableList<String> resourceConfigurationFilters,
ImmutableList<String> densities,
FilterBehavior behavior)
throws Exception {
- return ResourceFilter.forBaseAndAttrs(
- ResourceFilter.empty(behavior), getAttributeMap(resourceConfigurationFilters, densities));
+ return ResourceFilterFactory.forBaseAndAttrs(
+ ResourceFilterFactory.empty(behavior),
+ getAttributeMap(resourceConfigurationFilters, densities));
}
private AttributeMap getAttributeMap(
ImmutableList<String> resourceConfigurationFilters, ImmutableList<String> densities) {
return FakeAttributeMapper.builder()
.withStringList(
- ResourceFilter.RESOURCE_CONFIGURATION_FILTERS_NAME, resourceConfigurationFilters)
- .withStringList(ResourceFilter.DENSITIES_NAME, densities)
+ ResourceFilterFactory.RESOURCE_CONFIGURATION_FILTERS_NAME, resourceConfigurationFilters)
+ .withStringList(ResourceFilterFactory.DENSITIES_NAME, densities)
.build();
}
@Test
public void testWithAttrsFromAttrsNotSpecified() throws Exception {
assertThat(
- ResourceFilter.forBaseAndAttrs(
- ResourceFilter.empty(FilterBehavior.FILTER_IN_ANALYSIS),
+ ResourceFilterFactory.forBaseAndAttrs(
+ ResourceFilterFactory.empty(FilterBehavior.FILTER_IN_ANALYSIS),
FakeAttributeMapper.empty())
.hasFilters())
.isFalse();
@@ -592,7 +602,8 @@ public class ResourceFilterTest extends ResourceTestBase {
ImmutableList.of("hdpi"),
FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION,
false))
- .isSameAs(ResourceFilter.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION);
+ .isSameAs(
+ ResourceFilterFactory.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION);
}
@Test
@@ -603,7 +614,8 @@ public class ResourceFilterTest extends ResourceTestBase {
ImmutableList.<String>of(),
FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION,
true))
- .isSameAs(ResourceFilter.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION);
+ .isSameAs(
+ ResourceFilterFactory.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION);
}
@Test
@@ -621,12 +633,13 @@ public class ResourceFilterTest extends ResourceTestBase {
AddDynamicallyConfiguredResourceFilteringTransition addTransition =
(AddDynamicallyConfiguredResourceFilteringTransition) transition;
- ResourceFilter foundFilter =
- ResourceFilter.forBaseAndAttrs(
- ResourceFilter.empty(FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION),
+ ResourceFilterFactory foundFilter =
+ ResourceFilterFactory.forBaseAndAttrs(
+ ResourceFilterFactory.empty(
+ FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION),
addTransition.getAttrs());
- ResourceFilter expectedFilter =
+ ResourceFilterFactory expectedFilter =
makeResourceFilter(
resourceConfigurationFilters,
densities,
@@ -650,8 +663,8 @@ public class ResourceFilterTest extends ResourceTestBase {
assertPatchTransition(
makeResourceFilter(
"en", "ldpi", FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION),
- ResourceFilter.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION,
- ResourceFilter.empty(FilterBehavior.FILTER_IN_ANALYSIS));
+ ResourceFilterFactory.REMOVE_DYNAMICALLY_CONFIGURED_RESOURCE_FILTERING_TRANSITION,
+ ResourceFilterFactory.empty(FilterBehavior.FILTER_IN_ANALYSIS));
}
@Test
@@ -662,8 +675,8 @@ public class ResourceFilterTest extends ResourceTestBase {
AttributeMap attrs = getAttributeMap(resourceConfigurationFilters, densities);
assertPatchTransition(
- ResourceFilter.empty(FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION),
- new ResourceFilter.AddDynamicallyConfiguredResourceFilteringTransition(attrs),
+ ResourceFilterFactory.empty(FilterBehavior.FILTER_IN_ANALYSIS_WITH_DYNAMIC_CONFIGURATION),
+ new ResourceFilterFactory.AddDynamicallyConfiguredResourceFilteringTransition(attrs),
makeResourceFilter(
resourceConfigurationFilters,
densities,
@@ -671,29 +684,30 @@ public class ResourceFilterTest extends ResourceTestBase {
}
private void assertPatchTransition(
- ResourceFilter oldResourceFilter,
+ ResourceFilterFactory oldResourceFilterFactory,
PatchTransition transition,
- ResourceFilter expectedNewResourceFilter) {
- AndroidConfiguration.Options oldAndroidOptions = getAndroidOptions(oldResourceFilter);
+ ResourceFilterFactory expectedNewResourceFilterFactory) {
+ AndroidConfiguration.Options oldAndroidOptions = getAndroidOptions(oldResourceFilterFactory);
BuildOptions oldOptions = BuildOptions.builder().add(oldAndroidOptions).build();
BuildOptions newOptions = transition.apply(oldOptions);
// The old options should not have been changed
- assertThat(oldAndroidOptions.resourceFilter).isSameAs(oldResourceFilter);
- assertThat(oldAndroidOptions).isEqualTo(getAndroidOptions(oldResourceFilter));
+ assertThat(oldAndroidOptions.resourceFilterFactory).isSameAs(oldResourceFilterFactory);
+ assertThat(oldAndroidOptions).isEqualTo(getAndroidOptions(oldResourceFilterFactory));
- // Besides the ResourceFilter, the new options should be the same as the old ones
+ // Besides the ResourceFilterFactory, the new options should be the same as the old ones
assertThat(newOptions.getOptions()).hasSize(1);
AndroidConfiguration.Options newAndroidOptions =
newOptions.get(AndroidConfiguration.Options.class);
- assertThat(newAndroidOptions).isEqualTo(getAndroidOptions(expectedNewResourceFilter));
+ assertThat(newAndroidOptions).isEqualTo(getAndroidOptions(expectedNewResourceFilterFactory));
}
- private AndroidConfiguration.Options getAndroidOptions(ResourceFilter resourceFilter) {
+ private AndroidConfiguration.Options getAndroidOptions(
+ ResourceFilterFactory resourceFilterFactory) {
AndroidConfiguration.Options androidOptions =
(AndroidConfiguration.Options) new AndroidConfiguration.Options().getDefault();
- androidOptions.resourceFilter = resourceFilter;
+ androidOptions.resourceFilterFactory = resourceFilterFactory;
return androidOptions;
}