diff options
author | 2017-11-30 08:55:49 -0800 | |
---|---|---|
committer | 2017-11-30 08:58:15 -0800 | |
commit | 39c2a36bf8f502d55addd58e9e97bf2ebb46e4b0 (patch) | |
tree | d03277d06ea07cac689e88502b81949c5b6630c7 /src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java | |
parent | 38bd6d7e205df20bc94c8c7359cee81e500cdd16 (diff) |
Improve the error messaging by suppressing stack traces for expected errors.
RELNOTES: None
PiperOrigin-RevId: 177460834
Diffstat (limited to 'src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java')
-rw-r--r-- | src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java index 5f8b842859..e51192ce1e 100644 --- a/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java +++ b/src/tools/android/java/com/google/devtools/build/android/aapt2/ResourceCompiler.java @@ -17,7 +17,8 @@ package com.google.devtools.build.android.aapt2; import com.android.builder.core.VariantType; import com.android.repository.Revision; import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.Futures; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableList.Builder; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.devtools.build.android.AaptCommandBuilder; @@ -29,12 +30,30 @@ import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.logging.Logger; /** Invokes aapt2 to compile resources. */ public class ResourceCompiler { + static class CompileError extends Aapt2Exception { + + protected CompileError(Throwable e) { + super(e); + } + + private CompileError() { + super(); + } + + public static CompileError of(List<Throwable> compilationErrors) { + final CompileError compileError = new CompileError(); + compilationErrors.forEach(compileError::addSuppressed); + return compileError; + } + } + private static final Logger logger = Logger.getLogger(ResourceCompiler.class.getName()); private final CompilingVisitor compilingVisitor; @@ -131,7 +150,19 @@ public class ResourceCompiler { } List<Path> getCompiledArtifacts() throws InterruptedException, ExecutionException { - return Futures.allAsList(tasks).get(); + Builder<Path> builder = ImmutableList.builder(); + List<Throwable> compilationErrors = new ArrayList<>(); + for (ListenableFuture<Path> task : tasks) { + try { + builder.add(task.get()); + } catch (InterruptedException | ExecutionException e) { + compilationErrors.add(Optional.ofNullable(e.getCause()).orElse(e)); + } + } + if (compilationErrors.isEmpty()) { + return builder.build(); + } + throw CompileError.of(compilationErrors); } } |