From 5a2dd7a2099cfa5a50b07d2b407e478043727472 Mon Sep 17 00:00:00 2001 From: Googler Date: Mon, 9 May 2016 19:22:27 +0000 Subject: [PATCH] Renaming nonOverwriting to combining resources. -- MOS_MIGRATED_REVID=121863653 --- .../build/android/AndroidDataMerger.java | 2 +- .../build/android/AndroidDataSerializer.java | 2 +- .../build/android/DataResourceXml.java | 14 ++--- .../build/android/KeyValueConsumers.java | 10 +-- .../build/android/ParsedAndroidData.java | 61 ++++++++++--------- .../build/android/XmlResourceValues.java | 4 +- .../xml/StyleableXmlResourceValue.java | 4 +- 7 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java index 3b39205ad8b15d..c9a11bbe3608c6 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataMerger.java @@ -340,7 +340,7 @@ UnwrittenMergedAndroidData merge( ParsedAndroidData.of( ImmutableSet.of(), ImmutableMap.copyOf(overwritableDeps), - direct.mergeNonOverwritable(transitive), + direct.mergeCombining(transitive), ImmutableMap.copyOf(assets))); } catch (IOException e) { throw new MergingException(e); diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java index 056909e2951a38..89120c3f24e099 100644 --- a/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java +++ b/src/tools/android/java/com/google/devtools/build/android/AndroidDataSerializer.java @@ -149,7 +149,7 @@ private void readEntriesSegment( resourceName, FullyQualifiedName.isOverwritable(resourceName) ? consumers.overwritingConsumer - : consumers.nonOverwritingConsumer); + : consumers.combiningConsumer); } else { keys.put(RelativeAssetPath.fromProto(protoKey, currentFileSystem), consumers.assetConsumer); } diff --git a/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java b/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java index 86223b25190609..a29c5897435438 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java +++ b/src/tools/android/java/com/google/devtools/build/android/DataResourceXml.java @@ -56,7 +56,7 @@ public class DataResourceXml implements DataResource { /** - * Parses xml resources from a Path to the provided overwritable and nonOverwritable collections. + * Parses xml resources from a Path to the provided overwritable and combining collections. * * This method is a bit tricky in the service of performance -- creating several collections and * merging them was more expensive than writing to mutable collections directly. @@ -65,7 +65,7 @@ public class DataResourceXml implements DataResource { * @param path The path to the xml resource to be parsed. * @param fqnFactory Used to create {@link FullyQualifiedName}s from the resource names. * @param overwritingConsumer A consumer for overwritable {@link DataResourceXml}s. - * @param nonOverwritingConsumer A consumer for nonoverwritable {@link DataResourceXml}s. + * @param combiningConsumer A consumer for combining {@link DataResourceXml}s. * @throws XMLStreamException Thrown with the resource format is invalid. * @throws FactoryConfigurationError Thrown with the {@link XMLInputFactory} is misconfigured. * @throws IOException Thrown when there is an error reading a file. @@ -75,7 +75,7 @@ public static void parse( Path path, Factory fqnFactory, KeyValueConsumer overwritingConsumer, - KeyValueConsumer nonOverwritingConsumer) + KeyValueConsumer combiningConsumer) throws XMLStreamException, FactoryConfigurationError, IOException { XMLEventReader eventReader = xmlInputFactory.createXMLEventReader(Files.newBufferedReader(path, StandardCharsets.UTF_8)); @@ -94,14 +94,14 @@ public static void parse( path + " contains an unrecognized resource type:" + start, start.getLocation()); } if (resourceType == DECLARE_STYLEABLE) { - // Styleables are special, as they produce multiple overwrite and non-overwrite values, + // Styleables are special, as they produce multiple overwrite and combining values, // so we let the value handle the assignments. XmlResourceValues.parseDeclareStyleable( - fqnFactory, path, overwritingConsumer, nonOverwritingConsumer, eventReader, start); + fqnFactory, path, overwritingConsumer, combiningConsumer, eventReader, start); } else { - // Of simple resources, only IDs are nonOverwriting. + // Of simple resources, only IDs are combining. KeyValueConsumer consumer = - resourceType == ID ? nonOverwritingConsumer : overwritingConsumer; + resourceType == ID ? combiningConsumer : overwritingConsumer; FullyQualifiedName key = fqnFactory.create(resourceType, XmlResourceValues.getElementName(start)); consumer.consume( diff --git a/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java b/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java index 86789b27b4fc96..63b0a3a036ccba 100644 --- a/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java +++ b/src/tools/android/java/com/google/devtools/build/android/KeyValueConsumers.java @@ -23,21 +23,21 @@ class KeyValueConsumers { static KeyValueConsumers of( KeyValueConsumer overwritingConsumer, - KeyValueConsumer nonOverwritingConsumer, + KeyValueConsumer combiningConsumer, KeyValueConsumer assetConsumer) { - return new KeyValueConsumers(overwritingConsumer, nonOverwritingConsumer, assetConsumer); + return new KeyValueConsumers(overwritingConsumer, combiningConsumer, assetConsumer); } final KeyValueConsumer overwritingConsumer; - final KeyValueConsumer nonOverwritingConsumer; + final KeyValueConsumer combiningConsumer; final KeyValueConsumer assetConsumer; private KeyValueConsumers( KeyValueConsumer overwritingConsumer, - KeyValueConsumer nonOverwritingConsumer, + KeyValueConsumer combiningConsumer, KeyValueConsumer assetConsumer) { this.overwritingConsumer = overwritingConsumer; - this.nonOverwritingConsumer = nonOverwritingConsumer; + this.combiningConsumer = combiningConsumer; this.assetConsumer = assetConsumer; } } diff --git a/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java index 06290876af4c95..6730545908d7df 100644 --- a/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/ParsedAndroidData.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.devtools.build.android.xml.StyleableXmlResourceValue; import com.android.ide.common.res2.MergingException; @@ -54,28 +55,28 @@ public class ParsedAndroidData { static class Builder { private final Map overwritingResources; - private final Map nonOverwritingResources; + private final Map combiningResources; private final Map assets; private final Set conflicts; private final List errors = new ArrayList<>(); public Builder( Map overwritingResources, - Map nonOverwritingResources, + Map combiningResources, Map assets, Set conflicts) { this.overwritingResources = overwritingResources; - this.nonOverwritingResources = nonOverwritingResources; + this.combiningResources = combiningResources; this.assets = assets; this.conflicts = conflicts; } static Builder newBuilder() { final Map overwritingResources = new LinkedHashMap<>(); - final Map nonOverwritingResources = new LinkedHashMap<>(); + final Map combiningResources = new LinkedHashMap<>(); final Map assets = new LinkedHashMap<>(); final Set conflicts = new LinkedHashSet<>(); - return new Builder(overwritingResources, nonOverwritingResources, assets, conflicts); + return new Builder(overwritingResources, combiningResources, assets, conflicts); } private void checkForErrors() throws MergingException { @@ -93,14 +94,14 @@ ParsedAndroidData build() throws MergingException { return ParsedAndroidData.of( ImmutableSet.copyOf(conflicts), ImmutableMap.copyOf(overwritingResources), - ImmutableMap.copyOf(nonOverwritingResources), + ImmutableMap.copyOf(combiningResources), ImmutableMap.copyOf(assets)); } ResourceFileVisitor resourceVisitor() { return new ResourceFileVisitor( new OverwritableConsumer<>(overwritingResources, conflicts), - new CombiningConsumer(nonOverwritingResources), + new CombiningConsumer(combiningResources), errors); } @@ -112,7 +113,7 @@ AssetFileVisitor assetVisitorFor(Path path) { public KeyValueConsumers consumers() { return KeyValueConsumers.of( new OverwritableConsumer<>(overwritingResources, conflicts), - new CombiningConsumer(nonOverwritingResources), + new CombiningConsumer(combiningResources), new OverwritableConsumer<>(assets, conflicts)); } } @@ -223,7 +224,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO */ private static class ResourceFileVisitor extends SimpleFileVisitor { private final KeyValueConsumer overwritingConsumer; - private final KeyValueConsumer nonOverwritingConsumer; + private final KeyValueConsumer combiningResources; private final List errors; private boolean inValuesSubtree; private FullyQualifiedName.Factory fqnFactory; @@ -231,10 +232,10 @@ private static class ResourceFileVisitor extends SimpleFileVisitor { ResourceFileVisitor( KeyValueConsumer overwritingConsumer, - KeyValueConsumer nonOverwritingConsumer, + KeyValueConsumer combiningResources, List errors) { this.overwritingConsumer = overwritingConsumer; - this.nonOverwritingConsumer = nonOverwritingConsumer; + this.combiningResources = combiningResources; this.errors = errors; } @@ -270,7 +271,7 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO if (!Files.isDirectory(path) && !path.getFileName().toString().startsWith(".")) { if (inValuesSubtree) { DataResourceXml.parse( - xmlInputFactory, path, fqnFactory, overwritingConsumer, nonOverwritingConsumer); + xmlInputFactory, path, fqnFactory, overwritingConsumer, combiningResources); } else { String rawFqn = deriveRawFullyQualifiedName(path); FullyQualifiedName key = fqnFactory.parse(rawFqn); @@ -284,13 +285,13 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO } } - /** Creates ParsedAndroidData of conflicts, assets overwriting and nonOverwriting resources. */ + /** Creates ParsedAndroidData of conflicts, assets overwriting and combining resources. */ public static ParsedAndroidData of( ImmutableSet conflicts, ImmutableMap overwritingResources, - ImmutableMap nonOverwritingResources, + ImmutableMap combiningResources, ImmutableMap assets) { - return new ParsedAndroidData(conflicts, overwritingResources, nonOverwritingResources, assets); + return new ParsedAndroidData(conflicts, overwritingResources, combiningResources, assets); } /** @@ -334,17 +335,17 @@ public static ParsedAndroidData from(List dependencyAndro private final ImmutableSet conflicts; private final ImmutableMap overwritingResources; - private final ImmutableMap nonOverwritingResources; + private final ImmutableMap combiningResources; private final ImmutableMap assets; private ParsedAndroidData( ImmutableSet conflicts, ImmutableMap overwritingResources, - ImmutableMap nonOverwritingResources, + ImmutableMap combiningResources, ImmutableMap assets) { this.conflicts = conflicts; this.overwritingResources = overwritingResources; - this.nonOverwritingResources = nonOverwritingResources; + this.combiningResources = combiningResources; this.assets = assets; } @@ -352,7 +353,7 @@ private ParsedAndroidData( public String toString() { return MoreObjects.toStringHelper(this) .add("overwritingResources", overwritingResources) - .add("nonOverwritingResources", nonOverwritingResources) + .add("combiningResources", combiningResources) .add("assets", assets) .toString(); } @@ -367,14 +368,14 @@ public boolean equals(Object other) { } ParsedAndroidData that = (ParsedAndroidData) other; return Objects.equals(overwritingResources, that.overwritingResources) - && Objects.equals(nonOverwritingResources, that.nonOverwritingResources) + && Objects.equals(combiningResources, that.combiningResources) && Objects.equals(conflicts, that.conflicts) && Objects.equals(assets, that.assets); } @Override public int hashCode() { - return Objects.hash(conflicts, overwritingResources, nonOverwritingResources, assets); + return Objects.hash(conflicts, overwritingResources, combiningResources, assets); } /** @@ -393,18 +394,20 @@ Map getOverwritingResources() { } /** - * Returns a list of resources that would not overwrite other values when defined. + * Returns a list of resources are combined with other values that have the same key. * *

* Example: * - * A id resource (id.Foo) could be redefined at id.Foo with no adverse effects. + * A id resource (id.Foo) combined id.Foo with no adverse effects, whereas two stylable.Bar + * resources would be combined, resulting in a Styleable containing a union of the attributes. + * See {@link StyleableXmlResourceValue} for more information. * - * @return A map of key -> non-overwriting resources. + * @return A map of key -> combing resources. */ @VisibleForTesting - Map getNonOverwritingResources() { - return nonOverwritingResources; + Map getCombiningResources() { + return combiningResources; } /** @@ -432,7 +435,7 @@ Iterable> iterateOverwritableEntries() { } Iterable> iterateDataResourceEntries() { - return Iterables.concat(overwritingResources.entrySet(), nonOverwritingResources.entrySet()); + return Iterables.concat(overwritingResources.entrySet(), combiningResources.entrySet()); } boolean containsAsset(DataKey name) { @@ -451,12 +454,12 @@ MergeConflict foundAssetConflict(DataKey key, DataAsset value) { return MergeConflict.between(key, assets.get(key), value); } - ImmutableMap mergeNonOverwritable(ParsedAndroidData other) { + ImmutableMap mergeCombining(ParsedAndroidData other) { Map merged = new HashMap<>(); CombiningConsumer consumer = new CombiningConsumer(merged); for (Entry entry : Iterables.concat( - nonOverwritingResources.entrySet(), other.nonOverwritingResources.entrySet())) { + combiningResources.entrySet(), other.combiningResources.entrySet())) { consumer.consume(entry.getKey(), entry.getValue()); } return ImmutableMap.copyOf(merged); diff --git a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java index 978a4d0a69437b..3a0eefc3c9b330 100644 --- a/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java +++ b/src/tools/android/java/com/google/devtools/build/android/XmlResourceValues.java @@ -111,7 +111,7 @@ static void parseDeclareStyleable( FullyQualifiedName.Factory fqnFactory, Path path, KeyValueConsumer overwritingConsumer, - KeyValueConsumer nonOverwritingConsumer, + KeyValueConsumer combiningConsumer, XMLEventReader eventReader, StartElement start) throws XMLStreamException { @@ -134,7 +134,7 @@ static void parseDeclareStyleable( } } } - nonOverwritingConsumer.consume( + combiningConsumer.consume( fqnFactory.create(ResourceType.STYLEABLE, getElementName(start)), DataResourceXml.of(path, StyleableXmlResourceValue.of(members))); } diff --git a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java index 47da07fc26c71c..62fcf4b62988bb 100644 --- a/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java +++ b/src/tools/android/java/com/google/devtools/build/android/xml/StyleableXmlResourceValue.java @@ -140,8 +140,8 @@ public String toString() { * {@link FullyQualifiedName} results in a single Styleable containing a union of all the * attribute references. * - * @param value Another {@link StyleableXmlResourceValue} with the same {@link FullyQualifiedName} - * . + * @param value Another {@link StyleableXmlResourceValue} with the same + * {@link FullyQualifiedName}. * @return {@link StyleableXmlResourceValue} containing a sorted union of the attribute * references. * @throws IllegalArgumentException if value is not an {@link StyleableXmlResourceValue}.