diff options
| author | Paul Duffin <paulduffin@google.com> | 2018-12-06 11:04:01 +0000 |
|---|---|---|
| committer | Paul Duffin <paulduffin@google.com> | 2018-12-06 14:20:48 +0000 |
| commit | 0c34ceea574a7c7b902cb5da4a210702eca9e228 (patch) | |
| tree | 7975ccc54068a2a7f1ddf4e8dccf45b85b4bf039 /tools | |
| parent | 69431d3ba1c560f0b23bd2ad6257949deb679aa7 (diff) | |
| download | art-0c34ceea574a7c7b902cb5da4a210702eca9e228.tar.gz art-0c34ceea574a7c7b902cb5da4a210702eca9e228.tar.bz2 art-0c34ceea574a7c7b902cb5da4a210702eca9e228.zip | |
Make Javac throw an exception in the event of a compile error
Provides better feedback when writing tests that fail due to a compile
error.
Test: atest class2greylisttest
Bug: 119861512
Change-Id: I79d5a1c0406f070b5f02c5c8ec1a362e5d03ee39
Diffstat (limited to 'tools')
4 files changed, 37 insertions, 27 deletions
diff --git a/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeHandlerTest.java b/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeHandlerTest.java index 9d2f014e4e..9f924b2716 100644 --- a/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeHandlerTest.java +++ b/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeHandlerTest.java @@ -67,7 +67,7 @@ public class CovariantReturnTypeHandlerTest extends AnnotationHandlerTestBase { " @Annotation(returnType=Integer.class)", " public String method() {return null;}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, @@ -91,7 +91,7 @@ public class CovariantReturnTypeHandlerTest extends AnnotationHandlerTestBase { " @Annotation(returnType=Integer.class)", " public String method() {return null;}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, @@ -113,7 +113,7 @@ public class CovariantReturnTypeHandlerTest extends AnnotationHandlerTestBase { " @Annotation(returnType=Integer.class)", " public String method() {return null;}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, @@ -138,7 +138,7 @@ public class CovariantReturnTypeHandlerTest extends AnnotationHandlerTestBase { " @Annotation(returnType=Integer.class)", " public String field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, diff --git a/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeMultiHandlerTest.java b/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeMultiHandlerTest.java index 1202564948..25f284455b 100644 --- a/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeMultiHandlerTest.java +++ b/tools/class2greylist/test/src/com/android/class2greylist/CovariantReturnTypeMultiHandlerTest.java @@ -74,7 +74,7 @@ public class CovariantReturnTypeMultiHandlerTest extends AnnotationHandlerTestBa " @Annotation(returnType=Long.class)", " public String method() {return null;}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of("Lannotation/Annotation$Multi;", @@ -104,7 +104,7 @@ public class CovariantReturnTypeMultiHandlerTest extends AnnotationHandlerTestBa " @Annotation(returnType=Long.class)", " public String method() {return null;}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of("Lannotation/Annotation$Multi;", diff --git a/tools/class2greylist/test/src/com/android/class2greylist/UnsupportedAppUsageAnnotationHandlerTest.java b/tools/class2greylist/test/src/com/android/class2greylist/UnsupportedAppUsageAnnotationHandlerTest.java index cdf01afe7c..dc767fe3f5 100644 --- a/tools/class2greylist/test/src/com/android/class2greylist/UnsupportedAppUsageAnnotationHandlerTest.java +++ b/tools/class2greylist/test/src/com/android/class2greylist/UnsupportedAppUsageAnnotationHandlerTest.java @@ -82,7 +82,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno", " public void method() {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -103,7 +103,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno", " public Class() {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -124,7 +124,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno", " public int i;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -145,7 +145,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->method()V\")", " public void method() {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -166,7 +166,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->nomethod()V\")", " public void method() {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -186,7 +186,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " public void method() {}", " }", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class$Inner"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -205,7 +205,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT "public class Class {", " public void method() {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -224,7 +224,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->method(Ljava/lang/String;)V\")", " public void method(T arg) {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)) @@ -252,7 +252,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->method(Ljava/lang/String;)V\")", " public void method(T arg) {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)); @@ -284,7 +284,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->method(Ljava/lang/String;)V\")", " public void method(T arg) {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)); @@ -320,7 +320,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT "package a.b;", "public class Class extends Base implements Interface {", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)); @@ -354,7 +354,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno", " public void method(T arg) {}", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Set<String> publicApis = Sets.newHashSet( "La/b/Base;->method(Ljava/lang/Object;)V", @@ -385,7 +385,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->field:I\")", " public volatile int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler( @@ -407,7 +407,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(expectedSignature=\"La/b/Class;->wrong:I\")", " public volatile int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler(x -> true, NULL_SDK_MAP)); @@ -424,7 +424,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(maxTargetSdk=1)", " public int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler( @@ -444,7 +444,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno", " public int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler( @@ -464,7 +464,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno(maxTargetSdk=2)", " public int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); Map<String, AnnotationHandler> handlerMap = ImmutableMap.of(ANNOTATION, createGreylistHandler( @@ -493,7 +493,7 @@ public class UnsupportedAppUsageAnnotationHandlerTest extends AnnotationHandlerT " @Anno2(maxTargetSdk=2, trackingBug=123456789)", " public int field;", "}")); - assertThat(mJavac.compile()).isTrue(); + mJavac.compile(); new AnnotationVisitor(mJavac.getCompiledClass("a.b.Class"), mStatus, ImmutableMap.of("Lannotation/Anno2;", createGreylistHandler(x -> true, ImmutableMap.of(2, "flag2"))) diff --git a/tools/class2greylist/test/src/com/android/javac/Javac.java b/tools/class2greylist/test/src/com/android/javac/Javac.java index 202f4121fc..94e4e49ea8 100644 --- a/tools/class2greylist/test/src/com/android/javac/Javac.java +++ b/tools/class2greylist/test/src/com/android/javac/Javac.java @@ -18,6 +18,7 @@ package com.android.javac; import com.google.common.io.Files; +import java.util.stream.Collectors; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; @@ -76,15 +77,24 @@ public class Javac { return this; } - public boolean compile() { + public void compile() { + DiagnosticCollector<JavaFileObject> diagnosticCollector = new DiagnosticCollector<>(); JavaCompiler.CompilationTask task = mJavac.getTask( null, mFileMan, - null, + diagnosticCollector, null, null, mCompilationUnits); - return task.call(); + boolean result = task.call(); + if (!result) { + throw new IllegalStateException( + "Compilation failed:" + + diagnosticCollector.getDiagnostics() + .stream() + .map(Object::toString) + .collect(Collectors.joining("\n"))); + } } public InputStream getClassFile(String classname) throws IOException { |
