aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar cushon <cushon@google.com>2018-04-26 19:48:14 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-26 19:49:50 -0700
commita6a9843ddb869d911795bd9a634e725d5952dfb2 (patch)
tree6c2966bde91ed4f18a89d7fc77a5d9d114333d7b /src
parent968059d59719d7789b4b3fe97fe0d6be0e86682d (diff)
For --checkHashMismatch=ERROR, emit all errors instead of stopping at the first one
PiperOrigin-RevId: 194491274
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/google/devtools/build/android/ZipFilterActionTest.java12
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java10
-rw-r--r--src/tools/android/java/com/google/devtools/build/android/ZipFilterEntryFilter.java17
3 files changed, 24 insertions, 15 deletions
diff --git a/src/test/java/com/google/devtools/build/android/ZipFilterActionTest.java b/src/test/java/com/google/devtools/build/android/ZipFilterActionTest.java
index 7af59aebb0..22ce6339b3 100644
--- a/src/test/java/com/google/devtools/build/android/ZipFilterActionTest.java
+++ b/src/test/java/com/google/devtools/build/android/ZipFilterActionTest.java
@@ -132,7 +132,7 @@ public class ZipFilterActionTest {
private List<String> outputEntriesWithArgs(ImmutableList<String> args, File output)
throws IOException {
- ZipFilterAction.main(args.toArray(new String[0]));
+ ZipFilterAction.run(args.toArray(new String[0]));
List<String> filteredEntries = new ArrayList<>();
try (ZipFile zip = new ZipFile(output)) {
Enumeration<? extends ZipEntry> entries = zip.entries();
@@ -216,9 +216,8 @@ public class ZipFilterActionTest {
callback.assertOp(FilterOperation.COPY);
filter.accept("res/R.class", callback);
callback.assertOp(FilterOperation.SKIP);
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("name matches but the hash does not.");
filter.accept("baz.class", callback);
+ assertThat(filter.sawErrors()).isTrue();
}
@Test public void testFlags() throws Exception {
@@ -240,7 +239,7 @@ public class ZipFilterActionTest {
"--checkHashMismatch", "IGNORE");
thrown.expect(ZipException.class);
thrown.expectMessage("Zip file 'filter1' is malformed");
- ZipFilterAction.main(args.toArray(new String[0]));
+ ZipFilterAction.run(args.toArray(new String[0]));
}
@Test public void testFullIntegration() throws IOException {
@@ -283,9 +282,8 @@ public class ZipFilterActionTest {
"ERROR",
"--outputMode",
"DONT_CARE");
- thrown.expect(IllegalStateException.class);
- thrown.expectMessage("name matches but the hash does not");
- ZipFilterAction.main(args.toArray(new String[0]));
+ int exitCode = ZipFilterAction.run(args.toArray(new String[0]));
+ assertThat(exitCode).isEqualTo(1);
}
@Test
diff --git a/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java b/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java
index c774ec22f6..0a0744746d 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ZipFilterAction.java
@@ -28,7 +28,6 @@ import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Multimap;
import com.google.devtools.build.singlejar.ZipCombiner;
import com.google.devtools.build.singlejar.ZipCombiner.OutputMode;
-import com.google.devtools.build.singlejar.ZipEntryFilter;
import com.google.devtools.build.zip.ZipFileEntry;
import com.google.devtools.build.zip.ZipReader;
import java.io.IOException;
@@ -67,7 +66,7 @@ import java.util.regex.Pattern;
* --filterTypes [fileExtension[,fileExtension]...]
* --explicitFilters [fileRegex[,fileRegex]...]
* --outputMode [DONT_CARE|FORCE_DEFLATE|FORCE_STORED]
- * --errorOnHashMismatch
+ * --checkHashMismatch [IGNORE|WARN|ERROR]
* </pre>
*/
public class ZipFilterAction {
@@ -213,6 +212,10 @@ public class ZipFilterAction {
}
public static void main(String[] args) throws IOException {
+ System.exit(run(args));
+ }
+
+ static int run(String[] args) throws IOException {
Options options = new Options();
new JCommander(options).parse(args);
logger.fine(
@@ -241,7 +244,7 @@ public class ZipFilterAction {
if (options.errorOnHashMismatch) {
options.hashMismatchCheckMode = HashMismatchCheckMode.ERROR;
}
- ZipEntryFilter entryFilter =
+ ZipFilterEntryFilter entryFilter =
new ZipFilterEntryFilter(
explicitFilter, entriesToOmit, inputEntries.build(), options.hashMismatchCheckMode);
@@ -250,5 +253,6 @@ public class ZipFilterAction {
combiner.addZip(options.inputZip.toFile());
}
logger.fine(String.format("Filtering completed in %dms", timer.elapsed(TimeUnit.MILLISECONDS)));
+ return entryFilter.sawErrors() ? 1 : 0;
}
}
diff --git a/src/tools/android/java/com/google/devtools/build/android/ZipFilterEntryFilter.java b/src/tools/android/java/com/google/devtools/build/android/ZipFilterEntryFilter.java
index 95733396ca..2e801c350f 100644
--- a/src/tools/android/java/com/google/devtools/build/android/ZipFilterEntryFilter.java
+++ b/src/tools/android/java/com/google/devtools/build/android/ZipFilterEntryFilter.java
@@ -29,6 +29,11 @@ class ZipFilterEntryFilter implements ZipEntryFilter {
private final Multimap<String, Long> entriesToOmit;
private final Map<String, Long> inputEntries;
private final HashMismatchCheckMode hashMismatchCheckMode;
+ private boolean sawErrors = false;
+
+ public boolean sawErrors() {
+ return sawErrors;
+ }
/**
* Creates a new filter.
@@ -62,11 +67,12 @@ class ZipFilterEntryFilter implements ZipEntryFilter {
callback.skip();
} else {
if (hashMismatchCheckMode == HashMismatchCheckMode.ERROR) {
- throw new IllegalStateException(
- String.format(
- "Requested to filter entries of name "
- + "'%s'; name matches but the hash does not. Aborting",
- filename));
+ System.out.printf(
+ "\u001b[31mERROR:\u001b[0m Requested to filter entries of name "
+ + "'%s'; name matches but the hash does not.\n",
+ filename);
+ sawErrors = true;
+ callback.skip();
} else {
System.out.printf(
"\u001b[35mWARNING:\u001b[0m Requested to filter entries of name "
@@ -80,4 +86,5 @@ class ZipFilterEntryFilter implements ZipEntryFilter {
callback.copy(null);
}
}
+
}