aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/java/com/google/devtools/build/android
diff options
context:
space:
mode:
authorGravatar corysmith <corysmith@google.com>2018-05-10 07:00:43 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-05-10 07:02:24 -0700
commitc53e4579e19505f3cf10f690115b73b2050c4dde (patch)
treeb5f99e7bc7d489e6060cdb333ad9c036c87a0c68 /src/test/java/com/google/devtools/build/android
parentfc582319605f455bfdbac94fd177d68631644325 (diff)
Only include generated resources when pseudo locales are asked for.
CompileResources: generate pseudo locales into a separate compiled resource file when the pseudo locale flag is true and the locale is default (e.g. absent). The generated resources must be first in the returned list of compiled resource paths. This allows the user to define custom values to the pseudo locales (which, for some obscure reason, is accepted as a reasonable practice by aapt{,2}) AndroidResourceOutputs: record the type of compiled resource in the comment field of the zip entry for fast comparison. ResourceLinker: only include the generated resources when the pseudo locale is explicitly asked for. It's important to note that the ordering for compiled resources in the zip goes <generated>...<normal>...<default>. This means the default locale will overwrite the generated locale values. Annoying, but necessary, as that is current order before introducing this cl. RELNOTES:None PiperOrigin-RevId: 196111843
Diffstat (limited to 'src/test/java/com/google/devtools/build/android')
-rw-r--r--src/test/java/com/google/devtools/build/android/PathsSubject.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/java/com/google/devtools/build/android/PathsSubject.java b/src/test/java/com/google/devtools/build/android/PathsSubject.java
index 9b653b22fe..2b81087e95 100644
--- a/src/test/java/com/google/devtools/build/android/PathsSubject.java
+++ b/src/test/java/com/google/devtools/build/android/PathsSubject.java
@@ -14,10 +14,12 @@
package com.google.devtools.build.android;
import static com.google.common.truth.Truth.assertThat;
+import static java.util.stream.Collectors.joining;
import com.google.common.base.Joiner;
import com.google.common.truth.FailureMetadata;
import com.google.common.truth.Subject;
+import com.google.devtools.build.android.aapt2.ResourceCompiler.CompiledType;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
@@ -45,6 +47,14 @@ import org.xml.sax.SAXException;
/** A testing utility that allows assertions against Paths. */
public class PathsSubject extends Subject<PathsSubject, Path> {
+ private static final String PATH_NORMALIZER =
+ String.format(
+ "(%s)/(.*/)(javatests)",
+ Arrays.stream(CompiledType.values())
+ .map(CompiledType::asPrefix)
+ .map(p -> String.format("(?:%s)", p))
+ .collect(joining("|")));
+
PathsSubject(FailureMetadata failureMetadata, @Nullable Path subject) {
super(failureMetadata, subject);
}
@@ -68,10 +78,27 @@ public class PathsSubject extends Subject<PathsSubject, Path> {
new ZipFile(actual().toFile())
.stream()
.map(ZipEntry::getName)
+ .map(n -> n.replaceAll(PATH_NORMALIZER, "$1/$3"))
.collect(Collectors.toSet()))
.containsAllIn(Arrays.asList(paths));
}
+
+ void containsExactlyArchivedFilesIn(String... paths) throws IOException {
+ if (actual() == null) {
+ fail("should not be null.");
+ }
+ exists();
+
+ assertThat(
+ new ZipFile(actual().toFile())
+ .stream()
+ .map(ZipEntry::getName)
+ .map(n -> n.replaceAll(PATH_NORMALIZER, "$1/$3"))
+ .collect(Collectors.toSet()))
+ .containsExactly(paths);
+ }
+
void containsNoArchivedFilesIn(String... paths) throws IOException {
if (actual() == null) {
fail("should not be null.");
@@ -81,6 +108,7 @@ public class PathsSubject extends Subject<PathsSubject, Path> {
new ZipFile(actual().toFile())
.stream()
.map(ZipEntry::getName)
+ .map(n -> n.replaceAll(PATH_NORMALIZER, "$1/$3"))
.collect(Collectors.toSet()))
.containsNoneIn(Arrays.asList(paths));
}