diff options
-rw-r--r-- | src/test/java/com/google/devtools/build/android/DependencyAndroidDataTest.java | 20 | ||||
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java | 10 |
2 files changed, 23 insertions, 7 deletions
diff --git a/src/test/java/com/google/devtools/build/android/DependencyAndroidDataTest.java b/src/test/java/com/google/devtools/build/android/DependencyAndroidDataTest.java index 5aef80cf65..bdafa3f54e 100644 --- a/src/test/java/com/google/devtools/build/android/DependencyAndroidDataTest.java +++ b/src/test/java/com/google/devtools/build/android/DependencyAndroidDataTest.java @@ -56,7 +56,7 @@ public class DependencyAndroidDataTest { otherAssets = Files.createDirectories(root.resolve("otherassets")); } - @Test public void flagFullParse() throws Exception{ + @Test public void flagFullParse() { Truth.assertThat( DependencyAndroidData.valueOf( "res#otherres:assets#otherassets:AndroidManifest.xml:r.txt:symbols.zip:symbols.bin", @@ -71,7 +71,7 @@ public class DependencyAndroidDataTest { compiledResources)); } - @Test public void flagParseWithNoSymbolsFile() throws Exception{ + @Test public void flagParseWithNoSymbolsFile() { Truth.assertThat( DependencyAndroidData.valueOf( "res#otherres:assets#otherassets:AndroidManifest.xml:r.txt:", fileSystem)) @@ -85,7 +85,7 @@ public class DependencyAndroidDataTest { null)); } - @Test public void flagParseOmittedSymbolsFile() throws Exception{ + @Test public void flagParseOmittedSymbolsFile() { Truth.assertThat( DependencyAndroidData.valueOf( "res#otherres:assets#otherassets:AndroidManifest.xml:r.txt", fileSystem)) @@ -99,7 +99,7 @@ public class DependencyAndroidDataTest { null)); } - @Test public void flagParseWithEmptyResources() throws Exception{ + @Test public void flagParseWithEmptyResources() { Truth.assertThat( DependencyAndroidData.valueOf( ":assets:AndroidManifest.xml:r.txt:symbols.bin", fileSystem)) @@ -108,7 +108,7 @@ public class DependencyAndroidDataTest { ImmutableList.<Path>of(), ImmutableList.of(assets), manifest, rTxt, symbols, null)); } - @Test public void flagParseWithEmptyAssets() throws Exception{ + @Test public void flagParseWithEmptyAssets() { Truth.assertThat( DependencyAndroidData.valueOf("res::AndroidManifest.xml:r.txt:symbols.bin", fileSystem)) .isEqualTo( @@ -116,7 +116,7 @@ public class DependencyAndroidDataTest { ImmutableList.of(res), ImmutableList.<Path>of(), manifest, rTxt, symbols, null)); } - @Test public void flagParseWithEmptyResourcesAndAssets() throws Exception{ + @Test public void flagParseWithEmptyResourcesAndAssets() { Truth.assertThat( DependencyAndroidData.valueOf("::AndroidManifest.xml:r.txt:symbols.bin", fileSystem)) .isEqualTo( @@ -148,6 +148,14 @@ public class DependencyAndroidDataTest { } } + @Test public void flagNoRTxtWithSymbolsFails() { + try { + DependencyAndroidData.valueOf("::AndroidManifest.xml:::symbols.bin", fileSystem); + fail("expected exception for bad flag format"); + } catch (IllegalArgumentException expected) { + } + } + @Test public void flagMissingRTxtFails() { try { DependencyAndroidData.valueOf("::Manifest.xml:missing_file", fileSystem); diff --git a/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java b/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java index b4d4b99b3f..6eb9aa80d8 100644 --- a/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java +++ b/src/tools/android/java/com/google/devtools/build/android/DependencyAndroidData.java @@ -35,7 +35,15 @@ import java.util.regex.Pattern; * assets. */ class DependencyAndroidData extends SerializedAndroidData { - private static final Pattern VALID_REGEX = Pattern.compile(".*:.*:.+:.+(:.*){0,2}"); + + // From the start of the line, + // 1) match any number of characters that isn't ":" until a ":" (twice for resources and assets) + // 2) match at least one character that isn't ":" until a ":" (manifest) + // 3) match at least one character that isn't ":" until a ":" or end of line (r.txt) + // 4) if not end of line, optionally match anything that isn't ":" until a ":" (symbols.zip) + // 5) match anything that isn't ":" until end of line (symbols.bin) + private static final Pattern VALID_REGEX = + Pattern.compile("^([^:]*:){2}[^:]+:[^:]+(:|$)([^:]*:)?([^:]*)$"); public static final String EXPECTED_FORMAT = "resources[#resources]:assets[#assets]:manifest:r.txt(:symbols.zip?):symbols.bin"; |