You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2020/08/30 16:50:21 UTC

[lucene-solr] 02/03: Made missing doclet a regular project. This also means all the checks are applied to it (forbidden APIs, etc.).

This is an automated email from the ASF dual-hosted git repository.

dweiss pushed a commit to branch LUCENE-9215
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit a31831075f53bb246b5673b3e16edcb1b7d68a89
Author: Dawid Weiss <da...@carrotsearch.com>
AuthorDate: Sun Aug 30 18:49:39 2020 +0200

    Made missing doclet a regular project. This also means all the checks are applied to it (forbidden APIs, etc.).
---
 gradle/documentation/render-javadoc.gradle         | 21 +++++++++++++++++---
 gradle/validation/forbidden-apis.gradle            |  7 +++++++
 lucene/tools/missing-doclet/build.gradle           | 23 ++++++++++++++++++++++
 .../lucene/missingdoclet}/MissingDoclet.java       | 11 ++++++-----
 settings.gradle                                    |  1 +
 5 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/gradle/documentation/render-javadoc.gradle b/gradle/documentation/render-javadoc.gradle
index 49d904c..5245021 100644
--- a/gradle/documentation/render-javadoc.gradle
+++ b/gradle/documentation/render-javadoc.gradle
@@ -1,5 +1,4 @@
 import javax.annotation.Nullable
-import org.apache.lucene.gradle.MissingDoclet
 
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -23,6 +22,14 @@ import org.apache.lucene.gradle.MissingDoclet
 
 allprojects {
   plugins.withType(JavaPlugin) {
+    configurations {
+      missingdoclet
+    }
+
+    dependencies {
+      missingdoclet project(":lucene:tools:missing-doclet")
+    }
+
     ext {
       relativeDocPath = project.path.replaceFirst(/:\w+:/, "").replace(':', '/')
     }
@@ -41,6 +48,7 @@ allprojects {
       group "documentation"
 
       dependsOn sourceSets.main.compileClasspath
+
       classpath = sourceSets.main.compileClasspath;
       srcDirSet = sourceSets.main.java;
 
@@ -79,6 +87,10 @@ allprojects {
         "https://docs.oracle.com/en/java/javase/11/docs/api/": javaJavadocPackages,
         "https://junit.org/junit4/javadoc/4.12/": junitJavadocPackages
     ]
+
+    // Set up custom doclet.
+    dependsOn configurations.missingdoclet
+    docletpath = configurations.missingdoclet
   }
 }
 
@@ -362,6 +374,9 @@ class RenderJavadocTask extends DefaultTask {
   @CompileClasspath
   FileCollection classpath
 
+  @CompileClasspath
+  FileCollection docletpath
+
   @Input
   String title
 
@@ -446,8 +461,8 @@ class RenderJavadocTask extends DefaultTask {
     opts << [ '-tag', 'lucene.internal:a:NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.' ]
     opts << [ '-tag', "lucene.spi:t:SPI Name (case-insensitive: if the name is 'htmlStrip', 'htmlstrip' can be used when looking up the service)." ]
 
-    opts << [ '-doclet', MissingDoclet.class.getName() ]
-    opts << [ '-docletpath', project.rootProject.file("buildSrc/build/classes/java/main") ]
+    opts << [ '-doclet', "org.apache.lucene.missingdoclet.MissingDoclet" ]
+    opts << [ '-docletpath', docletpath.asPath ]
     opts << [ '--missing-level', javadocMissingLevel ]
     if (javadocMissingIgnore) {
       opts << [ '--missing-ignore', String.join(',', javadocMissingIgnore) ]
diff --git a/gradle/validation/forbidden-apis.gradle b/gradle/validation/forbidden-apis.gradle
index 5237570..a57fb71 100644
--- a/gradle/validation/forbidden-apis.gradle
+++ b/gradle/validation/forbidden-apis.gradle
@@ -103,6 +103,13 @@ allprojects { prj ->
       ]
     }
 
+    // Doclet does use exotic JDK APIs.
+    if (prj.path == ":lucene:tools:missing-doclet") {
+      forbiddenApisMain.bundledSignatures -= [
+          'jdk-non-portable'
+      ]
+    }
+
     // Configure lucene-specific rules.
     if (prj.path.startsWith(":lucene")) {
       forbiddenApisMain {
diff --git a/lucene/tools/missing-doclet/build.gradle b/lucene/tools/missing-doclet/build.gradle
new file mode 100644
index 0000000..1b2de9f
--- /dev/null
+++ b/lucene/tools/missing-doclet/build.gradle
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+apply plugin: 'java-library'
+
+description = 'Doclet-based javadoc validation.'
+
+dependencies {
+}
diff --git a/buildSrc/src/main/java/org/apache/lucene/gradle/MissingDoclet.java b/lucene/tools/missing-doclet/src/java/org/apache/lucene/missingdoclet/MissingDoclet.java
similarity index 97%
rename from buildSrc/src/main/java/org/apache/lucene/gradle/MissingDoclet.java
rename to lucene/tools/missing-doclet/src/java/org/apache/lucene/missingdoclet/MissingDoclet.java
index 75510ad..0fc130a 100644
--- a/buildSrc/src/main/java/org/apache/lucene/gradle/MissingDoclet.java
+++ b/lucene/tools/missing-doclet/src/java/org/apache/lucene/missingdoclet/MissingDoclet.java
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.lucene.gradle;
+package org.apache.lucene.missingdoclet;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -27,7 +27,6 @@ import javax.lang.model.element.Element;
 import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.ModuleElement;
-import javax.lang.model.element.VariableElement;
 import javax.lang.model.util.Elements;
 import javax.tools.Diagnostic;
 
@@ -98,7 +97,7 @@ public class MissingDoclet extends StandardDoclet {
 
       @Override
       public boolean process(String option, List<String> arguments) {
-        switch(arguments.get(0)) {
+        switch (arguments.get(0)) {
           case "package":
             level = PACKAGE;
             return true;
@@ -110,6 +109,7 @@ public class MissingDoclet extends StandardDoclet {
             return true;
           case "parameter":
             level = PARAMETER;
+            return true;
           default:
             return false;
         }
@@ -276,7 +276,8 @@ public class MissingDoclet extends StandardDoclet {
    * UweSays: It should not happen but it happens!
    */
   private boolean isSyntheticEnumMethod(Element element) {
-    if (element.getSimpleName().toString().equals("values") || element.getSimpleName().toString().equals("valueOf")) {
+    String simpleName = element.getSimpleName().toString();
+    if (simpleName.equals("values") || simpleName.equals("valueOf")) {
       if (element.getEnclosingElement().getKind() == ElementKind.ENUM) {
         return true;
       }
@@ -333,7 +334,7 @@ public class MissingDoclet extends StandardDoclet {
       }
       // now compare the method's formal parameter list against it
       for (var param : ((ExecutableElement)element).getParameters()) {
-        var name = ((VariableElement)param).getSimpleName().toString();
+        var name = param.getSimpleName().toString();
         if (!seenParameters.contains(name)) {
           error(element, "missing javadoc @param for parameter '" + name + "'");
         }
diff --git a/settings.gradle b/settings.gradle
index fdf46af..099ed64 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -48,6 +48,7 @@ include "lucene:spatial-extras"
 include "lucene:spatial3d"
 include "lucene:suggest"
 include "lucene:test-framework"
+include "lucene:tools:missing-doclet"
 
 include "solr:solrj"
 include "solr:core"