Skip to content

Commit

Permalink
Automated rollback of commit f672a31.
Browse files Browse the repository at this point in the history
*** Reason for rollback ***

Unclassified general breakages in tests. Rolling back for further investigation.

*** Original change description ***

Normalized the serialization proto to save space and allow greater versatility in storage.

RELNOTES: None
PiperOrigin-RevId: 186057879
  • Loading branch information
corbinrsmith-work authored and Copybara-Service committed Feb 16, 2018
1 parent d7a5617 commit d18d3e2
Show file tree
Hide file tree
Showing 56 changed files with 985 additions and 817 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void testAddWithNullPathValueAddsNothing() {

@Test
public void testAddRepeatedWithEmptyValuesAddsNothing() {
assertThat(new AaptCommandBuilder(aapt).addRepeated("-0", ImmutableList.of()).build())
assertThat(new AaptCommandBuilder(aapt).addRepeated("-0", ImmutableList.<String>of()).build())
.doesNotContain("-0");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public AndroidDataBuilder addAsset(String path, String... lines) {
}

public AndroidDataBuilder createManifest(String path, String manifestPackage, String... lines) {
return createManifest(path, manifestPackage, ImmutableList.of(), lines);
return createManifest(path, manifestPackage, ImmutableList.<String>of(), lines);
}

public AndroidDataBuilder createManifest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class AndroidDataMergerTest {
@Before
public void setUp() throws Exception {
fileSystem = Jimfs.newFileSystem();
fqnFactory = FullyQualifiedName.Factory.from(ImmutableList.of());
fqnFactory = FullyQualifiedName.Factory.from(ImmutableList.<String>of());
mergerLogger = Logger.getLogger(AndroidDataMerger.class.getCanonicalName());
loggingHandler = new TestLoggingHandler();
mergerLogger.addHandler(loggingHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class AndroidDataSerializerAndDeserializerTest {
@Before
public void createCleanEnvironment() throws Exception {
fs = Jimfs.newFileSystem();
fqnFactory = FullyQualifiedName.Factory.from(ImmutableList.of());
fqnFactory = FullyQualifiedName.Factory.from(ImmutableList.<String>of());
source = Files.createDirectory(fs.getPath("source"));
manifest = Files.createFile(source.resolve("AndroidManifest.xml"));
}
Expand Down Expand Up @@ -80,7 +80,8 @@ public void serializeCombiningResource() throws Exception {
UnwrittenMergedAndroidData.of(
manifest,
ParsedAndroidDataBuilder.buildOn(source, fqnFactory)
.combining(xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.combining(
xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.build(),
ParsedAndroidDataBuilder.empty());
expected.serializeTo(serializer);
Expand Down Expand Up @@ -158,7 +159,10 @@ public void serializeFileWithIds() throws Exception {
.createManifest("AndroidManifest.xml", "com.carroll.lewis", "")
.buildParsed();
UnwrittenMergedAndroidData expected =
UnwrittenMergedAndroidData.of(manifest, direct, ParsedAndroidDataBuilder.empty());
UnwrittenMergedAndroidData.of(
manifest,
direct,
ParsedAndroidDataBuilder.empty());
expected.serializeTo(serializer);
serializer.flushTo(binaryPath);

Expand All @@ -168,8 +172,10 @@ public void serializeFileWithIds() throws Exception {
deserializer.read(
binaryPath,
KeyValueConsumers.of(
overwriting, combining, null // assets
));
overwriting,
combining,
null // assets
));
Truth.assertThat(overwriting).isEqualTo(expected.getPrimary().getOverwritingResources());
Truth.assertThat(combining).isEqualTo(expected.getPrimary().getCombiningResources());
}
Expand All @@ -184,17 +190,17 @@ public void serialize() throws Exception {
ParsedAndroidDataBuilder.buildOn(source, fqnFactory)
.overwritable(
file("layout/banker").source("layout/banker.xml"),
xml("<resources>/foo")
.source("values/ids.xml")
.value(
ResourcesAttribute.of(
fqnFactory.parse("<resources>/foo"), "foo", "fooVal")))
.combining(xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
xml("<resources>/foo").source("values/ids.xml")
.value(ResourcesAttribute.of(
fqnFactory.parse("<resources>/foo"), "foo", "fooVal")))
.combining(
xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.assets(file().source("hunting/of/the/boojum"))
.build(),
ParsedAndroidDataBuilder.buildOn(source, fqnFactory)
.overwritable(file("layout/butcher").source("layout/butcher.xml"))
.combining(xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.combining(
xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.assets(file().source("hunting/of/the/snark"))
.build());
expected.serializeTo(serializer);
Expand Down Expand Up @@ -226,43 +232,36 @@ public void testDeserializeMissing() throws Exception {
ParsedAndroidDataBuilder.buildOn(source, fqnFactory)
.overwritable(
file("layout/banker").source("layout/banker.xml"),
xml("<resources>/foo")
.source("values/res.xml")
.value(
ResourcesAttribute.of(
fqnFactory.parse("<resources>/foo"), "foo", "fooVal")))
.combining(xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
xml("<resources>/foo").source("values/ids.xml")
.value(ResourcesAttribute.of(
fqnFactory.parse("<resources>/foo"), "foo", "fooVal")))
.combining(
xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.assets(file().source("hunting/of/the/boojum"))
.build(),
ParsedAndroidDataBuilder.buildOn(source, fqnFactory)
.overwritable(file("layout/butcher").source("layout/butcher.xml"))
.combining(xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.combining(
xml("id/snark").source("values/ids.xml").value(IdXmlResourceValue.of()))
.assets(file().source("hunting/of/the/snark"))
.build());
expected.serializeTo(serializer);
serializer.flushTo(binaryPath);

// Create a file to demonstrate an overmatched filtering
Files.createDirectories(source.resolve("res/values/ids.xml"));

AndroidDataDeserializer deserializer =
AndroidParsedDataDeserializer.withFilteredResources(
ImmutableList.of(
"the/boojum", "values/ids.xml", "layout/banker.xml", "values/res.xml"));
ImmutableList.of("the/boojum", "values/ids.xml", "layout/banker.xml"));

KeyValueConsumers primary =
KeyValueConsumers.of(
TestMapConsumer.ofResources(), // overwriting
TestMapConsumer.ofResources(), // combining
TestMapConsumer.ofAssets() // assets
null // assets
);

deserializer.read(binaryPath, primary);
Truth.assertThat(primary.overwritingConsumer).isEqualTo(Collections.emptyMap());
Truth.assertThat(primary.combiningConsumer)
.named("Filtered resources that exist should not be filtered.")
.isEqualTo(expected.getPrimary().getCombiningResources());
Truth.assertThat(primary.assetConsumer).isEqualTo(Collections.emptyMap());
Truth.assertThat(primary.combiningConsumer).isEqualTo(Collections.emptyMap());
}

private static class TestMapConsumer<T extends DataValue>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -44,7 +45,7 @@ public class AndroidResourceClassWriterTest {
public final ExpectedException thrown = ExpectedException.none();

private static final AndroidFrameworkAttrIdProvider mockAndroidFrameworkIds =
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.of());
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.<String, Integer>of());

@Before
public void createCleanEnvironment() {
Expand Down Expand Up @@ -99,13 +100,17 @@ public void simpleIdFromLayout() throws Exception {
ImmutableMap.of(
"AdiosButton", 0x7f030000,
"HelloView", 0x7f030001),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$layout")
.classContentsIsEqualTo(
ImmutableMap.of("some_layout", 0x7f020000), ImmutableMap.of(), false);
ImmutableMap.of("some_layout", 0x7f020000),
ImmutableMap.<String, List<Integer>>of(),
false
);
}

@Test
Expand Down Expand Up @@ -149,8 +154,9 @@ public void ninePatchFieldNames() throws Exception {
ImmutableMap.of(
"light", 0x7f020000,
"patchface", 0x7f020001),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
}

@Test
Expand Down Expand Up @@ -201,8 +207,9 @@ public void unionOfResourcesInConfigurations() throws Exception {
"light18", 0x7f020001,
"light19", 0x7f020002,
"light20", 0x7f020003),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
}

@Test
Expand Down Expand Up @@ -307,17 +314,19 @@ public void normalizeStyleAndStyleableNames() throws Exception {
"x_color", 0x7f010000,
"y_color", 0x7f010001,
"z_color", 0x7f010002),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$style")
.classContentsIsEqualTo(
ImmutableMap.of(
"YStyle", 0x7f020000,
"ZStyle_ABC", 0x7f020001),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$styleable")
Expand All @@ -330,12 +339,14 @@ public void normalizeStyleAndStyleableNames() throws Exception {
.put("com_google_android_Swirls_Fancy_y_color", 1)
.put("com_google_android_Swirls_Fancy_z_color", 2)
.build(),
ImmutableMap.of(
ImmutableMap.<String, List<Integer>>of(
"com_google_android_Dots",
ImmutableList.of(0x7f010000, 0x7f010001, 0x7f010002),
"com_google_android_Swirls_Fancy",
ImmutableList.of(0x7f010000, 0x7f010001, 0x7f010002)),
false);
ImmutableList.of(0x7f010000, 0x7f010001, 0x7f010002)
),
false
);
}

@Test
Expand Down Expand Up @@ -418,12 +429,18 @@ public void handleAndroidFrameworkAttributes() throws Exception {
ImmutableMap.of(
"aaa", 0x7f010000,
"zzz", 0x7f010001),
ImmutableMap.of(),
false);
ImmutableMap.<String, List<Integer>>of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$style")
.classContentsIsEqualTo(ImmutableMap.of("YStyle", 0x7f020000), ImmutableMap.of(), false);
.classContentsIsEqualTo(
ImmutableMap.of(
"YStyle", 0x7f020000),
ImmutableMap.<String, List<Integer>>of(),
false
);
assertAbout(paths)
.that(target)
.withClass("com.carroll.lewis.R$styleable")
Expand All @@ -432,11 +449,14 @@ public void handleAndroidFrameworkAttributes() throws Exception {
"com_google_android_Dots_android_textColor", 0,
"com_google_android_Dots_android_textSize", 1,
"com_google_android_Dots_aaa", 2,
"com_google_android_Dots_zzz", 3),
ImmutableMap.of(
"com_google_android_Dots_zzz", 3
),
ImmutableMap.<String, List<Integer>>of(
"com_google_android_Dots",
ImmutableList.of(0x01000000, 0x01000010, 0x7f010000, 0x7f010001)),
false);
ImmutableList.of(0x01000000, 0x01000010, 0x7f010000, 0x7f010001)
),
false
);
}

@Test
Expand All @@ -445,7 +465,9 @@ public void missingFrameworkAttribute() throws Exception {
Path source = fs.getPath("source");
AndroidResourceClassWriter resourceClassWriter =
AndroidResourceClassWriter.of(
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.of()), target, "com.carroll.lewis");
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.<String, Integer>of()),
target,
"com.carroll.lewis");
ParsedAndroidData direct =
AndroidDataBuilder.of(source)
.addResource(
Expand Down Expand Up @@ -478,7 +500,9 @@ public void missingAppAttribute() throws Exception {
Path source = fs.getPath("source");
AndroidResourceClassWriter resourceClassWriter =
AndroidResourceClassWriter.of(
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.of()), target, "com.carroll.lewis");
new MockAndroidFrameworkAttrIdProvider(ImmutableMap.<String, Integer>of()),
target,
"com.carroll.lewis");
ParsedAndroidData direct =
AndroidDataBuilder.of(source)
.addResource(
Expand Down Expand Up @@ -543,7 +567,11 @@ public void illegalFileResFieldNamesStart() throws Exception {
assertAbout(paths)
.that(target)
.withClass("com.boop.R$drawable")
.classContentsIsEqualTo(ImmutableMap.of("1", 0x7f020000), ImmutableMap.of(), false);
.classContentsIsEqualTo(
ImmutableMap.of("1", 0x7f020000),
ImmutableMap.<String, List<Integer>>of(),
false
);
}

/**
Expand Down Expand Up @@ -585,7 +613,11 @@ public void illegalFileResFieldNamesCharacters() throws Exception {
assertAbout(paths)
.that(target)
.withClass("com.boop.R$drawable")
.classContentsIsEqualTo(ImmutableMap.of("c++", 0x7f020000), ImmutableMap.of(), false);
.classContentsIsEqualTo(
ImmutableMap.of("c++", 0x7f020000),
ImmutableMap.<String, List<Integer>>of(),
false
);
}

/**
Expand Down Expand Up @@ -628,7 +660,11 @@ public void illegalValueResFieldNamesCharacters() throws Exception {
assertAbout(paths)
.that(target)
.withClass("com.boop.R$integer")
.classContentsIsEqualTo(ImmutableMap.of("c++", 0x7f020000), ImmutableMap.of(), false);
.classContentsIsEqualTo(
ImmutableMap.of("c++", 0x7f020000),
ImmutableMap.<String, List<Integer>>of(),
false
);
}

private static class MockAndroidFrameworkAttrIdProvider
Expand Down
Loading

0 comments on commit d18d3e2

Please sign in to comment.