aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
diff options
context:
space:
mode:
authorGravatar corysmith <corysmith@google.com>2018-07-31 09:28:07 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-07-31 09:29:56 -0700
commit0a635c5236ce30ea84b765ce752267992733a649 (patch)
tree7d12075435331b820bfe88f4efbee69dbcbcd7c2 /src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
parenta0f77be2887cc69ea43991dfb5a58934eb539c65 (diff)
Automated rollback of commit 8fe0f45852a620a078013310989396caed273342.
*** Reason for rollback *** Breaks a couple of builds due to a bad merge. *** Original change description *** Add apk converted to proto and all attributes from CompiledResources to ResourcesZip. Add new proto format for tool attributes stored in the AndroidDataXml for storing them in the resources.zip. RELNOTES:None PiperOrigin-RevId: 206774364
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java')
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java53
1 files changed, 6 insertions, 47 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
index 1af171ff53..b4ba3761fe 100644
--- a/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
+++ b/src/tools/android/java/com/google/devtools/build/android/AndroidCompiledDataDeserializer.java
@@ -16,7 +16,6 @@ package com.google.devtools.build.android;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.not;
import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
import android.aapt.pb.internal.ResourcesInternal.CompiledFile;
import com.android.SdkConstants;
@@ -79,7 +78,6 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.LittleEndianDataInputStream;
import com.google.devtools.build.android.FullyQualifiedName.Factory;
-import com.google.devtools.build.android.aapt2.CompiledResources;
import com.google.devtools.build.android.proto.SerializeFormat;
import com.google.devtools.build.android.proto.SerializeFormat.Header;
import com.google.devtools.build.android.xml.ResourcesAttribute.AttributeType;
@@ -90,11 +88,9 @@ import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.file.FileSystem;
-import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -103,12 +99,9 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
-import java.util.function.BiConsumer;
import java.util.logging.Logger;
-import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.annotation.concurrent.NotThreadSafe;
@@ -581,14 +574,11 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
}
private void readAttributesFile(
- InputStream resourceFileStream,
- FileSystem fileSystem,
- BiConsumer<DataKey, DataResource> combine,
- BiConsumer<DataKey, DataResource> overwrite)
+ InputStream resourceFileStream, FileSystem fileSystem, KeyValueConsumers consumers)
throws IOException {
Header header = Header.parseDelimitedFrom(resourceFileStream);
- List<FullyQualifiedName> fullyQualifiedNames = new ArrayList<>();
+ List<DataKey> fullyQualifiedNames = new ArrayList<>();
for (int i = 0; i < header.getEntryCount(); i++) {
SerializeFormat.DataKey protoKey =
SerializeFormat.DataKey.parseDelimitedFrom(resourceFileStream);
@@ -597,7 +587,7 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
DataSourceTable sourceTable = DataSourceTable.read(resourceFileStream, fileSystem, header);
- for (FullyQualifiedName fullyQualifiedName : fullyQualifiedNames) {
+ for (DataKey fullyQualifiedName : fullyQualifiedNames) {
SerializeFormat.DataValue protoValue =
SerializeFormat.DataValue.parseDelimitedFrom(resourceFileStream);
DataSource source = sourceTable.sourceFromId(protoValue.getSourceId());
@@ -605,40 +595,13 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
AttributeType attributeType = AttributeType.valueOf(protoValue.getXmlValue().getValueType());
if (attributeType.isCombining()) {
- combine.accept(fullyQualifiedName, dataResourceXml);
+ consumers.combiningConsumer.accept(fullyQualifiedName, dataResourceXml);
} else {
- overwrite.accept(fullyQualifiedName, dataResourceXml);
+ consumers.overwritingConsumer.accept(fullyQualifiedName, dataResourceXml);
}
}
}
- public Map<DataKey, DataResource> readAttributes(CompiledResources resources) {
- try (ZipFile zipFile = new ZipFile(resources.getZip().toFile())) {
- return zipFile
- .stream()
- .filter(e -> e.getName().endsWith(".attributes"))
- .flatMap(
- entry -> {
- try {
- final Stream.Builder<Entry<DataKey, DataResource>> builder = Stream.builder();
- final BiConsumer<DataKey, DataResource> consumeToStream =
- (k, v) -> builder.add(new SimpleImmutableEntry<>(k, v));
- readAttributesFile(
- zipFile.getInputStream(entry),
- FileSystems.getDefault(),
- consumeToStream,
- consumeToStream);
- return builder.build();
- } catch (IOException e) {
- throw new DeserializationException(e);
- }
- })
- .collect(toMap(Entry::getKey, Entry::getValue));
- } catch (IOException e) {
- throw new DeserializationException(e);
- }
- }
-
public void readTable(InputStream in, KeyValueConsumers consumers) throws IOException {
final ResourceTable resourceTable = ResourceTable.parseFrom(in);
readPackages(consumers, resourceTable);
@@ -677,11 +640,7 @@ public class AndroidCompiledDataDeserializer implements AndroidDataDeserializer
Factory fqnFactory = Factory.fromDirectoryName(dirNameAndQualifiers);
if (fileZipPath.endsWith(".attributes")) {
- readAttributesFile(
- resourceFileStream,
- inPath.getFileSystem(),
- consumers.combiningConsumer,
- consumers.overwritingConsumer);
+ readAttributesFile(resourceFileStream, inPath.getFileSystem(), consumers);
} else {
LittleEndianDataInputStream dataInputStream =
new LittleEndianDataInputStream(resourceFileStream);