Extract determining which manifest merger to use (legacy v android) to a separate method. This is so that android_local_test won't need access to the AndroidConfiguration fragment.
RELNOTES: None
@@ -205,19 +205,14 @@ public final class ApplicationManifest {
}
public ApplicationManifest mergeWith(RuleContext ruleContext, ResourceDependencies resourceDeps) {
- Map<Artifact, Label> mergeeManifests = getMergeeManifests(resourceDeps.getResources());
-
- boolean legacy = true;
- if (ruleContext.isLegalFragment(AndroidConfiguration.class)
- && ruleContext.getRule().isAttrDefined("manifest_merger", STRING)) {
- AndroidManifestMerger merger = AndroidManifestMerger.fromString(
- ruleContext.attributes().get("manifest_merger", STRING));
- if (merger == null) {
- merger = ruleContext.getFragment(AndroidConfiguration.class).getManifestMerger();
- }
- legacy = merger == AndroidManifestMerger.LEGACY;
+ boolean legacy = useLegacyMerging(ruleContext);
+ return mergeWith(ruleContext, resourceDeps, legacy);
}
+ public ApplicationManifest mergeWith(
+ RuleContext ruleContext, ResourceDependencies resourceDeps, boolean legacy) {
+ Map<Artifact, Label> mergeeManifests = getMergeeManifests(resourceDeps.getResources());
+
if (legacy) {
if (!mergeeManifests.isEmpty()) {
Artifact outputManifest = ruleContext.getUniqueDirectoryArtifact(
@@ -250,6 +245,20 @@ public final class ApplicationManifest {
return this;
}
+ private boolean useLegacyMerging(RuleContext ruleContext) {
+ boolean legacy = true;
+ if (ruleContext.isLegalFragment(AndroidConfiguration.class)
+ && ruleContext.getRule().isAttrDefined("manifest_merger", STRING)) {
+ AndroidManifestMerger merger = AndroidManifestMerger.fromString(
+ ruleContext.attributes().get("manifest_merger", STRING));
+ if (merger == null) {
+ merger = ruleContext.getFragment(AndroidConfiguration.class).getManifestMerger();
+ }
+ legacy = merger == AndroidManifestMerger.LEGACY;
+ }
+ return legacy;
+ }
+
private static Map<Artifact, Label> getMergeeManifests(
Iterable<ResourceContainer> resourceContainers) {
ImmutableSortedMap.Builder<Artifact, Label> builder =
