Merge "Remove the doc replacement Metalava option" am: d994da788d am: 890acc1ef4 am: 1430670afb am: 16a4a44724
Original change: https://android-review.googlesource.com/c/platform/tools/metalava/+/2068290
Change-Id: I4798e5c8ddfe54d9806f9f37547cfae6523e169a
Signed-off-by: Automerger Merge Worker <[email protected]>
diff --git a/src/main/java/com/android/tools/metalava/DocAnalyzer.kt b/src/main/java/com/android/tools/metalava/DocAnalyzer.kt
index 482725b..7e357c0 100644
--- a/src/main/java/com/android/tools/metalava/DocAnalyzer.kt
+++ b/src/main/java/com/android/tools/metalava/DocAnalyzer.kt
@@ -59,10 +59,6 @@
tweakGrammar()
- for (docReplacement in options.docReplacements) {
- codebase.accept(docReplacement)
- }
-
// TODO:
// insertMissingDocFromHiddenSuperclasses()
}
diff --git a/src/main/java/com/android/tools/metalava/DocReplacement.kt b/src/main/java/com/android/tools/metalava/DocReplacement.kt
deleted file mode 100644
index bc3c0de..0000000
--- a/src/main/java/com/android/tools/metalava/DocReplacement.kt
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.tools.metalava
-
-import com.android.tools.metalava.model.Item
-import com.android.tools.metalava.model.PackageItem
-import com.android.tools.metalava.model.visitors.ApiVisitor
-
-/**
- * An [ApiVisitor] that applies a regex replacement to the documentation of
- * [Item]s from the given packages and their sub-packages.
- */
-class DocReplacement(
- private val packageNames: List<String>,
- private val regex: Regex,
- private val replacement: String
-) : ApiVisitor() {
-
- private fun appliesToPackage(packageItem: PackageItem): Boolean {
- val fqn = packageItem.qualifiedName()
- return packageNames.any {
- pkg ->
- fqn.startsWith(pkg) && (fqn.length == pkg.length || fqn[pkg.length] == '.')
- }
- }
-
- override fun visitItem(item: Item) {
- val doc = item.documentation
- if (doc.isBlank()) {
- return
- }
- val pkg = item.containingPackage(strict = false)
- if (pkg != null && appliesToPackage(pkg)) {
- val new = doc.replace(regex, replacement)
- if (new != doc) {
- item.documentation = new
- }
- }
- }
-}
diff --git a/src/main/java/com/android/tools/metalava/Options.kt b/src/main/java/com/android/tools/metalava/Options.kt
index b6805ba..a65542e 100644
--- a/src/main/java/com/android/tools/metalava/Options.kt
+++ b/src/main/java/com/android/tools/metalava/Options.kt
@@ -136,7 +136,6 @@
const val ARG_UPDATE_API = "--only-update-api"
const val ARG_CHECK_API = "--only-check-api"
const val ARG_PASS_BASELINE_UPDATES = "--pass-baseline-updates"
-const val ARG_REPLACE_DOCUMENTATION = "--replace-documentation"
const val ARG_BASELINE = "--baseline"
const val ARG_BASELINE_API_LINT = "--baseline:api-lint"
const val ARG_BASELINE_CHECK_COMPATIBILITY_RELEASED = "--baseline:compatibility:released"
@@ -585,11 +584,6 @@
var reportEvenIfSuppressedWriter: PrintWriter? = null
/**
- * DocReplacements to apply to the documentation.
- */
- var docReplacements = mutableListOf<DocReplacement>()
-
- /**
* Whether to omit locations for warnings and errors. This is not a flag exposed to users
* or listed in help; this is intended for the unit test suite, used for example for the
* test which checks compatibility between signature and API files where the paths vary.
@@ -1145,14 +1139,6 @@
ARG_UPDATE_API, "--update-api" -> onlyUpdateApi = true
ARG_CHECK_API -> onlyCheckApi = true
- ARG_REPLACE_DOCUMENTATION -> {
- val packageNames = args[++index].split(":")
- val regex = Regex(args[++index])
- val replacement = args[++index]
- val docReplacement = DocReplacement(packageNames, regex, replacement)
- docReplacements.add(docReplacement)
- }
-
ARG_CONVERT_TO_JDIFF,
// doclava compatibility:
"-convert2xml",
@@ -2059,13 +2045,6 @@
"$ARG_MANIFEST <file>", "A manifest file, used to for check permissions to cross check APIs",
- "$ARG_REPLACE_DOCUMENTATION <p> <r> <t>",
- "Amongst nonempty documentation of items from Java " +
- "packages <p> and their subpackages, replaces any matches of regular expression <r> " +
- "with replacement text <t>. <p> is given as a nonempty list of Java package names separated " +
- "by ':' (e.g. \"java:android.util\"); <t> may contain backreferences (\$1, \$2 etc.) to " +
- "matching groups from <r>.",
-
"$ARG_HIDE_PACKAGE <package>",
"Remove the given packages from the API even if they have not been " +
"marked with @hide",
diff --git a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
index eaeab0d..de91122 100644
--- a/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
+++ b/src/test/java/com/android/tools/metalava/DocAnalyzerTest.kt
@@ -1845,101 +1845,6 @@
}
@Test
- fun `Rewrite external links for 129765390`() {
- // Tests rewriting links that go to {@docRoot}/../platform/ or {@docRoot}/../technotes,
- // which are hosted elsewhere. http://b/129765390
- check(
- sourceFiles = arrayOf(
- java(
- """
- package javax.security;
- /**
- * <a href="{@docRoot}/../technotes/guides/security/StandardNames.html#Cipher">Cipher Section</a>
- * <p>This class is a member of the
- * <a href="{@docRoot}/../technotes/guides/collections/index.html">
- * Java Collections Framework</a>.
- * <a href="../../../platform/serialization/spec/security.html">
- * Security Appendix</a>
- * <a href =
- * "../../../technotes/Example.html">valid</a>
- *
- *
- * The following examples are not touched.
- *
- * <a href="../../../foobar/Example.html">wrong directory<a/>
- * <a href="../ArrayList.html">wrong directory</a.
- * <a href="http://example.com/index.html">wrong directory/host</a>
- */
- public class Example { }
- """
- ),
- java(
- """
- package not.part.of.ojluni;
- /**
- * <p>This class is a member of the
- * <a href="{@docRoot}/../technotes/guides/collections/index.html">
- * Java Collections Framework</a>.
- */
- public class TestCollection { }
- """
- )
- ),
- checkCompilation = true,
- expectedIssues = null, // be unopinionated about whether there should be warnings
- docStubs = true,
- stubFiles = arrayOf(
- java(
- """
- package javax.security;
- /**
- * <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher">Cipher Section</a>
- * <p>This class is a member of the
- * <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/collections/index.html">
- * Java Collections Framework</a>.
- * <a href="https://docs.oracle.com/javase/8/docs/platform/serialization/spec/security.html">
- * Security Appendix</a>
- * <a href =
- * "https://docs.oracle.com/javase/8/docs/technotes/Example.html">valid</a>
- *
- *
- * The following examples are not touched.
- *
- * <a href="../../../foobar/Example.html">wrong directory<a/>
- * <a href="../ArrayList.html">wrong directory</a.
- * <a href="http://example.com/index.html">wrong directory/host</a>
- */
- @SuppressWarnings({"unchecked", "deprecation", "all"})
- public class Example {
- public Example() { throw new RuntimeException("Stub!"); }
- }
- """
- ),
- java(
- """
- package not.part.of.ojluni;
- /**
- * <p>This class is a member of the
- * <a href="{@docRoot}/../technotes/guides/collections/index.html">
- * Java Collections Framework</a>.
- */
- @SuppressWarnings({"unchecked", "deprecation", "all"})
- public class TestCollection {
- public TestCollection() { throw new RuntimeException("Stub!"); }
- }
- """
- )
- ),
- extraArguments = arrayOf(
- ARG_REPLACE_DOCUMENTATION,
- "com.sun:java:javax:jdk.net:sun",
- """(<a\s+href\s?=[\*\s]*")(?:(?:\{@docRoot\}/\.\./)|(?:(?:\.\./)+))((?:platform|technotes).+)">""",
- """$1https://docs.oracle.com/javase/8/docs/$2">"""
- )
- )
- }
-
- @Test
fun `Annotation annotating itself indirectly`() {
check(
sourceFiles = arrayOf(
diff --git a/src/test/java/com/android/tools/metalava/OptionsTest.kt b/src/test/java/com/android/tools/metalava/OptionsTest.kt
index 61e9fdb..73eecb3 100644
--- a/src/test/java/com/android/tools/metalava/OptionsTest.kt
+++ b/src/test/java/com/android/tools/metalava/OptionsTest.kt
@@ -103,12 +103,6 @@
A .jar file to read APIs from directly
--manifest <file>
A manifest file, used to for check permissions to cross check APIs
---replace-documentation <p> <r> <t>
- Amongst nonempty documentation of items from Java packages <p> and their
- subpackages, replaces any matches of regular expression <r> with
- replacement text <t>. <p> is given as a nonempty list of Java package names
- separated by ':' (e.g. "java:android.util"); <t> may contain backreferences
- ($1, $2 etc.) to matching groups from <r>.
--hide-package <package>
Remove the given packages from the API even if they have not been marked
with @hide