summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurimas Liutikas <aurimas@google.com>2020-05-15 21:50:09 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-15 21:50:09 +0000
commita2f54c44bc1333cd29b053a822649545563e74d1 (patch)
treeafb6b8d474f09cc9d675d37533ec422b4ab2b68a
parent2aa112719d2f5a6de6e1e9373b7b9a10921f0d22 (diff)
parent7b748839df6200a4f11d1997dc6b4002824ea694 (diff)
Fail metalava on global reporter issues. am: 7b748839df
Change-Id: I8700b04e362d838af56b75ec5b853fa7e8765974
-rw-r--r--src/main/java/com/android/tools/metalava/Driver.kt7
-rw-r--r--src/main/java/com/android/tools/metalava/Options.kt8
-rw-r--r--src/main/java/com/android/tools/metalava/Reporter.kt2
-rw-r--r--src/test/java/com/android/tools/metalava/ApiLintBaselineTest.kt15
-rw-r--r--src/test/java/com/android/tools/metalava/ApiLintTest.kt160
-rw-r--r--src/test/java/com/android/tools/metalava/ReporterTest.kt4
6 files changed, 187 insertions, 9 deletions
diff --git a/src/main/java/com/android/tools/metalava/Driver.kt b/src/main/java/com/android/tools/metalava/Driver.kt
index 5159cba..8de2bc6 100644
--- a/src/main/java/com/android/tools/metalava/Driver.kt
+++ b/src/main/java/com/android/tools/metalava/Driver.kt
@@ -97,11 +97,10 @@ fun run(
stderr: PrintWriter = PrintWriter(OutputStreamWriter(System.err)),
setExitCode: Boolean = false
): Boolean {
- var exitValue: Boolean
var exitCode = 0
try {
- var modifiedArgs = preprocessArgv(originalArgs)
+ val modifiedArgs = preprocessArgv(originalArgs)
progress("$PROGRAM_NAME started\n")
@@ -117,7 +116,6 @@ fun run(
if (options.allReporters.any { it.hasErrors() } && !options.passBaselineUpdates) {
exitCode = -1
}
- exitValue = true
} catch (e: DriverException) {
stdout.flush()
stderr.flush()
@@ -128,7 +126,6 @@ fun run(
stdout.println("\n${e.stdout}")
}
exitCode = e.exitCode
- exitValue = false
} finally {
Disposer.dispose(LintCoreApplicationEnvironment.get().parentDisposable)
}
@@ -159,7 +156,7 @@ fun run(
exit(exitCode)
}
- return exitValue
+ return exitCode == 0
}
private fun exit(exitCode: Int = 0) {
diff --git a/src/main/java/com/android/tools/metalava/Options.kt b/src/main/java/com/android/tools/metalava/Options.kt
index ed4877f..5ffa7ce 100644
--- a/src/main/java/com/android/tools/metalava/Options.kt
+++ b/src/main/java/com/android/tools/metalava/Options.kt
@@ -696,6 +696,7 @@ class Options(
var currentJar: File? = null
var delayedCheckApiFiles = false
var skipGenerateAnnotations = false
+ reporter = Reporter(null, null)
var baselineBuilder = Baseline.Builder().apply { description = "base" }
var baselineApiLintBuilder = Baseline.Builder().apply { description = "api-lint" }
@@ -1660,7 +1661,12 @@ class Options(
allBaselines = listOfNotNull(baseline, baselineApiLint, baselineCompatibilityReleased)
// Reporters are non-null.
- allReporters = listOf<Reporter>(reporterApiLint, reporterCompatibilityReleased, reporterCompatibilityCurrent)
+ allReporters = listOf(
+ reporter,
+ reporterApiLint,
+ reporterCompatibilityReleased,
+ reporterCompatibilityCurrent
+ )
checkFlagConsistency()
}
diff --git a/src/main/java/com/android/tools/metalava/Reporter.kt b/src/main/java/com/android/tools/metalava/Reporter.kt
index 7b63a9a..0fc3d1a 100644
--- a/src/main/java/com/android/tools/metalava/Reporter.kt
+++ b/src/main/java/com/android/tools/metalava/Reporter.kt
@@ -43,7 +43,7 @@ import java.io.PrintWriter
* "Global" [Reporter] used by most operations.
* Certain operations, such as api-lint and compatibility check, may use a custom [Reporter]
*/
-val reporter = Reporter(null, null)
+lateinit var reporter: Reporter
enum class Severity(private val displayName: String) {
INHERIT("inherit"),
diff --git a/src/test/java/com/android/tools/metalava/ApiLintBaselineTest.kt b/src/test/java/com/android/tools/metalava/ApiLintBaselineTest.kt
index 674da0f..7c8273e 100644
--- a/src/test/java/com/android/tools/metalava/ApiLintBaselineTest.kt
+++ b/src/test/java/com/android/tools/metalava/ApiLintBaselineTest.kt
@@ -109,6 +109,10 @@ class ApiLintBaselineTest : DriverTest() {
expectedIssues = """
src/android/pkg/MyEnum.java:3: error: Enums are discouraged in Android APIs [Enum] [Rule F5 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -143,7 +147,11 @@ class ApiLintBaselineTest : DriverTest() {
"""
)
),
- expectedFail = "",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ *** api-lint failed ***
+ """,
expectedOutput = """
1 new API lint issues were found.
See tools/metalava/API-LINT.md for how to handle these.
@@ -171,7 +179,10 @@ class ApiLintBaselineTest : DriverTest() {
"""
)
),
- expectedFail = "",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
expectedOutput = """
1 new API lint issues were found.
See tools/metalava/API-LINT.md for how to handle these.
diff --git a/src/test/java/com/android/tools/metalava/ApiLintTest.kt b/src/test/java/com/android/tools/metalava/ApiLintTest.kt
index 2a92bfc..2779748 100644
--- a/src/test/java/com/android/tools/metalava/ApiLintTest.kt
+++ b/src/test/java/com/android/tools/metalava/ApiLintTest.kt
@@ -43,6 +43,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/badlyNamedClass.java:11: warning: Acronyms should not be capitalized in method names: was `getID`, should this be `getId`? [AcronymName] [Rule S1 in go/android-api-guidelines]
src/android/pkg/badlyNamedClass.java:6: error: Constant field names must be named with only upper case characters: `android.pkg.badlyNamedClass#BadlyNamedField`, should be `BADLY_NAMED_FIELD`? [AllUpper] [Rule C2 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 9 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -214,6 +218,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/Constants.java:9: error: Constant field names must be named with only upper case characters: `android.pkg.Constants#myStrings`, should be `MY_STRINGS`? [AllUpper] [Rule C2 in go/android-api-guidelines]
src/android/pkg/Constants.java:7: error: Constant field names must be named with only upper case characters: `android.pkg.Constants#strings`, should be `STRINGS`? [AllUpper] [Rule C2 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 5 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -246,6 +254,10 @@ class ApiLintTest : DriverTest() {
expectedIssues = """
src/android/pkg/MyEnum.java:3: error: Enums are discouraged in Android APIs [Enum] [Rule F5 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -271,6 +283,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyInterfaceCallback.java:3: error: Callbacks must be abstract class instead of interface to enable extension in future API levels: MyInterfaceCallback [CallbackInterface] [Rule CL3 in go/android-api-guidelines]
src/android/pkg/MyObserver.java:3: warning: Class should be named MyCallback [CallbackName] [Rule L1 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 4 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -323,6 +339,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyCallback.java:3: error: Callback method names must follow the on<Something> style: bar [CallbackMethodName] [Rule L1 in go/android-api-guidelines]
src/android/pkg/MyClassListener.java:3: error: Listeners should be an interface, or otherwise renamed Callback: MyClassListener [ListenerInterface] [Rule L1 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -384,6 +404,10 @@ class ApiLintTest : DriverTest() {
src/android/accounts/Actions.java:6: error: Inconsistent action value; expected `android.accounts.action.ACCOUNT_OPENED`, was `android.accounts.ACCOUNT_OPENED` [ActionValue] [Rule C4 in go/android-api-guidelines]
src/android/accounts/Actions.java:8: error: Intent action constant name must be ACTION_FOO: SOMETHING [IntentName] [Rule C3 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -412,6 +436,10 @@ class ApiLintTest : DriverTest() {
src/android/accounts/Extras.java:7: error: Intent extra constant name must be EXTRA_FOO: RULE_ID [IntentName] [Rule C3 in go/android-api-guidelines]
src/android/accounts/Extras.java:6: error: Intent extra constant name must be EXTRA_FOO: SOMETHING_EXTRA [IntentName] [Rule C3 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -438,6 +466,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MissingEquals.java:4: error: Must override both equals and hashCode; missing one in android.pkg.MissingEquals [EqualsAndHashCode] [Rule M8 in go/android-api-guidelines]
src/android/pkg/MissingHashCode.java:7: error: Must override both equals and hashCode; missing one in android.pkg.MissingHashCode [EqualsAndHashCode] [Rule M8 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -503,6 +535,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/NonFinalParcelable.java:5: error: Parcelable classes must be final: android.pkg.NonFinalParcelable is not final [ParcelNotFinal] [Rule FW8 in go/android-api-guidelines]
src/android/pkg/ParcelableConstructor.java:6: error: Parcelable inflation is exposed through CREATOR, not raw constructors, in android.pkg.ParcelableConstructor [ParcelConstructor] [Rule FW3 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 5 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -588,6 +624,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:6: error: Protected methods not allowed; must be public: method android.pkg.MyClass.wrong()} [ProtectedMember] [Rule M7 in go/android-api-guidelines]
src/android/pkg/MyClass.java:8: error: Protected fields not allowed; must be public: field android.pkg.MyClass.wrong} [ProtectedMember] [Rule M7 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -625,6 +665,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:8: error: Internal field sBadStaticName must not be exposed [InternalField] [Rule F2 in go/android-api-guidelines]
src/android/pkg/MyClass.java:15: error: Internal field mBad must not be exposed [InternalField] [Rule F2 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 11 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -661,6 +705,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:8: error: Use android.net.Uri instead of java.net.URI (parameter param in android.pkg.MyClass.bad2(java.util.List<java.net.URI> param)) [AndroidUri] [Rule FW14 in go/android-api-guidelines]
src/android/pkg/MyClass.java:9: error: Use android.net.Uri instead of android.net.URL (parameter param in android.pkg.MyClass.bad3(android.net.URL param)) [AndroidUri] [Rule FW14 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -694,6 +742,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:17: error: BadFuture should not extend `java.util.concurrent.Future`. In AndroidX, use (but do not extend) ListenableFuture. In platform, use a combination of Consumer<T>, Executor, and CancellationSignal`. [BadFuture]
src/android/pkg/MyClass.java:19: error: BadFutureClass should not implement `java.util.concurrent.Future`. In AndroidX, use (but do not extend) ListenableFuture. In platform, use a combination of Consumer<T>, Executor, and CancellationSignal`. [BadFuture]
""",
+ expectedFail = """
+ 7 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -736,6 +788,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:20: error: Don't expose @LongDef: SomeLong must be hidden. [PublicTypedef] [Rule FW15 in go/android-api-guidelines]
src/android/pkg/MyClass.java:10: error: Don't expose @StringDef: SomeString must be hidden. [PublicTypedef] [Rule FW15 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -783,6 +839,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/RegistrationMethods.java:16: error: Found removeMismatchedListener but not addMismatchedListener in android.pkg.RegistrationMethods [PairedRegistration] [Rule L2 in go/android-api-guidelines]
src/android/pkg/RegistrationMethods.java:17: error: Listener methods should be named add/remove; was registerWrongListener [RegistrationName] [Rule L3 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 6 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -825,6 +885,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/CheckSynchronization2.kt:16: error: Internal locks must not be exposed (synchronizing on this or class is still externally observable): method android.pkg.CheckSynchronization2.errorMethod4() [VisiblySynchronized] [Rule M5 in go/android-api-guidelines]
src/android/pkg/CheckSynchronization2.kt:18: error: Internal locks must not be exposed (synchronizing on this or class is still externally observable): method android.pkg.CheckSynchronization2.errorMethod5() [VisiblySynchronized] [Rule M5 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 8 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -934,6 +998,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass4.java:3: error: Inconsistent class name; should be `<Foo>Receiver`, was `MyClass4` [ContextNameSuffix] [Rule C4 in go/android-api-guidelines]
src/android/pkg/MyOkActivity.java:3: error: MyOkActivity should not extend `Activity`. Activity subclasses are impossible to compose. Expose a composable API instead. [ForbiddenSuperClass]
""",
+ expectedFail = """
+ 8 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1055,6 +1123,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass1.java:3: error: Raw AIDL interfaces must not be exposed: MyClass1 extends Binder [RawAidl]
src/android/pkg/MyClass2.java:3: error: Raw AIDL interfaces must not be exposed: MyClass2 implements IInterface [RawAidl]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1092,6 +1164,10 @@ class ApiLintTest : DriverTest() {
expectedIssues = """
src/com/android/pkg/MyClass.java:3: error: Internal classes must not be exposed [InternalClasses]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1158,6 +1234,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:37: error: Symmetric method for `setWiFiRoamingSettingEnabledBad` must be named `isWiFiRoamingSettingEnabledBad`; was `getWiFiRoamingSettingEnabledBad` [GetterSetterNames] [Rule M6 in go/android-api-guidelines]
src/android/pkg/MyClass.java:40: error: Symmetric method for `setEnabledBad` must be named `isEnabledBad`; was `getEnabledBad` [GetterSetterNames] [Rule M6 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 7 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1218,6 +1298,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:9: error: Return type is concrete collection (`java.util.Vector`); must be higher-level interface [ConcreteCollection] [Rule CL2 in go/android-api-guidelines]
src/android/pkg/MyClass.java:10: error: Parameter type is concrete collection (`java.util.LinkedList`); must be higher-level interface [ConcreteCollection] [Rule CL2 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1295,6 +1379,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:10: warning: Methods taking no arguments should throw `IllegalStateException` instead of `java.lang.NullPointerException` [IllegalStateException] [Rule S1 in go/android-api-guidelines]
src/android/pkg/MyClass.java:11: error: Methods calling system APIs should rethrow `RemoteException` as `RuntimeException` (but do not list it in the throws clause) [RethrowRemoteException] [Rule FW9 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 6 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1326,6 +1414,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:4: error: Must never reference Google (`MyGoogleService`) [MentionsGoogle]
src/android/pkg/MyClass.java:5: error: Must never reference Google (`callGoogle`) [MentionsGoogle]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1352,6 +1444,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:9: error: Type must not be heavy BitSet (parameter bitset in android.pkg.MyClass.reverse(java.util.BitSet bitset)) [HeavyBitSet]
src/android/pkg/MyClass.java:6: error: Type must not be heavy BitSet (field android.pkg.MyClass.bitset) [HeavyBitSet]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1380,6 +1476,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyFirstManager.java:6: error: Managers must always be obtained from Context; no direct constructors [ManagerConstructor]
src/android/pkg/MyFirstManager.java:8: error: Managers must always be obtained from Context (`get`) [ManagerLookup]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1422,6 +1522,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:12: error: Must avoid boxed primitives (`java.lang.Double`) [AutoBoxing] [Rule M11 in go/android-api-guidelines]
src/android/pkg/MyClass.java:6: error: Must avoid boxed primitives (`java.lang.Integer`) [AutoBoxing] [Rule M11 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 4 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1453,6 +1557,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyUtils1.java:3: error: Fully-static utility classes must not have constructor [StaticUtils]
src/android/pkg/MyUtils2.java:3: error: Fully-static utility classes must not have constructor [StaticUtils]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1518,6 +1626,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:11: error: Context is distinct, so it must be the first argument (method `wrong`) [ContextFirst] [Rule M3 in go/android-api-guidelines]
src/android/pkg/MyClass.java:12: error: ContentResolver is distinct, so it must be the first argument (method `wrong`) [ContextFirst] [Rule M3 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1690,6 +1802,10 @@ class ApiLintTest : DriverTest() {
src/android/R.java:20: error: Expected resource name in `android.R.layout` to be in the `foo_bar_baz` style, was `wrongNameStyle` [ResourceFieldName]
src/android/R.java:31: error: Expected resource name in `android.R.style` to be in the `FooBar_Baz` style, was `wrong_style_name` [ResourceStyleFieldName] [Rule C7 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 4 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1837,6 +1953,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:7: error: Methods must not mention RuntimeException subclasses in throws clauses (was `java.lang.SecurityException`) [BannedThrow]
src/android/pkg/MyClass.java:6: error: Methods must not mention RuntimeException subclasses in throws clauses (was `java.lang.ClassCastException`) [BannedThrow]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1863,6 +1983,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/MyClass.java:3: error: Trouble must be reported through an `Exception`, not an `Error` (`MyClass` extends `Error`) [ExtendsError]
src/android/pkg/MySomething.java:3: error: Exceptions must be named `FooException`, was `MySomething` [ExceptionName]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -1902,6 +2026,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/UnitNameTest.java:22: error: Percentage must use ints, was `float` in `setErrorPercentage` [PercentageInt]
src/android/pkg/UnitNameTest.java:24: error: Expected method name units to be `Bytes`, was `Byte` in `readSingleByte` [MethodNameUnits]
""",
+ expectedFail = """
+ 11 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2144,6 +2272,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/KotlinKeywordTest.java:7: error: Avoid method names that are Kotlin hard keywords ("fun"); see https://android.github.io/kotlin-guides/interop.html#no-hard-keywords [KotlinKeyword]
src/android/pkg/KotlinKeywordTest.java:8: error: Avoid field names that are Kotlin hard keywords ("as"); see https://android.github.io/kotlin-guides/interop.html#no-hard-keywords [KotlinKeyword]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2175,6 +2307,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/KotlinOperatorTest.java:9: error: Only one of `plus` and `plusAssign` methods should be present for Kotlin [UniqueKotlinOperator]
src/android/pkg/KotlinOperatorTest.java:10: info: Method can be invoked as a compound assignment operator from Kotlin: `plusAssign` (this is usually desirable; just make sure it makes sense for this type of object) [KotlinOperator]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2306,6 +2442,10 @@ class ApiLintTest : DriverTest() {
src/android/content/Context.java:12: error: Inconsistent service constant name; expected `OTHER_SERVICE`, was `OTHER_MANAGER_SERVICE` [ServiceName] [Rule C4 in go/android-api-guidelines]
src/android/content/Context.java:9: error: Inconsistent service value; expected `other`, was `something` (Note: Do not change the name of already released services, which will break tools using `adb shell dumpsys`. Instead add `@SuppressLint("ServiceName"))` [ServiceName] [Rule C4 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2377,6 +2517,10 @@ class ApiLintTest : DriverTest() {
expectedIssues = """
src/android/pkg/CloneTest.java:7: error: Provide an explicit copy constructor instead of implementing `clone()` [NoClone]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2432,6 +2576,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/PdfTest.java:6: error: Must use ParcelFileDescriptor instead of FileDescriptor in parameter fd in android.pkg.PdfTest.error1(java.io.FileDescriptor fd) [UseParcelFileDescriptor] [Rule FW11 in go/android-api-guidelines]
src/android/pkg/PdfTest.java:7: error: Must use ParcelFileDescriptor instead of FileDescriptor in method android.pkg.PdfTest.getFileDescriptor() [UseParcelFileDescriptor] [Rule FW11 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2505,6 +2653,10 @@ class ApiLintTest : DriverTest() {
expectedIssues = """
src/android/pkg/MySingleton.java:8: error: Singleton classes should use `getInstance()` methods: `MySingleton` [SingletonConstructor]
""",
+ expectedFail = """
+ 1 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2548,6 +2700,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/IndirectActivity.java:2: error: IndirectActivity should not extend `Activity`. Activity subclasses are impossible to compose. Expose a composable API instead. [ForbiddenSuperClass]
src/android/pkg/MyTask.java:2: error: MyTask should not extend `AsyncTask`. AsyncTask is an implementation detail. Expose a listener or, in androidx, a `ListenableFuture` API instead [ForbiddenSuperClass]
""",
+ expectedFail = """
+ 3 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
@@ -2656,6 +2812,10 @@ class ApiLintTest : DriverTest() {
src/android/pkg/Foo.java:20: error: Missing nullability on parameter `duration` in method `methodMissingParamAnnotations` [MissingNullability]
src/android/pkg/Foo.java:7: error: Missing nullability on field `badField` in class `class android.pkg.Foo` [MissingNullability]
""",
+ expectedFail = """
+ 5 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""
diff --git a/src/test/java/com/android/tools/metalava/ReporterTest.kt b/src/test/java/com/android/tools/metalava/ReporterTest.kt
index 937b912..0368bf6 100644
--- a/src/test/java/com/android/tools/metalava/ReporterTest.kt
+++ b/src/test/java/com/android/tools/metalava/ReporterTest.kt
@@ -30,6 +30,10 @@ class ReporterTest : DriverTest() {
errorSeverityExpectedIssues = """
src/test/pkg/foo.java:2: error: Class must start with uppercase char: foo [StartWithUpper] [Rule S1 in go/android-api-guidelines]
""",
+ expectedFail = """
+ 2 new API lint issues were found.
+ See tools/metalava/API-LINT.md for how to handle these.
+ """,
sourceFiles = arrayOf(
java(
"""