aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2016-04-05 17:52:42 +0000
committerGravatar Lukacs Berki <lberki@google.com>2016-04-07 11:40:01 +0000
commit0f86dc815c46f5bde00e42fc875ed0502a1fac44 (patch)
tree54661f592792a5c35f6e7b5ec0134f995dcaebf4 /src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java
parentc0b4e2c5cc15c749afba7a238d6337c7c4d66004 (diff)
4.25 of 5: Writing of UnwrittenMergedAndroidData
Introduces the AndroidDataWriter and AndroidDataWritingVisitor to abstract the io operations from the data classes. Necessary refactoring to the stubbed write method on DataValue in DataAsset.writeAsset and DataResource.writeResource. New interface for the AttributeValues to reflect the simplifications of writing Resource Attributes. Of special note is the fact all xml is written into a single file, values.xml. This is following the Gradle convention and aapt has demonstrated a preference of only reading a values.xml and ignoring all other xml files in the values directory. Unless profiling demonstrates an advantage to writing multiple files (which I doubt), this merger carries on this convention. -- MOS_MIGRATED_REVID=119066611
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java53
1 files changed, 40 insertions, 13 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java
index 30cb43f289..633bd9403a 100644
--- a/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java
+++ b/src/tools/android/java/com/google/devtools/build/android/UnwrittenMergedAndroidData.java
@@ -18,6 +18,7 @@ import com.google.common.base.MoreObjects;
import java.io.IOException;
import java.nio.file.Path;
+import java.util.Map.Entry;
import java.util.Objects;
/**
@@ -26,7 +27,7 @@ import java.util.Objects;
public class UnwrittenMergedAndroidData {
private final Path manifest;
- private final ParsedAndroidData resources;
+ private final ParsedAndroidData primary;
private final ParsedAndroidData deps;
public static UnwrittenMergedAndroidData of(
@@ -35,28 +36,54 @@ public class UnwrittenMergedAndroidData {
}
private UnwrittenMergedAndroidData(
- Path manifest, ParsedAndroidData resources, ParsedAndroidData deps) {
+ Path manifest, ParsedAndroidData primary, ParsedAndroidData deps) {
this.manifest = manifest;
- this.resources = resources;
+ this.primary = primary;
this.deps = deps;
}
/**
- * Writes the android data to directories for consumption by aapt.
- * @param newResourceDirectory The new resource directory to write to.
+ * Writes the android data to the filesystem.
+ * @param mergedDataWriter Destination writer.
* @return A MergedAndroidData that is ready for further tool processing.
* @throws IOException when something goes wrong while writing.
*/
- public MergedAndroidData write(Path newResourceDirectory) throws IOException {
- // TODO(corysmith): Implement write.
- throw new UnsupportedOperationException();
+ public MergedAndroidData write(AndroidDataWriter mergedDataWriter) throws IOException {
+ try {
+ writeParsedAndroidData(primary, mergedDataWriter);
+ writeParsedAndroidData(deps, mergedDataWriter);
+ return new MergedAndroidData(
+ mergedDataWriter.resourceDirectory(),
+ mergedDataWriter.assetDirectory(),
+ mergedDataWriter.copyManifest(this.manifest));
+ } finally {
+ // Flush to make sure all writing is completed before returning a MergedAndroidData.
+ // If resources aren't fully written, the MergedAndroidData might be invalid.
+ mergedDataWriter.flush();
+ }
+ }
+
+ private void writeParsedAndroidData(
+ ParsedAndroidData resources, AndroidDataWritingVisitor mergedDataWriter) throws IOException {
+ for (Entry<DataKey, DataAsset> entry : resources.iterateAssetEntries()) {
+ // TODO(corysmith): Resolve the nit of casting to a RelativeAssetPath by sorting
+ // out the type structure and generics of DataKey, ParsedAndroidData, AndroidDataMerger and
+ // MergeConflict.
+ entry.getValue().writeAsset((RelativeAssetPath) entry.getKey(), mergedDataWriter);
+ }
+ for (Entry<DataKey, DataResource> entry : resources.iterateDataResourceEntries()) {
+ // TODO(corysmith): Resolve the nit of casting to a FullyQualifiedName by sorting
+ // out the type structure and generics of DataKey, ParsedAndroidData, AndroidDataMerger and
+ // MergeConflict.
+ entry.getValue().writeResource((FullyQualifiedName) entry.getKey(), mergedDataWriter);
+ }
}
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("manifest", manifest)
- .add("resources", resources)
+ .add("primary", primary)
.add("deps", deps)
.toString();
}
@@ -71,13 +98,13 @@ public class UnwrittenMergedAndroidData {
}
UnwrittenMergedAndroidData that = (UnwrittenMergedAndroidData) other;
return Objects.equals(manifest, that.manifest)
- && Objects.equals(resources, that.resources)
+ && Objects.equals(primary, that.primary)
&& Objects.equals(deps, that.deps);
}
@Override
public int hashCode() {
- return Objects.hash(manifest, resources, deps);
+ return Objects.hash(manifest, primary, deps);
}
@VisibleForTesting
@@ -86,8 +113,8 @@ public class UnwrittenMergedAndroidData {
}
@VisibleForTesting
- ParsedAndroidData getResources() {
- return resources;
+ ParsedAndroidData getPrimary() {
+ return primary;
}
@VisibleForTesting