You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2019/07/13 16:31:33 UTC
[cxf] branch master updated: CXF-8066: Support Doclet API (JDK13+)
(#566)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/master by this push:
new 7cb48e0 CXF-8066: Support Doclet API (JDK13+) (#566)
7cb48e0 is described below
commit 7cb48e03d9a2875bb590dc74330e3817d530d9bf
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sat Jul 13 12:31:26 2019 -0400
CXF-8066: Support Doclet API (JDK13+) (#566)
---
maven-plugins/java2wadl-plugin/pom.xml | 51 ++++++
.../cxf/maven_plugin/javatowadl/DumpJavaDoc.java | 2 +-
.../cxf/maven_plugin/javatowadl/Java2WADLMojo.java | 22 +--
.../cxf/maven_plugin/javatowadl/DumpJavaDoc.java | 194 +++++++++++++++++++++
4 files changed, 251 insertions(+), 18 deletions(-)
diff --git a/maven-plugins/java2wadl-plugin/pom.xml b/maven-plugins/java2wadl-plugin/pom.xml
index e743c04..6365779 100644
--- a/maven-plugins/java2wadl-plugin/pom.xml
+++ b/maven-plugins/java2wadl-plugin/pom.xml
@@ -208,5 +208,56 @@
</plugins>
</build>
</profile>
+
+ <profile>
+ <id>jdk13</id>
+ <activation>
+ <jdk>[13,)</jdk>
+ </activation>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-jdk13-compile</id>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <forceJavacCompilerUse>true</forceJavacCompilerUse>
+ <compileSourceRoots>
+ <compileSourceRoot>${project.basedir}/src/main/java13</compileSourceRoot>
+ </compileSourceRoots>
+ <outputDirectory>${project.build.outputDirectory}/META-INF/versions/13</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ <configuration>
+ <release>9</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>default-jar</id>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Multi-Release>true</Multi-Release>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ </profile>
</profiles>
</project>
diff --git a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java
index c194bb9..3b05e5b 100644
--- a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java
+++ b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java
@@ -101,7 +101,7 @@ public final class DumpJavaDoc {
}
}
if (!foundTagOption) {
- reporter.printError("Usage: -dumpJavaDocFile theFileToDumpJavaDocForLatarUse...");
+ reporter.printError("Usage: -dumpJavaDocFile theFileToDumpJavaDocForLaterUse...");
}
return foundTagOption;
}
diff --git a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
index 34e91d5..fc9def9 100644
--- a/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
+++ b/maven-plugins/java2wadl-plugin/src/main/java/org/apache/cxf/maven_plugin/javatowadl/Java2WADLMojo.java
@@ -307,27 +307,15 @@ public class Java2WADLMojo extends AbstractMojo {
+ outputFileExtension).replace("/", File.separator);
}
- BufferedWriter writer = null;
try {
FileUtils.mkDir(new File(outputFile).getParentFile());
- /*File wadlFile = new File(outputFile);
- if (!wadlFile.exists()) {
- wadlFile.createNewFile();
- }*/
- writer = new BufferedWriter(new FileWriter(outputFile));
- writer.write(wadl);
-
+ try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFile))) {
+ writer.write(wadl);
+ }
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
- } finally {
- try {
- if (writer != null) {
- writer.close();
- }
- } catch (IOException e) {
- throw new MojoExecutionException(e.getMessage(), e);
- }
- }
+ }
+
// Attach the generated wadl file to the artifacts that get deployed
// with the enclosing project
if (attachWadl && outputFile != null) {
diff --git a/maven-plugins/java2wadl-plugin/src/main/java13/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java b/maven-plugins/java2wadl-plugin/src/main/java13/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java
new file mode 100644
index 0000000..5ca20af
--- /dev/null
+++ b/maven-plugins/java2wadl-plugin/src/main/java13/org/apache/cxf/maven_plugin/javatowadl/DumpJavaDoc.java
@@ -0,0 +1,194 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.maven_plugin.javatowadl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+import java.util.Properties;
+
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.util.Elements;
+import javax.tools.Diagnostic;
+
+import com.sun.source.doctree.DocCommentTree;
+import com.sun.source.doctree.DocTree;
+import com.sun.source.doctree.ParamTree;
+import com.sun.source.doctree.ReturnTree;
+import com.sun.source.util.DocTrees;
+
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import javax.lang.model.SourceVersion;
+
+import jdk.javadoc.doclet.Doclet;
+import jdk.javadoc.doclet.DocletEnvironment;
+import jdk.javadoc.doclet.Reporter;
+
+public final class DumpJavaDoc implements Doclet {
+ private String dumpFileName;
+ private Reporter reporter;
+
+ private final class DumpJavaDocFileOption implements Option {
+ @Override
+ public int getArgumentCount() {
+ return 1;
+ }
+
+ @Override
+ public String getDescription() {
+ return "Specify the file to dump Javadoc for later use";
+ }
+
+ @Override
+ public Kind getKind() {
+ return Kind.STANDARD;
+ }
+
+ @Override
+ public List<String> getNames() {
+ return Collections.singletonList("-dumpJavaDocFile");
+ }
+
+ @Override
+ public String getParameters() {
+ return "theFileToDumpJavaDocForLaterUse";
+ }
+
+ @Override
+ public boolean process(String option, List<String> arguments) {
+ dumpFileName = arguments.get(0);
+ return true;
+ }
+ }
+
+ public DumpJavaDoc() {
+
+ }
+
+ @Override
+ public void init(Locale locale, Reporter reporter) {
+ this.reporter = reporter;
+ }
+
+ @Override
+ public String getName() {
+ return "DumpJavaDoc";
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.RELEASE_8;
+ }
+
+ @Override
+ public boolean run(DocletEnvironment docEnv) {
+ final Elements utils = docEnv.getElementUtils();
+ final DocTrees docTrees = docEnv.getDocTrees();
+
+ try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
+ final Properties javaDocMap = new Properties();
+ for (Element element : docEnv.getIncludedElements()) {
+ if (element.getKind() == ElementKind.CLASS) {
+ final TypeElement classDoc = (TypeElement) element;
+ final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
+
+ if (classCommentTree != null) {
+ javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
+ }
+
+ for (Element member: classDoc.getEnclosedElements()) {
+ // Skip all non-public methods
+ if (!member.getModifiers().contains(Modifier.PUBLIC)) {
+ continue;
+ }
+
+ if (member.getKind() == ElementKind.METHOD) {
+ final ExecutableElement method = (ExecutableElement) member;
+ final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
+ final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
+
+ if (methodCommentTree == null) {
+ javaDocMap.put(qualifiedName, "");
+ } else {
+ javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
+ for (DocTree tree: methodCommentTree.getBlockTags()) {
+ if (tree.getKind() == DocTree.Kind.RETURN) {
+ final ReturnTree returnTree = (ReturnTree) tree;
+ javaDocMap.put(qualifiedName + ".returnCommentTag",
+ getAllComments(returnTree.getDescription()));
+ } else if (tree.getKind() == DocTree.Kind.PARAM) {
+ final ParamTree paramTree = (ParamTree) tree;
+ final int index = getParamIndex(method, paramTree);
+ if (index >= 0) {
+ javaDocMap.put(qualifiedName + ".paramCommentTag." + index,
+ getAllComments(paramTree.getDescription()));
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ javaDocMap.store(os, "");
+ os.flush();
+ } catch (final IOException ex) {
+ reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
+ }
+
+ return true;
+ }
+
+ private int getParamIndex(final ExecutableElement method, final ParamTree paramTree) {
+ final List<? extends VariableElement> parameters = method.getParameters();
+
+ for (int i = 0; i < parameters.size(); ++i) {
+ if (paramTree.getName().getName().contentEquals(parameters.get(i).getSimpleName())) {
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ private String getAllComments(final Collection<? extends DocTree> comments) {
+ return comments
+ .stream()
+ .map(DocTree::toString)
+ .collect(Collectors.joining());
+ }
+
+ @Override
+ public Set<Option> getSupportedOptions() {
+ return Collections.singleton(new DumpJavaDocFileOption());
+ }
+}