diff --git a/API-LINT.md b/API-LINT.md index 76b2d09277dda64a60a6685a5e4aa7d79a887c41..f32cbb062ce5672704c5242d5a1b50c97df8ebfd 100644 --- a/API-LINT.md +++ b/API-LINT.md @@ -44,18 +44,40 @@ it is silently ignored. You can pass a flag to metalava ("--update-baseline") to tell it to update the baseline files with any new errors it comes across instead of reporting -them. With soong, you'd do something like this: +them. With soong, if you specify the baseline explicitly, like this: --- a/Android.bp +++ b/Android.bp @@ -1678,6 +1678,7 @@ droidstubs { }, api_lint: true, - baseline_filename: "baseline.txt", - + update_baseline: true, + ==> baseline_filename: "api/baseline.txt", <== jdiff_enabled: true, } +then the build system will automatically supply `--update-baseline` on your +behalf to a generated file in the out/ folder, and if there's a failure metalava +will tell you where to find the updated baseline which you can then copy into +place: + + ... + 93 new API lint issues were found. See tools/metalava/API-LINT.md for how to handle these. + ************************************************************ + Your API changes are triggering API Lint warnings or errors. + To make these errors go away, you have two choices: + + 1. You can suppress the errors with @SuppressLint("<id>") + 2. You can update the baseline by executing the following + command: + cp \ + out/soong/.intermediates/frameworks/base/system-api-stubs-docs/android_common/api/system-baseline.txt \ + frameworks/base/api/system-baseline.txt + To submit the revised baseline.txt to the main Android + repository, you will need approval. + ************************************************************ + + + Then re-run the build and you should now see diffs to the baseline file; git diff to make sure you're really only marking the issues you intended to include. diff --git a/src/main/java/com/android/tools/metalava/AnnotationsDiffer.kt b/src/main/java/com/android/tools/metalava/AnnotationsDiffer.kt index d9a276de3a3ee9920491f3d8c6b8b4517b53d553..760ebfbb821e05609c9b977dcf81cfcac7d66e74 100644 --- a/src/main/java/com/android/tools/metalava/AnnotationsDiffer.kt +++ b/src/main/java/com/android/tools/metalava/AnnotationsDiffer.kt @@ -26,6 +26,7 @@ import java.io.IOException import java.io.PrintWriter import java.io.StringWriter import java.util.function.Predicate +import kotlin.text.Charsets.UTF_8 /** * The [AnnotationsDiffer] can take a codebase with annotations, and subtract @@ -135,7 +136,7 @@ class AnnotationsDiffer( } } - apiFile.writeText(cleanedUp, Charsets.UTF_8) + apiFile.writeText(cleanedUp, UTF_8) } catch (e: IOException) { reporter.report(Errors.IO_ERROR, apiFile, "Cannot open file for write.") } diff --git a/src/main/java/com/android/tools/metalava/AnnotationsMerger.kt b/src/main/java/com/android/tools/metalava/AnnotationsMerger.kt index e7814c1e761679fe3aa0745b1ca42f8bf9740c61..795d99eba61947220d871b1c242803b38232e8b0 100644 --- a/src/main/java/com/android/tools/metalava/AnnotationsMerger.kt +++ b/src/main/java/com/android/tools/metalava/AnnotationsMerger.kt @@ -62,7 +62,6 @@ import com.android.tools.metalava.model.parseDocument import com.android.tools.metalava.model.psi.PsiAnnotationItem import com.android.tools.metalava.model.psi.PsiBasedCodebase import com.android.tools.metalava.model.visitors.ApiVisitor -import com.google.common.base.Charsets import com.google.common.io.ByteStreams import com.google.common.io.Closeables import com.google.common.io.Files @@ -76,6 +75,7 @@ import java.lang.reflect.Field import java.util.jar.JarInputStream import java.util.regex.Pattern import java.util.zip.ZipEntry +import kotlin.text.Charsets.UTF_8 /** Merges annotations into classes already registered in the given [Codebase] */ class AnnotationsMerger( @@ -152,7 +152,7 @@ class AnnotationsMerger( mergeFromJar(file) } else if (file.path.endsWith(DOT_XML)) { try { - val xml = Files.asCharSource(file, Charsets.UTF_8).read() + val xml = Files.asCharSource(file, UTF_8).read() mergeAnnotationsXml(file.path, xml) } catch (e: IOException) { error("Aborting: I/O problem during transform: " + e.toString()) @@ -182,7 +182,7 @@ class AnnotationsMerger( while (entry != null) { if (entry.name.endsWith(".xml")) { val bytes = ByteStreams.toByteArray(zis) - val xml = String(bytes, Charsets.UTF_8) + val xml = String(bytes, UTF_8) mergeAnnotationsXml(jar.path + ": " + entry, xml) } entry = zis.nextEntry diff --git a/src/main/java/com/android/tools/metalava/ApiLint.kt b/src/main/java/com/android/tools/metalava/ApiLint.kt index abe0b2db9f773c7ce0288b2e60303d92ad446add..26cda4335e8cc84c9b306a6a01a88f2ac3719228 100644 --- a/src/main/java/com/android/tools/metalava/ApiLint.kt +++ b/src/main/java/com/android/tools/metalava/ApiLint.kt @@ -197,22 +197,26 @@ class ApiLint(private val codebase: Codebase, private val oldCodebase: Codebase? if (apiLintIssues > 0) { // We've reported API lint violations; emit some verbiage to explain // how to suppress the error rules. - options.stdout.println("\n$apiLintIssues new API lint issues were found. See tools/metalava/API-LINT.md for how to handle these.") + options.stdout.println("\n$apiLintIssues new API lint issues were found.") val baseline = options.baseline if (baseline?.updateFile != null && baseline.file != null && !baseline.silentUpdate) { options.stdout.println(""" - ****************************** + ************************************************************ Your API changes are triggering API Lint warnings or errors. To make these errors go away, you have two choices: - 1. You can suppress the errors with @SuppressLint("<id>") - 2. You can update the baseline by executing the following command: - cp \ - ${baseline.updateFile} \ - ${baseline.file} - To submit the revised baseline.txt to the main Android repository, - you will need approval. - ****************************** + + 1. You can suppress the errors with @SuppressLint("<id>") + 2. You can update the baseline by executing the following + command: + cp \ + ${baseline.updateFile} \ + ${baseline.file} + To submit the revised baseline.txt to the main Android + repository, you will need approval. + ************************************************************ """.trimIndent()) + } else { + options.stdout.println("See tools/metalava/API-LINT.md for how to handle these.") } } } diff --git a/src/main/java/com/android/tools/metalava/Baseline.kt b/src/main/java/com/android/tools/metalava/Baseline.kt index 335cee4abfa1c381ef11604c0ab5b20e9ed537f4..f4ea6ee26fd88c56e9a6f8dd6ea3b66c22abc759 100644 --- a/src/main/java/com/android/tools/metalava/Baseline.kt +++ b/src/main/java/com/android/tools/metalava/Baseline.kt @@ -35,6 +35,7 @@ import com.intellij.psi.PsiParameter import org.jetbrains.kotlin.psi.psiUtil.parameterIndex import java.io.File import java.io.PrintWriter +import kotlin.text.Charsets.UTF_8 const val DEFAULT_BASELINE_NAME = "baseline.txt" @@ -181,7 +182,7 @@ class Baseline( private fun read() { val file = this.file ?: return - val lines = file.readLines(Charsets.UTF_8) + val lines = file.readLines(UTF_8) for (i in 0 until lines.size - 1) { val line = lines[i] if (line.startsWith("//") || @@ -235,7 +236,7 @@ class Baseline( sb.append("\n\n") } updateFile.parentFile?.mkdirs() - updateFile.writeText(sb.toString(), Charsets.UTF_8) + updateFile.writeText(sb.toString(), UTF_8) } else { updateFile.delete() } diff --git a/src/main/java/com/android/tools/metalava/Driver.kt b/src/main/java/com/android/tools/metalava/Driver.kt index 400c139b48cbaaccce9d7590f0b54c1546039bac..97ae453478cfca2026c9568be48bd273175d2312 100644 --- a/src/main/java/com/android/tools/metalava/Driver.kt +++ b/src/main/java/com/android/tools/metalava/Driver.kt @@ -139,7 +139,7 @@ fun run( options = Options(modifiedArgs, stdout, stderr) processFlags() - if (reporter.hasErrors() && !options.updateBaseline) { + if (reporter.hasErrors() && !options.passBaselineUpdates) { exitCode = -1 } exitValue = true @@ -160,7 +160,9 @@ fun run( if (options.verbose) { options.baseline?.dumpStats(options.stdout) } - stdout.println("$PROGRAM_NAME wrote updated baseline to ${options.baseline?.file}") + if (!options.quiet) { + stdout.println("$PROGRAM_NAME wrote updated baseline to ${options.baseline?.updateFile}") + } } options.baseline?.close() @@ -731,7 +733,7 @@ fun invokeDocumentationTool() { class PrintWriterOutputStream(private val writer: PrintWriter) : OutputStream() { override fun write(b: ByteArray) { - writer.write(String(b, Charsets.UTF_8)) + writer.write(String(b, UTF_8)) } override fun write(b: Int) { @@ -739,7 +741,7 @@ class PrintWriterOutputStream(private val writer: PrintWriter) : OutputStream() } override fun write(b: ByteArray, off: Int, len: Int) { - writer.write(String(b, off, len, Charsets.UTF_8)) + writer.write(String(b, off, len, UTF_8)) } override fun flush() { @@ -1018,7 +1020,7 @@ fun createReportFile( } val localTimer = Stopwatch.createStarted() try { - val writer = PrintWriter(Files.asCharSink(apiFile, Charsets.UTF_8).openBufferedStream()) + val writer = PrintWriter(Files.asCharSink(apiFile, UTF_8).openBufferedStream()) writer.use { printWriter -> val apiWriter = createVisitor(printWriter) codebase.accept(apiWriter) @@ -1139,7 +1141,7 @@ private fun addHiddenPackages( } else -> return } - var contents = Files.asCharSource(file, Charsets.UTF_8).read() + var contents = Files.asCharSource(file, UTF_8).read() if (javadoc) { contents = packageHtmlToJavadoc(contents) } @@ -1226,7 +1228,7 @@ private fun findRoot(file: File): File? { /** Finds the package of the given Java/Kotlin source file, if possible */ fun findPackage(file: File): String? { - val source = Files.asCharSource(file, Charsets.UTF_8).read() + val source = Files.asCharSource(file, UTF_8).read() return findPackage(source) } diff --git a/src/main/java/com/android/tools/metalava/ExtractAnnotations.kt b/src/main/java/com/android/tools/metalava/ExtractAnnotations.kt index dc33b27f2c46bb9bba98c961e3dc0d21339196c5..d69b1af6c7974392cbc0372f807f5d4f85e86034 100644 --- a/src/main/java/com/android/tools/metalava/ExtractAnnotations.kt +++ b/src/main/java/com/android/tools/metalava/ExtractAnnotations.kt @@ -35,7 +35,6 @@ import com.android.tools.metalava.model.psi.PsiAnnotationItem import com.android.tools.metalava.model.psi.PsiClassItem import com.android.tools.metalava.model.psi.PsiMethodItem import com.android.tools.metalava.model.visitors.ApiVisitor -import com.google.common.base.Charsets import com.google.common.xml.XmlEscapers import com.intellij.psi.JavaRecursiveElementVisitor import com.intellij.psi.PsiAnnotation @@ -63,6 +62,7 @@ import java.io.StringWriter import java.util.ArrayList import java.util.jar.JarEntry import java.util.jar.JarOutputStream +import kotlin.text.Charsets.UTF_8 // Like the tools/base Extractor class, but limited to our own (mapped) AnnotationItems, // and only those with source retention (and in particular right now that just means the @@ -148,7 +148,7 @@ class ExtractAnnotations( } writer.println("</root>\n") writer.close() - val bytes = writer.contents.toByteArray(Charsets.UTF_8) + val bytes = writer.contents.toByteArray(UTF_8) zos.write(bytes) zos.closeEntry() } diff --git a/src/main/java/com/android/tools/metalava/NullabilityAnnotationsValidator.kt b/src/main/java/com/android/tools/metalava/NullabilityAnnotationsValidator.kt index a5833b288658b246cc562d24018bf5c560d56027..0bdba6725546a49c68e0a6d50be2c1d6291d76c9 100644 --- a/src/main/java/com/android/tools/metalava/NullabilityAnnotationsValidator.kt +++ b/src/main/java/com/android/tools/metalava/NullabilityAnnotationsValidator.kt @@ -28,7 +28,7 @@ import com.android.tools.metalava.model.visitors.ApiVisitor import com.google.common.io.Files import java.io.File import java.io.PrintWriter -import java.nio.charset.StandardCharsets +import kotlin.text.Charsets.UTF_8 private const val RETURN_LABEL = "return value" @@ -106,7 +106,7 @@ class NullabilityAnnotationsValidator { fun validateAllFrom(codebase: Codebase, topLevelClassesList: File?) { if (topLevelClassesList != null) { val classes = - Files.readLines(topLevelClassesList, StandardCharsets.UTF_8) + Files.readLines(topLevelClassesList, UTF_8) .filterNot { it.isBlank() } .map { it.trim() } .filterNot { it.startsWith("#") } @@ -212,7 +212,7 @@ class NullabilityAnnotationsValidator { // Non-fatal issues are written to the warnings .txt file if present, else logged. if (warningsTxtFile != null) { - PrintWriter(Files.asCharSink(warningsTxtFile, Charsets.UTF_8).openBufferedStream()).use { w -> + PrintWriter(Files.asCharSink(warningsTxtFile, UTF_8).openBufferedStream()).use { w -> nonFatalIssues.forEach { w.println(it) } } } else { diff --git a/src/main/java/com/android/tools/metalava/Options.kt b/src/main/java/com/android/tools/metalava/Options.kt index 33a26da263eca01836e683ffc9d7a7fb77963d92..a0e301fc85108a1cce46b703480335d4a472dd1d 100644 --- a/src/main/java/com/android/tools/metalava/Options.kt +++ b/src/main/java/com/android/tools/metalava/Options.kt @@ -33,6 +33,7 @@ import java.io.StringWriter import java.util.Locale import kotlin.reflect.KMutableProperty1 import kotlin.reflect.full.memberProperties +import kotlin.text.Charsets.UTF_8 /** Global options for the metadata extraction tool */ var options = Options(emptyArray()) @@ -136,6 +137,7 @@ const val ARG_REWRITE_ANNOTATIONS = "--rewrite-annotations" const val ARG_INCLUDE_SOURCE_RETENTION = "--include-source-retention" const val ARG_INCLUDE_SIG_VERSION = "--include-signature-version" const val ARG_UPDATE_API = "--update-api" +const val ARG_PASS_BASELINE_UPDATES = "--pass-baseline-updates" const val ARG_DEX_API_MAPPING = "--dex-api-mapping" const val ARG_GENERATE_DOCUMENTATION = "--generate-documentation" const val ARG_BASELINE = "--baseline" @@ -502,6 +504,9 @@ class Options( /** Whether all baseline files need to be updated */ var updateBaseline = false + /** If updating baselines, don't fail the build */ + var passBaselineUpdates = false + /** Whether the baseline should only contain errors */ var baselineErrorsOnly = false @@ -750,6 +755,7 @@ class Options( } } } + ARG_PASS_BASELINE_UPDATES -> passBaselineUpdates = true ARG_PUBLIC, "-public" -> docLevel = DocLevel.PUBLIC ARG_PROTECTED, "-protected" -> docLevel = DocLevel.PROTECTED @@ -1349,6 +1355,9 @@ class Options( if (baselineFile == null) { val defaultBaselineFile = getDefaultBaselineFile() if (defaultBaselineFile != null && defaultBaselineFile.isFile) { + if (updateBaseline && updateBaselineFile == null) { + updateBaselineFile = defaultBaselineFile + } baseline = Baseline(defaultBaselineFile, updateBaselineFile, mergeBaseline) } else if (updateBaselineFile != null) { baseline = Baseline(null, updateBaselineFile, mergeBaseline) @@ -1359,6 +1368,9 @@ class Options( "// See tools/metalava/API-LINT.md for how to update this file.\n\n" else "" + if (updateBaseline && updateBaselineFile == null) { + updateBaselineFile = baselineFile + } baseline = Baseline(baselineFile, updateBaselineFile, mergeBaseline, headerComment) } @@ -1609,7 +1621,7 @@ class Options( if (!listFile.isFile) { throw DriverException("$listFile is not a file") } - val contents = Files.asCharSource(listFile, Charsets.UTF_8).read() + val contents = Files.asCharSource(listFile, UTF_8).read() val pathList = Splitter.on(CharMatcher.whitespace()).trimResults().omitEmptyStrings().split( contents ) @@ -1886,6 +1898,9 @@ class Options( "in the baseline, it will merge the existing baseline with the new baseline. This is useful " + "if $PROGRAM_NAME runs multiple times on the same source tree with different flags at different " + "times, such as occasionally with $ARG_API_LINT.", + ARG_PASS_BASELINE_UPDATES, "Normally, encountering error will fail the build, even when updating " + + "baselines. This flag allows you to tell $PROGRAM_NAME to continue without errors, such that " + + "all the baselines in the source tree can be updated in one go.", "", "\nJDiff:", "$ARG_XML_API <file>", "Like $ARG_API, but emits the API in the JDiff XML format instead", diff --git a/src/main/java/com/android/tools/metalava/RewriteAnnotations.kt b/src/main/java/com/android/tools/metalava/RewriteAnnotations.kt index 38f6a263d54fd12a0c7e354ad45026e4961407fe..520e97ac34337515db173894b45802c8aa7fbdd5 100644 --- a/src/main/java/com/android/tools/metalava/RewriteAnnotations.kt +++ b/src/main/java/com/android/tools/metalava/RewriteAnnotations.kt @@ -37,6 +37,7 @@ import java.nio.file.attribute.FileTime import java.util.jar.JarEntry import java.util.zip.ZipInputStream import java.util.zip.ZipOutputStream +import kotlin.text.Charsets.UTF_8 /** * Converts public stub annotation sources into package private annotation sources. @@ -61,7 +62,7 @@ class RewriteAnnotations { // Copy and convert target.parentFile.mkdirs() target.writeText( - source.readText(Charsets.UTF_8).replace( + source.readText(UTF_8).replace( "\npublic @interface", "\n@interface" ) diff --git a/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java b/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java index 00f3eb3126cb9c21107824d7d5c82ca1a67614a9..7a28c4ea47332b31438e1e2a890778a4d9bd7735 100644 --- a/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java +++ b/src/main/java/com/android/tools/metalava/doclava1/ApiFile.java @@ -33,7 +33,6 @@ import com.android.tools.metalava.model.text.TextPropertyItem; import com.android.tools.metalava.model.text.TextTypeItem; import com.android.tools.metalava.model.text.TextTypeParameterList; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; import com.google.common.io.Files; import kotlin.Pair; import kotlin.text.StringsKt; @@ -52,6 +51,7 @@ import static com.android.tools.metalava.ConstantsKt.JAVA_LANG_ANNOTATION; import static com.android.tools.metalava.ConstantsKt.JAVA_LANG_ENUM; import static com.android.tools.metalava.ConstantsKt.JAVA_LANG_STRING; import static com.android.tools.metalava.model.FieldItemKt.javaUnescapeString; +import static kotlin.text.Charsets.UTF_8; // // Copied from doclava1, but adapted to metalava's code model (plus tweaks to handle @@ -65,7 +65,7 @@ public class ApiFile { public static TextCodebase parseApi(File file, Boolean kotlinStyleNulls) throws ApiParseException { try { - String apiText = Files.asCharSource(file, Charsets.UTF_8).read(); + String apiText = Files.asCharSource(file, UTF_8).read(); return parseApi(file.getPath(), apiText, kotlinStyleNulls); } catch (IOException ex) { throw new ApiParseException("Error reading API file", ex); diff --git a/src/test/java/com/android/tools/metalava/AnnotationsDifferTest.kt b/src/test/java/com/android/tools/metalava/AnnotationsDifferTest.kt index 9e3999841c5184e169bad33eab5c5bdfcaa6af4a..382174480735cd91367e8d0c3a02788039a11acc 100644 --- a/src/test/java/com/android/tools/metalava/AnnotationsDifferTest.kt +++ b/src/test/java/com/android/tools/metalava/AnnotationsDifferTest.kt @@ -22,6 +22,7 @@ import org.junit.Assert.assertTrue import org.junit.Rule import org.junit.Test import org.junit.rules.TemporaryFolder +import kotlin.text.Charsets.UTF_8 class AnnotationsDifferTest { @get:Rule @@ -60,7 +61,7 @@ class AnnotationsDifferTest { options = Options(emptyArray()) AnnotationsDiffer(codebase, codebase2).writeDiffSignature(apiFile) assertTrue(apiFile.exists()) - val actual = apiFile.readText(Charsets.UTF_8) + val actual = apiFile.readText(UTF_8) assertEquals( """ package test.pkg { diff --git a/src/test/java/com/android/tools/metalava/ApiLintTest.kt b/src/test/java/com/android/tools/metalava/ApiLintTest.kt index dbbc41a8447596abc888d5f0a9212fabe0a362f9..87d9a7459a03e2eb0d1af1a4b7b30478c95d0ec6 100644 --- a/src/test/java/com/android/tools/metalava/ApiLintTest.kt +++ b/src/test/java/com/android/tools/metalava/ApiLintTest.kt @@ -110,7 +110,10 @@ class ApiLintTest : DriverTest() { """ ) ), - expectedOutput = "9 new API lint issues were found. See tools/metalava/API-LINT.md for how to handle these." + expectedOutput = """ + 9 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/CompatibilityCheckTest.kt b/src/test/java/com/android/tools/metalava/CompatibilityCheckTest.kt index 6c01e32849a29e733c05e0fc4d821d9d86937be1..a457fcdb4b4c38e9b8cee67883fe2ae6864c4782 100644 --- a/src/test/java/com/android/tools/metalava/CompatibilityCheckTest.kt +++ b/src/test/java/com/android/tools/metalava/CompatibilityCheckTest.kt @@ -19,6 +19,7 @@ package com.android.tools.metalava import org.junit.Ignore import org.junit.Test import java.io.File +import kotlin.text.Charsets.UTF_8 class CompatibilityCheckTest : DriverTest() { @@ -2421,7 +2422,7 @@ CompatibilityCheckTest : DriverTest() { println("Couldn't find $signatureFile: Check that pwd for test is correct. Skipping this test.") return } - val previousSignatureApi = signatureFile.readText(Charsets.UTF_8) + val previousSignatureApi = signatureFile.readText(UTF_8) check( checkDoclava1 = false, diff --git a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt index bc85a784ddef4862dbe33b8210f43aeb5de34a58..ea5b13fcbb72d874b86f2f8ae1c6347f0532fec3 100644 --- a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt +++ b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt @@ -7,6 +7,7 @@ import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import java.io.File +import kotlin.text.Charsets.UTF_8 /** Tests for the [DocAnalyzer] which enhances the docs */ class DocAnalyzerTest : DriverTest() { @@ -1552,7 +1553,7 @@ class DocAnalyzerTest : DriverTest() { ) ) - val doc = File(html, "test/pkg/LocationManager.html").readText(Charsets.UTF_8) + val doc = File(html, "test/pkg/LocationManager.html").readText(UTF_8) assertTrue( "Did not find matching javadoc fragment in LocationManager.html: actual content is\n$doc", doc.contains( diff --git a/src/test/java/com/android/tools/metalava/DriverTest.kt b/src/test/java/com/android/tools/metalava/DriverTest.kt index f862f3494177a1bf9ac964a1116617ac84b32c6a..780c0674a2b8a9334991a267d73c9f8f8a5a27f9 100644 --- a/src/test/java/com/android/tools/metalava/DriverTest.kt +++ b/src/test/java/com/android/tools/metalava/DriverTest.kt @@ -35,7 +35,6 @@ import com.android.tools.metalava.model.parseDocument import com.android.utils.FileUtils import com.android.utils.SdkUtils import com.android.utils.StdLogger -import com.google.common.base.Charsets import com.google.common.io.ByteStreams import com.google.common.io.Closeables import com.google.common.io.Files @@ -761,12 +760,12 @@ abstract class DriverTest { val signature = convert.fromApi val base = convert.baseApi val convertSig = temporaryFolder.newFile("convert-signatures$index.txt") - convertSig.writeText(signature.trimIndent(), Charsets.UTF_8) + convertSig.writeText(signature.trimIndent(), UTF_8) val extension = convert.format.preferredExtension() val output = temporaryFolder.newFile("convert-output$index$extension") val baseFile = if (base != null) { val baseFile = temporaryFolder.newFile("convert-signatures$index-base.txt") - baseFile.writeText(base.trimIndent(), Charsets.UTF_8) + baseFile.writeText(base.trimIndent(), UTF_8) baseFile } else { null @@ -1039,7 +1038,7 @@ abstract class DriverTest { val actualText = readFile(apiXmlFile, stripBlankLines, trim) assertEquals(stripComments(apiXml, stripLineComments = false).trimIndent(), actualText) // Make sure we can read back the files we write - parseDocument(apiXmlFile.readText(Charsets.UTF_8), false) + parseDocument(apiXmlFile.readText(UTF_8), false) } if (baseline != null && baselineFile != null) { @@ -1205,7 +1204,7 @@ abstract class DriverTest { validateNullabilityTxt.isFile ) val actualReport = - Files.asCharSource(validateNullabilityTxt, Charsets.UTF_8).readLines().map(String::trim).toSet() + Files.asCharSource(validateNullabilityTxt, UTF_8).readLines().map(String::trim).toSet() assertEquals(validateNullability, actualReport) } @@ -1320,7 +1319,7 @@ abstract class DriverTest { val signatureFile: File = apiFile ?: if (signatureSource != null) { val temp = temporaryFolder.newFile("jdiff-doclava-api.txt") - temp.writeText(signatureSource.trimIndent(), Charsets.UTF_8) + temp.writeText(signatureSource.trimIndent(), UTF_8) temp } else { fail("When verifying XML files with doclava you must either specify signatureSource or api") @@ -1349,11 +1348,11 @@ abstract class DriverTest { val base = convert.baseApi val strip = convert.strip val convertSig = temporaryFolder.newFile("doclava-jdiff-signatures$index.txt") - convertSig.writeText(signature.trimIndent(), Charsets.UTF_8) + convertSig.writeText(signature.trimIndent(), UTF_8) val output = temporaryFolder.newFile("doclava-jdiff-output$index.xml") val baseFile = if (base != null) { val baseFile = temporaryFolder.newFile("doclava-jdiff-signatures$index-base.txt") - baseFile.writeText(base.trimIndent(), Charsets.UTF_8) + baseFile.writeText(base.trimIndent(), UTF_8) baseFile } else { null @@ -1570,7 +1569,7 @@ abstract class DriverTest { try { val bytes = ByteStreams.toByteArray(stream) assertNotNull(bytes) - val xml = String(bytes, Charsets.UTF_8).replace("\r\n", "\n") + val xml = String(bytes, UTF_8).replace("\r\n", "\n") assertEquals(expected.trimIndent().trim(), xml.trimIndent().trim()) } finally { Closeables.closeQuietly(stream) @@ -1907,7 +1906,7 @@ abstract class DriverTest { } private fun readFile(file: File, stripBlankLines: Boolean = false, trim: Boolean = false): String { - var apiLines: List<String> = Files.asCharSource(file, Charsets.UTF_8).readLines() + var apiLines: List<String> = Files.asCharSource(file, UTF_8).readLines() if (stripBlankLines) { apiLines = apiLines.asSequence().filter { it.isNotBlank() }.toList() } diff --git a/src/test/java/com/android/tools/metalava/OptionsTest.kt b/src/test/java/com/android/tools/metalava/OptionsTest.kt index 7c61c9eac59ae290eb06e303ba54052f58d7753f..83726e2d756f2e723b9db03e688c2961052f5006 100644 --- a/src/test/java/com/android/tools/metalava/OptionsTest.kt +++ b/src/test/java/com/android/tools/metalava/OptionsTest.kt @@ -241,6 +241,11 @@ Diffs and Checks: on the same source tree with different flags at different times, such as occasionally with --api-lint. +--pass-baseline-updates Normally, encountering error will fail the + build, even when updating baselines. This flag + allows you to tell metalava to continue without + errors, such that all the baselines in the + source tree can be updated in one go. JDiff: --api-xml <file> Like --api, but emits the API in the JDiff XML diff --git a/src/test/java/com/android/tools/metalava/RewriteAnnotationsTest.kt b/src/test/java/com/android/tools/metalava/RewriteAnnotationsTest.kt index b8c2a416bee3f24671e251c7224095f4340b52df..a95fa2e3a5b5dd19323085510d1eee00be27e982 100644 --- a/src/test/java/com/android/tools/metalava/RewriteAnnotationsTest.kt +++ b/src/test/java/com/android/tools/metalava/RewriteAnnotationsTest.kt @@ -26,6 +26,7 @@ import org.junit.Test import java.io.File import java.lang.reflect.Modifier import java.net.URLClassLoader +import kotlin.text.Charsets.UTF_8 class RewriteAnnotationsTest : DriverTest() { @Test @@ -82,7 +83,7 @@ class RewriteAnnotationsTest : DriverTest() { @Retention(CLASS) @Target({METHOD, PARAMETER, FIELD}) @interface RecentlyNullable {} - """.trimIndent().trim(), recentlyNull.readText(Charsets.UTF_8).trim().replace("\r\n", "\n") + """.trimIndent().trim(), recentlyNull.readText(UTF_8).trim().replace("\r\n", "\n") ) }