You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2023/02/12 15:56:13 UTC
[maven-javadoc-plugin] 02/02: [MJAVADOC-740] Upgrade Parent to 39
This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit d02fd90c799e12825448ac538bf09abf2a059d82
Author: Michael Osipov <mi...@apache.org>
AuthorDate: Sun Feb 12 16:55:44 2023 +0100
[MJAVADOC-740] Upgrade Parent to 39
---
pom.xml | 116 +-
.../plugins/javadoc/AbstractFixJavadocMojo.java | 6924 +++++++++-----------
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 4791 ++++++--------
.../plugins/javadoc/AdditionalDependency.java | 61 +-
.../plugins/javadoc/AggregatorJavadocJar.java | 93 +-
.../javadoc/AggregatorJavadocNoForkReport.java | 12 +-
.../plugins/javadoc/AggregatorJavadocReport.java | 88 +-
.../plugins/javadoc/AggregatorTestJavadocJar.java | 93 +-
.../javadoc/AggregatorTestJavadocNoForkReport.java | 12 +-
.../javadoc/AggregatorTestJavadocReport.java | 88 +-
.../maven/plugins/javadoc/DependencyLink.java | 46 +-
.../maven/plugins/javadoc/FixJavadocMojo.java | 77 +-
.../javadoc/JavadocArchiveConfiguration.java | 12 +-
.../apache/maven/plugins/javadoc/JavadocJar.java | 593 +-
.../maven/plugins/javadoc/JavadocModule.java | 39 +-
.../maven/plugins/javadoc/JavadocNoForkReport.java | 14 +-
.../maven/plugins/javadoc/JavadocReport.java | 691 +-
.../apache/maven/plugins/javadoc/JavadocUtil.java | 3512 +++++-----
.../maven/plugins/javadoc/JavadocVersion.java | 169 +-
.../maven/plugins/javadoc/ResourcesBundleMojo.java | 274 +-
.../apache/maven/plugins/javadoc/StaleHelper.java | 159 +-
.../apache/maven/plugins/javadoc/SystemUtils.java | 52 +-
.../maven/plugins/javadoc/TestFixJavadocMojo.java | 155 +-
.../maven/plugins/javadoc/TestJavadocJar.java | 423 +-
.../plugins/javadoc/TestJavadocNoForkReport.java | 14 +-
.../maven/plugins/javadoc/TestJavadocReport.java | 671 +-
.../plugins/javadoc/TestResourcesBundleMojo.java | 131 +-
.../plugins/javadoc/resolver/JavadocBundle.java | 118 +-
.../plugins/javadoc/resolver/ResourceResolver.java | 843 ++-
.../javadoc/resolver/SourceResolverConfig.java | 328 +-
.../javadoc/AbstractFixJavadocMojoTest.java | 326 +-
.../plugins/javadoc/AbstractJavadocMojoTest.java | 171 +-
.../javadoc/AggregatorJavadocReportTest.java | 198 +-
.../maven/plugins/javadoc/FixJavadocMojoTest.java | 1272 ++--
.../maven/plugins/javadoc/JavadocJarTest.java | 387 +-
.../maven/plugins/javadoc/JavadocReportTest.java | 1440 ++--
.../maven/plugins/javadoc/JavadocUtilTest.java | 1376 ++--
.../maven/plugins/javadoc/JavadocVersionTest.java | 133 +-
.../apache/maven/plugins/javadoc/ProxyServer.java | 428 +-
.../plugins/javadoc/TestJavadocReportTest.java | 136 +-
.../io/xpp3/JavadocOptionsXpp3ReaderTest.java | 24 +-
.../AbstractAggregateChildMavenProjectStub.java | 160 +-
.../stubs/AbstractAggregateMavenProjectStub.java | 174 +-
...NotInSubFolderProject1TestMavenProjectStub.java | 65 +-
...NotInSubFolderProject2TestMavenProjectStub.java | 65 +-
...ggregateNotInSubFolderTestMavenProjectStub.java | 69 +-
.../AggregateProject1TestMavenProjectStub.java | 140 +-
.../AggregateProject2TestMavenProjectStub.java | 140 +-
...egateResourcesProject1TestMavenProjectStub.java | 65 +-
...egateResourcesProject2TestMavenProjectStub.java | 65 +-
.../AggregateResourcesTestMavenProjectStub.java | 69 +-
.../stubs/AggregateTestMavenProjectStub.java | 186 +-
.../stubs/CustomConfigurationMavenProjectStub.java | 204 +-
.../javadoc/stubs/DefaultArtifactHandlerStub.java | 98 +-
.../DefaultConfigurationMavenProjectStub.java | 159 +-
.../stubs/DocfilesTestMavenProjectStub.java | 161 +-
.../DocfilesWithJavaTestMavenProjectStub.java | 115 +-
.../stubs/DocletPathTestMavenProjectStub.java | 159 +-
.../javadoc/stubs/DocletTestMavenProjectStub.java | 161 +-
.../plugins/javadoc/stubs/FixMavenProjectStub.java | 198 +-
.../stubs/HeaderFooterTestMavenProjectStub.java | 120 +-
.../javadoc/stubs/HelpFileMavenProjectStub.java | 160 +-
.../stubs/JavadocJarArchiveConfigProjectStub.java | 73 +-
.../stubs/JavadocJarDefaultMavenProjectStub.java | 173 +-
.../JavadocJarFailOnErrorMavenProjectStub.java | 69 +-
.../JavadocJarInvalidDestdirMavenProjectStub.java | 170 +-
.../javadoc/stubs/JavadocPluginArtifactStub.java | 290 +-
.../javadoc/stubs/Jdk5TestMavenProjectStub.java | 159 +-
.../javadoc/stubs/Jdk6TestMavenProjectStub.java | 159 +-
.../javadoc/stubs/NewlineTestMavenProjectStub.java | 120 +-
.../OptionsUmlautEncodingMavenProjectStub.java | 65 +-
.../plugins/javadoc/stubs/PomMavenProjectStub.java | 135 +-
.../javadoc/stubs/ProxyTestMavenProjectStub.java | 175 +-
.../javadoc/stubs/QuotedPathMavenProjectStub.java | 159 +-
.../stubs/ResourcesTestMavenProjectStub.java | 120 +-
.../ResourcesWithExcludesTestMavenProjectStub.java | 120 +-
.../maven/plugins/javadoc/stubs/SettingsStub.java | 105 +-
...dDocletConflictOptionsTestMavenProjectStub.java | 120 +-
.../stubs/StylesheetFileMavenProjectStub.java | 160 +-
.../stubs/SubpackagesTestMavenProjectStub.java | 159 +-
.../javadoc/stubs/TagTestMavenProjectStub.java | 120 +-
.../stubs/TagletArtifactsMavenProjectStub.java | 152 +-
.../javadoc/stubs/TagletTestMavenProjectStub.java | 159 +-
.../javadoc/stubs/TestJavadocMavenProjectStub.java | 187 +-
.../WrongEncodingOptionsTestMavenProjectStub.java | 120 +-
85 files changed, 14947 insertions(+), 17545 deletions(-)
diff --git a/pom.xml b/pom.xml
index 81978849..1a469ea6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -18,14 +17,13 @@ KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugins</artifactId>
- <version>37</version>
+ <version>39</version>
<relativePath />
</parent>
@@ -34,53 +32,10 @@ under the License.
<packaging>maven-plugin</packaging>
<name>Apache Maven Javadoc Plugin</name>
- <description>
- The Apache Maven Javadoc Plugin is a plugin that uses the javadoc tool for
- generating javadocs for the specified project.
- </description>
+ <description>The Apache Maven Javadoc Plugin is a plugin that uses the javadoc tool for
+ generating javadocs for the specified project.</description>
<inceptionYear>2004</inceptionYear>
- <prerequisites>
- <maven>${mavenVersion}</maven>
- </prerequisites>
-
- <scm>
- <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git</connection>
- <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git</developerConnection>
- <url>https://github.com/apache/maven-javadoc-plugin/tree/${project.scm.tag}</url>
- <tag>HEAD</tag>
- </scm>
- <issueManagement>
- <system>jira</system>
- <url>https://issues.apache.org/jira/browse/MJAVADOC</url>
- </issueManagement>
- <ciManagement>
- <system>Jenkins</system>
- <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-javadoc-plugin/</url>
- </ciManagement>
- <distributionManagement>
- <site>
- <id>apache.website</id>
- <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url>
- </site>
- </distributionManagement>
-
- <properties>
- <javaVersion>8</javaVersion>
- <mavenVersion>3.2.5</mavenVersion>
- <doxiaVersion>1.11.1</doxiaVersion>
- <doxia-sitetoolsVersion>1.11.1</doxia-sitetoolsVersion>
- <wagonVersion>2.4</wagonVersion>
- <aetherVersion>1.0.0.v20140518</aetherVersion><!-- https://cwiki.apache.org/confluence/x/VIHOCg#MavenEcosystemCleanup-ResolverandMaven -->
- <plexus-java.version>1.1.0</plexus-java.version>
- <jetty.version>9.4.43.v20210629</jetty.version>
- <!-- for ITs -->
- <sitePluginVersion>3.12.1</sitePluginVersion>
- <projectInfoReportsPluginVersion>3.2.2</projectInfoReportsPluginVersion>
- <project.build.outputTimestamp>2022-08-10T19:51:10Z</project.build.outputTimestamp>
- <slf4jVersion>1.7.36</slf4jVersion>
- </properties>
-
<contributors>
<contributor>
<name>Ben Speakmon</name>
@@ -129,6 +84,48 @@ under the License.
</contributor>
</contributors>
+ <prerequisites>
+ <maven>${mavenVersion}</maven>
+ </prerequisites>
+
+ <scm>
+ <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git</connection>
+ <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git</developerConnection>
+ <tag>HEAD</tag>
+ <url>https://github.com/apache/maven-javadoc-plugin/tree/${project.scm.tag}</url>
+ </scm>
+ <issueManagement>
+ <system>jira</system>
+ <url>https://issues.apache.org/jira/browse/MJAVADOC</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Jenkins</system>
+ <url>https://ci-builds.apache.org/job/Maven/job/maven-box/job/maven-javadoc-plugin/</url>
+ </ciManagement>
+ <distributionManagement>
+ <site>
+ <id>apache.website</id>
+ <url>scm:svn:https://svn.apache.org/repos/asf/maven/website/components/${maven.site.path}</url>
+ </site>
+ </distributionManagement>
+
+ <properties>
+ <javaVersion>8</javaVersion>
+ <mavenVersion>3.2.5</mavenVersion>
+ <doxiaVersion>1.11.1</doxiaVersion>
+ <doxia-sitetoolsVersion>1.11.1</doxia-sitetoolsVersion>
+ <wagonVersion>2.4</wagonVersion>
+ <aetherVersion>1.0.0.v20140518</aetherVersion>
+ <!-- https://cwiki.apache.org/confluence/x/VIHOCg#MavenEcosystemCleanup-ResolverandMaven -->
+ <plexus-java.version>1.1.0</plexus-java.version>
+ <jetty.version>9.4.43.v20210629</jetty.version>
+ <!-- for ITs -->
+ <sitePluginVersion>3.12.1</sitePluginVersion>
+ <projectInfoReportsPluginVersion>3.2.2</projectInfoReportsPluginVersion>
+ <project.build.outputTimestamp>2022-08-10T19:51:10Z</project.build.outputTimestamp>
+ <slf4jVersion>1.7.36</slf4jVersion>
+ </properties>
+
<dependencyManagement>
<dependencies>
<dependency>
@@ -160,7 +157,8 @@ under the License.
</dependencyManagement>
<dependencies>
- <dependency> <!-- @TODO remove!! -->
+ <dependency>
+ <!-- @TODO remove!! -->
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${mavenVersion}</version>
@@ -433,6 +431,12 @@ under the License.
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
+ <configuration>
+ <version>1.1.1</version>
+ <models>
+ <model>src/main/mdo/javadocOptions.mdo</model>
+ </models>
+ </configuration>
<executions>
<execution>
<goals>
@@ -442,12 +446,6 @@ under the License.
</goals>
</execution>
</executions>
- <configuration>
- <version>1.1.1</version>
- <models>
- <model>src/main/mdo/javadocOptions.mdo</model>
- </models>
- </configuration>
</plugin>
<plugin>
<groupId>org.eclipse.sisu</groupId>
@@ -486,7 +484,8 @@ under the License.
<pomInclude>examples/*/pom.xml</pomInclude>
</pomIncludes>
<pomExcludes>
- <pomExclude>MJAVADOC-181/pom.xml</pomExclude> <!-- seems to be wrong, see comment in Jira issue -->
+ <pomExclude>MJAVADOC-181/pom.xml</pomExclude>
+ <!-- seems to be wrong, see comment in Jira issue -->
<pomExclude>output-encoding/pom.xml</pomExclude>
</pomExcludes>
<properties combine.self="override" />
@@ -571,7 +570,8 @@ under the License.
<onlyCurrentVersion>true</onlyCurrentVersion>
<resolutionIds>Fixed</resolutionIds>
<sortColumnNames>Type,Key</sortColumnNames>
- <maxEntries>1000</maxEntries> <!-- MCHANGES-124 -->
+ <maxEntries>1000</maxEntries>
+ <!-- MCHANGES-124 -->
</configuration>
<reportSets>
<reportSet>
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
index 61ff1abe..53987c95 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractFixJavadocMojo.java
@@ -1,3679 +1,3245 @@
-package org.apache.maven.plugins.javadoc;
-
-/*
- * 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.
- */
-
-import com.thoughtworks.qdox.JavaProjectBuilder;
-import com.thoughtworks.qdox.library.ClassLibraryBuilder;
-import com.thoughtworks.qdox.library.OrderedClassLibraryBuilder;
-import com.thoughtworks.qdox.model.DocletTag;
-import com.thoughtworks.qdox.model.JavaAnnotatedElement;
-import com.thoughtworks.qdox.model.JavaAnnotation;
-import com.thoughtworks.qdox.model.JavaClass;
-import com.thoughtworks.qdox.model.JavaConstructor;
-import com.thoughtworks.qdox.model.JavaExecutable;
-import com.thoughtworks.qdox.model.JavaField;
-import com.thoughtworks.qdox.model.JavaGenericDeclaration;
-import com.thoughtworks.qdox.model.JavaMember;
-import com.thoughtworks.qdox.model.JavaMethod;
-import com.thoughtworks.qdox.model.JavaParameter;
-import com.thoughtworks.qdox.model.JavaType;
-import com.thoughtworks.qdox.model.JavaTypeVariable;
-import com.thoughtworks.qdox.parser.ParseException;
-import com.thoughtworks.qdox.type.TypeResolver;
-
-import org.apache.commons.lang3.ClassUtils;
-import org.apache.commons.text.StringEscapeUtils;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DependencyResolutionRequiredException;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.plugins.annotations.Component;
-import org.apache.maven.plugins.annotations.Parameter;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.settings.Settings;
-import org.apache.maven.shared.invoker.MavenInvocationException;
-import org.codehaus.plexus.components.interactivity.InputHandler;
-import org.codehaus.plexus.languages.java.version.JavaVersion;
-import org.codehaus.plexus.util.FileUtils;
-import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.lang.reflect.Method;
-import java.net.MalformedURLException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * Abstract class to fix Javadoc documentation and tags in source files.
- * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/javadoc/doc-comment-spec.html#where-tags-can-be-used">Where Tags
- * Can Be Used</a>.
- * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
- * @since 2.6
- */
-public abstract class AbstractFixJavadocMojo
- extends AbstractMojo
-{
- /**
- * The vm line separator
- */
- private static final String EOL = System.getProperty( "line.separator" );
-
- /**
- * Tag name for @author *
- */
- private static final String AUTHOR_TAG = "author";
-
- /**
- * Tag name for @version *
- */
- private static final String VERSION_TAG = "version";
-
- /**
- * Tag name for @since *
- */
- private static final String SINCE_TAG = "since";
-
- /**
- * Tag name for @param *
- */
- private static final String PARAM_TAG = "param";
-
- /**
- * Tag name for @return *
- */
- private static final String RETURN_TAG = "return";
-
- /**
- * Tag name for @throws *
- */
- private static final String THROWS_TAG = "throws";
-
- /**
- * Tag name for @link *
- */
- private static final String LINK_TAG = "link";
-
- /**
- * Tag name for {@inheritDoc} *
- */
- private static final String INHERITED_TAG = "{@inheritDoc}";
-
- /**
- * Start Javadoc String i.e. <code>/**</code> *
- */
- private static final String START_JAVADOC = "/**";
-
- /**
- * End Javadoc String i.e. <code>*/</code> *
- */
- private static final String END_JAVADOC = "*/";
-
- /**
- * Javadoc Separator i.e. <code> * </code> *
- */
- private static final String SEPARATOR_JAVADOC = " * ";
-
- /**
- * Inherited Javadoc i.e. <code>/** {@inheritDoc} */</code> *
- */
- private static final String INHERITED_JAVADOC = START_JAVADOC + " " + INHERITED_TAG + " " + END_JAVADOC;
-
- /**
- * <code>all</code> parameter used by {@link #fixTags} *
- */
- private static final String FIX_TAGS_ALL = "all";
-
- /**
- * <code>public</code> parameter used by {@link #level} *
- */
- private static final String LEVEL_PUBLIC = "public";
-
- /**
- * <code>protected</code> parameter used by {@link #level} *
- */
- private static final String LEVEL_PROTECTED = "protected";
-
- /**
- * <code>package</code> parameter used by {@link #level} *
- */
- private static final String LEVEL_PACKAGE = "package";
-
- /**
- * <code>private</code> parameter used by {@link #level} *
- */
- private static final String LEVEL_PRIVATE = "private";
-
- /**
- * The Clirr Maven plugin groupId <code>org.codehaus.mojo</code> *
- */
- private static final String CLIRR_MAVEN_PLUGIN_GROUPID = "org.codehaus.mojo";
-
- /**
- * The Clirr Maven plugin artifactId <code>clirr-maven-plugin</code> *
- */
- private static final String CLIRR_MAVEN_PLUGIN_ARTIFACTID = "clirr-maven-plugin";
-
- /**
- * The latest Clirr Maven plugin version <code>2.2.2</code> *
- */
- private static final String CLIRR_MAVEN_PLUGIN_VERSION = "2.2.2";
-
- /**
- * The Clirr Maven plugin goal <code>check</code> *
- */
- private static final String CLIRR_MAVEN_PLUGIN_GOAL = "check";
-
- /**
- * Java Files Pattern.
- */
- public static final String JAVA_FILES = "**\\/*.java";
-
- /**
- * Default version value.
- */
- public static final String DEFAULT_VERSION_VALUE = "\u0024Id: \u0024Id";
-
- // ----------------------------------------------------------------------
- // Mojo components
- // ----------------------------------------------------------------------
-
- /**
- * Input handler, needed for command line handling.
- */
- @Component
- private InputHandler inputHandler;
-
- // ----------------------------------------------------------------------
- // Mojo parameters
- // ----------------------------------------------------------------------
-
- /**
- * Version to compare the current code against using the
- * <a href="http://mojo.codehaus.org/clirr-maven-plugin/">Clirr Maven Plugin</a>.
- * <br/>
- * See <a href="#defaultSince">defaultSince</a>.
- */
- @Parameter ( property = "comparisonVersion", defaultValue = "(,${project.version})" )
- private String comparisonVersion;
-
- /**
- * Default value for the Javadoc tag <code>@author</code>.
- * <br/>
- * If not specified, the <code>user.name</code> defined in the System properties will be used.
- */
- @Parameter ( property = "defaultAuthor" )
- private String defaultAuthor;
-
- /**
- * Default value for the Javadoc tag <code>@since</code>.
- */
- @Parameter ( property = "defaultSince", defaultValue = "${project.version}" )
- private String defaultSince;
-
- /**
- * Default value for the Javadoc tag <code>@version</code>.
- * <br/>
- * By default, it is <code>$Id:$</code>, corresponding to a
- * <a href="http://svnbook.red-bean.com/en/1.1/ch07s02.html#svn-ch-7-sect-2.3.4">SVN keyword</a>.
- * Refer to your SCM to use an other SCM keyword.
- */
- @Parameter ( property = "defaultVersion", defaultValue = DEFAULT_VERSION_VALUE )
- private String defaultVersion = "\u0024Id: \u0024"; // can't use default-value="\u0024Id: \u0024"
-
- /**
- * The file encoding to use when reading the source files. If the property
- * <code>project.build.sourceEncoding</code> is not set, the platform default encoding is used.
- */
- @Parameter ( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
- private String encoding;
-
- /**
- * Comma separated excludes Java files, i.e. <code>**/*Test.java</code>.
- */
- @Parameter ( property = "excludes" )
- private String excludes;
-
- /**
- * Comma separated tags to fix in classes, interfaces or methods Javadoc comments.
- * Possible values are:
- * <ul>
- * <li>all (fix all Javadoc tags)</li>
- * <li>author (fix only @author tag)</li>
- * <li>version (fix only @version tag)</li>
- * <li>since (fix only @since tag)</li>
- * <li>param (fix only @param tag)</li>
- * <li>return (fix only @return tag)</li>
- * <li>throws (fix only @throws tag)</li>
- * <li>link (fix only @link tag)</li>
- * </ul>
- */
- @Parameter ( property = "fixTags", defaultValue = "all" )
- private String fixTags;
-
- /**
- * Flag to fix the classes or interfaces Javadoc comments according the <code>level</code>.
- */
- @Parameter ( property = "fixClassComment", defaultValue = "true" )
- private boolean fixClassComment;
-
- /**
- * Flag to fix the fields Javadoc comments according the <code>level</code>.
- */
- @Parameter ( property = "fixFieldComment", defaultValue = "true" )
- private boolean fixFieldComment;
-
- /**
- * Flag to fix the methods Javadoc comments according the <code>level</code>.
- */
- @Parameter ( property = "fixMethodComment", defaultValue = "true" )
- private boolean fixMethodComment;
-
- /**
- * <p>Flag to remove throws tags from unknown classes.</p>
- * <p><strong>NOTE:</strong>Since 3.1.0 the default value has been changed to {@code true},
- * due to JavaDoc 8 strictness.
- */
- @Parameter ( property = "removeUnknownThrows", defaultValue = "true" )
- private boolean removeUnknownThrows;
-
- /**
- * Forcing the goal execution i.e. skip warranty messages (not recommended).
- */
- @Parameter ( property = "force" )
- private boolean force;
-
- /**
- * Flag to ignore or not Clirr.
- */
- @Parameter ( property = "ignoreClirr", defaultValue = "false" )
- protected boolean ignoreClirr;
-
- /**
- * Comma separated includes Java files, i.e. <code>**/*Test.java</code>.
- * <p/>
- * <strong>Note:</strong> default value is {@code **\/*.java}.
- */
- @Parameter ( property = "includes", defaultValue = JAVA_FILES )
- private String includes;
-
- /**
- * Specifies the access level for classes and members to show in the Javadocs.
- * Possible values are:
- * <ul>
- * <li>public (shows only public classes and members)</li>
- * <li>protected (shows only public and protected classes and members)</li>
- * <li>package (shows all classes and members not marked private)</li>
- * <li>private (shows all classes and members)</li>
- * </ul>
- * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">private, protected, public, package options for Javadoc</a>
- */
- @Parameter ( property = "level", defaultValue = "protected" )
- private String level;
-
- /**
- * The local repository where the artifacts are located, used by the tests.
- */
- @Parameter ( property = "localRepository" )
- private ArtifactRepository localRepository;
-
- /**
- * Output directory where Java classes will be rewritten.
- */
- @Parameter ( property = "outputDirectory", defaultValue = "${project.build.sourceDirectory}" )
- private File outputDirectory;
-
- /**
- * The Maven Project Object.
- */
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
- private MavenProject project;
-
- @Parameter ( defaultValue = "${session}", readonly = true, required = true )
- private MavenSession session;
-
- /**
- * The current user system settings for use in Maven.
- */
- @Parameter( defaultValue = "${settings}", readonly = true, required = true )
- private Settings settings;
-
- // ----------------------------------------------------------------------
- // Internal fields
- // ----------------------------------------------------------------------
-
- /**
- * The current project class loader.
- */
- private ClassLoader projectClassLoader;
-
- /**
- * Split {@link #fixTags} by comma.
- *
- * @see #init()
- */
- private String[] fixTagsSplitted;
-
- /**
- * New classes found by Clirr.
- */
- private List<String> clirrNewClasses;
-
- /**
- * New Methods in a Class (the key) found by Clirr.
- */
- private Map<String, List<String>> clirrNewMethods;
-
- /**
- * List of classes where <code>*since</code> is added. Will be used to add or not this tag in the methods.
- */
- private List<String> sinceClasses;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- if ( !fixClassComment && !fixFieldComment && !fixMethodComment )
- {
- getLog().info( "Specified to NOT fix classes, fields and methods. Nothing to do." );
- return;
- }
-
- // verify goal params
- init();
-
- if ( fixTagsSplitted.length == 0 )
- {
- getLog().info( "No fix tag specified. Nothing to do." );
- return;
- }
-
- // add warranty msg
- if ( !preCheck() )
- {
- return;
- }
-
- // run clirr
- try
- {
- executeClirr();
- }
- catch ( MavenInvocationException e )
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().error( "MavenInvocationException: " + e.getMessage(), e );
- }
- else
- {
- getLog().error( "MavenInvocationException: " + e.getMessage() );
- }
- getLog().info( "Clirr is ignored." );
- }
-
- // run qdox and process
- try
- {
- Collection<JavaClass> javaClasses = getQdoxClasses();
-
- if ( javaClasses != null )
- {
- for ( JavaClass javaClass : javaClasses )
- {
- processFix( javaClass );
- }
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "IOException: " + e.getMessage(), e );
- }
- }
-
- // ----------------------------------------------------------------------
- // protected methods
- // ----------------------------------------------------------------------
-
- protected final MavenProject getProject()
- {
- return project;
- }
-
- /**
- * @param p not null maven project.
- * @return the artifact type.
- */
- protected String getArtifactType( MavenProject p )
- {
- return p.getArtifact().getType();
- }
-
- /**
- * @param p not null maven project.
- * @return the list of source paths for the given project.
- */
- protected List<String> getProjectSourceRoots( MavenProject p )
- {
- return ( p.getCompileSourceRoots() == null
- ? Collections.<String>emptyList()
- : new LinkedList<>( p.getCompileSourceRoots() ) );
- }
-
- /**
- * @param p not null
- * @return the compile classpath elements
- * @throws DependencyResolutionRequiredException
- * if any
- */
- protected List<String> getCompileClasspathElements( MavenProject p )
- throws DependencyResolutionRequiredException
- {
- return ( p.getCompileClasspathElements() == null
- ? Collections.<String>emptyList()
- : new LinkedList<>( p.getCompileClasspathElements() ) );
- }
-
- /**
- * @param javaExecutable not null
- * @return the fully qualify name of javaMethod with signature
- */
- protected static String getJavaMethodAsString( JavaExecutable javaExecutable )
- {
- return javaExecutable.getDeclaringClass().getFullyQualifiedName() + "#" + javaExecutable.getCallSignature();
- }
-
- // ----------------------------------------------------------------------
- // private methods
- // ----------------------------------------------------------------------
-
- /**
- * Init goal parameters.
- */
- private void init()
- {
- // defaultAuthor
- if ( StringUtils.isEmpty( defaultAuthor ) )
- {
- defaultAuthor = System.getProperty( "user.name" );
- }
-
- // defaultSince
- int i = defaultSince.indexOf( "-" + Artifact.SNAPSHOT_VERSION );
- if ( i != -1 )
- {
- defaultSince = defaultSince.substring( 0, i );
- }
-
- // fixTags
- if ( !FIX_TAGS_ALL.equalsIgnoreCase( fixTags.trim() ) )
- {
- String[] split = StringUtils.split( fixTags, "," );
- List<String> filtered = new LinkedList<>();
- for ( String aSplit : split )
- {
- String s = aSplit.trim();
- if ( JavadocUtil.equalsIgnoreCase( s, FIX_TAGS_ALL, AUTHOR_TAG, VERSION_TAG, SINCE_TAG, PARAM_TAG,
- THROWS_TAG, LINK_TAG, RETURN_TAG ) )
- {
- filtered.add( s );
- }
- else
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "Unrecognized '" + s + "' for fixTags parameter. Ignored it!" );
- }
- }
- }
- fixTags = StringUtils.join( filtered.iterator(), "," );
- }
- fixTagsSplitted = StringUtils.split( fixTags, "," );
-
- // encoding
- if ( StringUtils.isEmpty( encoding ) )
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
- + ", i.e. build is platform dependent!" );
- }
- encoding = ReaderFactory.FILE_ENCODING;
- }
-
- // level
- level = level.trim();
- if ( !JavadocUtil.equalsIgnoreCase( level, LEVEL_PUBLIC, LEVEL_PROTECTED, LEVEL_PACKAGE, LEVEL_PRIVATE ) )
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "Unrecognized '" + level + "' for level parameter, using 'protected' level." );
- }
- level = "protected";
- }
- }
-
- /**
- * @return <code>true</code> if the user wants to proceed, <code>false</code> otherwise.
- * @throws MojoExecutionException if any
- */
- private boolean preCheck()
- throws MojoExecutionException
- {
- if ( force )
- {
- return true;
- }
-
- if ( outputDirectory != null && !outputDirectory.getAbsolutePath().equals(
- getProjectSourceDirectory().getAbsolutePath() ) )
- {
- return true;
- }
-
- if ( !settings.isInteractiveMode() )
- {
- getLog().error( "Maven is not attempt to interact with the user for input. "
- + "Verify the <interactiveMode/> configuration in your settings." );
- return false;
- }
-
- getLog().warn( "" );
- getLog().warn( " WARRANTY DISCLAIMER" );
- getLog().warn( "" );
- getLog().warn( "All warranties with regard to this Maven goal are disclaimed!" );
- getLog().warn( "The changes will be done directly in the source code." );
- getLog().warn( "The Maven Team strongly recommends the use of a SCM software BEFORE executing this goal." );
- getLog().warn( "" );
-
- while ( true )
- {
- getLog().info( "Are you sure to proceed? [Y]es [N]o" );
-
- try
- {
- String userExpression = inputHandler.readLine();
- if ( userExpression == null || JavadocUtil.equalsIgnoreCase( userExpression, "Y", "Yes" ) )
- {
- getLog().info( "OK, let's proceed..." );
- break;
- }
- if ( JavadocUtil.equalsIgnoreCase( userExpression, "N", "No" ) )
- {
- getLog().info( "No changes in your sources occur." );
- return false;
- }
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Unable to read from standard input.", e );
- }
- }
-
- return true;
- }
-
- /**
- * @return the source dir as File for the given project
- */
- private File getProjectSourceDirectory()
- {
- return new File( project.getBuild().getSourceDirectory() );
- }
-
- /**
- * Invoke Maven to run clirr-maven-plugin to find API differences.
- *
- * @throws MavenInvocationException if any
- */
- private void executeClirr()
- throws MavenInvocationException
- {
- if ( ignoreClirr )
- {
- getLog().info( "Clirr is ignored." );
- return;
- }
-
- String clirrGoal = getFullClirrGoal();
-
- // http://mojo.codehaus.org/clirr-maven-plugin/check-mojo.html
- File clirrTextOutputFile =
- FileUtils.createTempFile( "clirr", ".txt", new File( project.getBuild().getDirectory() ) );
- Properties properties = new Properties();
- properties.put( "textOutputFile", clirrTextOutputFile.getAbsolutePath() );
- properties.put( "comparisonVersion", comparisonVersion );
- properties.put( "failOnError", "false" );
- if ( JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore( "8" ) )
- {
- // ensure that Java7 picks up TLSv1.2 when connecting with Central
- properties.put( "https.protocols", "TLSv1.2" );
- }
-
- File invokerDir = new File( project.getBuild().getDirectory(), "invoker" );
- invokerDir.mkdirs();
- File invokerLogFile = FileUtils.createTempFile( "clirr-maven-plugin", ".txt", invokerDir );
-
- JavadocUtil.invokeMaven( getLog(), new File( localRepository.getBasedir() ), project.getFile(),
- Collections.singletonList( clirrGoal ), properties, invokerLogFile,
- session.getRequest().getGlobalSettingsFile() );
-
- try
- {
- if ( invokerLogFile.exists() )
- {
- String invokerLogContent =
- StringUtils.unifyLineSeparators( FileUtils.fileRead( invokerLogFile, "UTF-8" ) );
- // see org.codehaus.mojo.clirr.AbstractClirrMojo#getComparisonArtifact()
- final String artifactNotFoundMsg = "Unable to find a previous version of the project in the repository";
- if ( invokerLogContent.contains( artifactNotFoundMsg ) )
- {
- getLog().warn( "No previous artifact has been deployed, Clirr is ignored." );
- return;
- }
- }
- }
- catch ( IOException e )
- {
- getLog().debug( "IOException: " + e.getMessage() );
- }
-
- try
- {
- parseClirrTextOutputFile( clirrTextOutputFile );
- }
- catch ( IOException e )
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "IOException: " + e.getMessage(), e );
- }
- getLog().info( "IOException when parsing Clirr output '" + clirrTextOutputFile.getAbsolutePath()
- + "', Clirr is ignored." );
- }
- }
-
- /**
- * @param clirrTextOutputFile not null
- * @throws IOException if any
- */
- private void parseClirrTextOutputFile( File clirrTextOutputFile )
- throws IOException
- {
- if ( !clirrTextOutputFile.exists() )
- {
- if ( getLog().isInfoEnabled() )
- {
- getLog().info(
- "No Clirr output file '" + clirrTextOutputFile.getAbsolutePath() + "' exists, Clirr is ignored." );
- }
- return;
- }
-
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Clirr output file was created: " + clirrTextOutputFile.getAbsolutePath() );
- }
-
- clirrNewClasses = new LinkedList<>();
- clirrNewMethods = new LinkedHashMap<>();
-
- try ( BufferedReader reader = new BufferedReader( ReaderFactory.newReader( clirrTextOutputFile, "UTF-8" ) ) )
- {
-
- for ( String line = reader.readLine(); line != null; line = reader.readLine() )
- {
- String[] split = StringUtils.split( line, ":" );
- if ( split.length != 4 )
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Unable to parse the clirr line: " + line );
- }
- continue;
- }
-
- int code;
- try
- {
- code = Integer.parseInt( split[1].trim() );
- }
- catch ( NumberFormatException e )
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Unable to parse the clirr line: " + line );
- }
- continue;
- }
-
- // http://clirr.sourceforge.net/clirr-core/exegesis.html
- // 7011 - Method Added
- // 7012 - Method Added to Interface
- // 8000 - Class Added
-
- // CHECKSTYLE_OFF: MagicNumber
- switch ( code )
- {
- case 7011:
- methodAdded( split );
- break;
- case 7012:
- methodAdded( split );
- break;
- case 8000:
- clirrNewClasses.add( split[2].trim() );
- break;
- default:
- break;
- }
- // CHECKSTYLE_ON: MagicNumber
- }
- }
- if ( clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty() )
- {
- getLog().info( "Clirr NOT found API differences." );
- }
- else
- {
- getLog().info( "Clirr found API differences, i.e. new classes/interfaces or methods." );
- }
- }
-
- private void methodAdded( String[] split )
- {
- List<String> list = clirrNewMethods.get( split[2].trim() );
- if ( list == null )
- {
- list = new ArrayList<>();
- }
- String[] splits2 = StringUtils.split( split[3].trim(), "'" );
- if ( splits2.length != 3 )
- {
- return;
- }
- list.add( splits2[1].trim() );
- clirrNewMethods.put( split[2].trim(), list );
- }
-
- /**
- * @param tag not null
- * @return <code>true</code> if <code>tag</code> is defined in {@link #fixTags}.
- */
- private boolean fixTag( String tag )
- {
- if ( fixTagsSplitted.length == 1 && fixTagsSplitted[0].equals( FIX_TAGS_ALL ) )
- {
- return true;
- }
-
- for ( String aFixTagsSplitted : fixTagsSplitted )
- {
- if ( aFixTagsSplitted.trim().equals( tag ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Calling Qdox to find {@link JavaClass} objects from the Maven project sources.
- * Ignore java class if Qdox has parsing errors.
- *
- * @return an array of {@link JavaClass} found by QDox
- * @throws IOException if any
- * @throws MojoExecutionException if any
- */
- private Collection<JavaClass> getQdoxClasses()
- throws IOException, MojoExecutionException
- {
- if ( "pom".equalsIgnoreCase( project.getPackaging() ) )
- {
- getLog().warn( "This project has 'pom' packaging, no Java sources is available." );
- return null;
- }
-
- List<File> javaFiles = new LinkedList<>();
- for ( String sourceRoot : getProjectSourceRoots( project ) )
- {
- File f = new File( sourceRoot );
- if ( f.isDirectory() )
- {
- javaFiles.addAll( FileUtils.getFiles( f, includes, excludes, true ) );
- }
- else
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( f + " doesn't exist. Ignored it." );
- }
- }
- }
-
- ClassLibraryBuilder classLibraryBuilder = new OrderedClassLibraryBuilder();
- classLibraryBuilder.appendClassLoader( getProjectClassLoader() );
-
- JavaProjectBuilder builder = new JavaProjectBuilder( classLibraryBuilder );
- builder.setEncoding( encoding );
- for ( File f : javaFiles )
- {
- if ( !f.getAbsolutePath().toLowerCase( Locale.ENGLISH ).endsWith( ".java" ) && getLog().isWarnEnabled() )
- {
- getLog().warn( "'" + f + "' is not a Java file. Ignored it." );
- continue;
- }
-
- try
- {
- builder.addSource( f );
- }
- catch ( ParseException e )
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn( "QDOX ParseException: " + e.getMessage() + ". Can't fix it." );
- }
- }
- }
-
- return builder.getClasses();
- }
-
- /**
- * @return the classLoader for the given project using lazy instantiation.
- * @throws MojoExecutionException if any
- */
- private ClassLoader getProjectClassLoader()
- throws MojoExecutionException
- {
- if ( projectClassLoader == null )
- {
- List<String> classPath;
- try
- {
- classPath = getCompileClasspathElements( project );
- }
- catch ( DependencyResolutionRequiredException e )
- {
- throw new MojoExecutionException( "DependencyResolutionRequiredException: " + e.getMessage(), e );
- }
-
- List<URL> urls = new ArrayList<>( classPath.size() );
- for ( String filename : classPath )
- {
- try
- {
- urls.add( new File( filename ).toURI().toURL() );
- }
- catch ( MalformedURLException e )
- {
- throw new MojoExecutionException( "MalformedURLException: " + e.getMessage(), e );
- }
- }
-
- projectClassLoader = new URLClassLoader( urls.toArray( new URL[urls.size()] ), null );
- }
-
- return projectClassLoader;
- }
-
- /**
- * Process the given {@link JavaClass}, ie add missing javadoc tags depending user parameters.
- *
- * @param javaClass not null
- * @throws IOException if any
- * @throws MojoExecutionException if any
- */
- private void processFix( JavaClass javaClass )
- throws IOException, MojoExecutionException
- {
- // Skipping inner classes
- if ( javaClass.isInner() )
- {
- return;
- }
-
- File javaFile;
- try
- {
- javaFile = Paths.get( javaClass.getSource().getURL().toURI() ).toFile();
- }
- catch ( URISyntaxException e )
- {
- throw new MojoExecutionException( e.getMessage() );
- }
-
- // the original java content in memory
- final String originalContent = StringUtils.unifyLineSeparators( FileUtils.fileRead( javaFile, encoding ) );
-
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "Analyzing " + javaClass.getFullyQualifiedName() );
- }
-
- final StringWriter stringWriter = new StringWriter();
- boolean changeDetected = false;
- try ( BufferedReader reader = new BufferedReader( new StringReader( originalContent ) ) )
- {
-
- int lineNumber = 0;
- for ( String line = reader.readLine(); line != null; line = reader.readLine() )
- {
- lineNumber++;
- final String indent = autodetectIndentation( line );
-
- // fixing classes
- if ( javaClass.getComment() == null && javaClass.getAnnotations() != null
- && !javaClass.getAnnotations().isEmpty() )
- {
- if ( lineNumber == javaClass.getAnnotations().get( 0 ).getLineNumber() )
- {
- changeDetected |= fixClassComment( stringWriter, originalContent, javaClass, indent );
-
- takeCareSingleComment( stringWriter, originalContent, javaClass );
- }
- }
- else if ( lineNumber == javaClass.getLineNumber() )
- {
- changeDetected |= fixClassComment( stringWriter, originalContent, javaClass, indent );
-
- takeCareSingleComment( stringWriter, originalContent, javaClass );
- }
-
- // fixing fields
- if ( javaClass.getFields() != null )
- {
- for ( JavaField field : javaClass.getFields() )
- {
- if ( lineNumber == field.getLineNumber() )
- {
- changeDetected |= fixFieldComment( stringWriter, javaClass, field, indent );
- }
- }
- }
-
- // fixing methods
- if ( javaClass.getConstructors() != null )
- {
- for ( JavaConstructor method : javaClass.getConstructors() )
- {
- if ( lineNumber == method.getLineNumber() )
- {
- final boolean commentUpdated =
- fixMethodComment( stringWriter, originalContent, method, indent );
- if ( commentUpdated )
- {
- takeCareSingleComment( stringWriter, originalContent, method );
- }
- changeDetected |= commentUpdated;
- }
- }
- }
-
-
- // fixing methods
- for ( JavaMethod method : javaClass.getMethods() )
- {
- int methodLineNumber;
- if ( method.getComment() == null && !method.getAnnotations().isEmpty() )
- {
- methodLineNumber = method.getAnnotations().get( 0 ).getLineNumber();
- }
- else
- {
- methodLineNumber = method.getLineNumber();
- }
-
- if ( lineNumber == methodLineNumber )
- {
- final boolean commentUpdated =
- fixMethodComment( stringWriter, originalContent, method, indent );
- if ( commentUpdated )
- {
- takeCareSingleComment( stringWriter, originalContent, method );
- }
- changeDetected |= commentUpdated;
- }
- }
-
- stringWriter.write( line );
- stringWriter.write( EOL );
- }
- }
-
- if ( changeDetected )
- {
- if ( getLog().isInfoEnabled() )
- {
- getLog().info( "Saving changes to " + javaClass.getFullyQualifiedName() );
- }
-
- if ( outputDirectory != null && !outputDirectory.getAbsolutePath().equals(
- getProjectSourceDirectory().getAbsolutePath() ) )
- {
- String path = StringUtils.replace( javaFile.getAbsolutePath().replaceAll( "\\\\", "/" ),
- project.getBuild().getSourceDirectory().replaceAll( "\\\\", "/" ), "" );
- javaFile = new File( outputDirectory, path );
- javaFile.getParentFile().mkdirs();
- }
- writeFile( javaFile, encoding, stringWriter.toString() );
- }
- else
- {
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( "No changes made to " + javaClass.getFullyQualifiedName() );
- }
- }
- }
-
- /**
- * Take care of block or single comments between Javadoc comment and entity declaration ie:
- * <br/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* {Javadoc Comment}</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f7f5f">/*</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f7f5f">* {Block Comment}</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#3f7f5f">*/</font><br />
- * <font color="#808080">7</font> <font color="#ffffff"> </font>
- * <font color="#3f7f5f">// {Single comment}</font><br />
- * <font color="#808080">8</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
- * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
- * <font color="#000000">String s </font><font color="#000000">){}</font>
- * </code>
- *
- * @param stringWriter not null
- * @param originalContent not null
- * @param entity not null
- * @throws IOException if any
- * @see #extractOriginalJavadoc
- */
- private void takeCareSingleComment( final StringWriter stringWriter, final String originalContent,
- final JavaAnnotatedElement entity )
- throws IOException
- {
- if ( entity.getComment() == null )
- {
- return;
- }
-
- String javadocComment = trimRight( extractOriginalJavadoc( originalContent, entity ) );
- String extraComment = javadocComment.substring( javadocComment.indexOf( END_JAVADOC ) + END_JAVADOC.length() );
- if ( StringUtils.isNotEmpty( extraComment ) )
- {
- if ( extraComment.contains( EOL ) )
- {
- stringWriter.write( extraComment.substring( extraComment.indexOf( EOL ) + EOL.length() ) );
- }
- else
- {
- stringWriter.write( extraComment );
- }
- stringWriter.write( EOL );
- }
- }
-
- /**
- * Add/update Javadoc class comment.
- *
- * @param stringWriter
- * @param originalContent
- * @param javaClass
- * @param indent
- * @return {@code true} if the comment is updated, otherwise {@code false}
- * @throws MojoExecutionException
- * @throws IOException
- */
- private boolean fixClassComment( final StringWriter stringWriter, final String originalContent,
- final JavaClass javaClass, final String indent )
- throws MojoExecutionException, IOException
- {
- if ( !fixClassComment )
- {
- return false;
- }
-
- if ( !isInLevel( javaClass.getModifiers() ) )
- {
- return false;
- }
-
- // add
- if ( javaClass.getComment() == null )
- {
- addDefaultClassComment( stringWriter, javaClass, indent );
- return true;
- }
-
- // update
- return updateEntityComment( stringWriter, originalContent, javaClass, indent );
- }
-
- /**
- * @param modifiers list of modifiers (public, private, protected, package)
- * @return <code>true</code> if modifier is align with <code>level</code>.
- */
- private boolean isInLevel( List<String> modifiers )
- {
- if ( LEVEL_PUBLIC.equalsIgnoreCase( level.trim() ) )
- {
- return modifiers.contains( LEVEL_PUBLIC );
- }
-
- if ( LEVEL_PROTECTED.equalsIgnoreCase( level.trim() ) )
- {
- return ( modifiers.contains( LEVEL_PUBLIC ) || modifiers.contains( LEVEL_PROTECTED ) );
- }
-
- if ( LEVEL_PACKAGE.equalsIgnoreCase( level.trim() ) )
- {
- return !modifiers.contains( LEVEL_PRIVATE );
- }
-
- // should be private (shows all classes and members)
- return true;
- }
-
- /**
- * Add a default Javadoc for the given class, i.e.:
- * <br/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* {Comment based on the class name}</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@author </font>
- * <font color="#3f5fbf">X {added if addMissingAuthor}</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@version </font>
- * <font color="#3f5fbf">X {added if addMissingVersion}</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@since </font>
- * <font color="#3f5fbf">X {added if addMissingSince and new classes
- * from previous version}</font><br />
- * <font color="#808080">7</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">8</font> <font color="#7f0055"><b>public class </b></font>
- * <font color="#000000">DummyClass </font><font color="#000000">{}</font></code>
- * </code>
- *
- * @param stringWriter not null
- * @param javaClass not null
- * @param indent not null
- * @see #getDefaultClassJavadocComment(JavaClass)
- * @see #appendDefaultAuthorTag(StringBuilder, String)
- * @see #appendDefaultSinceTag(StringBuilder, String)
- * @see #appendDefaultVersionTag(StringBuilder, String)
- */
- private void addDefaultClassComment( final StringWriter stringWriter, final JavaClass javaClass,
- final String indent )
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( indent ).append( START_JAVADOC );
- sb.append( EOL );
- sb.append( indent ).append( SEPARATOR_JAVADOC );
- sb.append( getDefaultClassJavadocComment( javaClass ) );
- sb.append( EOL );
-
- appendSeparator( sb, indent );
-
- appendDefaultAuthorTag( sb, indent );
-
- appendDefaultVersionTag( sb, indent );
-
- if ( fixTag( SINCE_TAG ) )
- {
- if ( !ignoreClirr )
- {
- if ( isNewClassFromLastVersion( javaClass ) )
- {
- appendDefaultSinceTag( sb, indent );
- }
- }
- else
- {
- appendDefaultSinceTag( sb, indent );
- addSinceClasses( javaClass );
- }
- }
-
- sb.append( indent ).append( " " ).append( END_JAVADOC );
- sb.append( EOL );
-
- stringWriter.write( sb.toString() );
- }
-
- /**
- * Add Javadoc field comment, only for static fields or interface fields.
- *
- * @param stringWriter not null
- * @param javaClass not null
- * @param field not null
- * @param indent not null
- * @return {@code true} if comment was updated, otherwise {@code false}
- * @throws IOException if any
- */
- private boolean fixFieldComment( final StringWriter stringWriter, final JavaClass javaClass, final JavaField field,
- final String indent )
- throws IOException
- {
- if ( !fixFieldComment )
- {
- return false;
- }
-
- if ( !javaClass.isInterface() && ( !isInLevel( field.getModifiers() ) || !field.isStatic() ) )
- {
- return false;
- }
-
- // add
- if ( field.getComment() == null )
- {
- addDefaultFieldComment( stringWriter, field, indent );
- return true;
- }
-
- // no update
- return false;
- }
-
- /**
- * Add a default Javadoc for the given field, i.e.:
- * <br/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/** Constant </font><font color="#7f7f9f"><code></font>
- * <font color="#3f5fbf">MY_STRING_CONSTANT="value"</font>
- * <font color="#7f7f9f"></code> </font><font color="#3f5fbf">*/</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public static final </b></font>
- * <font color="#000000">String MY_STRING_CONSTANT = </font>
- * <font color="#2a00ff">"value"</font><font color="#000000">;</font>
- * </code>
- *
- * @param stringWriter not null
- * @param field not null
- * @param indent not null
- * @throws IOException if any
- */
- private void addDefaultFieldComment( final StringWriter stringWriter, final JavaField field, final String indent )
- throws IOException
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( indent ).append( START_JAVADOC ).append( " " );
- sb.append( "Constant <code>" ).append( field.getName() );
-
- if ( StringUtils.isNotEmpty( field.getInitializationExpression() ) )
- {
- String qualifiedName = field.getType().getFullyQualifiedName();
-
- if ( qualifiedName.equals( Byte.TYPE.toString() ) || qualifiedName.equals( Short.TYPE.toString() )
- || qualifiedName.equals( Integer.TYPE.toString() ) || qualifiedName.equals( Long.TYPE.toString() )
- || qualifiedName.equals( Float.TYPE.toString() ) || qualifiedName.equals( Double.TYPE.toString() )
- || qualifiedName.equals( Boolean.TYPE.toString() ) || qualifiedName.equals(
- Character.TYPE.toString() ) )
- {
- sb.append( "=" );
- sb.append( StringEscapeUtils.escapeHtml4( field.getInitializationExpression().trim() ) );
- }
-
- if ( qualifiedName.equals( String.class.getName() ) )
- {
- StringBuilder value = new StringBuilder();
- String[] lines = getLines( field.getInitializationExpression() );
- for ( String line : lines )
- {
- StringTokenizer token = new StringTokenizer( line.trim(), "\"\n\r" );
- while ( token.hasMoreTokens() )
- {
- String s = token.nextToken();
-
- if ( s.trim().equals( "+" ) )
- {
- continue;
- }
- if ( s.trim().endsWith( "\\" ) )
- {
- s += "\"";
- }
- value.append( s );
- }
- }
-
- sb.append( "=\"" );
- String escapedValue = StringEscapeUtils.escapeHtml4( value.toString() );
- // reduce the size
- // CHECKSTYLE_OFF: MagicNumber
- if ( escapedValue.length() < 40 )
- {
- sb.append( escapedValue ).append( "\"" );
- }
- else
- {
- sb.append( escapedValue, 0, 39 ).append( "\"{trunked}" );
- }
- // CHECKSTYLE_ON: MagicNumber
- }
- }
-
- sb.append( "</code> " ).append( END_JAVADOC );
- sb.append( EOL );
-
- stringWriter.write( sb.toString() );
- }
-
- /**
- * Add/update Javadoc method comment.
- *
- * @param stringWriter not null
- * @param originalContent not null
- * @param javaExecutable not null
- * @param indent not null
- * @return {@code true} if comment was updated, otherwise {@code false}
- * @throws MojoExecutionException if any
- * @throws IOException if any
- */
- private boolean fixMethodComment( final StringWriter stringWriter, final String originalContent,
- final JavaExecutable javaExecutable, final String indent )
- throws MojoExecutionException, IOException
- {
- if ( !fixMethodComment )
- {
- return false;
- }
-
- if ( !javaExecutable.getDeclaringClass().isInterface() && !isInLevel( javaExecutable.getModifiers() ) )
- {
- return false;
- }
-
- // add
- if ( javaExecutable.getComment() == null )
- {
- addDefaultMethodComment( stringWriter, javaExecutable, indent );
- return true;
- }
-
- // update
- return updateEntityComment( stringWriter, originalContent, javaExecutable, indent );
- }
-
- /**
- * Add in the buffer a default Javadoc for the given class:
- * <br/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* {Comment based on the method name}</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">X {added if addMissingParam}</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@return </font>
- * <font color="#3f5fbf">X {added if addMissingReturn}</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@throws </font>
- * <font color="#3f5fbf">X {added if addMissingThrows}</font><br />
- * <font color="#808080">7</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@since </font>
- * <font color="#3f5fbf">X {added if addMissingSince and new classes
- * from previous version}</font><br />
- * <font color="#808080">8</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">9</font> <font color="#7f0055"><b>public </b></font>
- * <font color="#7f0055"><b>void </b></font><font color="#000000">dummyMethod</font>
- * <font color="#000000">( </font><font color="#000000">String s </font>
- * <font color="#000000">){}</font>
- * </code>
- *
- * @param stringWriter not null
- * @param javaExecutable not null
- * @param indent not null
- * @throws MojoExecutionException if any
- * @see #getDefaultMethodJavadocComment
- * @see #appendDefaultSinceTag(StringBuilder, String)
- */
- private void addDefaultMethodComment( final StringWriter stringWriter, final JavaExecutable javaExecutable,
- final String indent )
- throws MojoExecutionException
- {
- StringBuilder sb = new StringBuilder();
-
- // special case
- if ( isInherited( javaExecutable ) )
- {
- sb.append( indent ).append( INHERITED_JAVADOC );
- sb.append( EOL );
-
- stringWriter.write( sb.toString() );
- return;
- }
-
- sb.append( indent ).append( START_JAVADOC );
- sb.append( EOL );
- sb.append( indent ).append( SEPARATOR_JAVADOC );
- sb.append( getDefaultMethodJavadocComment( javaExecutable ) );
- sb.append( EOL );
-
- boolean separatorAdded = false;
- if ( fixTag( PARAM_TAG ) )
- {
- if ( javaExecutable.getParameters() != null )
- {
- for ( JavaParameter javaParameter : javaExecutable.getParameters() )
- {
- separatorAdded = appendDefaultParamTag( sb, indent, separatorAdded, javaParameter );
- }
- }
- // is generic?
- if ( javaExecutable.getTypeParameters() != null )
- {
- for ( JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters() )
- {
- separatorAdded = appendDefaultParamTag( sb, indent, separatorAdded, typeParam );
- }
- }
- }
- if ( javaExecutable instanceof JavaMethod )
- {
- JavaMethod javaMethod = (JavaMethod) javaExecutable;
- if ( fixTag( RETURN_TAG ) && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid() )
- {
- separatorAdded = appendDefaultReturnTag( sb, indent, separatorAdded, javaMethod );
- }
-
- }
- if ( fixTag( THROWS_TAG ) && javaExecutable.getExceptions() != null )
- {
- for ( JavaType exception : javaExecutable.getExceptions() )
- {
- separatorAdded = appendDefaultThrowsTag( sb, indent, separatorAdded, exception );
- }
- }
- if ( fixTag( SINCE_TAG ) && isNewMethodFromLastRevision( javaExecutable ) )
- {
- separatorAdded = appendDefaultSinceTag( sb, indent, separatorAdded );
- }
-
- sb.append( indent ).append( " " ).append( END_JAVADOC );
- sb.append( EOL );
-
- stringWriter.write( sb.toString() );
- }
-
- /**
- * @param stringWriter not null
- * @param originalContent not null
- * @param entity not null
- * @param indent not null
- * @return the updated changeDetected flag
- * @throws MojoExecutionException if any
- * @throws IOException if any
- */
- private boolean updateEntityComment( final StringWriter stringWriter, final String originalContent,
- final JavaAnnotatedElement entity, final String indent )
- throws MojoExecutionException, IOException
- {
- boolean changeDetected = false;
-
- String old = null;
- String s = stringWriter.toString();
- int i = s.lastIndexOf( START_JAVADOC );
- if ( i != -1 )
- {
- String tmp = s.substring( 0, i );
- if ( tmp.lastIndexOf( EOL ) != -1 )
- {
- tmp = tmp.substring( 0, tmp.lastIndexOf( EOL ) );
- }
-
- old = stringWriter.getBuffer().substring( i );
-
- stringWriter.getBuffer().delete( 0, stringWriter.getBuffer().length() );
- stringWriter.write( tmp );
- stringWriter.write( EOL );
- }
- else
- {
- changeDetected = true;
- }
-
- updateJavadocComment( stringWriter, originalContent, entity, indent );
-
- if ( changeDetected )
- {
- return true; // return now if we already know there's a change
- }
-
- return !stringWriter.getBuffer().substring( i ).equals( old );
- }
-
- /**
- * @param stringWriter not null
- * @param originalContent not null
- * @param entity not null
- * @param indent not null
- * @throws MojoExecutionException if any
- * @throws IOException if any
- */
- private void updateJavadocComment( final StringWriter stringWriter, final String originalContent,
- final JavaAnnotatedElement entity, final String indent )
- throws MojoExecutionException, IOException
- {
- if ( entity.getComment() == null && ( entity.getTags() == null || entity.getTags().isEmpty() ) )
- {
- return;
- }
-
- boolean isJavaExecutable = entity instanceof JavaExecutable;
-
- StringBuilder sb = new StringBuilder();
-
- // special case for inherited method
- if ( isJavaExecutable )
- {
- JavaExecutable javaMethod = (JavaExecutable) entity;
-
- if ( isInherited( javaMethod ) )
- {
- // QDOX-154 could be empty
- if ( StringUtils.isEmpty( javaMethod.getComment() ) )
- {
- sb.append( indent ).append( INHERITED_JAVADOC );
- sb.append( EOL );
- stringWriter.write( sb.toString() );
- return;
- }
-
- String javadoc = getJavadocComment( originalContent, javaMethod );
-
- // case: /** {@inheritDoc} */ or no tags
- if ( hasInheritedTag( javadoc ) && ( javaMethod.getTags() == null
- || javaMethod.getTags().isEmpty() ) )
- {
- sb.append( indent ).append( INHERITED_JAVADOC );
- sb.append( EOL );
- stringWriter.write( sb.toString() );
- return;
- }
-
- if ( javadoc.contains( START_JAVADOC ) )
- {
- javadoc = javadoc.substring( javadoc.indexOf( START_JAVADOC ) + START_JAVADOC.length() );
- }
- if ( javadoc.contains( END_JAVADOC ) )
- {
- javadoc = javadoc.substring( 0, javadoc.indexOf( END_JAVADOC ) );
- }
-
- sb.append( indent ).append( START_JAVADOC );
- sb.append( EOL );
- if ( !javadoc.contains( INHERITED_TAG ) )
- {
- sb.append( indent ).append( SEPARATOR_JAVADOC ).append( INHERITED_TAG );
- sb.append( EOL );
- appendSeparator( sb, indent );
- }
- javadoc = removeLastEmptyJavadocLines( javadoc );
- javadoc = alignIndentationJavadocLines( javadoc, indent );
- sb.append( javadoc );
- sb.append( EOL );
- if ( javaMethod.getTags() != null )
- {
- for ( DocletTag docletTag : javaMethod.getTags() )
- {
- // Voluntary ignore these tags
- if ( JavadocUtil.equals( docletTag.getName(), PARAM_TAG, RETURN_TAG, THROWS_TAG ) )
- {
- continue;
- }
-
- String s = getJavadocComment( originalContent, entity, docletTag );
- s = removeLastEmptyJavadocLines( s );
- s = alignIndentationJavadocLines( s, indent );
- sb.append( s );
- sb.append( EOL );
- }
- }
- sb.append( indent ).append( " " ).append( END_JAVADOC );
- sb.append( EOL );
-
- if ( hasInheritedTag( sb.toString().trim() ) )
- {
- sb = new StringBuilder();
- sb.append( indent ).append( INHERITED_JAVADOC );
- sb.append( EOL );
- stringWriter.write( sb.toString() );
- return;
- }
-
- stringWriter.write( sb.toString() );
- return;
- }
- }
-
- sb.append( indent ).append( START_JAVADOC );
- sb.append( EOL );
-
- // comment
- if ( StringUtils.isNotEmpty( entity.getComment() ) )
- {
- updateJavadocComment( sb, originalContent, entity, indent );
- }
- else
- {
- addDefaultJavadocComment( sb, entity, indent, isJavaExecutable );
- }
-
- // tags
- updateJavadocTags( sb, originalContent, entity, indent, isJavaExecutable );
-
- sb = new StringBuilder( removeLastEmptyJavadocLines( sb.toString() ) ).append( EOL );
-
- sb.append( indent ).append( " " ).append( END_JAVADOC );
- sb.append( EOL );
-
- stringWriter.write( sb.toString() );
- }
-
- /**
- * @param sb not null
- * @param originalContent not null
- * @param entity not null
- * @param indent not null
- * @throws IOException if any
- */
- private void updateJavadocComment( final StringBuilder sb, final String originalContent,
- final JavaAnnotatedElement entity, final String indent )
- throws IOException
- {
- String comment = getJavadocComment( originalContent, entity );
- comment = removeLastEmptyJavadocLines( comment );
- comment = alignIndentationJavadocLines( comment, indent );
-
- if ( comment.contains( START_JAVADOC ) )
- {
- comment = comment.substring( comment.indexOf( START_JAVADOC ) + START_JAVADOC.length() );
- comment = indent + SEPARATOR_JAVADOC + comment.trim();
- }
- if ( comment.contains( END_JAVADOC ) )
- {
- comment = comment.substring( 0, comment.indexOf( END_JAVADOC ) );
- }
-
- if ( fixTag( LINK_TAG ) )
- {
- comment = replaceLinkTags( comment, entity );
- }
-
- String[] lines = getLines( comment );
- for ( String line : lines )
- {
- sb.append( indent ).append( " " ).append( line.trim() );
- sb.append( EOL );
- }
- }
-
- private static final Pattern REPLACE_LINK_TAGS_PATTERN = Pattern.compile( "\\{@link\\s" );
-
- static String replaceLinkTags( String comment, JavaAnnotatedElement entity )
- {
- StringBuilder resolvedComment = new StringBuilder();
- // scan comment for {@link someClassName} and try to resolve this
- Matcher linktagMatcher = REPLACE_LINK_TAGS_PATTERN.matcher( comment );
- int startIndex = 0;
- while ( linktagMatcher.find() )
- {
- int startName = linktagMatcher.end();
- resolvedComment.append( comment, startIndex, startName );
- int endName = comment.indexOf( "}", startName );
- if ( endName >= 0 )
- {
- String name;
- String link = comment.substring( startName, endName );
- int hashIndex = link.indexOf( '#' );
- if ( hashIndex >= 0 )
- {
- name = link.substring( 0, hashIndex );
- }
- else
- {
- name = link;
- }
- if ( StringUtils.isNotBlank( name ) )
- {
- String typeName;
- if ( entity instanceof JavaClass )
- {
- JavaClass clazz = (JavaClass) entity;
- typeName =
- TypeResolver.byClassName( clazz.getBinaryName(), clazz.getJavaClassLibrary(),
- clazz.getSource().getImports() ).resolveType( name.trim() );
- }
- else if ( entity instanceof JavaMember )
- {
- JavaClass clazz = ( (JavaMember) entity ).getDeclaringClass();
- typeName =
- TypeResolver.byClassName( clazz.getBinaryName(), clazz.getJavaClassLibrary(),
- clazz.getSource().getImports() ).resolveType( name.trim() );
- }
- else
- {
- typeName = null;
- }
-
- if ( typeName == null )
- {
- typeName = name.trim();
- }
- else
- {
- typeName = typeName.replaceAll( "\\$", "." );
- }
- //adjust name for inner classes
- resolvedComment.append( typeName );
- }
- if ( hashIndex >= 0 )
- {
- resolvedComment.append( link.substring( hashIndex ).trim() );
- }
- startIndex = endName;
- }
- else
- {
- startIndex = startName;
- }
-
- }
- resolvedComment.append( comment.substring( startIndex ) );
- return resolvedComment.toString();
-
- }
-
- /**
- * @param sb not null
- * @param entity not null
- * @param indent not null
- * @param isJavaExecutable
- */
- private void addDefaultJavadocComment( final StringBuilder sb, final JavaAnnotatedElement entity,
- final String indent, final boolean isJavaExecutable )
- {
- sb.append( indent ).append( SEPARATOR_JAVADOC );
- if ( isJavaExecutable )
- {
- sb.append( getDefaultMethodJavadocComment( (JavaExecutable) entity ) );
- }
- else
- {
- sb.append( getDefaultClassJavadocComment( (JavaClass) entity ) );
- }
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param originalContent not null
- * @param entity not null
- * @param indent not null
- * @param isJavaExecutable
- * @throws IOException if any
- * @throws MojoExecutionException if any
- */
- private void updateJavadocTags( final StringBuilder sb, final String originalContent,
- final JavaAnnotatedElement entity, final String indent,
- final boolean isJavaExecutable )
- throws IOException, MojoExecutionException
- {
- appendSeparator( sb, indent );
-
- // parse tags
- JavaEntityTags javaEntityTags = parseJavadocTags( originalContent, entity, indent, isJavaExecutable );
-
- // update and write tags
- updateJavadocTags( sb, entity, isJavaExecutable, javaEntityTags );
-
- // add missing tags...
- addMissingJavadocTags( sb, entity, indent, isJavaExecutable, javaEntityTags );
- }
-
- /**
- * Parse entity tags
- *
- * @param originalContent not null
- * @param entity not null
- * @param indent not null
- * @param isJavaMethod
- * @return an instance of {@link JavaEntityTags}
- * @throws IOException if any
- */
- JavaEntityTags parseJavadocTags( final String originalContent, final JavaAnnotatedElement entity,
- final String indent, final boolean isJavaMethod )
- throws IOException
- {
- JavaEntityTags javaEntityTags = new JavaEntityTags( entity, isJavaMethod );
- for ( DocletTag docletTag : entity.getTags() )
- {
- String originalJavadocTag = getJavadocComment( originalContent, entity, docletTag );
- originalJavadocTag = removeLastEmptyJavadocLines( originalJavadocTag );
- originalJavadocTag = alignIndentationJavadocLines( originalJavadocTag, indent );
-
- javaEntityTags.getNamesTags().add( docletTag.getName() );
-
- if ( isJavaMethod )
- {
- List<String> params = docletTag.getParameters();
- if ( params.size() < 1 )
- {
- continue;
- }
-
- String paramName = params.get( 0 );
- switch ( docletTag.getName() )
- {
- case PARAM_TAG:
- javaEntityTags.putJavadocParamTag( paramName, docletTag.getValue(), originalJavadocTag );
- break;
- case RETURN_TAG:
- javaEntityTags.setJavadocReturnTag( originalJavadocTag );
- break;
- case THROWS_TAG:
- javaEntityTags.putJavadocThrowsTag( paramName, originalJavadocTag );
- break;
- default:
- javaEntityTags.getUnknownTags().add( originalJavadocTag );
- break;
- }
- }
- else
- {
- javaEntityTags.getUnknownTags().add( originalJavadocTag );
- }
- }
-
- return javaEntityTags;
- }
-
- /**
- * Write tags according javaEntityTags.
- *
- * @param sb not null
- * @param entity not null
- * @param isJavaExecutable
- * @param javaEntityTags not null
- */
- private void updateJavadocTags( final StringBuilder sb, final JavaAnnotatedElement entity,
- final boolean isJavaExecutable, final JavaEntityTags javaEntityTags )
- {
- for ( DocletTag docletTag : entity.getTags() )
- {
- if ( isJavaExecutable )
- {
- JavaExecutable javaExecutable = (JavaExecutable) entity;
-
- List<String> params = docletTag.getParameters();
- if ( params.size() < 1 )
- {
- continue;
- }
-
- if ( docletTag.getName().equals( PARAM_TAG ) )
- {
- writeParamTag( sb, javaExecutable, javaEntityTags, params.get( 0 ), docletTag.getValue() );
- }
- else if ( docletTag.getName().equals( RETURN_TAG ) && javaExecutable instanceof JavaMethod )
- {
- writeReturnTag( sb, (JavaMethod) javaExecutable, javaEntityTags );
- }
- else if ( docletTag.getName().equals( THROWS_TAG ) )
- {
- writeThrowsTag( sb, javaExecutable, javaEntityTags, params );
- }
- else
- {
- // write unknown tags
- for ( Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); )
- {
- String originalJavadocTag = it.next();
- String simplified = StringUtils.removeDuplicateWhitespace( originalJavadocTag ).trim();
-
- if ( simplified.contains( "@" + docletTag.getName() ) )
- {
- it.remove();
- sb.append( originalJavadocTag );
- sb.append( EOL );
- }
- }
- }
- }
- else
- {
- for ( Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); )
- {
- String originalJavadocTag = it.next();
- String simplified = StringUtils.removeDuplicateWhitespace( originalJavadocTag ).trim();
-
- if ( simplified.contains( "@" + docletTag.getName() ) )
- {
- it.remove();
- sb.append( originalJavadocTag );
- sb.append( EOL );
- }
- }
- }
-
- if ( sb.toString().endsWith( EOL ) )
- {
- sb.delete( sb.toString().lastIndexOf( EOL ), sb.toString().length() );
- }
-
- sb.append( EOL );
- }
- }
-
- private void writeParamTag( final StringBuilder sb, final JavaExecutable javaExecutable,
- final JavaEntityTags javaEntityTags, String paramName, String paramValue )
- {
- if ( !fixTag( PARAM_TAG ) )
- {
- // write original param tag if found
- String originalJavadocTag = javaEntityTags.getJavadocParamTag( paramValue );
- if ( originalJavadocTag != null )
- {
- sb.append( originalJavadocTag );
- }
- return;
- }
-
- boolean found = false;
- JavaParameter javaParam = javaExecutable.getParameterByName( paramName );
- if ( javaParam == null )
- {
- // is generic?
- List<JavaTypeVariable<JavaGenericDeclaration>> typeParams = javaExecutable.getTypeParameters();
- for ( JavaTypeVariable<JavaGenericDeclaration> typeParam : typeParams )
- {
- if ( ( "<" + typeParam.getName() + ">" ).equals( paramName ) )
- {
- found = true;
- }
- }
- }
- else
- {
- found = true;
- }
-
- if ( !found )
- {
- if ( getLog().isWarnEnabled() )
- {
- getLog().warn(
- "Fixed unknown param '" + paramName + "' defined in " + getJavaMethodAsString( javaExecutable ) );
- }
-
- if ( sb.toString().endsWith( EOL ) )
- {
- sb.delete( sb.toString().lastIndexOf( EOL ), sb.toString().length() );
- }
- }
- else
- {
- String originalJavadocTag = javaEntityTags.getJavadocParamTag( paramValue );
- if ( originalJavadocTag != null )
- {
- sb.append( originalJavadocTag );
- String s = "@" + PARAM_TAG + " " + paramName;
- if ( StringUtils.removeDuplicateWhitespace( originalJavadocTag ).trim().endsWith( s ) )
- {
- sb.append( " " );
- sb.append( getDefaultJavadocForType( javaParam.getJavaClass() ) );
- }
- }
- }
- }
-
- private void writeReturnTag( final StringBuilder sb, final JavaMethod javaMethod,
- final JavaEntityTags javaEntityTags )
- {
- String originalJavadocTag = javaEntityTags.getJavadocReturnTag();
- if ( originalJavadocTag == null )
- {
- return;
- }
-
- if ( !fixTag( RETURN_TAG ) )
- {
- // write original param tag if found
- sb.append( originalJavadocTag );
- return;
- }
-
- if ( StringUtils.isNotEmpty( originalJavadocTag ) && javaMethod.getReturns() != null
- && !javaMethod.getReturns().isVoid() )
- {
- sb.append( originalJavadocTag );
- if ( originalJavadocTag.trim().endsWith( "@" + RETURN_TAG ) )
- {
- sb.append( " " );
- sb.append( getDefaultJavadocForType( javaMethod.getReturns() ) );
- }
- }
- }
-
- void writeThrowsTag( final StringBuilder sb, final JavaExecutable javaExecutable,
- final JavaEntityTags javaEntityTags, final List<String> params )
- {
- String exceptionClassName = params.get( 0 );
-
- String originalJavadocTag = javaEntityTags.getJavadocThrowsTag( exceptionClassName );
- if ( originalJavadocTag == null )
- {
- return;
- }
-
- if ( !fixTag( THROWS_TAG ) )
- {
- // write original param tag if found
- sb.append( originalJavadocTag );
- return;
- }
-
- if ( javaExecutable.getExceptions() != null )
- {
- for ( JavaType exception : javaExecutable.getExceptions() )
- {
- if ( exception.getFullyQualifiedName().endsWith( exceptionClassName ) )
- {
- originalJavadocTag = StringUtils.replace( originalJavadocTag, exceptionClassName,
- exception.getFullyQualifiedName() );
- if ( StringUtils.removeDuplicateWhitespace( originalJavadocTag ).trim().endsWith(
- "@" + THROWS_TAG + " " + exception.getValue() ) )
- {
- originalJavadocTag += " if any.";
- }
-
- sb.append( originalJavadocTag );
-
- // added qualified name
- javaEntityTags.putJavadocThrowsTag( exception.getValue(), originalJavadocTag );
-
- return;
- }
- }
- }
-
- Class<?> clazz = getClass( javaExecutable.getDeclaringClass(), exceptionClassName );
-
- if ( clazz != null )
- {
- if ( RuntimeException.class.isAssignableFrom( clazz ) )
- {
- sb.append( StringUtils.replace( originalJavadocTag, exceptionClassName, clazz.getName() ) );
-
- // added qualified name
- javaEntityTags.putJavadocThrowsTag( clazz.getName(), originalJavadocTag );
- }
- else if ( Throwable.class.isAssignableFrom( clazz ) )
- {
- getLog().debug( "Removing '" + originalJavadocTag + "'; Throwable not specified by "
- + getJavaMethodAsString( javaExecutable ) + " and it is not a RuntimeException." );
- }
- else
- {
- getLog().debug( "Removing '" + originalJavadocTag + "'; It is not a Throwable" );
- }
- }
- else if ( removeUnknownThrows )
- {
- getLog().warn( "Ignoring unknown throws '" + exceptionClassName + "' defined on "
- + getJavaMethodAsString( javaExecutable ) );
- }
- else
- {
- getLog().warn( "Found unknown throws '" + exceptionClassName + "' defined on "
- + getJavaMethodAsString( javaExecutable ) );
-
- sb.append( originalJavadocTag );
-
- if ( params.size() == 1 )
- {
- sb.append( " if any." );
- }
-
- javaEntityTags.putJavadocThrowsTag( exceptionClassName, originalJavadocTag );
- }
- }
-
- /**
- * Add missing tags not already written.
- *
- * @param sb not null
- * @param entity not null
- * @param indent not null
- * @param isJavaExecutable
- * @param javaEntityTags not null
- * @throws MojoExecutionException if any
- */
- private void addMissingJavadocTags( final StringBuilder sb, final JavaAnnotatedElement entity,
- final String indent, final boolean isJavaExecutable,
- final JavaEntityTags javaEntityTags )
- throws MojoExecutionException
- {
- if ( isJavaExecutable )
- {
- JavaExecutable javaExecutable = (JavaExecutable) entity;
-
- if ( fixTag( PARAM_TAG ) )
- {
- if ( javaExecutable.getParameters() != null )
- {
- for ( JavaParameter javaParameter : javaExecutable.getParameters() )
- {
- if ( !javaEntityTags.hasJavadocParamTag( javaParameter.getName() ) )
- {
- appendDefaultParamTag( sb, indent, javaParameter );
- }
- }
- }
- // is generic?
- if ( javaExecutable.getTypeParameters() != null )
- {
- for ( JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters() )
- {
- if ( !javaEntityTags.hasJavadocParamTag( "<" + typeParam.getName() + ">" ) )
- {
- appendDefaultParamTag( sb, indent, typeParam );
- }
- }
- }
- }
-
- if ( javaExecutable instanceof JavaMethod )
- {
- JavaMethod javaMethod = (JavaMethod) javaExecutable;
- if ( fixTag( RETURN_TAG ) && StringUtils.isEmpty( javaEntityTags.getJavadocReturnTag() )
- && javaMethod.getReturns() != null && !javaMethod.getReturns().isVoid() )
- {
- appendDefaultReturnTag( sb, indent, javaMethod );
- }
- }
-
- if ( fixTag( THROWS_TAG ) && javaExecutable.getExceptions() != null )
- {
- for ( JavaType exception : javaExecutable.getExceptions() )
- {
- if ( javaEntityTags.getJavadocThrowsTag( exception.getValue(), true ) == null )
- {
- appendDefaultThrowsTag( sb, indent, exception );
- }
- }
- }
- }
- else
- {
- if ( !javaEntityTags.getNamesTags().contains( AUTHOR_TAG ) )
- {
- appendDefaultAuthorTag( sb, indent );
- }
- if ( !javaEntityTags.getNamesTags().contains( VERSION_TAG ) )
- {
- appendDefaultVersionTag( sb, indent );
- }
- }
-
- if ( fixTag( SINCE_TAG ) && !javaEntityTags.getNamesTags().contains( SINCE_TAG ) )
- {
- if ( !isJavaExecutable )
- {
- if ( !ignoreClirr )
- {
- if ( isNewClassFromLastVersion( (JavaClass) entity ) )
- {
- appendDefaultSinceTag( sb, indent );
- }
- }
- else
- {
- appendDefaultSinceTag( sb, indent );
- addSinceClasses( (JavaClass) entity );
- }
- }
- else
- {
- if ( !ignoreClirr )
- {
- if ( isNewMethodFromLastRevision( (JavaExecutable) entity ) )
- {
- appendDefaultSinceTag( sb, indent );
- }
- }
- else if ( sinceClasses != null )
- {
- if ( entity instanceof JavaMember
- && !sinceClassesContains( ( (JavaMember) entity ).getDeclaringClass() ) )
- {
- appendDefaultSinceTag( sb, indent );
- }
- else if ( entity instanceof JavaClass
- && !sinceClassesContains( ( (JavaClass) entity ).getDeclaringClass() ) )
- {
- appendDefaultSinceTag( sb, indent );
- }
- }
- }
- }
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @return true if separator has been added.
- */
- private boolean appendDefaultAuthorTag( final StringBuilder sb, final String indent, boolean separatorAdded )
- {
- if ( !fixTag( AUTHOR_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultAuthorTag( sb, indent );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- */
- private void appendDefaultAuthorTag( final StringBuilder sb, final String indent )
- {
- if ( !fixTag( AUTHOR_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( AUTHOR_TAG ).append( " " );
- sb.append( defaultAuthor );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @return true if separator has been added.
- */
- private boolean appendDefaultSinceTag( final StringBuilder sb, final String indent, boolean separatorAdded )
- {
- if ( !fixTag( SINCE_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultSinceTag( sb, indent );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- */
- private void appendDefaultSinceTag( final StringBuilder sb, final String indent )
- {
- if ( !fixTag( SINCE_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( SINCE_TAG ).append( " " );
- sb.append( defaultSince );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @return true if separator has been added.
- */
- private boolean appendDefaultVersionTag( final StringBuilder sb, final String indent, boolean separatorAdded )
- {
- if ( !fixTag( VERSION_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultVersionTag( sb, indent );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- */
- private void appendDefaultVersionTag( final StringBuilder sb, final String indent )
- {
- if ( !fixTag( VERSION_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( VERSION_TAG ).append( " " );
- sb.append( defaultVersion );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @param typeParam not null
- * @return true if separator has been added.
- */
- private boolean appendDefaultParamTag( final StringBuilder sb, final String indent, boolean separatorAdded,
- final JavaParameter typeParam )
- {
- if ( !fixTag( PARAM_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultParamTag( sb, indent, typeParam );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @param typeParameter not null
- * @return true if separator has been added.
- */
- private boolean appendDefaultParamTag( final StringBuilder sb, final String indent, boolean separatorAdded,
- final JavaTypeVariable<JavaGenericDeclaration> typeParameter )
- {
- if ( !fixTag( PARAM_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultParamTag( sb, indent, typeParameter );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param typeParam not null
- */
- private void appendDefaultParamTag( final StringBuilder sb, final String indent, final JavaParameter typeParam )
- {
- if ( !fixTag( PARAM_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( PARAM_TAG ).append( " " );
- sb.append( typeParam.getName() );
- sb.append( " " );
- sb.append( getDefaultJavadocForType( typeParam.getJavaClass() ) );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param typeParameter not null
- */
- private void appendDefaultParamTag( final StringBuilder sb, final String indent,
- final JavaTypeVariable<JavaGenericDeclaration> typeParameter )
- {
- if ( !fixTag( PARAM_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( PARAM_TAG ).append( " " );
- sb.append( "<" ).append( typeParameter.getName() ).append( ">" );
- sb.append( " " );
- sb.append( getDefaultJavadocForType( typeParameter ) );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @param javaMethod not null
- * @return true if separator has been added.
- */
- private boolean appendDefaultReturnTag( final StringBuilder sb, final String indent, boolean separatorAdded,
- final JavaMethod javaMethod )
- {
- if ( !fixTag( RETURN_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultReturnTag( sb, indent, javaMethod );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param javaMethod not null
- */
- private void appendDefaultReturnTag( final StringBuilder sb, final String indent, final JavaMethod javaMethod )
- {
- if ( !fixTag( RETURN_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( RETURN_TAG ).append( " " );
- sb.append( getDefaultJavadocForType( javaMethod.getReturns() ) );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param separatorAdded
- * @param exception not null
- * @return true if separator has been added.
- */
- private boolean appendDefaultThrowsTag( final StringBuilder sb, final String indent, boolean separatorAdded,
- final JavaType exception )
- {
- if ( !fixTag( THROWS_TAG ) )
- {
- return separatorAdded;
- }
-
- if ( !separatorAdded )
- {
- appendSeparator( sb, indent );
- separatorAdded = true;
- }
-
- appendDefaultThrowsTag( sb, indent, exception );
- return separatorAdded;
- }
-
- /**
- * @param sb not null
- * @param indent not null
- * @param exception not null
- */
- private void appendDefaultThrowsTag( final StringBuilder sb, final String indent, final JavaType exception )
- {
- if ( !fixTag( THROWS_TAG ) )
- {
- return;
- }
-
- sb.append( indent ).append( " * @" ).append( THROWS_TAG ).append( " " );
- sb.append( exception.getFullyQualifiedName() );
- sb.append( " if any." );
- sb.append( EOL );
- }
-
- /**
- * @param sb not null
- * @param indent not null
- */
- private void appendSeparator( final StringBuilder sb, final String indent )
- {
- sb.append( indent ).append( " *" );
- sb.append( EOL );
- }
-
- /**
- * Verify if a method has <code>@java.lang.Override()</code> annotation or if it is an inherited method
- * from an interface or a super class. The goal is to handle <code>{@inheritDoc}</code> tag.
- *
- * @param javaMethod not null
- * @return <code>true</code> if the method is inherited, <code>false</code> otherwise.
- * @throws MojoExecutionException if any
- */
- private boolean isInherited( JavaExecutable javaMethod )
- throws MojoExecutionException
- {
- if ( javaMethod.getAnnotations() != null )
- {
- for ( JavaAnnotation annotation : javaMethod.getAnnotations() )
- {
- if ( annotation.toString().equals( "@java.lang.Override()" ) )
- {
- return true;
- }
- }
- }
-
- Class<?> clazz = getClass( javaMethod.getDeclaringClass().getFullyQualifiedName() );
-
- List<Class<?>> interfaces = ClassUtils.getAllInterfaces( clazz );
- for ( Class<?> intface : interfaces )
- {
- if ( isInherited( intface, javaMethod ) )
- {
- return true;
- }
- }
-
- List<Class<?>> classes = ClassUtils.getAllSuperclasses( clazz );
- for ( Class<?> superClass : classes )
- {
- if ( isInherited( superClass, javaMethod ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @param clazz the Java class object, not null
- * @param javaMethod the QDox JavaMethod object not null
- * @return <code>true</code> if <code>javaMethod</code> exists in the given <code>clazz</code>,
- * <code>false</code> otherwise.
- * @see #isInherited(JavaExecutable)
- */
- private boolean isInherited( Class<?> clazz, JavaExecutable javaMethod )
- {
- for ( Method method : clazz.getDeclaredMethods() )
- {
- if ( !method.getName().equals( javaMethod.getName() ) )
- {
- continue;
- }
-
- if ( method.getParameterTypes().length != javaMethod.getParameters().size() )
- {
- continue;
- }
-
- boolean found = false;
- int j = 0;
- for ( Class<?> paramType : method.getParameterTypes() )
- {
- String name1 = paramType.getName();
- String name2 = javaMethod.getParameters().get( j++ ).getType().getFullyQualifiedName();
- found = name1.equals( name2 ); // TODO check algo, seems broken (only takes in account the last param)
- }
-
- return found;
- }
-
- return false;
- }
-
- /**
- * @param clazz
- * @return
- */
- private String getDefaultJavadocForType( JavaClass clazz )
- {
- StringBuilder sb = new StringBuilder();
-
- if ( !JavaTypeVariable.class.isAssignableFrom( clazz.getClass() ) && clazz.isPrimitive() )
- {
- if ( clazz.isArray() )
- {
- sb.append( "an array of " ).append( clazz.getComponentType().getCanonicalName() );
- }
- else
- {
- sb.append( "a " ).append( clazz.getCanonicalName() );
- }
- return sb.toString();
- }
-
- StringBuilder javadocLink = new StringBuilder();
- try
- {
- getClass( clazz.getCanonicalName() );
-
- javadocLink.append( "{@link " );
-
- if ( clazz.isArray() )
- {
- javadocLink.append( clazz.getComponentType().getCanonicalName() );
- }
- else
- {
- javadocLink.append( clazz.getCanonicalName() );
- }
- javadocLink.append( "}" );
- }
- catch ( Exception e )
- {
- javadocLink.append( clazz.getValue() );
- }
-
- if ( clazz.isArray() )
- {
- sb.append( "an array of " ).append( javadocLink ).append( " objects" );
- }
- else
- {
- sb.append( "a " ).append( javadocLink ).append( " object" );
- }
-
- return sb.toString();
- }
-
- private String getDefaultJavadocForType( JavaTypeVariable<JavaGenericDeclaration> typeParameter )
- {
- return "a " + typeParameter.getName() + " class";
- }
-
- /**
- * Check under Clirr if this given class is newer from the last version.
- *
- * @param javaClass a given class not null
- * @return <code>true</code> if Clirr said that this class is added from the last version,
- * <code>false</code> otherwise or if {@link #clirrNewClasses} is null.
- */
- private boolean isNewClassFromLastVersion( JavaClass javaClass )
- {
- return ( clirrNewClasses != null ) && clirrNewClasses.contains( javaClass.getFullyQualifiedName() );
- }
-
- /**
- * Check under Clirr if this given method is newer from the last version.
- *
- * @param javaExecutable a given method not null
- * @return <code>true</code> if Clirr said that this method is added from the last version,
- * <code>false</code> otherwise or if {@link #clirrNewMethods} is null.
- * @throws MojoExecutionException if any
- */
- private boolean isNewMethodFromLastRevision( JavaExecutable javaExecutable )
- throws MojoExecutionException
- {
- if ( clirrNewMethods == null )
- {
- return false;
- }
-
- List<String> clirrMethods = clirrNewMethods.get( javaExecutable.getDeclaringClass().getFullyQualifiedName() );
- if ( clirrMethods == null )
- {
- return false;
- }
-
- for ( String clirrMethod : clirrMethods )
- {
- // see net.sf.clirr.core.internal.checks.MethodSetCheck#getMethodId(JavaType clazz, Method method)
- String retrn = "";
- if ( javaExecutable instanceof JavaMethod && ( (JavaMethod) javaExecutable ).getReturns() != null )
- {
- retrn = ( (JavaMethod) javaExecutable ).getReturns().getFullyQualifiedName();
- }
- StringBuilder params = new StringBuilder();
- for ( JavaParameter parameter : javaExecutable.getParameters() )
- {
- if ( params.length() > 0 )
- {
- params.append( ", " );
- }
- params.append( parameter.getResolvedFullyQualifiedName() );
- }
- if ( clirrMethod.contains( retrn + " " ) && clirrMethod.contains( javaExecutable.getName() + "(" )
- && clirrMethod.contains( "(" + params.toString() + ")" ) )
- {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * @param className not null
- * @return the Class corresponding to the given class name using the project classloader.
- * @throws MojoExecutionException if class not found
- * @see ClassUtils#getClass(ClassLoader, String, boolean)
- * @see #getProjectClassLoader()
- */
- private Class<?> getClass( String className )
- throws MojoExecutionException
- {
- try
- {
- return ClassUtils.getClass( getProjectClassLoader(), className, false );
- }
- catch ( ClassNotFoundException e )
- {
- throw new MojoExecutionException( "ClassNotFoundException: " + e.getMessage(), e );
- }
- }
-
- /**
- * Returns the Class object assignable for {@link RuntimeException} class and associated with the given
- * exception class name.
- *
- * @param currentClass not null
- * @param exceptionClassName not null, an exception class name defined as:
- * <ul>
- * <li>exception class fully qualified</li>
- * <li>exception class in the same package</li>
- * <li>exception inner class</li>
- * <li>exception class in java.lang package</li>
- * </ul>
- * @return the class if found, otherwise {@code null}.
- * @see #getClass(String)
- */
- private Class<?> getClass( JavaClass currentClass, String exceptionClassName )
- {
- String[] potentialClassNames =
- new String[]{ exceptionClassName, currentClass.getPackage().getName() + "." + exceptionClassName,
- currentClass.getPackage().getName() + "." + currentClass.getName() + "$" + exceptionClassName,
- "java.lang." + exceptionClassName };
-
- Class<?> clazz = null;
- for ( String potentialClassName : potentialClassNames )
- {
- try
- {
- clazz = getClass( potentialClassName );
- }
- catch ( MojoExecutionException e )
- {
- // nop
- }
- if ( clazz != null )
- {
- return clazz;
- }
- }
-
- return null;
- }
-
- /**
- * @param javaClass not null
- */
- private void addSinceClasses( JavaClass javaClass )
- {
- if ( sinceClasses == null )
- {
- sinceClasses = new ArrayList<>();
- }
- sinceClasses.add( javaClass.getFullyQualifiedName() );
- }
-
- private boolean sinceClassesContains( JavaClass javaClass )
- {
- return sinceClasses.contains( javaClass.getFullyQualifiedName() );
- }
-
- // ----------------------------------------------------------------------
- // Static methods
- // ----------------------------------------------------------------------
-
- /**
- * Write content into the given javaFile and using the given encoding.
- * All line separators will be unified.
- *
- * @param javaFile not null
- * @param encoding not null
- * @param content not null
- * @throws IOException if any
- */
- private static void writeFile( final File javaFile, final String encoding, final String content )
- throws IOException
- {
- String unified = StringUtils.unifyLineSeparators( content );
- FileUtils.fileWrite( javaFile, encoding, unified );
- }
-
- /**
- * @return the full clirr goal, i.e. <code>groupId:artifactId:version:goal</code>. The clirr-plugin version
- * could be load from the pom.properties in the clirr-maven-plugin dependency.
- */
- private static String getFullClirrGoal()
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( CLIRR_MAVEN_PLUGIN_GROUPID ).append( ":" ).append( CLIRR_MAVEN_PLUGIN_ARTIFACTID ).append( ":" );
-
- String clirrVersion = CLIRR_MAVEN_PLUGIN_VERSION;
-
- String resource = "META-INF/maven/" + CLIRR_MAVEN_PLUGIN_GROUPID + "/" + CLIRR_MAVEN_PLUGIN_ARTIFACTID
- + "/pom.properties";
-
- try ( InputStream resourceAsStream =
- AbstractFixJavadocMojo.class.getClassLoader().getResourceAsStream( resource ) )
- {
-
- if ( resourceAsStream != null )
- {
- Properties properties = new Properties();
- properties.load( resourceAsStream );
- if ( StringUtils.isNotEmpty( properties.getProperty( "version" ) ) )
- {
- clirrVersion = properties.getProperty( "version" );
- }
- }
- }
- catch ( IOException e )
- {
- // nop
- }
-
- sb.append( clirrVersion ).append( ":" ).append( CLIRR_MAVEN_PLUGIN_GOAL );
-
- return sb.toString();
- }
-
- /**
- * Default comment for class.
- *
- * @param javaClass not null
- * @return a default comment for class.
- */
- private static String getDefaultClassJavadocComment( final JavaClass javaClass )
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( "<p>" );
- if ( javaClass.isAbstract() )
- {
- sb.append( "Abstract " );
- }
-
- sb.append( javaClass.getName() );
-
- if ( !javaClass.isInterface() )
- {
- sb.append( " class." );
- }
- else
- {
- sb.append( " interface." );
- }
-
- sb.append( "</p>" );
-
- return sb.toString();
- }
-
- /**
- * Default comment for method with taking care of getter/setter in the javaMethod name.
- *
- * @param javaExecutable not null
- * @return a default comment for method
- */
- private static String getDefaultMethodJavadocComment( final JavaExecutable javaExecutable )
- {
- if ( javaExecutable instanceof JavaConstructor )
- {
- return "<p>Constructor for " + javaExecutable.getName() + ".</p>";
- }
-
- if ( javaExecutable.getName().length() > 3 && ( javaExecutable.getName().startsWith( "get" )
- || javaExecutable.getName().startsWith( "set" ) ) )
- {
- String field = StringUtils.lowercaseFirstLetter( javaExecutable.getName().substring( 3 ) );
-
- JavaClass clazz = javaExecutable.getDeclaringClass();
-
- if ( clazz.getFieldByName( field ) == null )
- {
- return "<p>" + javaExecutable.getName() + ".</p>";
- }
-
- StringBuilder sb = new StringBuilder();
-
- sb.append( "<p>" );
- if ( javaExecutable.getName().startsWith( "get" ) )
- {
- sb.append( "Getter " );
- }
- else if ( javaExecutable.getName().startsWith( "set" ) )
- {
- sb.append( "Setter " );
- }
- sb.append( "for the field <code>" ).append( field ).append( "</code>.</p>" );
-
- return sb.toString();
- }
-
- return "<p>" + javaExecutable.getName() + ".</p>";
- }
-
- /**
- * Try to find if a Javadoc comment has an {@link #INHERITED_TAG} for instance:
- * <pre>
- * /** {@inheritDoc} */
- * </pre>
- * or
- * <pre>
- * /**
- *  * {@inheritDoc}
- *  */
- * </pre>
- *
- * @param content not null
- * @return <code>true</code> if the content has an inherited tag, <code>false</code> otherwise.
- */
- private static boolean hasInheritedTag( final String content )
- {
- final String inheritedTagPattern =
- "^\\s*(\\/\\*\\*)?(\\s*(\\*)?)*(\\{)@inheritDoc\\s*(\\})(\\s*(\\*)?)*(\\*\\/)?$";
- return Pattern.matches( inheritedTagPattern, StringUtils.removeDuplicateWhitespace( content ) );
- }
-
- /**
- * Workaround for QDOX-146 about whitespace.
- * Ideally we want to use <code>entity.getComment()</code>
- * <br/>
- * For instance, with the following snippet:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"></font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
- * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
- * <font color="#000000">String s </font><font color="#000000">){}</font><br />
- * </code>
- * <p/>
- * <br/>
- * The return will be:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * </code>
- *
- * @param javaClassContent original class content not null
- * @param entity not null
- * @return the javadoc comment for the entity without any tags.
- * @throws IOException if any
- */
- static String getJavadocComment( final String javaClassContent, final JavaAnnotatedElement entity )
- throws IOException
- {
- if ( entity.getComment() == null )
- {
- return "";
- }
-
- String originalJavadoc = extractOriginalJavadocContent( javaClassContent, entity );
-
- StringBuilder sb = new StringBuilder();
- BufferedReader lr = new BufferedReader( new StringReader( originalJavadoc ) );
- String line;
- while ( ( line = lr.readLine() ) != null )
- {
- String l = StringUtils.removeDuplicateWhitespace( line.trim() );
- if ( l.startsWith( "* @" ) || l.startsWith( "*@" ) )
- {
- break;
- }
- sb.append( line ).append( EOL );
- }
-
- return trimRight( sb.toString() );
- }
-
- /**
- * Work around for QDOX-146 about whitespace.
- * Ideally we want to use <code>docletTag.getValue()</code>
- * <br/>
- * For instance, with the following snippet:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"></font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
- * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
- * <font color="#000000">String s </font><font color="#000000">){}</font><br />
- * </code>
- * <p/>
- * <br/>
- * The return will be:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * </code>
- *
- * @param javaClassContent original class content not null
- * @param entity not null
- * @param docletTag not null
- * @return the javadoc comment for the entity without Javadoc tags.
- * @throws IOException if any
- */
- String getJavadocComment( final String javaClassContent, final JavaAnnotatedElement entity,
- final DocletTag docletTag )
- throws IOException
- {
- if ( docletTag.getValue() == null || docletTag.getParameters().isEmpty() )
- {
- return "";
- }
-
- String originalJavadoc = extractOriginalJavadocContent( javaClassContent, entity );
-
- StringBuilder sb = new StringBuilder();
- BufferedReader lr = new BufferedReader( new StringReader( originalJavadoc ) );
- String line;
- boolean found = false;
-
- // matching first line of doclettag
- Pattern p = Pattern.compile( "(\\s*\\*\\s?@" + docletTag.getName() + ")\\s+"
- + "(\\Q" + docletTag.getValue().split( "\r\n|\r|\n" )[0] + "\\E)" );
-
- while ( ( line = lr.readLine() ) != null )
- {
- Matcher m = p.matcher( line );
- if ( m.matches() )
- {
- if ( fixTag( LINK_TAG ) )
- {
- line = replaceLinkTags( line, entity );
- }
- sb.append( line ).append( EOL );
- found = true;
- }
- else
- {
- if ( line.trim().startsWith( "* @" ) || line.trim().startsWith( "*@" ) )
- {
- found = false;
- }
- if ( found )
- {
- if ( fixTag( LINK_TAG ) )
- {
- line = replaceLinkTags( line, entity );
- }
- sb.append( line ).append( EOL );
- }
- }
- }
-
- return trimRight( sb.toString() );
- }
-
- /**
- * Extract the original Javadoc and others comments up to {@link #START_JAVADOC} form the entity. This method
- * takes care of the Javadoc indentation. All javadoc lines will be trimmed on right.
- * <br/>
- * For instance, with the following snippet:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"></font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
- * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
- * <font color="#000000">String s </font><font color="#000000">){}</font><br />
- * </code>
- * <p/>
- * <br/>
- * The return will be:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * </code>
- *
- * @param javaClassContent not null
- * @param entity not null
- * @return return the original javadoc as String for the current entity
- * @throws IOException if any
- */
- static String extractOriginalJavadoc( final String javaClassContent, final JavaAnnotatedElement entity )
- throws IOException
- {
- if ( entity.getComment() == null )
- {
- return "";
- }
-
- String[] javaClassContentLines = getLines( javaClassContent );
- List<String> list = new LinkedList<>();
- for ( int i = entity.getLineNumber() - 2; i >= 0; i-- )
- {
- String line = javaClassContentLines[i];
-
- list.add( trimRight( line ) );
- if ( line.trim().startsWith( START_JAVADOC ) )
- {
- break;
- }
- }
-
- Collections.reverse( list );
-
- return StringUtils.join( list.iterator(), EOL );
- }
-
- /**
- * Extract the Javadoc comment between {@link #START_JAVADOC} and {@link #END_JAVADOC} form the entity. This method
- * takes care of the Javadoc indentation. All javadoc lines will be trimmed on right.
- * <br/>
- * For instance, with the following snippet:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"></font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">/**</font><br />
- * <font color="#808080">3</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">4</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * <font color="#808080">5</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">*/</font><br />
- * <font color="#808080">6</font> <font color="#ffffff"> </font>
- * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
- * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
- * <font color="#000000">String s </font><font color="#000000">){}</font><br />
- * </code>
- * <p/>
- * <br/>
- * The return will be:
- * <br/>
- * <p/>
- * <code>
- * <font color="#808080">1</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
- * <font color="#808080">2</font> <font color="#ffffff"> </font>
- * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
- * <font color="#3f5fbf">s a String</font><br />
- * </code>
- *
- * @param javaClassContent not null
- * @param entity not null
- * @return return the original javadoc as String for the current entity
- * @throws IOException if any
- */
- static String extractOriginalJavadocContent( final String javaClassContent,
- final JavaAnnotatedElement entity )
- throws IOException
- {
- if ( entity.getComment() == null )
- {
- return "";
- }
-
- String originalJavadoc = extractOriginalJavadoc( javaClassContent, entity );
- int index = originalJavadoc.indexOf( START_JAVADOC );
- if ( index != -1 )
- {
- originalJavadoc = originalJavadoc.substring( index + START_JAVADOC.length() );
- }
- index = originalJavadoc.indexOf( END_JAVADOC );
- if ( index != -1 )
- {
- originalJavadoc = originalJavadoc.substring( 0, index );
- }
- if ( originalJavadoc.startsWith( "\r\n" ) )
- {
- originalJavadoc = originalJavadoc.substring( 2 );
- }
- else if ( originalJavadoc.startsWith( "\n" ) || originalJavadoc.startsWith( "\r" ) )
- {
- originalJavadoc = originalJavadoc.substring( 1 );
- }
-
- return trimRight( originalJavadoc );
- }
-
- /**
- * @param content not null
- * @return the content without last lines containing javadoc separator (ie <code> * </code>)
- * @throws IOException if any
- * @see #getJavadocComment(String, JavaAnnotatedElement, DocletTag)
- */
- private static String removeLastEmptyJavadocLines( final String content )
- throws IOException
- {
- if ( !content.contains( EOL ) )
- {
- return content;
- }
-
- String[] lines = getLines( content );
- if ( lines.length == 1 )
- {
- return content;
- }
-
- List<String> linesList = new LinkedList<>( Arrays.asList( lines ) );
-
- Collections.reverse( linesList );
-
- for ( Iterator<String> it = linesList.iterator(); it.hasNext(); )
- {
- String line = it.next();
-
- if ( line.trim().equals( "*" ) )
- {
- it.remove();
- }
- else
- {
- break;
- }
- }
-
- Collections.reverse( linesList );
-
- return StringUtils.join( linesList.iterator(), EOL );
- }
-
- /**
- * @param content not null
- * @return the javadoc comment with the given indentation
- * @throws IOException if any
- * @see #getJavadocComment(String, JavaAnnotatedElement, DocletTag)
- */
- private static String alignIndentationJavadocLines( final String content, final String indent )
- throws IOException
- {
- StringBuilder sb = new StringBuilder();
- for ( String line : getLines( content ) )
- {
- if ( sb.length() > 0 )
- {
- sb.append( EOL );
- }
- if ( !line.trim().startsWith( "*" ) )
- {
- line = "*" + line;
- }
- sb.append( indent ).append( " " ).append( trimLeft( line ) );
- }
-
- return sb.toString();
- }
-
- /**
- * Autodetect the indentation of a given line:
- * <pre>
- * autodetectIndentation( null ) = "";
- * autodetectIndentation( "a" ) = "";
- * autodetectIndentation( " a" ) = " ";
- * autodetectIndentation( "\ta" ) = "\t";
- * </pre>
- *
- * @param line not null
- * @return the indentation for the given line.
- */
- private static String autodetectIndentation( final String line )
- {
- if ( StringUtils.isEmpty( line ) )
- {
- return "";
- }
-
- return line.substring( 0, line.indexOf( trimLeft( line ) ) );
- }
-
- /**
- * @param content not null
- * @return an array of all content lines
- * @throws IOException if any
- */
- private static String[] getLines( final String content )
- throws IOException
- {
- List<String> lines = new LinkedList<>();
-
- BufferedReader reader = new BufferedReader( new StringReader( content ) );
- String line = reader.readLine();
- while ( line != null )
- {
- lines.add( line );
- line = reader.readLine();
- }
-
- return lines.toArray( new String[lines.size()] );
- }
-
- /**
- * Trim a given line on the left:
- * <pre>
- * trimLeft( null ) = "";
- * trimLeft( " " ) = "";
- * trimLeft( "a" ) = "a";
- * trimLeft( " a" ) = "a";
- * trimLeft( "\ta" ) = "a";
- * trimLeft( " a " ) = "a ";
- * </pre>
- *
- * @param text
- * @return the text trimmed on left side or empty if text is null.
- */
- private static String trimLeft( final String text )
- {
- if ( StringUtils.isEmpty( text ) || StringUtils.isEmpty( text.trim() ) )
- {
- return "";
- }
-
- String textTrimmed = text.trim();
- return text.substring( text.indexOf( textTrimmed ) );
- }
-
- /**
- * Trim a given line on the right:
- * <pre>
- * trimRight( null ) = "";
- * trimRight( " " ) = "";
- * trimRight( "a" ) = "a";
- * trimRight( "a\t" ) = "a";
- * trimRight( " a " ) = " a";
- * </pre>
- *
- * @param text
- * @return the text trimmed on tight side or empty if text is null.
- */
- private static String trimRight( final String text )
- {
- if ( StringUtils.isEmpty( text ) || StringUtils.isEmpty( text.trim() ) )
- {
- return "";
- }
-
- String textTrimmed = text.trim();
- return text.substring( 0, text.indexOf( textTrimmed ) + textTrimmed.length() );
- }
-
-
- /**
- * Wrapper class for the entity's tags.
- */
- class JavaEntityTags
- {
- private final JavaAnnotatedElement entity;
-
- private final boolean isJavaMethod;
-
- /**
- * List of tag names.
- */
- private List<String> namesTags;
-
- /**
- * Map with java parameter as key and original Javadoc lines as values.
- */
- private Map<String, String> tagParams;
-
- private Set<String> documentedParams = new HashSet<>();
-
- /**
- * Original javadoc lines.
- */
- private String tagReturn;
-
- /**
- * Map with java throw as key and original Javadoc lines as values.
- */
- private Map<String, String> tagThrows;
-
- /**
- * Original javadoc lines for unknown tags.
- */
- private List<String> unknownsTags;
-
- JavaEntityTags( JavaAnnotatedElement entity, boolean isJavaMethod )
- {
- this.entity = entity;
- this.isJavaMethod = isJavaMethod;
- this.namesTags = new LinkedList<>();
- this.tagParams = new LinkedHashMap<>();
- this.tagThrows = new LinkedHashMap<>();
- this.unknownsTags = new LinkedList<>();
- }
-
- public List<String> getNamesTags()
- {
- return namesTags;
- }
-
- public String getJavadocReturnTag()
- {
- return tagReturn;
- }
-
- public void setJavadocReturnTag( String s )
- {
- tagReturn = s;
- }
-
- public List<String> getUnknownTags()
- {
- return unknownsTags;
- }
-
- public void putJavadocParamTag( String paramName, String paramValue, String originalJavadocTag )
- {
- documentedParams.add( paramName );
- tagParams.put( paramValue, originalJavadocTag );
- }
-
- public String getJavadocParamTag( String paramValue )
- {
- String originalJavadocTag = tagParams.get( paramValue );
- if ( originalJavadocTag == null && getLog().isWarnEnabled() )
- {
- getLog().warn( getMessage( paramValue, "javaEntityTags.tagParams" ) );
- }
- return originalJavadocTag;
- }
-
- public boolean hasJavadocParamTag( String paramName )
- {
- return documentedParams.contains( paramName );
- }
-
- public void putJavadocThrowsTag( String paramName, String originalJavadocTag )
- {
- tagThrows.put( paramName, originalJavadocTag );
- }
-
- public String getJavadocThrowsTag( String paramName )
- {
- return getJavadocThrowsTag( paramName, false );
- }
-
- public String getJavadocThrowsTag( String paramName, boolean nullable )
- {
- String originalJavadocTag = tagThrows.get( paramName );
- if ( !nullable && originalJavadocTag == null && getLog().isWarnEnabled() )
- {
- getLog().warn( getMessage( paramName, "javaEntityTags.tagThrows" ) );
- }
-
- return originalJavadocTag;
- }
-
- private String getMessage( String paramName, String mapName )
- {
- StringBuilder msg = new StringBuilder();
- msg.append( "No param '" ).append( paramName ).append( "' key found in " ).append( mapName )
- .append( " for the entity: " );
- if ( isJavaMethod )
- {
- JavaMethod javaMethod = (JavaMethod) entity;
- msg.append( getJavaMethodAsString( javaMethod ) );
- }
- else
- {
- JavaClass javaClass = (JavaClass) entity;
- msg.append( javaClass.getFullyQualifiedName() );
- }
-
- return msg.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
-
- sb.append( "namesTags=" ).append( namesTags ).append( "\n" );
- sb.append( "tagParams=" ).append( tagParams ).append( "\n" );
- sb.append( "tagReturn=" ).append( tagReturn ).append( "\n" );
- sb.append( "tagThrows=" ).append( tagThrows ).append( "\n" );
- sb.append( "unknownsTags=" ).append( unknownsTags ).append( "\n" );
-
- return sb.toString();
- }
- }
-}
+/*
+ * 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.maven.plugins.javadoc;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import com.thoughtworks.qdox.JavaProjectBuilder;
+import com.thoughtworks.qdox.library.ClassLibraryBuilder;
+import com.thoughtworks.qdox.library.OrderedClassLibraryBuilder;
+import com.thoughtworks.qdox.model.DocletTag;
+import com.thoughtworks.qdox.model.JavaAnnotatedElement;
+import com.thoughtworks.qdox.model.JavaAnnotation;
+import com.thoughtworks.qdox.model.JavaClass;
+import com.thoughtworks.qdox.model.JavaConstructor;
+import com.thoughtworks.qdox.model.JavaExecutable;
+import com.thoughtworks.qdox.model.JavaField;
+import com.thoughtworks.qdox.model.JavaGenericDeclaration;
+import com.thoughtworks.qdox.model.JavaMember;
+import com.thoughtworks.qdox.model.JavaMethod;
+import com.thoughtworks.qdox.model.JavaParameter;
+import com.thoughtworks.qdox.model.JavaType;
+import com.thoughtworks.qdox.model.JavaTypeVariable;
+import com.thoughtworks.qdox.parser.ParseException;
+import com.thoughtworks.qdox.type.TypeResolver;
+import org.apache.commons.lang3.ClassUtils;
+import org.apache.commons.text.StringEscapeUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugins.annotations.Component;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.invoker.MavenInvocationException;
+import org.codehaus.plexus.components.interactivity.InputHandler;
+import org.codehaus.plexus.languages.java.version.JavaVersion;
+import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.StringUtils;
+
+/**
+ * Abstract class to fix Javadoc documentation and tags in source files.
+ * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/javadoc/doc-comment-spec.html#where-tags-can-be-used">Where Tags
+ * Can Be Used</a>.
+ * @author <a href="mailto:vincent.siveton@gmail.com">Vincent Siveton</a>
+ * @since 2.6
+ */
+public abstract class AbstractFixJavadocMojo extends AbstractMojo {
+ /**
+ * The vm line separator
+ */
+ private static final String EOL = System.getProperty("line.separator");
+
+ /**
+ * Tag name for @author *
+ */
+ private static final String AUTHOR_TAG = "author";
+
+ /**
+ * Tag name for @version *
+ */
+ private static final String VERSION_TAG = "version";
+
+ /**
+ * Tag name for @since *
+ */
+ private static final String SINCE_TAG = "since";
+
+ /**
+ * Tag name for @param *
+ */
+ private static final String PARAM_TAG = "param";
+
+ /**
+ * Tag name for @return *
+ */
+ private static final String RETURN_TAG = "return";
+
+ /**
+ * Tag name for @throws *
+ */
+ private static final String THROWS_TAG = "throws";
+
+ /**
+ * Tag name for @link *
+ */
+ private static final String LINK_TAG = "link";
+
+ /**
+ * Tag name for {@inheritDoc} *
+ */
+ private static final String INHERITED_TAG = "{@inheritDoc}";
+
+ /**
+ * Start Javadoc String i.e. <code>/**</code> *
+ */
+ private static final String START_JAVADOC = "/**";
+
+ /**
+ * End Javadoc String i.e. <code>*/</code> *
+ */
+ private static final String END_JAVADOC = "*/";
+
+ /**
+ * Javadoc Separator i.e. <code> * </code> *
+ */
+ private static final String SEPARATOR_JAVADOC = " * ";
+
+ /**
+ * Inherited Javadoc i.e. <code>/** {@inheritDoc} */</code> *
+ */
+ private static final String INHERITED_JAVADOC = START_JAVADOC + " " + INHERITED_TAG + " " + END_JAVADOC;
+
+ /**
+ * <code>all</code> parameter used by {@link #fixTags} *
+ */
+ private static final String FIX_TAGS_ALL = "all";
+
+ /**
+ * <code>public</code> parameter used by {@link #level} *
+ */
+ private static final String LEVEL_PUBLIC = "public";
+
+ /**
+ * <code>protected</code> parameter used by {@link #level} *
+ */
+ private static final String LEVEL_PROTECTED = "protected";
+
+ /**
+ * <code>package</code> parameter used by {@link #level} *
+ */
+ private static final String LEVEL_PACKAGE = "package";
+
+ /**
+ * <code>private</code> parameter used by {@link #level} *
+ */
+ private static final String LEVEL_PRIVATE = "private";
+
+ /**
+ * The Clirr Maven plugin groupId <code>org.codehaus.mojo</code> *
+ */
+ private static final String CLIRR_MAVEN_PLUGIN_GROUPID = "org.codehaus.mojo";
+
+ /**
+ * The Clirr Maven plugin artifactId <code>clirr-maven-plugin</code> *
+ */
+ private static final String CLIRR_MAVEN_PLUGIN_ARTIFACTID = "clirr-maven-plugin";
+
+ /**
+ * The latest Clirr Maven plugin version <code>2.2.2</code> *
+ */
+ private static final String CLIRR_MAVEN_PLUGIN_VERSION = "2.2.2";
+
+ /**
+ * The Clirr Maven plugin goal <code>check</code> *
+ */
+ private static final String CLIRR_MAVEN_PLUGIN_GOAL = "check";
+
+ /**
+ * Java Files Pattern.
+ */
+ public static final String JAVA_FILES = "**\\/*.java";
+
+ /**
+ * Default version value.
+ */
+ public static final String DEFAULT_VERSION_VALUE = "\u0024Id: \u0024Id";
+
+ // ----------------------------------------------------------------------
+ // Mojo components
+ // ----------------------------------------------------------------------
+
+ /**
+ * Input handler, needed for command line handling.
+ */
+ @Component
+ private InputHandler inputHandler;
+
+ // ----------------------------------------------------------------------
+ // Mojo parameters
+ // ----------------------------------------------------------------------
+
+ /**
+ * Version to compare the current code against using the
+ * <a href="http://mojo.codehaus.org/clirr-maven-plugin/">Clirr Maven Plugin</a>.
+ * <br/>
+ * See <a href="#defaultSince">defaultSince</a>.
+ */
+ @Parameter(property = "comparisonVersion", defaultValue = "(,${project.version})")
+ private String comparisonVersion;
+
+ /**
+ * Default value for the Javadoc tag <code>@author</code>.
+ * <br/>
+ * If not specified, the <code>user.name</code> defined in the System properties will be used.
+ */
+ @Parameter(property = "defaultAuthor")
+ private String defaultAuthor;
+
+ /**
+ * Default value for the Javadoc tag <code>@since</code>.
+ */
+ @Parameter(property = "defaultSince", defaultValue = "${project.version}")
+ private String defaultSince;
+
+ /**
+ * Default value for the Javadoc tag <code>@version</code>.
+ * <br/>
+ * By default, it is <code>$Id:$</code>, corresponding to a
+ * <a href="http://svnbook.red-bean.com/en/1.1/ch07s02.html#svn-ch-7-sect-2.3.4">SVN keyword</a>.
+ * Refer to your SCM to use an other SCM keyword.
+ */
+ @Parameter(property = "defaultVersion", defaultValue = DEFAULT_VERSION_VALUE)
+ private String defaultVersion = "\u0024Id: \u0024"; // can't use default-value="\u0024Id: \u0024"
+
+ /**
+ * The file encoding to use when reading the source files. If the property
+ * <code>project.build.sourceEncoding</code> is not set, the platform default encoding is used.
+ */
+ @Parameter(property = "encoding", defaultValue = "${project.build.sourceEncoding}")
+ private String encoding;
+
+ /**
+ * Comma separated excludes Java files, i.e. <code>**/*Test.java</code>.
+ */
+ @Parameter(property = "excludes")
+ private String excludes;
+
+ /**
+ * Comma separated tags to fix in classes, interfaces or methods Javadoc comments.
+ * Possible values are:
+ * <ul>
+ * <li>all (fix all Javadoc tags)</li>
+ * <li>author (fix only @author tag)</li>
+ * <li>version (fix only @version tag)</li>
+ * <li>since (fix only @since tag)</li>
+ * <li>param (fix only @param tag)</li>
+ * <li>return (fix only @return tag)</li>
+ * <li>throws (fix only @throws tag)</li>
+ * <li>link (fix only @link tag)</li>
+ * </ul>
+ */
+ @Parameter(property = "fixTags", defaultValue = "all")
+ private String fixTags;
+
+ /**
+ * Flag to fix the classes or interfaces Javadoc comments according the <code>level</code>.
+ */
+ @Parameter(property = "fixClassComment", defaultValue = "true")
+ private boolean fixClassComment;
+
+ /**
+ * Flag to fix the fields Javadoc comments according the <code>level</code>.
+ */
+ @Parameter(property = "fixFieldComment", defaultValue = "true")
+ private boolean fixFieldComment;
+
+ /**
+ * Flag to fix the methods Javadoc comments according the <code>level</code>.
+ */
+ @Parameter(property = "fixMethodComment", defaultValue = "true")
+ private boolean fixMethodComment;
+
+ /**
+ * <p>Flag to remove throws tags from unknown classes.</p>
+ * <p><strong>NOTE:</strong>Since 3.1.0 the default value has been changed to {@code true},
+ * due to JavaDoc 8 strictness.
+ */
+ @Parameter(property = "removeUnknownThrows", defaultValue = "true")
+ private boolean removeUnknownThrows;
+
+ /**
+ * Forcing the goal execution i.e. skip warranty messages (not recommended).
+ */
+ @Parameter(property = "force")
+ private boolean force;
+
+ /**
+ * Flag to ignore or not Clirr.
+ */
+ @Parameter(property = "ignoreClirr", defaultValue = "false")
+ protected boolean ignoreClirr;
+
+ /**
+ * Comma separated includes Java files, i.e. <code>**/*Test.java</code>.
+ * <p/>
+ * <strong>Note:</strong> default value is {@code **\/*.java}.
+ */
+ @Parameter(property = "includes", defaultValue = JAVA_FILES)
+ private String includes;
+
+ /**
+ * Specifies the access level for classes and members to show in the Javadocs.
+ * Possible values are:
+ * <ul>
+ * <li>public (shows only public classes and members)</li>
+ * <li>protected (shows only public and protected classes and members)</li>
+ * <li>package (shows all classes and members not marked private)</li>
+ * <li>private (shows all classes and members)</li>
+ * </ul>
+ * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">private, protected, public, package options for Javadoc</a>
+ */
+ @Parameter(property = "level", defaultValue = "protected")
+ private String level;
+
+ /**
+ * The local repository where the artifacts are located, used by the tests.
+ */
+ @Parameter(property = "localRepository")
+ private ArtifactRepository localRepository;
+
+ /**
+ * Output directory where Java classes will be rewritten.
+ */
+ @Parameter(property = "outputDirectory", defaultValue = "${project.build.sourceDirectory}")
+ private File outputDirectory;
+
+ /**
+ * The Maven Project Object.
+ */
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
+ private MavenProject project;
+
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
+ private MavenSession session;
+
+ /**
+ * The current user system settings for use in Maven.
+ */
+ @Parameter(defaultValue = "${settings}", readonly = true, required = true)
+ private Settings settings;
+
+ // ----------------------------------------------------------------------
+ // Internal fields
+ // ----------------------------------------------------------------------
+
+ /**
+ * The current project class loader.
+ */
+ private ClassLoader projectClassLoader;
+
+ /**
+ * Split {@link #fixTags} by comma.
+ *
+ * @see #init()
+ */
+ private String[] fixTagsSplitted;
+
+ /**
+ * New classes found by Clirr.
+ */
+ private List<String> clirrNewClasses;
+
+ /**
+ * New Methods in a Class (the key) found by Clirr.
+ */
+ private Map<String, List<String>> clirrNewMethods;
+
+ /**
+ * List of classes where <code>*since</code> is added. Will be used to add or not this tag in the methods.
+ */
+ private List<String> sinceClasses;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ if (!fixClassComment && !fixFieldComment && !fixMethodComment) {
+ getLog().info("Specified to NOT fix classes, fields and methods. Nothing to do.");
+ return;
+ }
+
+ // verify goal params
+ init();
+
+ if (fixTagsSplitted.length == 0) {
+ getLog().info("No fix tag specified. Nothing to do.");
+ return;
+ }
+
+ // add warranty msg
+ if (!preCheck()) {
+ return;
+ }
+
+ // run clirr
+ try {
+ executeClirr();
+ } catch (MavenInvocationException e) {
+ if (getLog().isDebugEnabled()) {
+ getLog().error("MavenInvocationException: " + e.getMessage(), e);
+ } else {
+ getLog().error("MavenInvocationException: " + e.getMessage());
+ }
+ getLog().info("Clirr is ignored.");
+ }
+
+ // run qdox and process
+ try {
+ Collection<JavaClass> javaClasses = getQdoxClasses();
+
+ if (javaClasses != null) {
+ for (JavaClass javaClass : javaClasses) {
+ processFix(javaClass);
+ }
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("IOException: " + e.getMessage(), e);
+ }
+ }
+
+ // ----------------------------------------------------------------------
+ // protected methods
+ // ----------------------------------------------------------------------
+
+ protected final MavenProject getProject() {
+ return project;
+ }
+
+ /**
+ * @param p not null maven project.
+ * @return the artifact type.
+ */
+ protected String getArtifactType(MavenProject p) {
+ return p.getArtifact().getType();
+ }
+
+ /**
+ * @param p not null maven project.
+ * @return the list of source paths for the given project.
+ */
+ protected List<String> getProjectSourceRoots(MavenProject p) {
+ return (p.getCompileSourceRoots() == null
+ ? Collections.<String>emptyList()
+ : new LinkedList<>(p.getCompileSourceRoots()));
+ }
+
+ /**
+ * @param p not null
+ * @return the compile classpath elements
+ * @throws DependencyResolutionRequiredException
+ * if any
+ */
+ protected List<String> getCompileClasspathElements(MavenProject p) throws DependencyResolutionRequiredException {
+ return (p.getCompileClasspathElements() == null
+ ? Collections.<String>emptyList()
+ : new LinkedList<>(p.getCompileClasspathElements()));
+ }
+
+ /**
+ * @param javaExecutable not null
+ * @return the fully qualify name of javaMethod with signature
+ */
+ protected static String getJavaMethodAsString(JavaExecutable javaExecutable) {
+ return javaExecutable.getDeclaringClass().getFullyQualifiedName() + "#" + javaExecutable.getCallSignature();
+ }
+
+ // ----------------------------------------------------------------------
+ // private methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Init goal parameters.
+ */
+ private void init() {
+ // defaultAuthor
+ if (StringUtils.isEmpty(defaultAuthor)) {
+ defaultAuthor = System.getProperty("user.name");
+ }
+
+ // defaultSince
+ int i = defaultSince.indexOf("-" + Artifact.SNAPSHOT_VERSION);
+ if (i != -1) {
+ defaultSince = defaultSince.substring(0, i);
+ }
+
+ // fixTags
+ if (!FIX_TAGS_ALL.equalsIgnoreCase(fixTags.trim())) {
+ String[] split = StringUtils.split(fixTags, ",");
+ List<String> filtered = new LinkedList<>();
+ for (String aSplit : split) {
+ String s = aSplit.trim();
+ if (JavadocUtil.equalsIgnoreCase(
+ s,
+ FIX_TAGS_ALL,
+ AUTHOR_TAG,
+ VERSION_TAG,
+ SINCE_TAG,
+ PARAM_TAG,
+ THROWS_TAG,
+ LINK_TAG,
+ RETURN_TAG)) {
+ filtered.add(s);
+ } else {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("Unrecognized '" + s + "' for fixTags parameter. Ignored it!");
+ }
+ }
+ }
+ fixTags = StringUtils.join(filtered.iterator(), ",");
+ }
+ fixTagsSplitted = StringUtils.split(fixTags, ",");
+
+ // encoding
+ if (StringUtils.isEmpty(encoding)) {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("File encoding has not been set, using platform encoding " + ReaderFactory.FILE_ENCODING
+ + ", i.e. build is platform dependent!");
+ }
+ encoding = ReaderFactory.FILE_ENCODING;
+ }
+
+ // level
+ level = level.trim();
+ if (!JavadocUtil.equalsIgnoreCase(level, LEVEL_PUBLIC, LEVEL_PROTECTED, LEVEL_PACKAGE, LEVEL_PRIVATE)) {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("Unrecognized '" + level + "' for level parameter, using 'protected' level.");
+ }
+ level = "protected";
+ }
+ }
+
+ /**
+ * @return <code>true</code> if the user wants to proceed, <code>false</code> otherwise.
+ * @throws MojoExecutionException if any
+ */
+ private boolean preCheck() throws MojoExecutionException {
+ if (force) {
+ return true;
+ }
+
+ if (outputDirectory != null
+ && !outputDirectory
+ .getAbsolutePath()
+ .equals(getProjectSourceDirectory().getAbsolutePath())) {
+ return true;
+ }
+
+ if (!settings.isInteractiveMode()) {
+ getLog().error("Maven is not attempt to interact with the user for input. "
+ + "Verify the <interactiveMode/> configuration in your settings.");
+ return false;
+ }
+
+ getLog().warn("");
+ getLog().warn(" WARRANTY DISCLAIMER");
+ getLog().warn("");
+ getLog().warn("All warranties with regard to this Maven goal are disclaimed!");
+ getLog().warn("The changes will be done directly in the source code.");
+ getLog().warn("The Maven Team strongly recommends the use of a SCM software BEFORE executing this goal.");
+ getLog().warn("");
+
+ while (true) {
+ getLog().info("Are you sure to proceed? [Y]es [N]o");
+
+ try {
+ String userExpression = inputHandler.readLine();
+ if (userExpression == null || JavadocUtil.equalsIgnoreCase(userExpression, "Y", "Yes")) {
+ getLog().info("OK, let's proceed...");
+ break;
+ }
+ if (JavadocUtil.equalsIgnoreCase(userExpression, "N", "No")) {
+ getLog().info("No changes in your sources occur.");
+ return false;
+ }
+ } catch (IOException e) {
+ throw new MojoExecutionException("Unable to read from standard input.", e);
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * @return the source dir as File for the given project
+ */
+ private File getProjectSourceDirectory() {
+ return new File(project.getBuild().getSourceDirectory());
+ }
+
+ /**
+ * Invoke Maven to run clirr-maven-plugin to find API differences.
+ *
+ * @throws MavenInvocationException if any
+ */
+ private void executeClirr() throws MavenInvocationException {
+ if (ignoreClirr) {
+ getLog().info("Clirr is ignored.");
+ return;
+ }
+
+ String clirrGoal = getFullClirrGoal();
+
+ // http://mojo.codehaus.org/clirr-maven-plugin/check-mojo.html
+ File clirrTextOutputFile = FileUtils.createTempFile(
+ "clirr", ".txt", new File(project.getBuild().getDirectory()));
+ Properties properties = new Properties();
+ properties.put("textOutputFile", clirrTextOutputFile.getAbsolutePath());
+ properties.put("comparisonVersion", comparisonVersion);
+ properties.put("failOnError", "false");
+ if (JavaVersion.JAVA_SPECIFICATION_VERSION.isBefore("8")) {
+ // ensure that Java7 picks up TLSv1.2 when connecting with Central
+ properties.put("https.protocols", "TLSv1.2");
+ }
+
+ File invokerDir = new File(project.getBuild().getDirectory(), "invoker");
+ invokerDir.mkdirs();
+ File invokerLogFile = FileUtils.createTempFile("clirr-maven-plugin", ".txt", invokerDir);
+
+ JavadocUtil.invokeMaven(
+ getLog(),
+ new File(localRepository.getBasedir()),
+ project.getFile(),
+ Collections.singletonList(clirrGoal),
+ properties,
+ invokerLogFile,
+ session.getRequest().getGlobalSettingsFile());
+
+ try {
+ if (invokerLogFile.exists()) {
+ String invokerLogContent = StringUtils.unifyLineSeparators(FileUtils.fileRead(invokerLogFile, "UTF-8"));
+ // see org.codehaus.mojo.clirr.AbstractClirrMojo#getComparisonArtifact()
+ final String artifactNotFoundMsg = "Unable to find a previous version of the project in the repository";
+ if (invokerLogContent.contains(artifactNotFoundMsg)) {
+ getLog().warn("No previous artifact has been deployed, Clirr is ignored.");
+ return;
+ }
+ }
+ } catch (IOException e) {
+ getLog().debug("IOException: " + e.getMessage());
+ }
+
+ try {
+ parseClirrTextOutputFile(clirrTextOutputFile);
+ } catch (IOException e) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("IOException: " + e.getMessage(), e);
+ }
+ getLog().info("IOException when parsing Clirr output '" + clirrTextOutputFile.getAbsolutePath()
+ + "', Clirr is ignored.");
+ }
+ }
+
+ /**
+ * @param clirrTextOutputFile not null
+ * @throws IOException if any
+ */
+ private void parseClirrTextOutputFile(File clirrTextOutputFile) throws IOException {
+ if (!clirrTextOutputFile.exists()) {
+ if (getLog().isInfoEnabled()) {
+ getLog().info("No Clirr output file '" + clirrTextOutputFile.getAbsolutePath()
+ + "' exists, Clirr is ignored.");
+ }
+ return;
+ }
+
+ if (getLog().isInfoEnabled()) {
+ getLog().info("Clirr output file was created: " + clirrTextOutputFile.getAbsolutePath());
+ }
+
+ clirrNewClasses = new LinkedList<>();
+ clirrNewMethods = new LinkedHashMap<>();
+
+ try (BufferedReader reader = new BufferedReader(ReaderFactory.newReader(clirrTextOutputFile, "UTF-8"))) {
+
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ String[] split = StringUtils.split(line, ":");
+ if (split.length != 4) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Unable to parse the clirr line: " + line);
+ }
+ continue;
+ }
+
+ int code;
+ try {
+ code = Integer.parseInt(split[1].trim());
+ } catch (NumberFormatException e) {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Unable to parse the clirr line: " + line);
+ }
+ continue;
+ }
+
+ // http://clirr.sourceforge.net/clirr-core/exegesis.html
+ // 7011 - Method Added
+ // 7012 - Method Added to Interface
+ // 8000 - Class Added
+
+ // CHECKSTYLE_OFF: MagicNumber
+ switch (code) {
+ case 7011:
+ methodAdded(split);
+ break;
+ case 7012:
+ methodAdded(split);
+ break;
+ case 8000:
+ clirrNewClasses.add(split[2].trim());
+ break;
+ default:
+ break;
+ }
+ // CHECKSTYLE_ON: MagicNumber
+ }
+ }
+ if (clirrNewClasses.isEmpty() && clirrNewMethods.isEmpty()) {
+ getLog().info("Clirr NOT found API differences.");
+ } else {
+ getLog().info("Clirr found API differences, i.e. new classes/interfaces or methods.");
+ }
+ }
+
+ private void methodAdded(String[] split) {
+ List<String> list = clirrNewMethods.get(split[2].trim());
+ if (list == null) {
+ list = new ArrayList<>();
+ }
+ String[] splits2 = StringUtils.split(split[3].trim(), "'");
+ if (splits2.length != 3) {
+ return;
+ }
+ list.add(splits2[1].trim());
+ clirrNewMethods.put(split[2].trim(), list);
+ }
+
+ /**
+ * @param tag not null
+ * @return <code>true</code> if <code>tag</code> is defined in {@link #fixTags}.
+ */
+ private boolean fixTag(String tag) {
+ if (fixTagsSplitted.length == 1 && fixTagsSplitted[0].equals(FIX_TAGS_ALL)) {
+ return true;
+ }
+
+ for (String aFixTagsSplitted : fixTagsSplitted) {
+ if (aFixTagsSplitted.trim().equals(tag)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Calling Qdox to find {@link JavaClass} objects from the Maven project sources.
+ * Ignore java class if Qdox has parsing errors.
+ *
+ * @return an array of {@link JavaClass} found by QDox
+ * @throws IOException if any
+ * @throws MojoExecutionException if any
+ */
+ private Collection<JavaClass> getQdoxClasses() throws IOException, MojoExecutionException {
+ if ("pom".equalsIgnoreCase(project.getPackaging())) {
+ getLog().warn("This project has 'pom' packaging, no Java sources is available.");
+ return null;
+ }
+
+ List<File> javaFiles = new LinkedList<>();
+ for (String sourceRoot : getProjectSourceRoots(project)) {
+ File f = new File(sourceRoot);
+ if (f.isDirectory()) {
+ javaFiles.addAll(FileUtils.getFiles(f, includes, excludes, true));
+ } else {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn(f + " doesn't exist. Ignored it.");
+ }
+ }
+ }
+
+ ClassLibraryBuilder classLibraryBuilder = new OrderedClassLibraryBuilder();
+ classLibraryBuilder.appendClassLoader(getProjectClassLoader());
+
+ JavaProjectBuilder builder = new JavaProjectBuilder(classLibraryBuilder);
+ builder.setEncoding(encoding);
+ for (File f : javaFiles) {
+ if (!f.getAbsolutePath().toLowerCase(Locale.ENGLISH).endsWith(".java") && getLog().isWarnEnabled()) {
+ getLog().warn("'" + f + "' is not a Java file. Ignored it.");
+ continue;
+ }
+
+ try {
+ builder.addSource(f);
+ } catch (ParseException e) {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("QDOX ParseException: " + e.getMessage() + ". Can't fix it.");
+ }
+ }
+ }
+
+ return builder.getClasses();
+ }
+
+ /**
+ * @return the classLoader for the given project using lazy instantiation.
+ * @throws MojoExecutionException if any
+ */
+ private ClassLoader getProjectClassLoader() throws MojoExecutionException {
+ if (projectClassLoader == null) {
+ List<String> classPath;
+ try {
+ classPath = getCompileClasspathElements(project);
+ } catch (DependencyResolutionRequiredException e) {
+ throw new MojoExecutionException("DependencyResolutionRequiredException: " + e.getMessage(), e);
+ }
+
+ List<URL> urls = new ArrayList<>(classPath.size());
+ for (String filename : classPath) {
+ try {
+ urls.add(new File(filename).toURI().toURL());
+ } catch (MalformedURLException e) {
+ throw new MojoExecutionException("MalformedURLException: " + e.getMessage(), e);
+ }
+ }
+
+ projectClassLoader = new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
+ }
+
+ return projectClassLoader;
+ }
+
+ /**
+ * Process the given {@link JavaClass}, ie add missing javadoc tags depending user parameters.
+ *
+ * @param javaClass not null
+ * @throws IOException if any
+ * @throws MojoExecutionException if any
+ */
+ private void processFix(JavaClass javaClass) throws IOException, MojoExecutionException {
+ // Skipping inner classes
+ if (javaClass.isInner()) {
+ return;
+ }
+
+ File javaFile;
+ try {
+ javaFile = Paths.get(javaClass.getSource().getURL().toURI()).toFile();
+ } catch (URISyntaxException e) {
+ throw new MojoExecutionException(e.getMessage());
+ }
+
+ // the original java content in memory
+ final String originalContent = StringUtils.unifyLineSeparators(FileUtils.fileRead(javaFile, encoding));
+
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Analyzing " + javaClass.getFullyQualifiedName());
+ }
+
+ final StringWriter stringWriter = new StringWriter();
+ boolean changeDetected = false;
+ try (BufferedReader reader = new BufferedReader(new StringReader(originalContent))) {
+
+ int lineNumber = 0;
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ lineNumber++;
+ final String indent = autodetectIndentation(line);
+
+ // fixing classes
+ if (javaClass.getComment() == null
+ && javaClass.getAnnotations() != null
+ && !javaClass.getAnnotations().isEmpty()) {
+ if (lineNumber == javaClass.getAnnotations().get(0).getLineNumber()) {
+ changeDetected |= fixClassComment(stringWriter, originalContent, javaClass, indent);
+
+ takeCareSingleComment(stringWriter, originalContent, javaClass);
+ }
+ } else if (lineNumber == javaClass.getLineNumber()) {
+ changeDetected |= fixClassComment(stringWriter, originalContent, javaClass, indent);
+
+ takeCareSingleComment(stringWriter, originalContent, javaClass);
+ }
+
+ // fixing fields
+ if (javaClass.getFields() != null) {
+ for (JavaField field : javaClass.getFields()) {
+ if (lineNumber == field.getLineNumber()) {
+ changeDetected |= fixFieldComment(stringWriter, javaClass, field, indent);
+ }
+ }
+ }
+
+ // fixing methods
+ if (javaClass.getConstructors() != null) {
+ for (JavaConstructor method : javaClass.getConstructors()) {
+ if (lineNumber == method.getLineNumber()) {
+ final boolean commentUpdated =
+ fixMethodComment(stringWriter, originalContent, method, indent);
+ if (commentUpdated) {
+ takeCareSingleComment(stringWriter, originalContent, method);
+ }
+ changeDetected |= commentUpdated;
+ }
+ }
+ }
+
+ // fixing methods
+ for (JavaMethod method : javaClass.getMethods()) {
+ int methodLineNumber;
+ if (method.getComment() == null && !method.getAnnotations().isEmpty()) {
+ methodLineNumber = method.getAnnotations().get(0).getLineNumber();
+ } else {
+ methodLineNumber = method.getLineNumber();
+ }
+
+ if (lineNumber == methodLineNumber) {
+ final boolean commentUpdated = fixMethodComment(stringWriter, originalContent, method, indent);
+ if (commentUpdated) {
+ takeCareSingleComment(stringWriter, originalContent, method);
+ }
+ changeDetected |= commentUpdated;
+ }
+ }
+
+ stringWriter.write(line);
+ stringWriter.write(EOL);
+ }
+ }
+
+ if (changeDetected) {
+ if (getLog().isInfoEnabled()) {
+ getLog().info("Saving changes to " + javaClass.getFullyQualifiedName());
+ }
+
+ if (outputDirectory != null
+ && !outputDirectory
+ .getAbsolutePath()
+ .equals(getProjectSourceDirectory().getAbsolutePath())) {
+ String path = StringUtils.replace(
+ javaFile.getAbsolutePath().replaceAll("\\\\", "/"),
+ project.getBuild().getSourceDirectory().replaceAll("\\\\", "/"),
+ "");
+ javaFile = new File(outputDirectory, path);
+ javaFile.getParentFile().mkdirs();
+ }
+ writeFile(javaFile, encoding, stringWriter.toString());
+ } else {
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("No changes made to " + javaClass.getFullyQualifiedName());
+ }
+ }
+ }
+
+ /**
+ * Take care of block or single comments between Javadoc comment and entity declaration ie:
+ * <br/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* {Javadoc Comment}</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f7f5f">/*</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f7f5f">* {Block Comment}</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#3f7f5f">*/</font><br />
+ * <font color="#808080">7</font> <font color="#ffffff"> </font>
+ * <font color="#3f7f5f">// {Single comment}</font><br />
+ * <font color="#808080">8</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
+ * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
+ * <font color="#000000">String s </font><font color="#000000">){}</font>
+ * </code>
+ *
+ * @param stringWriter not null
+ * @param originalContent not null
+ * @param entity not null
+ * @throws IOException if any
+ * @see #extractOriginalJavadoc
+ */
+ private void takeCareSingleComment(
+ final StringWriter stringWriter, final String originalContent, final JavaAnnotatedElement entity)
+ throws IOException {
+ if (entity.getComment() == null) {
+ return;
+ }
+
+ String javadocComment = trimRight(extractOriginalJavadoc(originalContent, entity));
+ String extraComment = javadocComment.substring(javadocComment.indexOf(END_JAVADOC) + END_JAVADOC.length());
+ if (StringUtils.isNotEmpty(extraComment)) {
+ if (extraComment.contains(EOL)) {
+ stringWriter.write(extraComment.substring(extraComment.indexOf(EOL) + EOL.length()));
+ } else {
+ stringWriter.write(extraComment);
+ }
+ stringWriter.write(EOL);
+ }
+ }
+
+ /**
+ * Add/update Javadoc class comment.
+ *
+ * @param stringWriter
+ * @param originalContent
+ * @param javaClass
+ * @param indent
+ * @return {@code true} if the comment is updated, otherwise {@code false}
+ * @throws MojoExecutionException
+ * @throws IOException
+ */
+ private boolean fixClassComment(
+ final StringWriter stringWriter,
+ final String originalContent,
+ final JavaClass javaClass,
+ final String indent)
+ throws MojoExecutionException, IOException {
+ if (!fixClassComment) {
+ return false;
+ }
+
+ if (!isInLevel(javaClass.getModifiers())) {
+ return false;
+ }
+
+ // add
+ if (javaClass.getComment() == null) {
+ addDefaultClassComment(stringWriter, javaClass, indent);
+ return true;
+ }
+
+ // update
+ return updateEntityComment(stringWriter, originalContent, javaClass, indent);
+ }
+
+ /**
+ * @param modifiers list of modifiers (public, private, protected, package)
+ * @return <code>true</code> if modifier is align with <code>level</code>.
+ */
+ private boolean isInLevel(List<String> modifiers) {
+ if (LEVEL_PUBLIC.equalsIgnoreCase(level.trim())) {
+ return modifiers.contains(LEVEL_PUBLIC);
+ }
+
+ if (LEVEL_PROTECTED.equalsIgnoreCase(level.trim())) {
+ return (modifiers.contains(LEVEL_PUBLIC) || modifiers.contains(LEVEL_PROTECTED));
+ }
+
+ if (LEVEL_PACKAGE.equalsIgnoreCase(level.trim())) {
+ return !modifiers.contains(LEVEL_PRIVATE);
+ }
+
+ // should be private (shows all classes and members)
+ return true;
+ }
+
+ /**
+ * Add a default Javadoc for the given class, i.e.:
+ * <br/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* {Comment based on the class name}</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@author </font>
+ * <font color="#3f5fbf">X {added if addMissingAuthor}</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@version </font>
+ * <font color="#3f5fbf">X {added if addMissingVersion}</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@since </font>
+ * <font color="#3f5fbf">X {added if addMissingSince and new classes
+ * from previous version}</font><br />
+ * <font color="#808080">7</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">8</font> <font color="#7f0055"><b>public class </b></font>
+ * <font color="#000000">DummyClass </font><font color="#000000">{}</font></code>
+ * </code>
+ *
+ * @param stringWriter not null
+ * @param javaClass not null
+ * @param indent not null
+ * @see #getDefaultClassJavadocComment(JavaClass)
+ * @see #appendDefaultAuthorTag(StringBuilder, String)
+ * @see #appendDefaultSinceTag(StringBuilder, String)
+ * @see #appendDefaultVersionTag(StringBuilder, String)
+ */
+ private void addDefaultClassComment(
+ final StringWriter stringWriter, final JavaClass javaClass, final String indent) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(indent).append(START_JAVADOC);
+ sb.append(EOL);
+ sb.append(indent).append(SEPARATOR_JAVADOC);
+ sb.append(getDefaultClassJavadocComment(javaClass));
+ sb.append(EOL);
+
+ appendSeparator(sb, indent);
+
+ appendDefaultAuthorTag(sb, indent);
+
+ appendDefaultVersionTag(sb, indent);
+
+ if (fixTag(SINCE_TAG)) {
+ if (!ignoreClirr) {
+ if (isNewClassFromLastVersion(javaClass)) {
+ appendDefaultSinceTag(sb, indent);
+ }
+ } else {
+ appendDefaultSinceTag(sb, indent);
+ addSinceClasses(javaClass);
+ }
+ }
+
+ sb.append(indent).append(" ").append(END_JAVADOC);
+ sb.append(EOL);
+
+ stringWriter.write(sb.toString());
+ }
+
+ /**
+ * Add Javadoc field comment, only for static fields or interface fields.
+ *
+ * @param stringWriter not null
+ * @param javaClass not null
+ * @param field not null
+ * @param indent not null
+ * @return {@code true} if comment was updated, otherwise {@code false}
+ * @throws IOException if any
+ */
+ private boolean fixFieldComment(
+ final StringWriter stringWriter, final JavaClass javaClass, final JavaField field, final String indent)
+ throws IOException {
+ if (!fixFieldComment) {
+ return false;
+ }
+
+ if (!javaClass.isInterface() && (!isInLevel(field.getModifiers()) || !field.isStatic())) {
+ return false;
+ }
+
+ // add
+ if (field.getComment() == null) {
+ addDefaultFieldComment(stringWriter, field, indent);
+ return true;
+ }
+
+ // no update
+ return false;
+ }
+
+ /**
+ * Add a default Javadoc for the given field, i.e.:
+ * <br/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/** Constant </font><font color="#7f7f9f"><code></font>
+ * <font color="#3f5fbf">MY_STRING_CONSTANT="value"</font>
+ * <font color="#7f7f9f"></code> </font><font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public static final </b></font>
+ * <font color="#000000">String MY_STRING_CONSTANT = </font>
+ * <font color="#2a00ff">"value"</font><font color="#000000">;</font>
+ * </code>
+ *
+ * @param stringWriter not null
+ * @param field not null
+ * @param indent not null
+ * @throws IOException if any
+ */
+ private void addDefaultFieldComment(final StringWriter stringWriter, final JavaField field, final String indent)
+ throws IOException {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(indent).append(START_JAVADOC).append(" ");
+ sb.append("Constant <code>").append(field.getName());
+
+ if (StringUtils.isNotEmpty(field.getInitializationExpression())) {
+ String qualifiedName = field.getType().getFullyQualifiedName();
+
+ if (qualifiedName.equals(Byte.TYPE.toString())
+ || qualifiedName.equals(Short.TYPE.toString())
+ || qualifiedName.equals(Integer.TYPE.toString())
+ || qualifiedName.equals(Long.TYPE.toString())
+ || qualifiedName.equals(Float.TYPE.toString())
+ || qualifiedName.equals(Double.TYPE.toString())
+ || qualifiedName.equals(Boolean.TYPE.toString())
+ || qualifiedName.equals(Character.TYPE.toString())) {
+ sb.append("=");
+ sb.append(StringEscapeUtils.escapeHtml4(
+ field.getInitializationExpression().trim()));
+ }
+
+ if (qualifiedName.equals(String.class.getName())) {
+ StringBuilder value = new StringBuilder();
+ String[] lines = getLines(field.getInitializationExpression());
+ for (String line : lines) {
+ StringTokenizer token = new StringTokenizer(line.trim(), "\"\n\r");
+ while (token.hasMoreTokens()) {
+ String s = token.nextToken();
+
+ if (s.trim().equals("+")) {
+ continue;
+ }
+ if (s.trim().endsWith("\\")) {
+ s += "\"";
+ }
+ value.append(s);
+ }
+ }
+
+ sb.append("=\"");
+ String escapedValue = StringEscapeUtils.escapeHtml4(value.toString());
+ // reduce the size
+ // CHECKSTYLE_OFF: MagicNumber
+ if (escapedValue.length() < 40) {
+ sb.append(escapedValue).append("\"");
+ } else {
+ sb.append(escapedValue, 0, 39).append("\"{trunked}");
+ }
+ // CHECKSTYLE_ON: MagicNumber
+ }
+ }
+
+ sb.append("</code> ").append(END_JAVADOC);
+ sb.append(EOL);
+
+ stringWriter.write(sb.toString());
+ }
+
+ /**
+ * Add/update Javadoc method comment.
+ *
+ * @param stringWriter not null
+ * @param originalContent not null
+ * @param javaExecutable not null
+ * @param indent not null
+ * @return {@code true} if comment was updated, otherwise {@code false}
+ * @throws MojoExecutionException if any
+ * @throws IOException if any
+ */
+ private boolean fixMethodComment(
+ final StringWriter stringWriter,
+ final String originalContent,
+ final JavaExecutable javaExecutable,
+ final String indent)
+ throws MojoExecutionException, IOException {
+ if (!fixMethodComment) {
+ return false;
+ }
+
+ if (!javaExecutable.getDeclaringClass().isInterface() && !isInLevel(javaExecutable.getModifiers())) {
+ return false;
+ }
+
+ // add
+ if (javaExecutable.getComment() == null) {
+ addDefaultMethodComment(stringWriter, javaExecutable, indent);
+ return true;
+ }
+
+ // update
+ return updateEntityComment(stringWriter, originalContent, javaExecutable, indent);
+ }
+
+ /**
+ * Add in the buffer a default Javadoc for the given class:
+ * <br/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* {Comment based on the method name}</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">X {added if addMissingParam}</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@return </font>
+ * <font color="#3f5fbf">X {added if addMissingReturn}</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@throws </font>
+ * <font color="#3f5fbf">X {added if addMissingThrows}</font><br />
+ * <font color="#808080">7</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@since </font>
+ * <font color="#3f5fbf">X {added if addMissingSince and new classes
+ * from previous version}</font><br />
+ * <font color="#808080">8</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">9</font> <font color="#7f0055"><b>public </b></font>
+ * <font color="#7f0055"><b>void </b></font><font color="#000000">dummyMethod</font>
+ * <font color="#000000">( </font><font color="#000000">String s </font>
+ * <font color="#000000">){}</font>
+ * </code>
+ *
+ * @param stringWriter not null
+ * @param javaExecutable not null
+ * @param indent not null
+ * @throws MojoExecutionException if any
+ * @see #getDefaultMethodJavadocComment
+ * @see #appendDefaultSinceTag(StringBuilder, String)
+ */
+ private void addDefaultMethodComment(
+ final StringWriter stringWriter, final JavaExecutable javaExecutable, final String indent)
+ throws MojoExecutionException {
+ StringBuilder sb = new StringBuilder();
+
+ // special case
+ if (isInherited(javaExecutable)) {
+ sb.append(indent).append(INHERITED_JAVADOC);
+ sb.append(EOL);
+
+ stringWriter.write(sb.toString());
+ return;
+ }
+
+ sb.append(indent).append(START_JAVADOC);
+ sb.append(EOL);
+ sb.append(indent).append(SEPARATOR_JAVADOC);
+ sb.append(getDefaultMethodJavadocComment(javaExecutable));
+ sb.append(EOL);
+
+ boolean separatorAdded = false;
+ if (fixTag(PARAM_TAG)) {
+ if (javaExecutable.getParameters() != null) {
+ for (JavaParameter javaParameter : javaExecutable.getParameters()) {
+ separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, javaParameter);
+ }
+ }
+ // is generic?
+ if (javaExecutable.getTypeParameters() != null) {
+ for (JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters()) {
+ separatorAdded = appendDefaultParamTag(sb, indent, separatorAdded, typeParam);
+ }
+ }
+ }
+ if (javaExecutable instanceof JavaMethod) {
+ JavaMethod javaMethod = (JavaMethod) javaExecutable;
+ if (fixTag(RETURN_TAG)
+ && javaMethod.getReturns() != null
+ && !javaMethod.getReturns().isVoid()) {
+ separatorAdded = appendDefaultReturnTag(sb, indent, separatorAdded, javaMethod);
+ }
+ }
+ if (fixTag(THROWS_TAG) && javaExecutable.getExceptions() != null) {
+ for (JavaType exception : javaExecutable.getExceptions()) {
+ separatorAdded = appendDefaultThrowsTag(sb, indent, separatorAdded, exception);
+ }
+ }
+ if (fixTag(SINCE_TAG) && isNewMethodFromLastRevision(javaExecutable)) {
+ separatorAdded = appendDefaultSinceTag(sb, indent, separatorAdded);
+ }
+
+ sb.append(indent).append(" ").append(END_JAVADOC);
+ sb.append(EOL);
+
+ stringWriter.write(sb.toString());
+ }
+
+ /**
+ * @param stringWriter not null
+ * @param originalContent not null
+ * @param entity not null
+ * @param indent not null
+ * @return the updated changeDetected flag
+ * @throws MojoExecutionException if any
+ * @throws IOException if any
+ */
+ private boolean updateEntityComment(
+ final StringWriter stringWriter,
+ final String originalContent,
+ final JavaAnnotatedElement entity,
+ final String indent)
+ throws MojoExecutionException, IOException {
+ boolean changeDetected = false;
+
+ String old = null;
+ String s = stringWriter.toString();
+ int i = s.lastIndexOf(START_JAVADOC);
+ if (i != -1) {
+ String tmp = s.substring(0, i);
+ if (tmp.lastIndexOf(EOL) != -1) {
+ tmp = tmp.substring(0, tmp.lastIndexOf(EOL));
+ }
+
+ old = stringWriter.getBuffer().substring(i);
+
+ stringWriter.getBuffer().delete(0, stringWriter.getBuffer().length());
+ stringWriter.write(tmp);
+ stringWriter.write(EOL);
+ } else {
+ changeDetected = true;
+ }
+
+ updateJavadocComment(stringWriter, originalContent, entity, indent);
+
+ if (changeDetected) {
+ return true; // return now if we already know there's a change
+ }
+
+ return !stringWriter.getBuffer().substring(i).equals(old);
+ }
+
+ /**
+ * @param stringWriter not null
+ * @param originalContent not null
+ * @param entity not null
+ * @param indent not null
+ * @throws MojoExecutionException if any
+ * @throws IOException if any
+ */
+ private void updateJavadocComment(
+ final StringWriter stringWriter,
+ final String originalContent,
+ final JavaAnnotatedElement entity,
+ final String indent)
+ throws MojoExecutionException, IOException {
+ if (entity.getComment() == null
+ && (entity.getTags() == null || entity.getTags().isEmpty())) {
+ return;
+ }
+
+ boolean isJavaExecutable = entity instanceof JavaExecutable;
+
+ StringBuilder sb = new StringBuilder();
+
+ // special case for inherited method
+ if (isJavaExecutable) {
+ JavaExecutable javaMethod = (JavaExecutable) entity;
+
+ if (isInherited(javaMethod)) {
+ // QDOX-154 could be empty
+ if (StringUtils.isEmpty(javaMethod.getComment())) {
+ sb.append(indent).append(INHERITED_JAVADOC);
+ sb.append(EOL);
+ stringWriter.write(sb.toString());
+ return;
+ }
+
+ String javadoc = getJavadocComment(originalContent, javaMethod);
+
+ // case: /** {@inheritDoc} */ or no tags
+ if (hasInheritedTag(javadoc)
+ && (javaMethod.getTags() == null || javaMethod.getTags().isEmpty())) {
+ sb.append(indent).append(INHERITED_JAVADOC);
+ sb.append(EOL);
+ stringWriter.write(sb.toString());
+ return;
+ }
+
+ if (javadoc.contains(START_JAVADOC)) {
+ javadoc = javadoc.substring(javadoc.indexOf(START_JAVADOC) + START_JAVADOC.length());
+ }
+ if (javadoc.contains(END_JAVADOC)) {
+ javadoc = javadoc.substring(0, javadoc.indexOf(END_JAVADOC));
+ }
+
+ sb.append(indent).append(START_JAVADOC);
+ sb.append(EOL);
+ if (!javadoc.contains(INHERITED_TAG)) {
+ sb.append(indent).append(SEPARATOR_JAVADOC).append(INHERITED_TAG);
+ sb.append(EOL);
+ appendSeparator(sb, indent);
+ }
+ javadoc = removeLastEmptyJavadocLines(javadoc);
+ javadoc = alignIndentationJavadocLines(javadoc, indent);
+ sb.append(javadoc);
+ sb.append(EOL);
+ if (javaMethod.getTags() != null) {
+ for (DocletTag docletTag : javaMethod.getTags()) {
+ // Voluntary ignore these tags
+ if (JavadocUtil.equals(docletTag.getName(), PARAM_TAG, RETURN_TAG, THROWS_TAG)) {
+ continue;
+ }
+
+ String s = getJavadocComment(originalContent, entity, docletTag);
+ s = removeLastEmptyJavadocLines(s);
+ s = alignIndentationJavadocLines(s, indent);
+ sb.append(s);
+ sb.append(EOL);
+ }
+ }
+ sb.append(indent).append(" ").append(END_JAVADOC);
+ sb.append(EOL);
+
+ if (hasInheritedTag(sb.toString().trim())) {
+ sb = new StringBuilder();
+ sb.append(indent).append(INHERITED_JAVADOC);
+ sb.append(EOL);
+ stringWriter.write(sb.toString());
+ return;
+ }
+
+ stringWriter.write(sb.toString());
+ return;
+ }
+ }
+
+ sb.append(indent).append(START_JAVADOC);
+ sb.append(EOL);
+
+ // comment
+ if (StringUtils.isNotEmpty(entity.getComment())) {
+ updateJavadocComment(sb, originalContent, entity, indent);
+ } else {
+ addDefaultJavadocComment(sb, entity, indent, isJavaExecutable);
+ }
+
+ // tags
+ updateJavadocTags(sb, originalContent, entity, indent, isJavaExecutable);
+
+ sb = new StringBuilder(removeLastEmptyJavadocLines(sb.toString())).append(EOL);
+
+ sb.append(indent).append(" ").append(END_JAVADOC);
+ sb.append(EOL);
+
+ stringWriter.write(sb.toString());
+ }
+
+ /**
+ * @param sb not null
+ * @param originalContent not null
+ * @param entity not null
+ * @param indent not null
+ * @throws IOException if any
+ */
+ private void updateJavadocComment(
+ final StringBuilder sb,
+ final String originalContent,
+ final JavaAnnotatedElement entity,
+ final String indent)
+ throws IOException {
+ String comment = getJavadocComment(originalContent, entity);
+ comment = removeLastEmptyJavadocLines(comment);
+ comment = alignIndentationJavadocLines(comment, indent);
+
+ if (comment.contains(START_JAVADOC)) {
+ comment = comment.substring(comment.indexOf(START_JAVADOC) + START_JAVADOC.length());
+ comment = indent + SEPARATOR_JAVADOC + comment.trim();
+ }
+ if (comment.contains(END_JAVADOC)) {
+ comment = comment.substring(0, comment.indexOf(END_JAVADOC));
+ }
+
+ if (fixTag(LINK_TAG)) {
+ comment = replaceLinkTags(comment, entity);
+ }
+
+ String[] lines = getLines(comment);
+ for (String line : lines) {
+ sb.append(indent).append(" ").append(line.trim());
+ sb.append(EOL);
+ }
+ }
+
+ private static final Pattern REPLACE_LINK_TAGS_PATTERN = Pattern.compile("\\{@link\\s");
+
+ static String replaceLinkTags(String comment, JavaAnnotatedElement entity) {
+ StringBuilder resolvedComment = new StringBuilder();
+ // scan comment for {@link someClassName} and try to resolve this
+ Matcher linktagMatcher = REPLACE_LINK_TAGS_PATTERN.matcher(comment);
+ int startIndex = 0;
+ while (linktagMatcher.find()) {
+ int startName = linktagMatcher.end();
+ resolvedComment.append(comment, startIndex, startName);
+ int endName = comment.indexOf("}", startName);
+ if (endName >= 0) {
+ String name;
+ String link = comment.substring(startName, endName);
+ int hashIndex = link.indexOf('#');
+ if (hashIndex >= 0) {
+ name = link.substring(0, hashIndex);
+ } else {
+ name = link;
+ }
+ if (StringUtils.isNotBlank(name)) {
+ String typeName;
+ if (entity instanceof JavaClass) {
+ JavaClass clazz = (JavaClass) entity;
+ typeName = TypeResolver.byClassName(
+ clazz.getBinaryName(),
+ clazz.getJavaClassLibrary(),
+ clazz.getSource().getImports())
+ .resolveType(name.trim());
+ } else if (entity instanceof JavaMember) {
+ JavaClass clazz = ((JavaMember) entity).getDeclaringClass();
+ typeName = TypeResolver.byClassName(
+ clazz.getBinaryName(),
+ clazz.getJavaClassLibrary(),
+ clazz.getSource().getImports())
+ .resolveType(name.trim());
+ } else {
+ typeName = null;
+ }
+
+ if (typeName == null) {
+ typeName = name.trim();
+ } else {
+ typeName = typeName.replaceAll("\\$", ".");
+ }
+ // adjust name for inner classes
+ resolvedComment.append(typeName);
+ }
+ if (hashIndex >= 0) {
+ resolvedComment.append(link.substring(hashIndex).trim());
+ }
+ startIndex = endName;
+ } else {
+ startIndex = startName;
+ }
+ }
+ resolvedComment.append(comment.substring(startIndex));
+ return resolvedComment.toString();
+ }
+
+ /**
+ * @param sb not null
+ * @param entity not null
+ * @param indent not null
+ * @param isJavaExecutable
+ */
+ private void addDefaultJavadocComment(
+ final StringBuilder sb,
+ final JavaAnnotatedElement entity,
+ final String indent,
+ final boolean isJavaExecutable) {
+ sb.append(indent).append(SEPARATOR_JAVADOC);
+ if (isJavaExecutable) {
+ sb.append(getDefaultMethodJavadocComment((JavaExecutable) entity));
+ } else {
+ sb.append(getDefaultClassJavadocComment((JavaClass) entity));
+ }
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param originalContent not null
+ * @param entity not null
+ * @param indent not null
+ * @param isJavaExecutable
+ * @throws IOException if any
+ * @throws MojoExecutionException if any
+ */
+ private void updateJavadocTags(
+ final StringBuilder sb,
+ final String originalContent,
+ final JavaAnnotatedElement entity,
+ final String indent,
+ final boolean isJavaExecutable)
+ throws IOException, MojoExecutionException {
+ appendSeparator(sb, indent);
+
+ // parse tags
+ JavaEntityTags javaEntityTags = parseJavadocTags(originalContent, entity, indent, isJavaExecutable);
+
+ // update and write tags
+ updateJavadocTags(sb, entity, isJavaExecutable, javaEntityTags);
+
+ // add missing tags...
+ addMissingJavadocTags(sb, entity, indent, isJavaExecutable, javaEntityTags);
+ }
+
+ /**
+ * Parse entity tags
+ *
+ * @param originalContent not null
+ * @param entity not null
+ * @param indent not null
+ * @param isJavaMethod
+ * @return an instance of {@link JavaEntityTags}
+ * @throws IOException if any
+ */
+ JavaEntityTags parseJavadocTags(
+ final String originalContent,
+ final JavaAnnotatedElement entity,
+ final String indent,
+ final boolean isJavaMethod)
+ throws IOException {
+ JavaEntityTags javaEntityTags = new JavaEntityTags(entity, isJavaMethod);
+ for (DocletTag docletTag : entity.getTags()) {
+ String originalJavadocTag = getJavadocComment(originalContent, entity, docletTag);
+ originalJavadocTag = removeLastEmptyJavadocLines(originalJavadocTag);
+ originalJavadocTag = alignIndentationJavadocLines(originalJavadocTag, indent);
+
+ javaEntityTags.getNamesTags().add(docletTag.getName());
+
+ if (isJavaMethod) {
+ List<String> params = docletTag.getParameters();
+ if (params.size() < 1) {
+ continue;
+ }
+
+ String paramName = params.get(0);
+ switch (docletTag.getName()) {
+ case PARAM_TAG:
+ javaEntityTags.putJavadocParamTag(paramName, docletTag.getValue(), originalJavadocTag);
+ break;
+ case RETURN_TAG:
+ javaEntityTags.setJavadocReturnTag(originalJavadocTag);
+ break;
+ case THROWS_TAG:
+ javaEntityTags.putJavadocThrowsTag(paramName, originalJavadocTag);
+ break;
+ default:
+ javaEntityTags.getUnknownTags().add(originalJavadocTag);
+ break;
+ }
+ } else {
+ javaEntityTags.getUnknownTags().add(originalJavadocTag);
+ }
+ }
+
+ return javaEntityTags;
+ }
+
+ /**
+ * Write tags according javaEntityTags.
+ *
+ * @param sb not null
+ * @param entity not null
+ * @param isJavaExecutable
+ * @param javaEntityTags not null
+ */
+ private void updateJavadocTags(
+ final StringBuilder sb,
+ final JavaAnnotatedElement entity,
+ final boolean isJavaExecutable,
+ final JavaEntityTags javaEntityTags) {
+ for (DocletTag docletTag : entity.getTags()) {
+ if (isJavaExecutable) {
+ JavaExecutable javaExecutable = (JavaExecutable) entity;
+
+ List<String> params = docletTag.getParameters();
+ if (params.size() < 1) {
+ continue;
+ }
+
+ if (docletTag.getName().equals(PARAM_TAG)) {
+ writeParamTag(sb, javaExecutable, javaEntityTags, params.get(0), docletTag.getValue());
+ } else if (docletTag.getName().equals(RETURN_TAG) && javaExecutable instanceof JavaMethod) {
+ writeReturnTag(sb, (JavaMethod) javaExecutable, javaEntityTags);
+ } else if (docletTag.getName().equals(THROWS_TAG)) {
+ writeThrowsTag(sb, javaExecutable, javaEntityTags, params);
+ } else {
+ // write unknown tags
+ for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); ) {
+ String originalJavadocTag = it.next();
+ String simplified = StringUtils.removeDuplicateWhitespace(originalJavadocTag)
+ .trim();
+
+ if (simplified.contains("@" + docletTag.getName())) {
+ it.remove();
+ sb.append(originalJavadocTag);
+ sb.append(EOL);
+ }
+ }
+ }
+ } else {
+ for (Iterator<String> it = javaEntityTags.getUnknownTags().iterator(); it.hasNext(); ) {
+ String originalJavadocTag = it.next();
+ String simplified = StringUtils.removeDuplicateWhitespace(originalJavadocTag)
+ .trim();
+
+ if (simplified.contains("@" + docletTag.getName())) {
+ it.remove();
+ sb.append(originalJavadocTag);
+ sb.append(EOL);
+ }
+ }
+ }
+
+ if (sb.toString().endsWith(EOL)) {
+ sb.delete(sb.toString().lastIndexOf(EOL), sb.toString().length());
+ }
+
+ sb.append(EOL);
+ }
+ }
+
+ private void writeParamTag(
+ final StringBuilder sb,
+ final JavaExecutable javaExecutable,
+ final JavaEntityTags javaEntityTags,
+ String paramName,
+ String paramValue) {
+ if (!fixTag(PARAM_TAG)) {
+ // write original param tag if found
+ String originalJavadocTag = javaEntityTags.getJavadocParamTag(paramValue);
+ if (originalJavadocTag != null) {
+ sb.append(originalJavadocTag);
+ }
+ return;
+ }
+
+ boolean found = false;
+ JavaParameter javaParam = javaExecutable.getParameterByName(paramName);
+ if (javaParam == null) {
+ // is generic?
+ List<JavaTypeVariable<JavaGenericDeclaration>> typeParams = javaExecutable.getTypeParameters();
+ for (JavaTypeVariable<JavaGenericDeclaration> typeParam : typeParams) {
+ if (("<" + typeParam.getName() + ">").equals(paramName)) {
+ found = true;
+ }
+ }
+ } else {
+ found = true;
+ }
+
+ if (!found) {
+ if (getLog().isWarnEnabled()) {
+ getLog().warn("Fixed unknown param '" + paramName + "' defined in "
+ + getJavaMethodAsString(javaExecutable));
+ }
+
+ if (sb.toString().endsWith(EOL)) {
+ sb.delete(sb.toString().lastIndexOf(EOL), sb.toString().length());
+ }
+ } else {
+ String originalJavadocTag = javaEntityTags.getJavadocParamTag(paramValue);
+ if (originalJavadocTag != null) {
+ sb.append(originalJavadocTag);
+ String s = "@" + PARAM_TAG + " " + paramName;
+ if (StringUtils.removeDuplicateWhitespace(originalJavadocTag)
+ .trim()
+ .endsWith(s)) {
+ sb.append(" ");
+ sb.append(getDefaultJavadocForType(javaParam.getJavaClass()));
+ }
+ }
+ }
+ }
+
+ private void writeReturnTag(
+ final StringBuilder sb, final JavaMethod javaMethod, final JavaEntityTags javaEntityTags) {
+ String originalJavadocTag = javaEntityTags.getJavadocReturnTag();
+ if (originalJavadocTag == null) {
+ return;
+ }
+
+ if (!fixTag(RETURN_TAG)) {
+ // write original param tag if found
+ sb.append(originalJavadocTag);
+ return;
+ }
+
+ if (StringUtils.isNotEmpty(originalJavadocTag)
+ && javaMethod.getReturns() != null
+ && !javaMethod.getReturns().isVoid()) {
+ sb.append(originalJavadocTag);
+ if (originalJavadocTag.trim().endsWith("@" + RETURN_TAG)) {
+ sb.append(" ");
+ sb.append(getDefaultJavadocForType(javaMethod.getReturns()));
+ }
+ }
+ }
+
+ void writeThrowsTag(
+ final StringBuilder sb,
+ final JavaExecutable javaExecutable,
+ final JavaEntityTags javaEntityTags,
+ final List<String> params) {
+ String exceptionClassName = params.get(0);
+
+ String originalJavadocTag = javaEntityTags.getJavadocThrowsTag(exceptionClassName);
+ if (originalJavadocTag == null) {
+ return;
+ }
+
+ if (!fixTag(THROWS_TAG)) {
+ // write original param tag if found
+ sb.append(originalJavadocTag);
+ return;
+ }
+
+ if (javaExecutable.getExceptions() != null) {
+ for (JavaType exception : javaExecutable.getExceptions()) {
+ if (exception.getFullyQualifiedName().endsWith(exceptionClassName)) {
+ originalJavadocTag = StringUtils.replace(
+ originalJavadocTag, exceptionClassName, exception.getFullyQualifiedName());
+ if (StringUtils.removeDuplicateWhitespace(originalJavadocTag)
+ .trim()
+ .endsWith("@" + THROWS_TAG + " " + exception.getValue())) {
+ originalJavadocTag += " if any.";
+ }
+
+ sb.append(originalJavadocTag);
+
+ // added qualified name
+ javaEntityTags.putJavadocThrowsTag(exception.getValue(), originalJavadocTag);
+
+ return;
+ }
+ }
+ }
+
+ Class<?> clazz = getClass(javaExecutable.getDeclaringClass(), exceptionClassName);
+
+ if (clazz != null) {
+ if (RuntimeException.class.isAssignableFrom(clazz)) {
+ sb.append(StringUtils.replace(originalJavadocTag, exceptionClassName, clazz.getName()));
+
+ // added qualified name
+ javaEntityTags.putJavadocThrowsTag(clazz.getName(), originalJavadocTag);
+ } else if (Throwable.class.isAssignableFrom(clazz)) {
+ getLog().debug("Removing '" + originalJavadocTag + "'; Throwable not specified by "
+ + getJavaMethodAsString(javaExecutable) + " and it is not a RuntimeException.");
+ } else {
+ getLog().debug("Removing '" + originalJavadocTag + "'; It is not a Throwable");
+ }
+ } else if (removeUnknownThrows) {
+ getLog().warn("Ignoring unknown throws '" + exceptionClassName + "' defined on "
+ + getJavaMethodAsString(javaExecutable));
+ } else {
+ getLog().warn("Found unknown throws '" + exceptionClassName + "' defined on "
+ + getJavaMethodAsString(javaExecutable));
+
+ sb.append(originalJavadocTag);
+
+ if (params.size() == 1) {
+ sb.append(" if any.");
+ }
+
+ javaEntityTags.putJavadocThrowsTag(exceptionClassName, originalJavadocTag);
+ }
+ }
+
+ /**
+ * Add missing tags not already written.
+ *
+ * @param sb not null
+ * @param entity not null
+ * @param indent not null
+ * @param isJavaExecutable
+ * @param javaEntityTags not null
+ * @throws MojoExecutionException if any
+ */
+ private void addMissingJavadocTags(
+ final StringBuilder sb,
+ final JavaAnnotatedElement entity,
+ final String indent,
+ final boolean isJavaExecutable,
+ final JavaEntityTags javaEntityTags)
+ throws MojoExecutionException {
+ if (isJavaExecutable) {
+ JavaExecutable javaExecutable = (JavaExecutable) entity;
+
+ if (fixTag(PARAM_TAG)) {
+ if (javaExecutable.getParameters() != null) {
+ for (JavaParameter javaParameter : javaExecutable.getParameters()) {
+ if (!javaEntityTags.hasJavadocParamTag(javaParameter.getName())) {
+ appendDefaultParamTag(sb, indent, javaParameter);
+ }
+ }
+ }
+ // is generic?
+ if (javaExecutable.getTypeParameters() != null) {
+ for (JavaTypeVariable<JavaGenericDeclaration> typeParam : javaExecutable.getTypeParameters()) {
+ if (!javaEntityTags.hasJavadocParamTag("<" + typeParam.getName() + ">")) {
+ appendDefaultParamTag(sb, indent, typeParam);
+ }
+ }
+ }
+ }
+
+ if (javaExecutable instanceof JavaMethod) {
+ JavaMethod javaMethod = (JavaMethod) javaExecutable;
+ if (fixTag(RETURN_TAG)
+ && StringUtils.isEmpty(javaEntityTags.getJavadocReturnTag())
+ && javaMethod.getReturns() != null
+ && !javaMethod.getReturns().isVoid()) {
+ appendDefaultReturnTag(sb, indent, javaMethod);
+ }
+ }
+
+ if (fixTag(THROWS_TAG) && javaExecutable.getExceptions() != null) {
+ for (JavaType exception : javaExecutable.getExceptions()) {
+ if (javaEntityTags.getJavadocThrowsTag(exception.getValue(), true) == null) {
+ appendDefaultThrowsTag(sb, indent, exception);
+ }
+ }
+ }
+ } else {
+ if (!javaEntityTags.getNamesTags().contains(AUTHOR_TAG)) {
+ appendDefaultAuthorTag(sb, indent);
+ }
+ if (!javaEntityTags.getNamesTags().contains(VERSION_TAG)) {
+ appendDefaultVersionTag(sb, indent);
+ }
+ }
+
+ if (fixTag(SINCE_TAG) && !javaEntityTags.getNamesTags().contains(SINCE_TAG)) {
+ if (!isJavaExecutable) {
+ if (!ignoreClirr) {
+ if (isNewClassFromLastVersion((JavaClass) entity)) {
+ appendDefaultSinceTag(sb, indent);
+ }
+ } else {
+ appendDefaultSinceTag(sb, indent);
+ addSinceClasses((JavaClass) entity);
+ }
+ } else {
+ if (!ignoreClirr) {
+ if (isNewMethodFromLastRevision((JavaExecutable) entity)) {
+ appendDefaultSinceTag(sb, indent);
+ }
+ } else if (sinceClasses != null) {
+ if (entity instanceof JavaMember
+ && !sinceClassesContains(((JavaMember) entity).getDeclaringClass())) {
+ appendDefaultSinceTag(sb, indent);
+ } else if (entity instanceof JavaClass
+ && !sinceClassesContains(((JavaClass) entity).getDeclaringClass())) {
+ appendDefaultSinceTag(sb, indent);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultAuthorTag(final StringBuilder sb, final String indent, boolean separatorAdded) {
+ if (!fixTag(AUTHOR_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultAuthorTag(sb, indent);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ */
+ private void appendDefaultAuthorTag(final StringBuilder sb, final String indent) {
+ if (!fixTag(AUTHOR_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(AUTHOR_TAG).append(" ");
+ sb.append(defaultAuthor);
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultSinceTag(final StringBuilder sb, final String indent, boolean separatorAdded) {
+ if (!fixTag(SINCE_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultSinceTag(sb, indent);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ */
+ private void appendDefaultSinceTag(final StringBuilder sb, final String indent) {
+ if (!fixTag(SINCE_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(SINCE_TAG).append(" ");
+ sb.append(defaultSince);
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultVersionTag(final StringBuilder sb, final String indent, boolean separatorAdded) {
+ if (!fixTag(VERSION_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultVersionTag(sb, indent);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ */
+ private void appendDefaultVersionTag(final StringBuilder sb, final String indent) {
+ if (!fixTag(VERSION_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(VERSION_TAG).append(" ");
+ sb.append(defaultVersion);
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @param typeParam not null
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultParamTag(
+ final StringBuilder sb, final String indent, boolean separatorAdded, final JavaParameter typeParam) {
+ if (!fixTag(PARAM_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultParamTag(sb, indent, typeParam);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @param typeParameter not null
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultParamTag(
+ final StringBuilder sb,
+ final String indent,
+ boolean separatorAdded,
+ final JavaTypeVariable<JavaGenericDeclaration> typeParameter) {
+ if (!fixTag(PARAM_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultParamTag(sb, indent, typeParameter);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param typeParam not null
+ */
+ private void appendDefaultParamTag(final StringBuilder sb, final String indent, final JavaParameter typeParam) {
+ if (!fixTag(PARAM_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(PARAM_TAG).append(" ");
+ sb.append(typeParam.getName());
+ sb.append(" ");
+ sb.append(getDefaultJavadocForType(typeParam.getJavaClass()));
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param typeParameter not null
+ */
+ private void appendDefaultParamTag(
+ final StringBuilder sb, final String indent, final JavaTypeVariable<JavaGenericDeclaration> typeParameter) {
+ if (!fixTag(PARAM_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(PARAM_TAG).append(" ");
+ sb.append("<").append(typeParameter.getName()).append(">");
+ sb.append(" ");
+ sb.append(getDefaultJavadocForType(typeParameter));
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @param javaMethod not null
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultReturnTag(
+ final StringBuilder sb, final String indent, boolean separatorAdded, final JavaMethod javaMethod) {
+ if (!fixTag(RETURN_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultReturnTag(sb, indent, javaMethod);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param javaMethod not null
+ */
+ private void appendDefaultReturnTag(final StringBuilder sb, final String indent, final JavaMethod javaMethod) {
+ if (!fixTag(RETURN_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(RETURN_TAG).append(" ");
+ sb.append(getDefaultJavadocForType(javaMethod.getReturns()));
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param separatorAdded
+ * @param exception not null
+ * @return true if separator has been added.
+ */
+ private boolean appendDefaultThrowsTag(
+ final StringBuilder sb, final String indent, boolean separatorAdded, final JavaType exception) {
+ if (!fixTag(THROWS_TAG)) {
+ return separatorAdded;
+ }
+
+ if (!separatorAdded) {
+ appendSeparator(sb, indent);
+ separatorAdded = true;
+ }
+
+ appendDefaultThrowsTag(sb, indent, exception);
+ return separatorAdded;
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ * @param exception not null
+ */
+ private void appendDefaultThrowsTag(final StringBuilder sb, final String indent, final JavaType exception) {
+ if (!fixTag(THROWS_TAG)) {
+ return;
+ }
+
+ sb.append(indent).append(" * @").append(THROWS_TAG).append(" ");
+ sb.append(exception.getFullyQualifiedName());
+ sb.append(" if any.");
+ sb.append(EOL);
+ }
+
+ /**
+ * @param sb not null
+ * @param indent not null
+ */
+ private void appendSeparator(final StringBuilder sb, final String indent) {
+ sb.append(indent).append(" *");
+ sb.append(EOL);
+ }
+
+ /**
+ * Verify if a method has <code>@java.lang.Override()</code> annotation or if it is an inherited method
+ * from an interface or a super class. The goal is to handle <code>{@inheritDoc}</code> tag.
+ *
+ * @param javaMethod not null
+ * @return <code>true</code> if the method is inherited, <code>false</code> otherwise.
+ * @throws MojoExecutionException if any
+ */
+ private boolean isInherited(JavaExecutable javaMethod) throws MojoExecutionException {
+ if (javaMethod.getAnnotations() != null) {
+ for (JavaAnnotation annotation : javaMethod.getAnnotations()) {
+ if (annotation.toString().equals("@java.lang.Override()")) {
+ return true;
+ }
+ }
+ }
+
+ Class<?> clazz = getClass(javaMethod.getDeclaringClass().getFullyQualifiedName());
+
+ List<Class<?>> interfaces = ClassUtils.getAllInterfaces(clazz);
+ for (Class<?> intface : interfaces) {
+ if (isInherited(intface, javaMethod)) {
+ return true;
+ }
+ }
+
+ List<Class<?>> classes = ClassUtils.getAllSuperclasses(clazz);
+ for (Class<?> superClass : classes) {
+ if (isInherited(superClass, javaMethod)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param clazz the Java class object, not null
+ * @param javaMethod the QDox JavaMethod object not null
+ * @return <code>true</code> if <code>javaMethod</code> exists in the given <code>clazz</code>,
+ * <code>false</code> otherwise.
+ * @see #isInherited(JavaExecutable)
+ */
+ private boolean isInherited(Class<?> clazz, JavaExecutable javaMethod) {
+ for (Method method : clazz.getDeclaredMethods()) {
+ if (!method.getName().equals(javaMethod.getName())) {
+ continue;
+ }
+
+ if (method.getParameterTypes().length != javaMethod.getParameters().size()) {
+ continue;
+ }
+
+ boolean found = false;
+ int j = 0;
+ for (Class<?> paramType : method.getParameterTypes()) {
+ String name1 = paramType.getName();
+ String name2 = javaMethod.getParameters().get(j++).getType().getFullyQualifiedName();
+ found = name1.equals(name2); // TODO check algo, seems broken (only takes in account the last param)
+ }
+
+ return found;
+ }
+
+ return false;
+ }
+
+ /**
+ * @param clazz
+ * @return
+ */
+ private String getDefaultJavadocForType(JavaClass clazz) {
+ StringBuilder sb = new StringBuilder();
+
+ if (!JavaTypeVariable.class.isAssignableFrom(clazz.getClass()) && clazz.isPrimitive()) {
+ if (clazz.isArray()) {
+ sb.append("an array of ").append(clazz.getComponentType().getCanonicalName());
+ } else {
+ sb.append("a ").append(clazz.getCanonicalName());
+ }
+ return sb.toString();
+ }
+
+ StringBuilder javadocLink = new StringBuilder();
+ try {
+ getClass(clazz.getCanonicalName());
+
+ javadocLink.append("{@link ");
+
+ if (clazz.isArray()) {
+ javadocLink.append(clazz.getComponentType().getCanonicalName());
+ } else {
+ javadocLink.append(clazz.getCanonicalName());
+ }
+ javadocLink.append("}");
+ } catch (Exception e) {
+ javadocLink.append(clazz.getValue());
+ }
+
+ if (clazz.isArray()) {
+ sb.append("an array of ").append(javadocLink).append(" objects");
+ } else {
+ sb.append("a ").append(javadocLink).append(" object");
+ }
+
+ return sb.toString();
+ }
+
+ private String getDefaultJavadocForType(JavaTypeVariable<JavaGenericDeclaration> typeParameter) {
+ return "a " + typeParameter.getName() + " class";
+ }
+
+ /**
+ * Check under Clirr if this given class is newer from the last version.
+ *
+ * @param javaClass a given class not null
+ * @return <code>true</code> if Clirr said that this class is added from the last version,
+ * <code>false</code> otherwise or if {@link #clirrNewClasses} is null.
+ */
+ private boolean isNewClassFromLastVersion(JavaClass javaClass) {
+ return (clirrNewClasses != null) && clirrNewClasses.contains(javaClass.getFullyQualifiedName());
+ }
+
+ /**
+ * Check under Clirr if this given method is newer from the last version.
+ *
+ * @param javaExecutable a given method not null
+ * @return <code>true</code> if Clirr said that this method is added from the last version,
+ * <code>false</code> otherwise or if {@link #clirrNewMethods} is null.
+ * @throws MojoExecutionException if any
+ */
+ private boolean isNewMethodFromLastRevision(JavaExecutable javaExecutable) throws MojoExecutionException {
+ if (clirrNewMethods == null) {
+ return false;
+ }
+
+ List<String> clirrMethods =
+ clirrNewMethods.get(javaExecutable.getDeclaringClass().getFullyQualifiedName());
+ if (clirrMethods == null) {
+ return false;
+ }
+
+ for (String clirrMethod : clirrMethods) {
+ // see net.sf.clirr.core.internal.checks.MethodSetCheck#getMethodId(JavaType clazz, Method method)
+ String retrn = "";
+ if (javaExecutable instanceof JavaMethod && ((JavaMethod) javaExecutable).getReturns() != null) {
+ retrn = ((JavaMethod) javaExecutable).getReturns().getFullyQualifiedName();
+ }
+ StringBuilder params = new StringBuilder();
+ for (JavaParameter parameter : javaExecutable.getParameters()) {
+ if (params.length() > 0) {
+ params.append(", ");
+ }
+ params.append(parameter.getResolvedFullyQualifiedName());
+ }
+ if (clirrMethod.contains(retrn + " ")
+ && clirrMethod.contains(javaExecutable.getName() + "(")
+ && clirrMethod.contains("(" + params.toString() + ")")) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * @param className not null
+ * @return the Class corresponding to the given class name using the project classloader.
+ * @throws MojoExecutionException if class not found
+ * @see ClassUtils#getClass(ClassLoader, String, boolean)
+ * @see #getProjectClassLoader()
+ */
+ private Class<?> getClass(String className) throws MojoExecutionException {
+ try {
+ return ClassUtils.getClass(getProjectClassLoader(), className, false);
+ } catch (ClassNotFoundException e) {
+ throw new MojoExecutionException("ClassNotFoundException: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Returns the Class object assignable for {@link RuntimeException} class and associated with the given
+ * exception class name.
+ *
+ * @param currentClass not null
+ * @param exceptionClassName not null, an exception class name defined as:
+ * <ul>
+ * <li>exception class fully qualified</li>
+ * <li>exception class in the same package</li>
+ * <li>exception inner class</li>
+ * <li>exception class in java.lang package</li>
+ * </ul>
+ * @return the class if found, otherwise {@code null}.
+ * @see #getClass(String)
+ */
+ private Class<?> getClass(JavaClass currentClass, String exceptionClassName) {
+ String[] potentialClassNames = new String[] {
+ exceptionClassName,
+ currentClass.getPackage().getName() + "." + exceptionClassName,
+ currentClass.getPackage().getName() + "." + currentClass.getName() + "$" + exceptionClassName,
+ "java.lang." + exceptionClassName
+ };
+
+ Class<?> clazz = null;
+ for (String potentialClassName : potentialClassNames) {
+ try {
+ clazz = getClass(potentialClassName);
+ } catch (MojoExecutionException e) {
+ // nop
+ }
+ if (clazz != null) {
+ return clazz;
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param javaClass not null
+ */
+ private void addSinceClasses(JavaClass javaClass) {
+ if (sinceClasses == null) {
+ sinceClasses = new ArrayList<>();
+ }
+ sinceClasses.add(javaClass.getFullyQualifiedName());
+ }
+
+ private boolean sinceClassesContains(JavaClass javaClass) {
+ return sinceClasses.contains(javaClass.getFullyQualifiedName());
+ }
+
+ // ----------------------------------------------------------------------
+ // Static methods
+ // ----------------------------------------------------------------------
+
+ /**
+ * Write content into the given javaFile and using the given encoding.
+ * All line separators will be unified.
+ *
+ * @param javaFile not null
+ * @param encoding not null
+ * @param content not null
+ * @throws IOException if any
+ */
+ private static void writeFile(final File javaFile, final String encoding, final String content) throws IOException {
+ String unified = StringUtils.unifyLineSeparators(content);
+ FileUtils.fileWrite(javaFile, encoding, unified);
+ }
+
+ /**
+ * @return the full clirr goal, i.e. <code>groupId:artifactId:version:goal</code>. The clirr-plugin version
+ * could be load from the pom.properties in the clirr-maven-plugin dependency.
+ */
+ private static String getFullClirrGoal() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(CLIRR_MAVEN_PLUGIN_GROUPID)
+ .append(":")
+ .append(CLIRR_MAVEN_PLUGIN_ARTIFACTID)
+ .append(":");
+
+ String clirrVersion = CLIRR_MAVEN_PLUGIN_VERSION;
+
+ String resource = "META-INF/maven/" + CLIRR_MAVEN_PLUGIN_GROUPID + "/" + CLIRR_MAVEN_PLUGIN_ARTIFACTID
+ + "/pom.properties";
+
+ try (InputStream resourceAsStream =
+ AbstractFixJavadocMojo.class.getClassLoader().getResourceAsStream(resource)) {
+
+ if (resourceAsStream != null) {
+ Properties properties = new Properties();
+ properties.load(resourceAsStream);
+ if (StringUtils.isNotEmpty(properties.getProperty("version"))) {
+ clirrVersion = properties.getProperty("version");
+ }
+ }
+ } catch (IOException e) {
+ // nop
+ }
+
+ sb.append(clirrVersion).append(":").append(CLIRR_MAVEN_PLUGIN_GOAL);
+
+ return sb.toString();
+ }
+
+ /**
+ * Default comment for class.
+ *
+ * @param javaClass not null
+ * @return a default comment for class.
+ */
+ private static String getDefaultClassJavadocComment(final JavaClass javaClass) {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("<p>");
+ if (javaClass.isAbstract()) {
+ sb.append("Abstract ");
+ }
+
+ sb.append(javaClass.getName());
+
+ if (!javaClass.isInterface()) {
+ sb.append(" class.");
+ } else {
+ sb.append(" interface.");
+ }
+
+ sb.append("</p>");
+
+ return sb.toString();
+ }
+
+ /**
+ * Default comment for method with taking care of getter/setter in the javaMethod name.
+ *
+ * @param javaExecutable not null
+ * @return a default comment for method
+ */
+ private static String getDefaultMethodJavadocComment(final JavaExecutable javaExecutable) {
+ if (javaExecutable instanceof JavaConstructor) {
+ return "<p>Constructor for " + javaExecutable.getName() + ".</p>";
+ }
+
+ if (javaExecutable.getName().length() > 3
+ && (javaExecutable.getName().startsWith("get")
+ || javaExecutable.getName().startsWith("set"))) {
+ String field =
+ StringUtils.lowercaseFirstLetter(javaExecutable.getName().substring(3));
+
+ JavaClass clazz = javaExecutable.getDeclaringClass();
+
+ if (clazz.getFieldByName(field) == null) {
+ return "<p>" + javaExecutable.getName() + ".</p>";
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("<p>");
+ if (javaExecutable.getName().startsWith("get")) {
+ sb.append("Getter ");
+ } else if (javaExecutable.getName().startsWith("set")) {
+ sb.append("Setter ");
+ }
+ sb.append("for the field <code>").append(field).append("</code>.</p>");
+
+ return sb.toString();
+ }
+
+ return "<p>" + javaExecutable.getName() + ".</p>";
+ }
+
+ /**
+ * Try to find if a Javadoc comment has an {@link #INHERITED_TAG} for instance:
+ * <pre>
+ * /** {@inheritDoc} */
+ * </pre>
+ * or
+ * <pre>
+ * /**
+ *  * {@inheritDoc}
+ *  */
+ * </pre>
+ *
+ * @param content not null
+ * @return <code>true</code> if the content has an inherited tag, <code>false</code> otherwise.
+ */
+ private static boolean hasInheritedTag(final String content) {
+ final String inheritedTagPattern =
+ "^\\s*(\\/\\*\\*)?(\\s*(\\*)?)*(\\{)@inheritDoc\\s*(\\})(\\s*(\\*)?)*(\\*\\/)?$";
+ return Pattern.matches(inheritedTagPattern, StringUtils.removeDuplicateWhitespace(content));
+ }
+
+ /**
+ * Workaround for QDOX-146 about whitespace.
+ * Ideally we want to use <code>entity.getComment()</code>
+ * <br/>
+ * For instance, with the following snippet:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"></font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
+ * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
+ * <font color="#000000">String s </font><font color="#000000">){}</font><br />
+ * </code>
+ * <p/>
+ * <br/>
+ * The return will be:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * </code>
+ *
+ * @param javaClassContent original class content not null
+ * @param entity not null
+ * @return the javadoc comment for the entity without any tags.
+ * @throws IOException if any
+ */
+ static String getJavadocComment(final String javaClassContent, final JavaAnnotatedElement entity)
+ throws IOException {
+ if (entity.getComment() == null) {
+ return "";
+ }
+
+ String originalJavadoc = extractOriginalJavadocContent(javaClassContent, entity);
+
+ StringBuilder sb = new StringBuilder();
+ BufferedReader lr = new BufferedReader(new StringReader(originalJavadoc));
+ String line;
+ while ((line = lr.readLine()) != null) {
+ String l = StringUtils.removeDuplicateWhitespace(line.trim());
+ if (l.startsWith("* @") || l.startsWith("*@")) {
+ break;
+ }
+ sb.append(line).append(EOL);
+ }
+
+ return trimRight(sb.toString());
+ }
+
+ /**
+ * Work around for QDOX-146 about whitespace.
+ * Ideally we want to use <code>docletTag.getValue()</code>
+ * <br/>
+ * For instance, with the following snippet:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"></font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
+ * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
+ * <font color="#000000">String s </font><font color="#000000">){}</font><br />
+ * </code>
+ * <p/>
+ * <br/>
+ * The return will be:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * </code>
+ *
+ * @param javaClassContent original class content not null
+ * @param entity not null
+ * @param docletTag not null
+ * @return the javadoc comment for the entity without Javadoc tags.
+ * @throws IOException if any
+ */
+ String getJavadocComment(
+ final String javaClassContent, final JavaAnnotatedElement entity, final DocletTag docletTag)
+ throws IOException {
+ if (docletTag.getValue() == null || docletTag.getParameters().isEmpty()) {
+ return "";
+ }
+
+ String originalJavadoc = extractOriginalJavadocContent(javaClassContent, entity);
+
+ StringBuilder sb = new StringBuilder();
+ BufferedReader lr = new BufferedReader(new StringReader(originalJavadoc));
+ String line;
+ boolean found = false;
+
+ // matching first line of doclettag
+ Pattern p = Pattern.compile("(\\s*\\*\\s?@" + docletTag.getName() + ")\\s+" + "(\\Q"
+ + docletTag.getValue().split("\r\n|\r|\n")[0] + "\\E)");
+
+ while ((line = lr.readLine()) != null) {
+ Matcher m = p.matcher(line);
+ if (m.matches()) {
+ if (fixTag(LINK_TAG)) {
+ line = replaceLinkTags(line, entity);
+ }
+ sb.append(line).append(EOL);
+ found = true;
+ } else {
+ if (line.trim().startsWith("* @") || line.trim().startsWith("*@")) {
+ found = false;
+ }
+ if (found) {
+ if (fixTag(LINK_TAG)) {
+ line = replaceLinkTags(line, entity);
+ }
+ sb.append(line).append(EOL);
+ }
+ }
+ }
+
+ return trimRight(sb.toString());
+ }
+
+ /**
+ * Extract the original Javadoc and others comments up to {@link #START_JAVADOC} form the entity. This method
+ * takes care of the Javadoc indentation. All javadoc lines will be trimmed on right.
+ * <br/>
+ * For instance, with the following snippet:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"></font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
+ * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
+ * <font color="#000000">String s </font><font color="#000000">){}</font><br />
+ * </code>
+ * <p/>
+ * <br/>
+ * The return will be:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * </code>
+ *
+ * @param javaClassContent not null
+ * @param entity not null
+ * @return return the original javadoc as String for the current entity
+ * @throws IOException if any
+ */
+ static String extractOriginalJavadoc(final String javaClassContent, final JavaAnnotatedElement entity)
+ throws IOException {
+ if (entity.getComment() == null) {
+ return "";
+ }
+
+ String[] javaClassContentLines = getLines(javaClassContent);
+ List<String> list = new LinkedList<>();
+ for (int i = entity.getLineNumber() - 2; i >= 0; i--) {
+ String line = javaClassContentLines[i];
+
+ list.add(trimRight(line));
+ if (line.trim().startsWith(START_JAVADOC)) {
+ break;
+ }
+ }
+
+ Collections.reverse(list);
+
+ return StringUtils.join(list.iterator(), EOL);
+ }
+
+ /**
+ * Extract the Javadoc comment between {@link #START_JAVADOC} and {@link #END_JAVADOC} form the entity. This method
+ * takes care of the Javadoc indentation. All javadoc lines will be trimmed on right.
+ * <br/>
+ * For instance, with the following snippet:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"></font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">/**</font><br />
+ * <font color="#808080">3</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">4</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * <font color="#808080">5</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">*/</font><br />
+ * <font color="#808080">6</font> <font color="#ffffff"> </font>
+ * <font color="#7f0055"><b>public </b></font><font color="#7f0055"><b>void </b></font>
+ * <font color="#000000">dummyMethod</font><font color="#000000">( </font>
+ * <font color="#000000">String s </font><font color="#000000">){}</font><br />
+ * </code>
+ * <p/>
+ * <br/>
+ * The return will be:
+ * <br/>
+ * <p/>
+ * <code>
+ * <font color="#808080">1</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* Dummy Javadoc comment.</font><br />
+ * <font color="#808080">2</font> <font color="#ffffff"> </font>
+ * <font color="#3f5fbf">* </font><font color="#7f9fbf">@param </font>
+ * <font color="#3f5fbf">s a String</font><br />
+ * </code>
+ *
+ * @param javaClassContent not null
+ * @param entity not null
+ * @return return the original javadoc as String for the current entity
+ * @throws IOException if any
+ */
+ static String extractOriginalJavadocContent(final String javaClassContent, final JavaAnnotatedElement entity)
+ throws IOException {
+ if (entity.getComment() == null) {
+ return "";
+ }
+
+ String originalJavadoc = extractOriginalJavadoc(javaClassContent, entity);
+ int index = originalJavadoc.indexOf(START_JAVADOC);
+ if (index != -1) {
+ originalJavadoc = originalJavadoc.substring(index + START_JAVADOC.length());
+ }
+ index = originalJavadoc.indexOf(END_JAVADOC);
+ if (index != -1) {
+ originalJavadoc = originalJavadoc.substring(0, index);
+ }
+ if (originalJavadoc.startsWith("\r\n")) {
+ originalJavadoc = originalJavadoc.substring(2);
+ } else if (originalJavadoc.startsWith("\n") || originalJavadoc.startsWith("\r")) {
+ originalJavadoc = originalJavadoc.substring(1);
+ }
+
+ return trimRight(originalJavadoc);
+ }
+
+ /**
+ * @param content not null
+ * @return the content without last lines containing javadoc separator (ie <code> * </code>)
+ * @throws IOException if any
+ * @see #getJavadocComment(String, JavaAnnotatedElement, DocletTag)
+ */
+ private static String removeLastEmptyJavadocLines(final String content) throws IOException {
+ if (!content.contains(EOL)) {
+ return content;
+ }
+
+ String[] lines = getLines(content);
+ if (lines.length == 1) {
+ return content;
+ }
+
+ List<String> linesList = new LinkedList<>(Arrays.asList(lines));
+
+ Collections.reverse(linesList);
+
+ for (Iterator<String> it = linesList.iterator(); it.hasNext(); ) {
+ String line = it.next();
+
+ if (line.trim().equals("*")) {
+ it.remove();
+ } else {
+ break;
+ }
+ }
+
+ Collections.reverse(linesList);
+
+ return StringUtils.join(linesList.iterator(), EOL);
+ }
+
+ /**
+ * @param content not null
+ * @return the javadoc comment with the given indentation
+ * @throws IOException if any
+ * @see #getJavadocComment(String, JavaAnnotatedElement, DocletTag)
+ */
+ private static String alignIndentationJavadocLines(final String content, final String indent) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ for (String line : getLines(content)) {
+ if (sb.length() > 0) {
+ sb.append(EOL);
+ }
+ if (!line.trim().startsWith("*")) {
+ line = "*" + line;
+ }
+ sb.append(indent).append(" ").append(trimLeft(line));
+ }
+
+ return sb.toString();
+ }
+
+ /**
+ * Autodetect the indentation of a given line:
+ * <pre>
+ * autodetectIndentation( null ) = "";
+ * autodetectIndentation( "a" ) = "";
+ * autodetectIndentation( " a" ) = " ";
+ * autodetectIndentation( "\ta" ) = "\t";
+ * </pre>
+ *
+ * @param line not null
+ * @return the indentation for the given line.
+ */
+ private static String autodetectIndentation(final String line) {
+ if (StringUtils.isEmpty(line)) {
+ return "";
+ }
+
+ return line.substring(0, line.indexOf(trimLeft(line)));
+ }
+
+ /**
+ * @param content not null
+ * @return an array of all content lines
+ * @throws IOException if any
+ */
+ private static String[] getLines(final String content) throws IOException {
+ List<String> lines = new LinkedList<>();
+
+ BufferedReader reader = new BufferedReader(new StringReader(content));
+ String line = reader.readLine();
+ while (line != null) {
+ lines.add(line);
+ line = reader.readLine();
+ }
+
+ return lines.toArray(new String[lines.size()]);
+ }
+
+ /**
+ * Trim a given line on the left:
+ * <pre>
+ * trimLeft( null ) = "";
+ * trimLeft( " " ) = "";
+ * trimLeft( "a" ) = "a";
+ * trimLeft( " a" ) = "a";
+ * trimLeft( "\ta" ) = "a";
+ * trimLeft( " a " ) = "a ";
+ * </pre>
+ *
+ * @param text
+ * @return the text trimmed on left side or empty if text is null.
+ */
+ private static String trimLeft(final String text) {
+ if (StringUtils.isEmpty(text) || StringUtils.isEmpty(text.trim())) {
+ return "";
+ }
+
+ String textTrimmed = text.trim();
+ return text.substring(text.indexOf(textTrimmed));
+ }
+
+ /**
+ * Trim a given line on the right:
+ * <pre>
+ * trimRight( null ) = "";
+ * trimRight( " " ) = "";
+ * trimRight( "a" ) = "a";
+ * trimRight( "a\t" ) = "a";
+ * trimRight( " a " ) = " a";
+ * </pre>
+ *
+ * @param text
+ * @return the text trimmed on tight side or empty if text is null.
+ */
+ private static String trimRight(final String text) {
+ if (StringUtils.isEmpty(text) || StringUtils.isEmpty(text.trim())) {
+ return "";
+ }
+
+ String textTrimmed = text.trim();
+ return text.substring(0, text.indexOf(textTrimmed) + textTrimmed.length());
+ }
+
+ /**
+ * Wrapper class for the entity's tags.
+ */
+ class JavaEntityTags {
+ private final JavaAnnotatedElement entity;
+
+ private final boolean isJavaMethod;
+
+ /**
+ * List of tag names.
+ */
+ private List<String> namesTags;
+
+ /**
+ * Map with java parameter as key and original Javadoc lines as values.
+ */
+ private Map<String, String> tagParams;
+
+ private Set<String> documentedParams = new HashSet<>();
+
+ /**
+ * Original javadoc lines.
+ */
+ private String tagReturn;
+
+ /**
+ * Map with java throw as key and original Javadoc lines as values.
+ */
+ private Map<String, String> tagThrows;
+
+ /**
+ * Original javadoc lines for unknown tags.
+ */
+ private List<String> unknownsTags;
+
+ JavaEntityTags(JavaAnnotatedElement entity, boolean isJavaMethod) {
+ this.entity = entity;
+ this.isJavaMethod = isJavaMethod;
+ this.namesTags = new LinkedList<>();
+ this.tagParams = new LinkedHashMap<>();
+ this.tagThrows = new LinkedHashMap<>();
+ this.unknownsTags = new LinkedList<>();
+ }
+
+ public List<String> getNamesTags() {
+ return namesTags;
+ }
+
+ public String getJavadocReturnTag() {
+ return tagReturn;
+ }
+
+ public void setJavadocReturnTag(String s) {
+ tagReturn = s;
+ }
+
+ public List<String> getUnknownTags() {
+ return unknownsTags;
+ }
+
+ public void putJavadocParamTag(String paramName, String paramValue, String originalJavadocTag) {
+ documentedParams.add(paramName);
+ tagParams.put(paramValue, originalJavadocTag);
+ }
+
+ public String getJavadocParamTag(String paramValue) {
+ String originalJavadocTag = tagParams.get(paramValue);
+ if (originalJavadocTag == null && getLog().isWarnEnabled()) {
+ getLog().warn(getMessage(paramValue, "javaEntityTags.tagParams"));
+ }
+ return originalJavadocTag;
+ }
+
+ public boolean hasJavadocParamTag(String paramName) {
+ return documentedParams.contains(paramName);
+ }
+
+ public void putJavadocThrowsTag(String paramName, String originalJavadocTag) {
+ tagThrows.put(paramName, originalJavadocTag);
+ }
+
+ public String getJavadocThrowsTag(String paramName) {
+ return getJavadocThrowsTag(paramName, false);
+ }
+
+ public String getJavadocThrowsTag(String paramName, boolean nullable) {
+ String originalJavadocTag = tagThrows.get(paramName);
+ if (!nullable && originalJavadocTag == null && getLog().isWarnEnabled()) {
+ getLog().warn(getMessage(paramName, "javaEntityTags.tagThrows"));
+ }
+
+ return originalJavadocTag;
+ }
+
+ private String getMessage(String paramName, String mapName) {
+ StringBuilder msg = new StringBuilder();
+ msg.append("No param '")
+ .append(paramName)
+ .append("' key found in ")
+ .append(mapName)
+ .append(" for the entity: ");
+ if (isJavaMethod) {
+ JavaMethod javaMethod = (JavaMethod) entity;
+ msg.append(getJavaMethodAsString(javaMethod));
+ } else {
+ JavaClass javaClass = (JavaClass) entity;
+ msg.append(javaClass.getFullyQualifiedName());
+ }
+
+ return msg.toString();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("namesTags=").append(namesTags).append("\n");
+ sb.append("tagParams=").append(tagParams).append("\n");
+ sb.append("tagReturn=").append(tagReturn).append("\n");
+ sb.append("tagThrows=").append(tagThrows).append("\n");
+ sb.append("unknownsTags=").append(unknownsTags).append("\n");
+
+ return sb.toString();
+ }
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index 546f2b75..e9f38d54 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -1,5 +1,3 @@
-package org.apache.maven.plugins.javadoc;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.plugins.javadoc;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.plugins.javadoc;
import java.io.File;
import java.io.FileNotFoundException;
@@ -159,9 +158,7 @@ import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative;
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html">The javadoc Command</a>
* @since 2.0
*/
-public abstract class AbstractJavadocMojo
- extends AbstractMojo
-{
+public abstract class AbstractJavadocMojo extends AbstractMojo {
/**
* Classifier used in the name of the javadoc-options XML file, and in the resources bundle
* artifact that gets attached to the project. This one is used for non-test javadocs.
@@ -183,7 +180,7 @@ public abstract class AbstractJavadocMojo
/**
* The Javadoc script file name when <code>debug</code> parameter is on, i.e. javadoc.bat or javadoc.sh
*/
- protected static final String DEBUG_JAVADOC_SCRIPT_NAME = "javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" );
+ protected static final String DEBUG_JAVADOC_SCRIPT_NAME = "javadoc." + (SystemUtils.IS_OS_WINDOWS ? "bat" : "sh");
/**
* The <code>options</code> file name in the output directory when calling:
@@ -218,7 +215,6 @@ public abstract class AbstractJavadocMojo
private static final String PACKAGE_LIST = "package-list";
private static final String ELEMENT_LIST = "element-list";
-
/**
* For Javadoc options appears since Java 1.4.
* See <a href="https://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/whatsnew-1.4.1.html#summary">
@@ -226,7 +222,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- private static final JavaVersion SINCE_JAVADOC_1_4 = JavaVersion.parse( "1.4" );
+ private static final JavaVersion SINCE_JAVADOC_1_4 = JavaVersion.parse("1.4");
/**
* For Javadoc options appears since Java 1.4.2.
@@ -236,7 +232,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- private static final JavaVersion SINCE_JAVADOC_1_4_2 = JavaVersion.parse( "1.4.2" );
+ private static final JavaVersion SINCE_JAVADOC_1_4_2 = JavaVersion.parse("1.4.2");
/**
* For Javadoc options appears since Java 5.0.
@@ -246,7 +242,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- private static final JavaVersion SINCE_JAVADOC_1_5 = JavaVersion.parse( "1.5" );
+ private static final JavaVersion SINCE_JAVADOC_1_5 = JavaVersion.parse("1.5");
/**
* For Javadoc options appears since Java 6.0.
@@ -255,7 +251,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.4
*/
- private static final JavaVersion SINCE_JAVADOC_1_6 = JavaVersion.parse( "1.6" );
+ private static final JavaVersion SINCE_JAVADOC_1_6 = JavaVersion.parse("1.6");
/**
* For Javadoc options appears since Java 8.0.
@@ -264,7 +260,7 @@ public abstract class AbstractJavadocMojo
*
* @since 3.0.0
*/
- private static final JavaVersion SINCE_JAVADOC_1_8 = JavaVersion.parse( "1.8" );
+ private static final JavaVersion SINCE_JAVADOC_1_8 = JavaVersion.parse("1.8");
/**
*
@@ -289,7 +285,7 @@ public abstract class AbstractJavadocMojo
@Component
private RepositorySystem repoSystem;
- @Parameter( defaultValue = "${repositorySystemSession}", readonly = true, required = true )
+ @Parameter(defaultValue = "${repositorySystemSession}", readonly = true, required = true)
private RepositorySystemSession repoSession;
@Component
@@ -317,7 +313,7 @@ public abstract class AbstractJavadocMojo
* The current build session instance. This is used for
* toolchain manager API calls.
*/
- @Parameter( defaultValue = "${session}", readonly = true, required = true )
+ @Parameter(defaultValue = "${session}", readonly = true, required = true)
protected MavenSession session;
/**
@@ -325,22 +321,22 @@ public abstract class AbstractJavadocMojo
*
* @since 2.3
*/
- @Parameter( defaultValue = "${settings}", readonly = true, required = true )
+ @Parameter(defaultValue = "${settings}", readonly = true, required = true)
private Settings settings;
/**
* The Maven Project Object
*/
- @Parameter( defaultValue = "${project}", readonly = true, required = true )
+ @Parameter(defaultValue = "${project}", readonly = true, required = true)
protected MavenProject project;
- @Parameter( defaultValue = "${mojoExecution}", readonly = true )
+ @Parameter(defaultValue = "${mojoExecution}", readonly = true)
private MojoExecution mojo;
/**
* Specify if the Javadoc should operate in offline mode.
*/
- @Parameter( defaultValue = "${settings.offline}", required = true, readonly = true )
+ @Parameter(defaultValue = "${settings.offline}", required = true, readonly = true)
private boolean isOffline;
/**
@@ -353,7 +349,7 @@ public abstract class AbstractJavadocMojo
* @see #docfilessubdirs
* @since 2.1
*/
- @Parameter( defaultValue = "${basedir}/src/main/javadoc" )
+ @Parameter(defaultValue = "${basedir}/src/main/javadoc")
private File javadocDirectory;
/**
@@ -380,7 +376,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.3
*/
- @Parameter( property = "additionalJOption" )
+ @Parameter(property = "additionalJOption")
private String additionalJOption;
/**
@@ -417,19 +413,19 @@ public abstract class AbstractJavadocMojo
*
* @since 2.5
*/
- @Parameter( property = "resourcesArtifacts" )
+ @Parameter(property = "resourcesArtifacts")
private ResourcesArtifact[] resourcesArtifacts;
/**
* The local repository where the artifacts are located.
*/
- @Parameter( property = "localRepository" )
+ @Parameter(property = "localRepository")
private ArtifactRepository localRepository;
/**
* The projects in the reactor for aggregation report.
*/
- @Parameter( property = "reactorProjects", readonly = true )
+ @Parameter(property = "reactorProjects", readonly = true)
private List<MavenProject> reactorProjects;
/**
@@ -439,7 +435,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- @Parameter( property = "debug", defaultValue = "false" )
+ @Parameter(property = "debug", defaultValue = "false")
private boolean debug;
/**
@@ -448,7 +444,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.3
*/
- @Parameter( property = "javadocExecutable" )
+ @Parameter(property = "javadocExecutable")
private String javadocExecutable;
/**
@@ -456,7 +452,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.3
*/
- @Parameter( property = "javadocVersion" )
+ @Parameter(property = "javadocVersion")
private String javadocVersion;
/**
@@ -469,7 +465,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.5
*/
- @Parameter( property = "maven.javadoc.skip", defaultValue = "false" )
+ @Parameter(property = "maven.javadoc.skip", defaultValue = "false")
protected boolean skip;
/**
@@ -477,16 +473,15 @@ public abstract class AbstractJavadocMojo
*
* @since 2.5
*/
- @Parameter( property = "maven.javadoc.failOnError", defaultValue = "true" )
+ @Parameter(property = "maven.javadoc.failOnError", defaultValue = "true")
protected boolean failOnError;
-
/**
* Specifies if the build will fail if there are warning during javadoc execution or not.
*
* @since 3.0.1
*/
- @Parameter( property = "maven.javadoc.failOnWarnings", defaultValue = "false" )
+ @Parameter(property = "maven.javadoc.failOnWarnings", defaultValue = "false")
protected boolean failOnWarnings;
/**
@@ -508,7 +503,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.5
*/
- @Parameter( property = "useStandardDocletOptions", defaultValue = "true" )
+ @Parameter(property = "useStandardDocletOptions", defaultValue = "true")
protected boolean useStandardDocletOptions;
/**
@@ -529,7 +524,7 @@ public abstract class AbstractJavadocMojo
* @see #dependencyLinks
* @since 2.6
*/
- @Parameter( property = "detectLinks", defaultValue = "false" )
+ @Parameter(property = "detectLinks", defaultValue = "false")
private boolean detectLinks;
/**
@@ -548,7 +543,7 @@ public abstract class AbstractJavadocMojo
* @see #offlineLinks
* @since 2.6
*/
- @Parameter( property = "detectOfflineLinks", defaultValue = "true" )
+ @Parameter(property = "detectOfflineLinks", defaultValue = "true")
private boolean detectOfflineLinks;
/**
@@ -564,7 +559,7 @@ public abstract class AbstractJavadocMojo
* @see #javaApiLinks
* @since 2.6
*/
- @Parameter( property = "detectJavaApiLink", defaultValue = "true" )
+ @Parameter(property = "detectJavaApiLink", defaultValue = "true")
private boolean detectJavaApiLink;
/**
@@ -583,7 +578,7 @@ public abstract class AbstractJavadocMojo
* </dl>
* @since 2.6
*/
- @Parameter( property = "javaApiLinks" )
+ @Parameter(property = "javaApiLinks")
private Properties javaApiLinks;
/**
@@ -592,7 +587,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.8
*/
- @Parameter( property = "validateLinks", defaultValue = "false" )
+ @Parameter(property = "validateLinks", defaultValue = "false")
private boolean validateLinks;
// ----------------------------------------------------------------------
@@ -607,7 +602,7 @@ public abstract class AbstractJavadocMojo
* Javadoc option bootclasspath</a>.
* @since 2.5
*/
- @Parameter( property = "bootclasspath" )
+ @Parameter(property = "bootclasspath")
private String bootclasspath;
/**
@@ -631,7 +626,7 @@ public abstract class AbstractJavadocMojo
* Javadoc option bootclasspath</a>
* @since 2.5
*/
- @Parameter( property = "bootclasspathArtifacts" )
+ @Parameter(property = "bootclasspathArtifacts")
private BootclasspathArtifact[] bootclasspathArtifacts;
/**
@@ -640,14 +635,14 @@ public abstract class AbstractJavadocMojo
* "https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">
* Javadoc option breakiterator</a>.
*/
- @Parameter( property = "breakiterator", defaultValue = "false" )
+ @Parameter(property = "breakiterator", defaultValue = "false")
private boolean breakiterator;
/**
* Specifies the class file that starts the doclet used in generating the documentation.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option doclet</a>.
*/
- @Parameter( property = "doclet" )
+ @Parameter(property = "doclet")
private String doclet;
/**
@@ -667,7 +662,7 @@ public abstract class AbstractJavadocMojo
* <br/>
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option docletpath</a>.
*/
- @Parameter( property = "docletArtifact" )
+ @Parameter(property = "docletArtifact")
private DocletArtifact docletArtifact;
/**
@@ -690,7 +685,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option docletpath</a>.
* @since 2.1
*/
- @Parameter( property = "docletArtifacts" )
+ @Parameter(property = "docletArtifacts")
private DocletArtifact[] docletArtifacts;
/**
@@ -699,7 +694,7 @@ public abstract class AbstractJavadocMojo
* a colon (<code>:</code>) or a semicolon (<code>;</code>).
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option docletpath</a>.
*/
- @Parameter( property = "docletPath" )
+ @Parameter(property = "docletPath")
private String docletPath;
/**
@@ -710,7 +705,7 @@ public abstract class AbstractJavadocMojo
* this was reverted in 2.5.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-encoding">Javadoc option encoding</a>.
*/
- @Parameter( property = "encoding", defaultValue = "${project.build.sourceEncoding}" )
+ @Parameter(property = "encoding", defaultValue = "${project.build.sourceEncoding}")
private String encoding;
/**
@@ -730,7 +725,7 @@ public abstract class AbstractJavadocMojo
* </pre>
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option exclude</a>.
*/
- @Parameter( property = "excludePackageNames" )
+ @Parameter(property = "excludePackageNames")
private String excludePackageNames;
/**
@@ -738,14 +733,14 @@ public abstract class AbstractJavadocMojo
* colon (<code>:</code>) or a semicolon (<code>;</code>).
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-extdirs">Javadoc option extdirs</a>.
*/
- @Parameter( property = "extdirs" )
+ @Parameter(property = "extdirs")
private String extdirs;
/**
* Specifies the locale that javadoc uses when generating documentation.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option locale</a>.
*/
- @Parameter( property = "locale" )
+ @Parameter(property = "locale")
private String locale;
/**
@@ -755,7 +750,7 @@ public abstract class AbstractJavadocMojo
* <code>m</code>, <code>mb</code>, <code>g</code>, <code>gb</code>, <code>t</code>, <code>tb</code>.
* If no unit specified, the default unit is <code>m</code>.
*/
- @Parameter( property = "maxmemory" )
+ @Parameter(property = "maxmemory")
private String maxmemory;
/**
@@ -765,7 +760,7 @@ public abstract class AbstractJavadocMojo
* <code>m</code>, <code>mb</code>, <code>g</code>, <code>gb</code>, <code>t</code>, <code>tb</code>.
* If no unit specified, the default unit is <code>m</code>.
*/
- @Parameter( property = "minmemory" )
+ @Parameter(property = "minmemory")
private String minmemory;
/**
@@ -773,7 +768,7 @@ public abstract class AbstractJavadocMojo
* Javadoc 1.1. This is no longer supported since Javadoc 1.4 (shipped with JDK 1.4)
* @see <a href="https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javadoc.html#a1.1">Javadoc option 1.1</a>.
*/
- @Parameter( property = "old", defaultValue = "false" )
+ @Parameter(property = "old", defaultValue = "false")
private boolean old;
/**
@@ -784,7 +779,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Javadoc option overview</a>.
* <br/>
*/
- @Parameter( property = "overview", defaultValue = "${basedir}/src/main/javadoc/overview.html" )
+ @Parameter(property = "overview", defaultValue = "${basedir}/src/main/javadoc/overview.html")
private File overview;
/**
@@ -797,7 +792,7 @@ public abstract class AbstractJavadocMojo
* Since Java 5.0.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option quiet</a>.
*/
- @Parameter( property = "quiet", defaultValue = "false" )
+ @Parameter(property = "quiet", defaultValue = "false")
private boolean quiet;
/**
@@ -811,14 +806,14 @@ public abstract class AbstractJavadocMojo
* </ul>
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc options private, protected, public and package</a>
*/
- @Parameter( property = "show", defaultValue = "protected" )
+ @Parameter(property = "show", defaultValue = "protected")
private String show;
/**
* Provide source compatibility with specified release. Since JDK 9 rather use {@link #release}.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-source">Javadoc option source</a>.
*/
- @Parameter( property = "source", defaultValue = "${maven.compiler.source}" )
+ @Parameter(property = "source", defaultValue = "${maven.compiler.source}")
private String source;
/**
@@ -827,7 +822,7 @@ public abstract class AbstractJavadocMojo
* @since JDK 9
* @since 3.1.0
*/
- @Parameter( defaultValue = "${maven.compiler.release}" )
+ @Parameter(defaultValue = "${maven.compiler.release}")
private String release;
/**
@@ -835,7 +830,7 @@ public abstract class AbstractJavadocMojo
* multiple paths by separating them with a colon (<code>:</code>) or a semicolon (<code>;</code>).
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-source-path">Javadoc option sourcepath</a>.
*/
- @Parameter( property = "sourcepath" )
+ @Parameter(property = "sourcepath")
private String sourcepath;
/**
@@ -843,14 +838,14 @@ public abstract class AbstractJavadocMojo
* colons (<code>:</code>).
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option subpackages</a>.
*/
- @Parameter( property = "subpackages" )
+ @Parameter(property = "subpackages")
private String subpackages;
/**
* Provides more detailed messages while javadoc is running.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#options-for-javadoc">Javadoc option verbose</a>.
*/
- @Parameter( property = "verbose", defaultValue = "false" )
+ @Parameter(property = "verbose", defaultValue = "false")
private boolean verbose;
// ----------------------------------------------------------------------
@@ -861,7 +856,7 @@ public abstract class AbstractJavadocMojo
* Specifies whether or not the author text is included in the generated Javadocs.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option author</a>.
*/
- @Parameter( property = "author", defaultValue = "true" )
+ @Parameter(property = "author", defaultValue = "true")
private boolean author;
/**
@@ -873,9 +868,10 @@ public abstract class AbstractJavadocMojo
* be used as {currentYear}. This way it is possible to generate reproducible javadoc jars.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option bottom</a>.
*/
- @Parameter( property = "bottom",
- defaultValue = "Copyright © {inceptionYear}–{currentYear} {organizationName}. "
- + "All rights reserved." )
+ @Parameter(
+ property = "bottom",
+ defaultValue = "Copyright © {inceptionYear}–{currentYear} {organizationName}. "
+ + "All rights reserved.")
private String bottom;
/**
@@ -883,7 +879,7 @@ public abstract class AbstractJavadocMojo
* the {@link #docencoding} parameter.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option charset</a>.
*/
- @Parameter( property = "charset" )
+ @Parameter(property = "charset")
private String charset;
/**
@@ -891,7 +887,7 @@ public abstract class AbstractJavadocMojo
* <code>UTF-8</code>.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option docencoding</a>.
*/
- @Parameter( property = "docencoding", defaultValue = "${project.reporting.outputEncoding}" )
+ @Parameter(property = "docencoding", defaultValue = "${project.reporting.outputEncoding}")
private String docencoding;
/**
@@ -902,7 +898,7 @@ public abstract class AbstractJavadocMojo
* @see #excludedocfilessubdir
* @see #javadocDirectory
*/
- @Parameter( property = "docfilessubdirs", defaultValue = "false" )
+ @Parameter(property = "docfilessubdirs", defaultValue = "false")
private boolean docfilessubdirs;
/**
@@ -911,14 +907,14 @@ public abstract class AbstractJavadocMojo
*
* @since 3.0.0
*/
- @Parameter( property = "doclint" )
+ @Parameter(property = "doclint")
private String doclint;
/**
* Specifies the title to be placed near the top of the overview summary file.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option doctitle</a>.
*/
- @Parameter( property = "doctitle", defaultValue = "${project.name} ${project.version} API" )
+ @Parameter(property = "doctitle", defaultValue = "${project.name} ${project.version} API")
private String doctitle;
/**
@@ -927,14 +923,14 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option excludedocfilessubdir</a>.
* @see #docfilessubdirs
*/
- @Parameter( property = "excludedocfilessubdir" )
+ @Parameter(property = "excludedocfilessubdir")
private String excludedocfilessubdir;
/**
* Specifies the footer text to be placed at the bottom of each output file.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option footer</a>.
*/
- @Parameter( property = "footer" )
+ @Parameter(property = "footer")
private String footer;
/**
@@ -973,7 +969,7 @@ public abstract class AbstractJavadocMojo
* Specifies the header text to be placed at the top of each output file.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option header</a>.
*/
- @Parameter( property = "header" )
+ @Parameter(property = "header")
private String header;
/**
@@ -1017,7 +1013,7 @@ public abstract class AbstractJavadocMojo
* <code>groupId:artifactId:version</code> javadoc plugin dependency.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option helpfile</a>.
*/
- @Parameter( property = "helpfile" )
+ @Parameter(property = "helpfile")
private String helpfile;
/**
@@ -1026,7 +1022,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- @Parameter( property = "keywords", defaultValue = "false" )
+ @Parameter(property = "keywords", defaultValue = "false")
private boolean keywords;
/**
@@ -1035,7 +1031,7 @@ public abstract class AbstractJavadocMojo
* <b>Notes</b>:
* <ol>
* <li>only used if {@code isOffline} is set to <code>false</code>.</li>
- * <li>all given links should have a fetchable <code>/package-list</code> or <code>/element-list</code>
+ * <li>all given links should have a fetchable <code>/package-list</code> or <code>/element-list</code>
* (since Java 10). For instance:
* <pre>
* <links>
@@ -1050,10 +1046,9 @@ public abstract class AbstractJavadocMojo
* </ol>
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option link</a>.
*/
- @Parameter( property = "links" )
+ @Parameter(property = "links")
protected ArrayList<String> links;
-
/**
* Redefine the apidoc URL for specific dependencies when using {@link #detectLinks}.
* Useful if the dependency wasn't build with Maven or when the apidocs have been moved.
@@ -1080,14 +1075,14 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option linksource/a>.
* <br/>
*/
- @Parameter( property = "linksource", defaultValue = "false" )
+ @Parameter(property = "linksource", defaultValue = "false")
private boolean linksource;
/**
* Suppress the entire comment body, including the main description and all tags, generating only declarations.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option nocomment</a>.
*/
- @Parameter( property = "nocomment", defaultValue = "false" )
+ @Parameter(property = "nocomment", defaultValue = "false")
private boolean nocomment;
/**
@@ -1095,7 +1090,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option nodeprecated</a>.
* <br/>
*/
- @Parameter( property = "nodeprecated", defaultValue = "false" )
+ @Parameter(property = "nodeprecated", defaultValue = "false")
private boolean nodeprecated;
/**
@@ -1104,7 +1099,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">
* Doclet option nodeprecatedlist</a>.
*/
- @Parameter( property = "nodeprecatedlist", defaultValue = "false" )
+ @Parameter(property = "nodeprecatedlist", defaultValue = "false")
private boolean nodeprecatedlist;
/**
@@ -1113,7 +1108,7 @@ public abstract class AbstractJavadocMojo
* <b>Note</b>: could be in conflict with {@link #helpfile}.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option nohelp</a>.
*/
- @Parameter( property = "nohelp", defaultValue = "false" )
+ @Parameter(property = "nohelp", defaultValue = "false")
private boolean nohelp;
/**
@@ -1122,14 +1117,14 @@ public abstract class AbstractJavadocMojo
* <b>Note</b>: could be in conflict with {@link #splitindex}
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option noindex</a>.
*/
- @Parameter( property = "noindex", defaultValue = "false" )
+ @Parameter(property = "noindex", defaultValue = "false")
private boolean noindex;
/**
* Omits the navigation bar from the generated docs.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option nonavbar</a>.
*/
- @Parameter( property = "nonavbar", defaultValue = "false" )
+ @Parameter(property = "nonavbar", defaultValue = "false")
private boolean nonavbar;
/**
@@ -1142,7 +1137,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.4
*/
- @Parameter( property = "nooverview", defaultValue = "false" )
+ @Parameter(property = "nooverview", defaultValue = "false")
private boolean nooverview;
/**
@@ -1155,14 +1150,14 @@ public abstract class AbstractJavadocMojo
* </pre>
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option noqualifier</a>.
*/
- @Parameter( property = "noqualifier" )
+ @Parameter(property = "noqualifier")
private String noqualifier;
/**
* Omits from the generated docs the "Since" sections associated with the since tags.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option nosince</a>.
*/
- @Parameter( property = "nosince", defaultValue = "false" )
+ @Parameter(property = "nosince", defaultValue = "false")
private boolean nosince;
/**
@@ -1174,14 +1169,14 @@ public abstract class AbstractJavadocMojo
*
* @since 2.1
*/
- @Parameter( property = "notimestamp", defaultValue = "false" )
+ @Parameter(property = "notimestamp", defaultValue = "false")
private boolean notimestamp;
/**
* Omits the class/interface hierarchy pages from the generated docs.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option notree</a>
*/
- @Parameter( property = "notree", defaultValue = "false" )
+ @Parameter(property = "notree", defaultValue = "false")
private boolean notree;
/**
@@ -1203,15 +1198,18 @@ public abstract class AbstractJavadocMojo
* @see OfflineLink.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet">Doclet option linkoffline</a>
*/
- @Parameter( property = "offlineLinks" )
+ @Parameter(property = "offlineLinks")
private OfflineLink[] offlineLinks;
/**
* Specifies the destination directory where javadoc saves the generated HTML files.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#additional-options-provided-by-the-standard-doclet">Doclet option d</a>
*/
- @Parameter( property = "destDir", alias = "destDir", defaultValue = "${project.build.directory}/apidocs",
- required = true )
+ @Parameter(
+ property = "destDir",
+ alias = "destDir",
+ defaultValue = "${project.build.directory}/apidocs",
+ required = true)
protected File outputDirectory;
/**
@@ -1219,14 +1217,14 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://bugs.openjdk.org/browse/JDK-4770521">Bug Report about missing documentation</a>
* @since 2.1
*/
- @Parameter( property = "packagesheader" )
+ @Parameter(property = "packagesheader")
private String packagesheader;
/**
* Generates compile-time warnings for missing serial tags.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option serialwarn</a>
*/
- @Parameter( property = "serialwarn", defaultValue = "false" )
+ @Parameter(property = "serialwarn", defaultValue = "false")
private boolean serialwarn;
/**
@@ -1236,7 +1234,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option sourcetab</a>
* @since 2.1
*/
- @Parameter( property = "sourcetab", alias = "linksourcetab" )
+ @Parameter(property = "sourcetab", alias = "linksourcetab")
private int sourcetab;
/**
@@ -1246,7 +1244,7 @@ public abstract class AbstractJavadocMojo
* <b>Note</b>: could be in conflict with {@link #noindex}.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option splitindex</a>.
*/
- @Parameter( property = "splitindex", defaultValue = "false" )
+ @Parameter(property = "splitindex", defaultValue = "false")
private boolean splitindex;
/**
@@ -1256,7 +1254,7 @@ public abstract class AbstractJavadocMojo
* Possible values: <code>maven<code> or <code>java</code>.
* @deprecated This is no longer evaluated, instead use {@link #addStylesheets} to customize the CSS.
*/
- @Parameter( property = "stylesheet", defaultValue = "java" )
+ @Parameter(property = "stylesheet", defaultValue = "java")
@Deprecated
private String stylesheet;
@@ -1296,10 +1294,10 @@ public abstract class AbstractJavadocMojo
* </pre>
* Where <code>path/to/your/resource/yourstylesheet.css</code> is defined in the
* <code>groupId:artifactId:version</code> javadoc plugin dependency.
- * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option
+ * @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option
* stylesheetfile</a>.
*/
- @Parameter( property = "stylesheetfile" )
+ @Parameter(property = "stylesheetfile")
private String stylesheetfile;
/**
@@ -1319,7 +1317,7 @@ public abstract class AbstractJavadocMojo
* Specifies the class file that starts the taglet used in generating the documentation for that tag.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option taglet</a>.
*/
- @Parameter( property = "taglet" )
+ @Parameter(property = "taglet")
private String taglet;
/**
@@ -1347,7 +1345,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option tagletpath</a>.
* @since 2.1
*/
- @Parameter( property = "tagletArtifact" )
+ @Parameter(property = "tagletArtifact")
private TagletArtifact tagletArtifact;
/**
@@ -1370,7 +1368,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet options taglet and tagletpath</a>
* @since 2.5
*/
- @Parameter( property = "tagletArtifacts" )
+ @Parameter(property = "tagletArtifacts")
private TagletArtifact[] tagletArtifacts;
/**
@@ -1378,7 +1376,7 @@ public abstract class AbstractJavadocMojo
* multiple paths by separating them with a colon (<code>:</code>) or a semicolon (<code>;</code>).
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option tagletpath</a>.
*/
- @Parameter( property = "tagletpath" )
+ @Parameter(property = "tagletpath")
private String tagletpath;
/**
@@ -1404,7 +1402,7 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet options taglet and tagletpath</a>
* @since 2.1
*/
- @Parameter( property = "taglets" )
+ @Parameter(property = "taglets")
private Taglet[] taglets;
/**
@@ -1434,7 +1432,7 @@ public abstract class AbstractJavadocMojo
* See <a href="./apidocs/org/apache/maven/plugins/javadoc/options/Tag.html">Javadoc</a>.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option tag</a>.
*/
- @Parameter( property = "tags" )
+ @Parameter(property = "tags")
private Tag[] tags;
/**
@@ -1443,28 +1441,28 @@ public abstract class AbstractJavadocMojo
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option top</a>.
* @since 2.4
*/
- @Parameter( property = "top" )
+ @Parameter(property = "top")
private String top;
/**
* Includes one "Use" page for each documented class and package.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option use</a>.
*/
- @Parameter( property = "use", defaultValue = "true" )
+ @Parameter(property = "use", defaultValue = "true")
private boolean use;
/**
* Includes the given version text in the generated docs.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option version</a>.
*/
- @Parameter( property = "version", defaultValue = "true" )
+ @Parameter(property = "version", defaultValue = "true")
private boolean version;
/**
* Specifies the title to be placed in the HTML title tag.
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javadoc.html#standard-doclet-options">Doclet option windowtitle</a>.
*/
- @Parameter( property = "windowtitle", defaultValue = "${project.name} ${project.version} API" )
+ @Parameter(property = "windowtitle", defaultValue = "${project.name} ${project.version} API")
private String windowtitle;
/**
@@ -1473,7 +1471,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.7
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
private boolean includeDependencySources;
/**
@@ -1482,7 +1480,7 @@ public abstract class AbstractJavadocMojo
* @see #includeDependencySources
* @since 2.7
*/
- @Parameter( defaultValue = "${project.build.directory}/distro-javadoc-sources" )
+ @Parameter(defaultValue = "${project.build.directory}/distro-javadoc-sources")
private File sourceDependencyCacheDir;
/**
@@ -1494,7 +1492,7 @@ public abstract class AbstractJavadocMojo
* @deprecated if these sources depend on transitive dependencies, those dependencies should be added to the pom as
* direct dependencies
*/
- @Parameter( defaultValue = "false" )
+ @Parameter(defaultValue = "false")
@Deprecated
private boolean includeTransitiveDependencySources;
@@ -1522,7 +1520,7 @@ public abstract class AbstractJavadocMojo
*
* @since 2.7
*/
- @Parameter( defaultValue = "${project.build.directory}/javadoc-bundle-options", readonly = true )
+ @Parameter(defaultValue = "${project.build.directory}/javadoc-bundle-options", readonly = true)
private File javadocOptionsDir;
/**
@@ -1570,11 +1568,11 @@ public abstract class AbstractJavadocMojo
private List<String> sourceFileExcludes;
/**
- * To apply a security fix on generated javadoc, see
+ * To apply a security fix on generated javadoc, see
* <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2013-1571>CVE-2013-157</a>.
* @since 2.9.1
*/
- @Parameter( defaultValue = "true", property = "maven.javadoc.applyJavadocSecurityFix" )
+ @Parameter(defaultValue = "true", property = "maven.javadoc.applyJavadocSecurityFix")
private boolean applyJavadocSecurityFix = true;
/**
@@ -1621,11 +1619,11 @@ public abstract class AbstractJavadocMojo
*
* @since 3.2.0
*/
- @Parameter( property = "staleDataPath",
- defaultValue = "${project.build.directory}/maven-javadoc-plugin-stale-data.txt" )
+ @Parameter(
+ property = "staleDataPath",
+ defaultValue = "${project.build.directory}/maven-javadoc-plugin-stale-data.txt")
private File staleDataPath;
-
/**
* <p>
* Comma separated list of modules (artifactId) to not add in aggregated javadoc
@@ -1633,7 +1631,7 @@ public abstract class AbstractJavadocMojo
*
* @since 3.2.0
*/
- @Parameter( property = "maven.javadoc.skippedModules" )
+ @Parameter(property = "maven.javadoc.skippedModules")
private String skippedModules;
/**
@@ -1643,7 +1641,7 @@ public abstract class AbstractJavadocMojo
*
* @since 3.2.0
*/
- @Parameter( defaultValue = "${project.build.outputTimestamp}" )
+ @Parameter(defaultValue = "${project.build.outputTimestamp}")
protected String outputTimestamp;
// ----------------------------------------------------------------------
@@ -1657,8 +1655,7 @@ public abstract class AbstractJavadocMojo
* @see AggregatorJavadocReport
* @see AggregatorTestJavadocReport
*/
- protected boolean isAggregator()
- {
+ protected boolean isAggregator() {
return false;
}
@@ -1667,21 +1664,18 @@ public abstract class AbstractJavadocMojo
*
* @return <code>true</code> if the goal generates Test Javadocs, <code>false</code> otherwise.
*/
- protected boolean isTest()
- {
+ protected boolean isTest() {
return false;
}
/**
* @return the output directory
*/
- protected String getOutputDirectory()
- {
+ protected String getOutputDirectory() {
return outputDirectory.getAbsoluteFile().toString();
}
- protected MavenProject getProject()
- {
+ protected MavenProject getProject() {
return project;
}
@@ -1690,14 +1684,12 @@ public abstract class AbstractJavadocMojo
* @return the list of directories where compiled classes are placed for the given project. These dirs are
* added in the javadoc classpath.
*/
- protected List<File> getProjectBuildOutputDirs( MavenProject p )
- {
- if ( StringUtils.isEmpty( p.getBuild().getOutputDirectory() ) )
- {
+ protected List<File> getProjectBuildOutputDirs(MavenProject p) {
+ if (StringUtils.isEmpty(p.getBuild().getOutputDirectory())) {
return Collections.emptyList();
}
- return Collections.singletonList( new File( p.getBuild().getOutputDirectory() ) );
+ return Collections.singletonList(new File(p.getBuild().getOutputDirectory()));
}
/**
@@ -1706,38 +1698,28 @@ public abstract class AbstractJavadocMojo
* @param project
* @return
*/
- protected File getClassesFile( MavenProject project )
- {
- if ( !isAggregator() && isTest() )
- {
+ protected File getClassesFile(MavenProject project) {
+ if (!isAggregator() && isTest()) {
return null;
}
- if ( project.getArtifact() != null && project.getArtifact().getFile() != null )
- {
+ if (project.getArtifact() != null && project.getArtifact().getFile() != null) {
File artifactFile = project.getArtifact().getFile();
- if ( artifactFile.isDirectory() || artifactFile.getName().endsWith( ".jar" ) )
- {
+ if (artifactFile.isDirectory() || artifactFile.getName().endsWith(".jar")) {
return artifactFile;
}
- }
- else if ( project.getExecutionProject() != null
- && project.getExecutionProject().getArtifact() != null
- && project.getExecutionProject().getArtifact().getFile() != null )
- {
+ } else if (project.getExecutionProject() != null
+ && project.getExecutionProject().getArtifact() != null
+ && project.getExecutionProject().getArtifact().getFile() != null) {
File artifactFile = project.getExecutionProject().getArtifact().getFile();
- if ( artifactFile.isDirectory() || artifactFile.getName().endsWith( ".jar" ) )
- {
+ if (artifactFile.isDirectory() || artifactFile.getName().endsWith(".jar")) {
return artifactFile;
}
}
- if ( project.getBuild().getOutputDirectory() != null )
- {
- return new File( project.getBuild().getOutputDirectory() );
- }
- else
- {
+ if (project.getBuild().getOutputDirectory() != null) {
+ return new File(project.getBuild().getOutputDirectory());
+ } else {
return null;
}
}
@@ -1746,134 +1728,114 @@ public abstract class AbstractJavadocMojo
* @param p not null maven project
* @return the list of source paths for the given project
*/
- protected List<String> getProjectSourceRoots( MavenProject p )
- {
- if ( "pom".equals( p.getPackaging().toLowerCase() ) )
- {
+ protected List<String> getProjectSourceRoots(MavenProject p) {
+ if ("pom".equals(p.getPackaging().toLowerCase())) {
return Collections.emptyList();
}
- return ( p.getCompileSourceRoots() == null
- ? Collections.<String>emptyList()
- : new LinkedList<>( p.getCompileSourceRoots() ) );
+ return (p.getCompileSourceRoots() == null
+ ? Collections.<String>emptyList()
+ : new LinkedList<>(p.getCompileSourceRoots()));
}
/**
* @param p not null maven project
* @return the list of source paths for the execution project of the given project
*/
- protected List<String> getExecutionProjectSourceRoots( MavenProject p )
- {
- if ( "pom".equals( p.getExecutionProject().getPackaging().toLowerCase() ) )
- {
+ protected List<String> getExecutionProjectSourceRoots(MavenProject p) {
+ if ("pom".equals(p.getExecutionProject().getPackaging().toLowerCase())) {
return Collections.emptyList();
}
- return ( p.getExecutionProject().getCompileSourceRoots() == null
- ? Collections.<String>emptyList()
- : new LinkedList<>( p.getExecutionProject().getCompileSourceRoots() ) );
+ return (p.getExecutionProject().getCompileSourceRoots() == null
+ ? Collections.<String>emptyList()
+ : new LinkedList<>(p.getExecutionProject().getCompileSourceRoots()));
}
/**
* @return the current javadoc directory
*/
- protected File getJavadocDirectory()
- {
+ protected File getJavadocDirectory() {
return javadocDirectory;
}
/**
* @return the doclint specific checks configuration
*/
- protected String getDoclint()
- {
+ protected String getDoclint() {
return doclint;
}
/**
* @return the title to be placed near the top of the overview summary file
*/
- protected String getDoctitle()
- {
+ protected String getDoctitle() {
return doctitle;
}
/**
* @return the overview documentation file from the user parameter or from the <code>javadocdirectory</code>
*/
- protected File getOverview()
- {
+ protected File getOverview() {
return overview;
}
/**
* @return the title to be placed in the HTML title tag
*/
- protected String getWindowtitle()
- {
+ protected String getWindowtitle() {
return windowtitle;
}
/**
* @return the charset attribute or the value of {@link #getDocencoding()} if <code>null</code>.
*/
- private String getCharset()
- {
- return ( StringUtils.isEmpty( charset ) ) ? getDocencoding() : charset;
+ private String getCharset() {
+ return (StringUtils.isEmpty(charset)) ? getDocencoding() : charset;
}
/**
* @return the docencoding attribute or <code>UTF-8</code> if <code>null</code>.
*/
- private String getDocencoding()
- {
- return ( StringUtils.isEmpty( docencoding ) ) ? ReaderFactory.UTF_8 : docencoding;
+ private String getDocencoding() {
+ return (StringUtils.isEmpty(docencoding)) ? ReaderFactory.UTF_8 : docencoding;
}
/**
* @return the encoding attribute or the value of <code>file.encoding</code> system property if <code>null</code>.
*/
- private String getEncoding()
- {
- return ( StringUtils.isEmpty( encoding ) ) ? ReaderFactory.FILE_ENCODING : encoding;
+ private String getEncoding() {
+ return (StringUtils.isEmpty(encoding)) ? ReaderFactory.FILE_ENCODING : encoding;
}
@Override
- public void execute()
- throws MojoExecutionException, MojoFailureException
- {
- verifyRemovedParameter( "aggregator" );
- verifyRemovedParameter( "proxyHost" );
- verifyRemovedParameter( "proxyPort" );
- verifyReplacedParameter( "additionalparam", "additionalOptions" );
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ verifyRemovedParameter("aggregator");
+ verifyRemovedParameter("proxyHost");
+ verifyRemovedParameter("proxyPort");
+ verifyReplacedParameter("additionalparam", "additionalOptions");
doExecute();
}
abstract void doExecute() throws MojoExecutionException, MojoFailureException;
- protected final void verifyRemovedParameter( String paramName )
- {
+ protected final void verifyRemovedParameter(String paramName) {
Xpp3Dom configDom = mojo.getConfiguration();
- if ( configDom != null )
- {
- if ( configDom.getChild( paramName ) != null )
- {
- throw new IllegalArgumentException( "parameter '" + paramName
- + "' has been removed from the plugin, please verify documentation." );
+ if (configDom != null) {
+ if (configDom.getChild(paramName) != null) {
+ throw new IllegalArgumentException(
+ "parameter '" + paramName + "' has been removed from the plugin, please verify documentation.");
}
}
}
- private void verifyReplacedParameter( String oldParamName, String newParamNew )
- {
+ private void verifyReplacedParameter(String oldParamName, String newParamNew) {
Xpp3Dom configDom = mojo.getConfiguration();
- if ( configDom != null )
- {
- if ( configDom.getChild( oldParamName ) != null )
- {
- throw new IllegalArgumentException( "parameter '" + oldParamName
- + "' has been replaced with " + newParamNew + ", please verify documentation." );
+ if (configDom != null) {
+ if (configDom.getChild(oldParamName) != null) {
+ throw new IllegalArgumentException("parameter '" + oldParamName + "' has been replaced with "
+ + newParamNew + ", please verify documentation.");
}
}
}
@@ -1885,40 +1847,31 @@ public abstract class AbstractJavadocMojo
* @param unusedLocale the wanted locale (actually unused).
* @throws MavenReportException if any
*/
- protected void executeReport( Locale unusedLocale )
- throws MavenReportException
- {
- if ( skip )
- {
- getLog().info( "Skipping javadoc generation" );
+ protected void executeReport(Locale unusedLocale) throws MavenReportException {
+ if (skip) {
+ getLog().info("Skipping javadoc generation");
return;
}
- if ( getLog().isDebugEnabled() )
- {
+ if (getLog().isDebugEnabled()) {
this.debug = true;
}
// NOTE: Always generate this file, to allow javadocs from modules to be aggregated via
// useDependencySources in a distro module build.
- try
- {
+ try {
buildJavadocOptions();
- }
- catch ( IOException e )
- {
- throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );
+ } catch (IOException e) {
+ throw new MavenReportException("Failed to generate javadoc options file: " + e.getMessage(), e);
}
Collection<JavadocModule> sourcePaths = getSourcePaths();
- Collection<Path> collectedSourcePaths = sourcePaths.stream()
- .flatMap( e -> e.getSourcePaths().stream() )
- .collect( Collectors.toList() );
+ Collection<Path> collectedSourcePaths =
+ sourcePaths.stream().flatMap(e -> e.getSourcePaths().stream()).collect(Collectors.toList());
- Map<Path, Collection<String>> files = getFiles( collectedSourcePaths );
- if ( !canGenerateReport( files ) )
- {
+ Map<Path, Collection<String>> files = getFiles(collectedSourcePaths);
+ if (!canGenerateReport(files)) {
return;
}
@@ -1927,38 +1880,30 @@ public abstract class AbstractJavadocMojo
// ----------------------------------------------------------------------
String jExecutable;
- try
- {
+ try {
jExecutable = getJavadocExecutable();
+ } catch (IOException e) {
+ throw new MavenReportException("Unable to find javadoc command: " + e.getMessage(), e);
}
- catch ( IOException e )
- {
- throw new MavenReportException( "Unable to find javadoc command: " + e.getMessage(), e );
- }
- setFJavadocVersion( new File( jExecutable ) );
+ setFJavadocVersion(new File(jExecutable));
Collection<String> packageNames;
- if ( javadocRuntimeVersion.isAtLeast( "9" ) )
- {
- packageNames = getPackageNamesRespectingJavaModules( sourcePaths );
- }
- else
- {
- packageNames = getPackageNames( files );
+ if (javadocRuntimeVersion.isAtLeast("9")) {
+ packageNames = getPackageNamesRespectingJavaModules(sourcePaths);
+ } else {
+ packageNames = getPackageNames(files);
}
// ----------------------------------------------------------------------
// Javadoc output directory as File
// ----------------------------------------------------------------------
- File javadocOutputDirectory = new File( getOutputDirectory() );
- if ( javadocOutputDirectory.exists() && !javadocOutputDirectory.isDirectory() )
- {
- throw new MavenReportException( "IOException: " + getOutputDirectory() + " is not a directory." );
+ File javadocOutputDirectory = new File(getOutputDirectory());
+ if (javadocOutputDirectory.exists() && !javadocOutputDirectory.isDirectory()) {
+ throw new MavenReportException("IOException: " + getOutputDirectory() + " is not a directory.");
}
- if ( javadocOutputDirectory.exists() && !javadocOutputDirectory.canWrite() )
- {
- throw new MavenReportException( "IOException: " + getOutputDirectory() + " is not writable." );
+ if (javadocOutputDirectory.exists() && !javadocOutputDirectory.canWrite()) {
+ throw new MavenReportException("IOException: " + getOutputDirectory() + " is not writable.");
}
javadocOutputDirectory.mkdirs();
@@ -1966,35 +1911,32 @@ public abstract class AbstractJavadocMojo
// Copy all resources
// ----------------------------------------------------------------------
- copyAllResources( javadocOutputDirectory );
+ copyAllResources(javadocOutputDirectory);
// ----------------------------------------------------------------------
// Create command line for Javadoc
// ----------------------------------------------------------------------
Commandline cmd = new Commandline();
- cmd.getShell().setQuotedArgumentsEnabled( false ); // for Javadoc JVM args
- cmd.setWorkingDirectory( javadocOutputDirectory.getAbsolutePath() );
- cmd.setExecutable( jExecutable );
+ cmd.getShell().setQuotedArgumentsEnabled(false); // for Javadoc JVM args
+ cmd.setWorkingDirectory(javadocOutputDirectory.getAbsolutePath());
+ cmd.setExecutable(jExecutable);
// ----------------------------------------------------------------------
// Wrap Javadoc JVM args
// ----------------------------------------------------------------------
- addMemoryArg( cmd, "-Xmx", this.maxmemory );
- addMemoryArg( cmd, "-Xms", this.minmemory );
- addProxyArg( cmd );
+ addMemoryArg(cmd, "-Xmx", this.maxmemory);
+ addMemoryArg(cmd, "-Xms", this.minmemory);
+ addProxyArg(cmd);
- if ( StringUtils.isNotEmpty( additionalJOption ) )
- {
- cmd.createArg().setValue( additionalJOption );
+ if (StringUtils.isNotEmpty(additionalJOption)) {
+ cmd.createArg().setValue(additionalJOption);
}
- if ( additionalJOptions != null && additionalJOptions.length != 0 )
- {
- for ( String jo : additionalJOptions )
- {
- cmd.createArg().setValue( jo );
+ if (additionalJOptions != null && additionalJOptions.length != 0) {
+ for (String jo : additionalJOptions) {
+ cmd.createArg().setValue(jo);
}
}
@@ -2004,13 +1946,10 @@ public abstract class AbstractJavadocMojo
List<String> standardDocletArguments = new ArrayList<>();
Set<OfflineLink> offlineLinks;
- if ( StringUtils.isEmpty( doclet ) || useStandardDocletOptions )
- {
+ if (StringUtils.isEmpty(doclet) || useStandardDocletOptions) {
offlineLinks = getLinkofflines();
- addStandardDocletOptions( javadocOutputDirectory, standardDocletArguments, offlineLinks );
- }
- else
- {
+ addStandardDocletOptions(javadocOutputDirectory, standardDocletArguments, offlineLinks);
+ } else {
offlineLinks = Collections.emptySet();
}
@@ -2019,19 +1958,18 @@ public abstract class AbstractJavadocMojo
// ----------------------------------------------------------------------
List<String> javadocArguments = new ArrayList<>();
- addJavadocOptions( javadocOutputDirectory, javadocArguments, sourcePaths, offlineLinks );
+ addJavadocOptions(javadocOutputDirectory, javadocArguments, sourcePaths, offlineLinks);
// ----------------------------------------------------------------------
// Write options file and include it in the command line
// ----------------------------------------------------------------------
- List<String> arguments = new ArrayList<>( javadocArguments.size() + standardDocletArguments.size() );
- arguments.addAll( javadocArguments );
- arguments.addAll( standardDocletArguments );
+ List<String> arguments = new ArrayList<>(javadocArguments.size() + standardDocletArguments.size());
+ arguments.addAll(javadocArguments);
+ arguments.addAll(standardDocletArguments);
- if ( arguments.size() > 0 )
- {
- addCommandLineOptions( cmd, arguments, javadocOutputDirectory );
+ if (arguments.size() > 0) {
+ addCommandLineOptions(cmd, arguments, javadocOutputDirectory);
}
// ----------------------------------------------------------------------
@@ -2042,47 +1980,38 @@ public abstract class AbstractJavadocMojo
// package-based mode and force javadoc into file-based mode unless subpackages are
// specified. Subpackages take precedence over file-based include/excludes. Why? Because
// getFiles(...) returns an empty list when subpackages are specified.
- boolean includesExcludesActive =
- ( sourceFileIncludes != null && !sourceFileIncludes.isEmpty() )
- || ( sourceFileExcludes != null && !sourceFileExcludes.isEmpty() );
- if ( includesExcludesActive && !StringUtils.isEmpty( subpackages ) )
- {
- getLog().warn( "sourceFileIncludes and sourceFileExcludes have no effect when subpackages are specified!" );
+ boolean includesExcludesActive = (sourceFileIncludes != null && !sourceFileIncludes.isEmpty())
+ || (sourceFileExcludes != null && !sourceFileExcludes.isEmpty());
+ if (includesExcludesActive && !StringUtils.isEmpty(subpackages)) {
+ getLog().warn("sourceFileIncludes and sourceFileExcludes have no effect when subpackages are specified!");
includesExcludesActive = false;
}
- if ( !packageNames.isEmpty() && !includesExcludesActive )
- {
- addCommandLinePackages( cmd, javadocOutputDirectory, packageNames );
+ if (!packageNames.isEmpty() && !includesExcludesActive) {
+ addCommandLinePackages(cmd, javadocOutputDirectory, packageNames);
// ----------------------------------------------------------------------
// Write argfile file and include it in the command line
// ----------------------------------------------------------------------
- List<String> specialFiles = getSpecialFiles( files );
+ List<String> specialFiles = getSpecialFiles(files);
- if ( !specialFiles.isEmpty() )
- {
- addCommandLineArgFile( cmd, javadocOutputDirectory, specialFiles );
+ if (!specialFiles.isEmpty()) {
+ addCommandLineArgFile(cmd, javadocOutputDirectory, specialFiles);
}
- }
- else
- {
+ } else {
// ----------------------------------------------------------------------
// Write argfile file and include it in the command line
// ----------------------------------------------------------------------
List<String> allFiles = new ArrayList<>();
- for ( Map.Entry<Path, Collection<String>> filesEntry : files.entrySet() )
- {
- for ( String file : filesEntry.getValue() )
- {
- allFiles.add( filesEntry.getKey().resolve( file ).toString() );
+ for (Map.Entry<Path, Collection<String>> filesEntry : files.entrySet()) {
+ for (String file : filesEntry.getValue()) {
+ allFiles.add(filesEntry.getKey().resolve(file).toString());
}
}
- if ( !files.isEmpty() )
- {
- addCommandLineArgFile( cmd, javadocOutputDirectory, allFiles );
+ if (!files.isEmpty()) {
+ addCommandLineArgFile(cmd, javadocOutputDirectory, allFiles);
}
}
@@ -2090,56 +2019,43 @@ public abstract class AbstractJavadocMojo
// Execute command line
// ----------------------------------------------------------------------
- executeJavadocCommandLine( cmd, javadocOutputDirectory );
+ executeJavadocCommandLine(cmd, javadocOutputDirectory);
// delete generated javadoc files only if no error and no debug mode
// [MJAVADOC-336] Use File.delete() instead of File.deleteOnExit() to
// prevent these files from making their way into archives.
- if ( !debug )
- {
- for ( int i = 0; i < cmd.getArguments().length; i++ )
- {
+ if (!debug) {
+ for (int i = 0; i < cmd.getArguments().length; i++) {
String arg = cmd.getArguments()[i].trim();
- if ( !arg.startsWith( "@" ) )
- {
+ if (!arg.startsWith("@")) {
continue;
}
- File argFile = new File( javadocOutputDirectory, arg.substring( 1 ) );
- if ( argFile.exists() )
- {
+ File argFile = new File(javadocOutputDirectory, arg.substring(1));
+ if (argFile.exists()) {
argFile.delete();
}
}
- File scriptFile = new File( javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME );
- if ( scriptFile.exists() )
- {
+ File scriptFile = new File(javadocOutputDirectory, DEBUG_JAVADOC_SCRIPT_NAME);
+ if (scriptFile.exists()) {
scriptFile.delete();
}
}
- if ( applyJavadocSecurityFix )
- {
+ if (applyJavadocSecurityFix) {
// finally, patch the Javadoc vulnerability in older Javadoc tools (CVE-2013-1571):
- try
- {
- final int patched = fixFrameInjectionBug( javadocOutputDirectory, getDocencoding() );
- if ( patched > 0 )
- {
- getLog().info(
- String.format( "Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in %d files.",
- patched ) );
+ try {
+ final int patched = fixFrameInjectionBug(javadocOutputDirectory, getDocencoding());
+ if (patched > 0) {
+ getLog().info(String.format(
+ "Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in %d files.", patched));
}
+ } catch (IOException e) {
+ throw new MavenReportException("Failed to patch javadocs vulnerability: " + e.getMessage(), e);
}
- catch ( IOException e )
- {
- throw new MavenReportException( "Failed to patch javadocs vulnerability: " + e.getMessage(), e );
- }
- }
- else
- {
- getLog().info( "applying javadoc security fix has been disabled" );
+ } else {
+ getLog().info("applying javadoc security fix has been disabled");
}
}
@@ -2150,40 +2066,29 @@ public abstract class AbstractJavadocMojo
* @return a List that contains the specific path for every source file
* @throws MavenReportException {@link MavenReportException} issue while generating report
*/
- protected Map<Path, Collection<String>> getFiles( Collection<Path> sourcePaths )
- throws MavenReportException
- {
- Map<Path, Collection<String>> mappedFiles = new LinkedHashMap<>( sourcePaths.size() );
- if ( StringUtils.isEmpty( subpackages ) )
- {
+ protected Map<Path, Collection<String>> getFiles(Collection<Path> sourcePaths) throws MavenReportException {
+ Map<Path, Collection<String>> mappedFiles = new LinkedHashMap<>(sourcePaths.size());
+ if (StringUtils.isEmpty(subpackages)) {
Collection<String> excludedPackages = getExcludedPackages();
final boolean autoExclude;
- if ( release != null )
- {
- autoExclude = JavaVersion.parse( release ).isBefore( "9" );
- }
- else if ( source != null )
- {
- autoExclude = JavaVersion.parse( source ).isBefore( "9" );
- }
- else
- {
+ if (release != null) {
+ autoExclude = JavaVersion.parse(release).isBefore("9");
+ } else if (source != null) {
+ autoExclude = JavaVersion.parse(source).isBefore("9");
+ } else {
autoExclude = false;
}
- for ( Path sourcePath : sourcePaths )
- {
+ for (Path sourcePath : sourcePaths) {
File sourceDirectory = sourcePath.toFile();
- List<String> files = new ArrayList<>( JavadocUtil.getFilesFromSource( sourceDirectory,
- sourceFileIncludes, sourceFileExcludes,
- excludedPackages ) );
+ List<String> files = new ArrayList<>(JavadocUtil.getFilesFromSource(
+ sourceDirectory, sourceFileIncludes, sourceFileExcludes, excludedPackages));
- if ( autoExclude && files.remove( "module-info.java" ) )
- {
- getLog().debug( "Auto exclude module-info.java due to source value" );
+ if (autoExclude && files.remove("module-info.java")) {
+ getLog().debug("Auto exclude module-info.java due to source value");
}
- mappedFiles.put( sourcePath, files );
+ mappedFiles.put(sourcePath, files);
}
}
@@ -2198,21 +2103,16 @@ public abstract class AbstractJavadocMojo
* @throws MavenReportException {@link MavenReportException} issue while generating report
* @see JavadocUtil#pruneDirs(MavenProject, Collection)
*/
- protected Collection<JavadocModule> getSourcePaths()
- throws MavenReportException
- {
+ protected Collection<JavadocModule> getSourcePaths() throws MavenReportException {
Collection<JavadocModule> mappedSourcePaths = new ArrayList<>();
- if ( StringUtils.isEmpty( sourcepath ) )
- {
- if ( !"pom".equals( project.getPackaging() ) )
- {
+ if (StringUtils.isEmpty(sourcepath)) {
+ if (!"pom".equals(project.getPackaging())) {
Set<Path> sourcePaths =
- new LinkedHashSet<>( JavadocUtil.pruneDirs( project, getProjectSourceRoots( project ) ) );
+ new LinkedHashSet<>(JavadocUtil.pruneDirs(project, getProjectSourceRoots(project)));
- if ( project.getExecutionProject() != null )
- {
- sourcePaths.addAll( JavadocUtil.pruneDirs( project, getExecutionProjectSourceRoots( project ) ) );
+ if (project.getExecutionProject() != null) {
+ sourcePaths.addAll(JavadocUtil.pruneDirs(project, getExecutionProjectSourceRoots(project)));
}
/*
@@ -2220,112 +2120,93 @@ public abstract class AbstractJavadocMojo
* the opposite. If not, the javadoc tool always copies doc files, even if -docfilessubdirs is not
* setted.
*/
- if ( getJavadocDirectory() != null )
- {
+ if (getJavadocDirectory() != null) {
File javadocDir = getJavadocDirectory();
- if ( javadocDir.exists() && javadocDir.isDirectory() )
- {
- Collection<Path> l =
- JavadocUtil.pruneDirs( project,
- Collections.singletonList( getJavadocDirectory().getAbsolutePath() ) );
- sourcePaths.addAll( l );
+ if (javadocDir.exists() && javadocDir.isDirectory()) {
+ Collection<Path> l = JavadocUtil.pruneDirs(
+ project,
+ Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
+ sourcePaths.addAll(l);
}
}
- if ( !sourcePaths.isEmpty() )
- {
- mappedSourcePaths.add( buildJavadocModule( project, sourcePaths ) );
+ if (!sourcePaths.isEmpty()) {
+ mappedSourcePaths.add(buildJavadocModule(project, sourcePaths));
}
}
- if ( isAggregator() )
- {
- for ( MavenProject subProject : getAggregatedProjects() )
- {
- if ( subProject != project )
- {
+ if (isAggregator()) {
+ for (MavenProject subProject : getAggregatedProjects()) {
+ if (subProject != project) {
Collection<Path> additionalSourcePaths = new ArrayList<>();
- List<String> sourceRoots = getProjectSourceRoots( subProject );
+ List<String> sourceRoots = getProjectSourceRoots(subProject);
- if ( subProject.getExecutionProject() != null )
- {
- sourceRoots.addAll( getExecutionProjectSourceRoots( subProject ) );
+ if (subProject.getExecutionProject() != null) {
+ sourceRoots.addAll(getExecutionProjectSourceRoots(subProject));
}
- ArtifactHandler artifactHandler = subProject.getArtifact().getArtifactHandler();
- if ( "java".equals( artifactHandler.getLanguage() ) )
- {
- additionalSourcePaths.addAll( JavadocUtil.pruneDirs( subProject, sourceRoots ) );
+ ArtifactHandler artifactHandler =
+ subProject.getArtifact().getArtifactHandler();
+ if ("java".equals(artifactHandler.getLanguage())) {
+ additionalSourcePaths.addAll(JavadocUtil.pruneDirs(subProject, sourceRoots));
}
- if ( getJavadocDirectory() != null )
- {
- String javadocDirRelative =
- PathUtils.toRelative( project.getBasedir(),
- getJavadocDirectory().getAbsolutePath() );
- File javadocDir = new File( subProject.getBasedir(), javadocDirRelative );
- if ( javadocDir.exists() && javadocDir.isDirectory() )
- {
- Collection<Path> l = JavadocUtil.pruneDirs( subProject, Collections.singletonList(
- javadocDir.getAbsolutePath() ) );
- additionalSourcePaths.addAll( l );
+ if (getJavadocDirectory() != null) {
+ String javadocDirRelative = PathUtils.toRelative(
+ project.getBasedir(), getJavadocDirectory().getAbsolutePath());
+ File javadocDir = new File(subProject.getBasedir(), javadocDirRelative);
+ if (javadocDir.exists() && javadocDir.isDirectory()) {
+ Collection<Path> l = JavadocUtil.pruneDirs(
+ subProject, Collections.singletonList(javadocDir.getAbsolutePath()));
+ additionalSourcePaths.addAll(l);
}
}
- if ( !additionalSourcePaths.isEmpty() )
- {
- mappedSourcePaths.add( buildJavadocModule( subProject , additionalSourcePaths ) );
+ if (!additionalSourcePaths.isEmpty()) {
+ mappedSourcePaths.add(buildJavadocModule(subProject, additionalSourcePaths));
}
}
}
}
- if ( includeDependencySources )
- {
- mappedSourcePaths.addAll( getDependencySourcePaths() );
+ if (includeDependencySources) {
+ mappedSourcePaths.addAll(getDependencySourcePaths());
}
- }
- else
- {
+ } else {
Collection<Path> sourcePaths =
- JavadocUtil.pruneDirs( project,
- new ArrayList<>( Arrays.asList( JavadocUtil.splitPath( sourcepath ) ) ) );
- if ( getJavadocDirectory() != null )
- {
- Collection<Path> l = JavadocUtil.pruneDirs( project, Collections.singletonList(
- getJavadocDirectory().getAbsolutePath() ) );
- sourcePaths.addAll( l );
+ JavadocUtil.pruneDirs(project, new ArrayList<>(Arrays.asList(JavadocUtil.splitPath(sourcepath))));
+ if (getJavadocDirectory() != null) {
+ Collection<Path> l = JavadocUtil.pruneDirs(
+ project, Collections.singletonList(getJavadocDirectory().getAbsolutePath()));
+ sourcePaths.addAll(l);
}
- if ( !sourcePaths.isEmpty() )
- {
- mappedSourcePaths.add( new JavadocModule( ArtifactUtils.versionlessKey( project.getGroupId(),
- project.getArtifactId() ),
- getClassesFile( project ),
- sourcePaths ) );
+ if (!sourcePaths.isEmpty()) {
+ mappedSourcePaths.add(new JavadocModule(
+ ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()),
+ getClassesFile(project),
+ sourcePaths));
}
}
return mappedSourcePaths;
}
- private JavadocModule buildJavadocModule( MavenProject project, Collection<Path> sourcePaths )
- {
- File classessFile = getClassesFile( project );
- ResolvePathResult resolvePathResult = getResolvePathResult( classessFile );
- if ( resolvePathResult == null )
- {
- return new JavadocModule( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ),
- classessFile,
- sourcePaths );
- }
- else
- {
- return new JavadocModule( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ),
- classessFile,
- sourcePaths,
- resolvePathResult.getModuleDescriptor(),
- resolvePathResult.getModuleNameSource() );
+ private JavadocModule buildJavadocModule(MavenProject project, Collection<Path> sourcePaths) {
+ File classessFile = getClassesFile(project);
+ ResolvePathResult resolvePathResult = getResolvePathResult(classessFile);
+ if (resolvePathResult == null) {
+ return new JavadocModule(
+ ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()),
+ classessFile,
+ sourcePaths);
+ } else {
+ return new JavadocModule(
+ ArtifactUtils.versionlessKey(project.getGroupId(), project.getArtifactId()),
+ classessFile,
+ sourcePaths,
+ resolvePathResult.getModuleDescriptor(),
+ resolvePathResult.getModuleNameSource());
}
}
@@ -2335,34 +2216,29 @@ public abstract class AbstractJavadocMojo
* @param aggregatedProject the project being aggregated
* @param reactorProjectsMap map of (still) available reactor projects
*/
- private Set<MavenProject> modulesForAggregatedProject( MavenProject aggregatedProject,
- Map<Path, MavenProject> reactorProjectsMap )
- {
+ private Set<MavenProject> modulesForAggregatedProject(
+ MavenProject aggregatedProject, Map<Path, MavenProject> reactorProjectsMap) {
// Maven does not supply an easy way to get the projects representing
// the modules of a project. So we will get the paths to the base
// directories of the modules from the project and compare with the
// base directories of the projects in the reactor.
- if ( aggregatedProject.getModules().isEmpty() )
- {
- return Collections.singleton( aggregatedProject );
+ if (aggregatedProject.getModules().isEmpty()) {
+ return Collections.singleton(aggregatedProject);
}
Path basePath = aggregatedProject.getBasedir().toPath();
List<Path> modulePaths = new LinkedList<>();
- for ( String module : aggregatedProject.getModules() )
- {
- modulePaths.add( basePath.resolve( module ).normalize() );
+ for (String module : aggregatedProject.getModules()) {
+ modulePaths.add(basePath.resolve(module).normalize());
}
Set<MavenProject> aggregatedModules = new LinkedHashSet<>();
- for ( Path modulePath : modulePaths )
- {
- MavenProject module = reactorProjectsMap.remove( modulePath );
- if ( module != null )
- {
- aggregatedModules.addAll( modulesForAggregatedProject( module, reactorProjectsMap ) );
+ for (Path modulePath : modulePaths) {
+ MavenProject module = reactorProjectsMap.remove(modulePath);
+ if (module != null) {
+ aggregatedModules.addAll(modulesForAggregatedProject(module, reactorProjectsMap));
}
}
@@ -2375,8 +2251,7 @@ public abstract class AbstractJavadocMojo
* @param config {@link SourceResolverConfig}
* @return {@link SourceResolverConfig}
*/
- protected SourceResolverConfig configureDependencySourceResolution( final SourceResolverConfig config )
- {
+ protected SourceResolverConfig configureDependencySourceResolution(final SourceResolverConfig config) {
return config.withCompileSources();
}
@@ -2386,34 +2261,25 @@ public abstract class AbstractJavadocMojo
* @return List of source paths.
* @throws MavenReportException {@link MavenReportException}
*/
- protected final Collection<JavadocModule> getDependencySourcePaths()
- throws MavenReportException
- {
- try
- {
- if ( sourceDependencyCacheDir.exists() )
- {
- FileUtils.forceDelete( sourceDependencyCacheDir );
+ protected final Collection<JavadocModule> getDependencySourcePaths() throws MavenReportException {
+ try {
+ if (sourceDependencyCacheDir.exists()) {
+ FileUtils.forceDelete(sourceDependencyCacheDir);
sourceDependencyCacheDir.mkdirs();
}
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
throw new MavenReportException(
- "Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e );
+ "Failed to delete cache directory: " + sourceDependencyCacheDir + "\nReason: " + e.getMessage(), e);
}
final SourceResolverConfig config = getDependencySourceResolverConfig();
- try
- {
- return resourceResolver.resolveDependencySourcePaths( config );
- }
- catch ( org.apache.maven.artifact.resolver.ArtifactResolutionException
- | org.apache.maven.artifact.resolver.ArtifactNotFoundException e )
- {
+ try {
+ return resourceResolver.resolveDependencySourcePaths(config);
+ } catch (org.apache.maven.artifact.resolver.ArtifactResolutionException
+ | org.apache.maven.artifact.resolver.ArtifactNotFoundException e) {
throw new MavenReportException(
- "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e );
+ "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e);
}
}
@@ -2423,17 +2289,15 @@ public abstract class AbstractJavadocMojo
*
* @return
*/
- private TransformableFilter createDependencyArtifactFilter()
- {
+ private TransformableFilter createDependencyArtifactFilter() {
Set<Artifact> dependencyArtifacts = project.getDependencyArtifacts();
- List<String> artifactPatterns = new ArrayList<>( dependencyArtifacts.size() );
- for ( Artifact artifact : dependencyArtifacts )
- {
- artifactPatterns.add( artifact.getGroupId() + ":" + artifact.getArtifactId() );
+ List<String> artifactPatterns = new ArrayList<>(dependencyArtifacts.size());
+ for (Artifact artifact : dependencyArtifacts) {
+ artifactPatterns.add(artifact.getGroupId() + ":" + artifact.getArtifactId());
}
- return new PatternInclusionsFilter( artifactPatterns );
+ return new PatternInclusionsFilter(artifactPatterns);
}
/**
@@ -2442,44 +2306,35 @@ public abstract class AbstractJavadocMojo
*
* @since 2.7
*/
- private SourceResolverConfig getDependencySourceResolverConfig()
- {
+ private SourceResolverConfig getDependencySourceResolverConfig() {
final List<TransformableFilter> andFilters = new ArrayList<>();
final List<String> dependencyIncludes = dependencySourceIncludes;
final List<String> dependencyExcludes = dependencySourceExcludes;
- if ( !includeTransitiveDependencySources || isNotEmpty( dependencyIncludes ) || isNotEmpty(
- dependencyExcludes ) )
- {
- if ( !includeTransitiveDependencySources )
- {
- andFilters.add( createDependencyArtifactFilter() );
+ if (!includeTransitiveDependencySources || isNotEmpty(dependencyIncludes) || isNotEmpty(dependencyExcludes)) {
+ if (!includeTransitiveDependencySources) {
+ andFilters.add(createDependencyArtifactFilter());
}
- if ( isNotEmpty( dependencyIncludes ) )
- {
- andFilters.add( new PatternInclusionsFilter( dependencyIncludes ) );
+ if (isNotEmpty(dependencyIncludes)) {
+ andFilters.add(new PatternInclusionsFilter(dependencyIncludes));
}
- if ( isNotEmpty( dependencyExcludes ) )
- {
- andFilters.add( new PatternExclusionsFilter( dependencyExcludes ) );
+ if (isNotEmpty(dependencyExcludes)) {
+ andFilters.add(new PatternExclusionsFilter(dependencyExcludes));
}
}
- return configureDependencySourceResolution( new SourceResolverConfig( project,
- getProjectBuildingRequest( project ),
- sourceDependencyCacheDir )
- .withReactorProjects( this.reactorProjects ) )
- .withFilter( new AndFilter( andFilters ) );
-
+ return configureDependencySourceResolution(
+ new SourceResolverConfig(project, getProjectBuildingRequest(project), sourceDependencyCacheDir)
+ .withReactorProjects(this.reactorProjects))
+ .withFilter(new AndFilter(andFilters));
}
- private ProjectBuildingRequest getProjectBuildingRequest( MavenProject currentProject )
- {
- return new DefaultProjectBuildingRequest( session.getProjectBuildingRequest() )
- .setRemoteRepositories( currentProject.getRemoteArtifactRepositories() );
+ private ProjectBuildingRequest getProjectBuildingRequest(MavenProject currentProject) {
+ return new DefaultProjectBuildingRequest(session.getProjectBuildingRequest())
+ .setRemoteRepositories(currentProject.getRemoteArtifactRepositories());
}
/**
@@ -2489,17 +2344,14 @@ public abstract class AbstractJavadocMojo
* @param files the project files
* @return a boolean that indicates whether javadoc report can be generated or not
*/
- protected boolean canGenerateReport( Map<Path, Collection<String>> files )
- {
- for ( Collection<String> filesValues : files.values() )
- {
- if ( !filesValues.isEmpty() )
- {
+ protected boolean canGenerateReport(Map<Path, Collection<String>> files) {
+ for (Collection<String> filesValues : files.values()) {
+ if (!filesValues.isEmpty()) {
return true;
}
}
- return !StringUtils.isEmpty( subpackages );
+ return !StringUtils.isEmpty(subpackages);
}
// ----------------------------------------------------------------------
@@ -2514,23 +2366,19 @@ public abstract class AbstractJavadocMojo
* @return a String that contains the exclude argument that will be used by javadoc
* @throws MavenReportException
*/
- private String getExcludedPackages( Collection<Path> sourcePaths )
- throws MavenReportException
- {
+ private String getExcludedPackages(Collection<Path> sourcePaths) throws MavenReportException {
List<String> excludedNames = null;
- if ( StringUtils.isNotEmpty( sourcepath ) && StringUtils.isNotEmpty( subpackages ) )
- {
+ if (StringUtils.isNotEmpty(sourcepath) && StringUtils.isNotEmpty(subpackages)) {
Collection<String> excludedPackages = getExcludedPackages();
- excludedNames = JavadocUtil.getExcludedPackages( sourcePaths, excludedPackages );
+ excludedNames = JavadocUtil.getExcludedPackages(sourcePaths, excludedPackages);
}
String excludeArg = "";
- if ( StringUtils.isNotEmpty( subpackages ) && excludedNames != null )
- {
+ if (StringUtils.isNotEmpty(subpackages) && excludedNames != null) {
// add the excludedpackage names
- excludeArg = StringUtils.join( excludedNames.iterator(), ":" );
+ excludeArg = StringUtils.join(excludedNames.iterator(), ":");
}
return excludeArg;
@@ -2544,13 +2392,11 @@ public abstract class AbstractJavadocMojo
* string (colon (<code>:</code>) on Solaris or semicolon (<code>;</code>) on Windows).
* @see File#pathSeparator
*/
- private String getSourcePath( Collection<Path> sourcePaths )
- {
+ private String getSourcePath(Collection<Path> sourcePaths) {
String sourcePath = null;
- if ( StringUtils.isEmpty( subpackages ) || StringUtils.isNotEmpty( sourcepath ) )
- {
- sourcePath = StringUtils.join( sourcePaths.iterator(), File.pathSeparator );
+ if (StringUtils.isEmpty(subpackages) || StringUtils.isNotEmpty(sourcepath)) {
+ sourcePath = StringUtils.join(sourcePaths.iterator(), File.pathSeparator);
}
return sourcePath;
@@ -2563,71 +2409,56 @@ public abstract class AbstractJavadocMojo
* @return an array of String objects that contain the package names
* @throws MavenReportException
*/
- private Collection<String> getExcludedPackages()
- throws MavenReportException
- {
+ private Collection<String> getExcludedPackages() throws MavenReportException {
Set<String> excluded = new LinkedHashSet<>();
- if ( includeDependencySources )
- {
- try
- {
+ if (includeDependencySources) {
+ try {
resolveDependencyBundles();
- }
- catch ( IOException e )
- {
+ } catch (IOException e) {
throw new MavenReportException(
- "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e );
+ "Failed to resolve javadoc bundles from dependencies: " + e.getMessage(), e);
}
- if ( isNotEmpty( dependencyJavadocBundles ) )
- {
- for ( JavadocBundle bundle : dependencyJavadocBundles )
- {
+ if (isNotEmpty(dependencyJavadocBundles)) {
+ for (JavadocBundle bundle : dependencyJavadocBundles) {
JavadocOptions options = bundle.getOptions();
- if ( options != null && isNotEmpty( options.getExcludePackageNames() ) )
- {
- excluded.addAll( options.getExcludePackageNames() );
+ if (options != null && isNotEmpty(options.getExcludePackageNames())) {
+ excluded.addAll(options.getExcludePackageNames());
}
}
}
}
// for the specified excludePackageNames
- if ( StringUtils.isNotEmpty( excludePackageNames ) )
- {
- List<String> packageNames = Arrays.asList( excludePackageNames.split( "[,:;]" ) );
- excluded.addAll( trimValues( packageNames ) );
+ if (StringUtils.isNotEmpty(excludePackageNames)) {
+ List<String> packageNames = Arrays.asList(excludePackageNames.split("[,:;]"));
+ excluded.addAll(trimValues(packageNames));
}
return excluded;
}
- private static List<String> trimValues( List<String> items )
- {
- List<String> result = new ArrayList<>( items.size() );
- for ( String item : items )
- {
+ private static List<String> trimValues(List<String> items) {
+ List<String> result = new ArrayList<>(items.size());
+ for (String item : items) {
String trimmed = item.trim();
- if ( StringUtils.isEmpty( trimmed ) )
- {
+ if (StringUtils.isEmpty(trimmed)) {
continue;
}
- result.add( trimmed );
+ result.add(trimmed);
}
return result;
}
- private List<org.eclipse.aether.graph.Dependency> toResolverDependencies( List<Dependency> dependencies )
- {
- if ( dependencies == null )
- {
+ private List<org.eclipse.aether.graph.Dependency> toResolverDependencies(List<Dependency> dependencies) {
+ if (dependencies == null) {
return null;
}
- ArtifactTypeRegistry registry = RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager );
+ ArtifactTypeRegistry registry = RepositoryUtils.newArtifactTypeRegistry(artifactHandlerManager);
return dependencies.stream()
- .map( d -> RepositoryUtils.toDependency( d, registry ) )
- .collect( Collectors.toList() );
+ .map(d -> RepositoryUtils.toDependency(d, registry))
+ .collect(Collectors.toList());
}
/**
@@ -2640,114 +2471,94 @@ public abstract class AbstractJavadocMojo
* @return all classpath elements
* @throws MavenReportException if any.
*/
- private Collection<File> getPathElements()
- throws MavenReportException
- {
+ private Collection<File> getPathElements() throws MavenReportException {
Set<File> classpathElements = new LinkedHashSet<>();
Map<String, Artifact> compileArtifactMap = new LinkedHashMap<>();
- if ( isTest() )
- {
- classpathElements.addAll( getProjectBuildOutputDirs( project ) );
+ if (isTest()) {
+ classpathElements.addAll(getProjectBuildOutputDirs(project));
}
- populateCompileArtifactMap( compileArtifactMap, project.getArtifacts() );
+ populateCompileArtifactMap(compileArtifactMap, project.getArtifacts());
- if ( isAggregator() )
- {
+ if (isAggregator()) {
Collection<MavenProject> aggregatorProjects = getAggregatedProjects();
List<String> reactorArtifacts = new ArrayList<>();
- for ( MavenProject p : aggregatorProjects )
- {
- reactorArtifacts.add( p.getGroupId() + ':' + p.getArtifactId() );
- }
-
- DependencyFilter dependencyFilter = new AndDependencyFilter(
- new PatternExclusionsDependencyFilter( reactorArtifacts ),
- getDependencyScopeFilter() );
-
- for ( MavenProject subProject : aggregatorProjects )
- {
- if ( subProject != project )
- {
- File projectArtifactFile = getClassesFile( subProject );
- if ( projectArtifactFile != null )
- {
- classpathElements.add( projectArtifactFile );
- }
- else
- {
- classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );
+ for (MavenProject p : aggregatorProjects) {
+ reactorArtifacts.add(p.getGroupId() + ':' + p.getArtifactId());
+ }
+
+ DependencyFilter dependencyFilter = new AndDependencyFilter(
+ new PatternExclusionsDependencyFilter(reactorArtifacts), getDependencyScopeFilter());
+
+ for (MavenProject subProject : aggregatorProjects) {
+ if (subProject != project) {
+ File projectArtifactFile = getClassesFile(subProject);
+ if (projectArtifactFile != null) {
+ classpathElements.add(projectArtifactFile);
+ } else {
+ classpathElements.addAll(getProjectBuildOutputDirs(subProject));
}
- try
- {
+ try {
StringBuilder sb = new StringBuilder();
- sb.append( "Compiled artifacts for " );
- sb.append( subProject.getGroupId() ).append( ":" );
- sb.append( subProject.getArtifactId() ).append( ":" );
- sb.append( subProject.getVersion() ).append( '\n' );
+ sb.append("Compiled artifacts for ");
+ sb.append(subProject.getGroupId()).append(":");
+ sb.append(subProject.getArtifactId()).append(":");
+ sb.append(subProject.getVersion()).append('\n');
List<Dependency> managedDependencies = null;
- if ( subProject.getDependencyManagement() != null )
- {
- managedDependencies = subProject.getDependencyManagement().getDependencies();
+ if (subProject.getDependencyManagement() != null) {
+ managedDependencies =
+ subProject.getDependencyManagement().getDependencies();
}
- CollectRequest collRequest = new CollectRequest(
- toResolverDependencies( subProject.getDependencies() ),
- toResolverDependencies( managedDependencies ),
- subProject.getRemoteProjectRepositories() );
- DependencyRequest depRequest = new DependencyRequest( collRequest, dependencyFilter );
- for ( ArtifactResult artifactResult
- : repoSystem.resolveDependencies( repoSession, depRequest ).getArtifactResults() )
- {
- List<Artifact> artifacts = Collections.singletonList(
- RepositoryUtils.toArtifact( artifactResult.getArtifact() ) );
- populateCompileArtifactMap( compileArtifactMap, artifacts );
-
- sb.append( artifactResult.getArtifact().getFile() ).append( '\n' );
+ CollectRequest collRequest = new CollectRequest(
+ toResolverDependencies(subProject.getDependencies()),
+ toResolverDependencies(managedDependencies),
+ subProject.getRemoteProjectRepositories());
+ DependencyRequest depRequest = new DependencyRequest(collRequest, dependencyFilter);
+ for (ArtifactResult artifactResult : repoSystem
+ .resolveDependencies(repoSession, depRequest)
+ .getArtifactResults()) {
+ List<Artifact> artifacts =
+ Collections.singletonList(RepositoryUtils.toArtifact(artifactResult.getArtifact()));
+ populateCompileArtifactMap(compileArtifactMap, artifacts);
+
+ sb.append(artifactResult.getArtifact().getFile()).append('\n');
}
- if ( getLog().isDebugEnabled() )
- {
- getLog().debug( sb.toString() );
+ if (getLog().isDebugEnabled()) {
+ getLog().debug(sb.toString());
}
- }
- catch ( DependencyResolutionException e )
- {
- throw new MavenReportException( e.getMessage(), e );
+ } catch (DependencyResolutionException e) {
+ throw new MavenReportException(e.getMessage(), e);
}
}
}
}
- for ( Artifact a : compileArtifactMap.values() )
- {
- classpathElements.add( a.getFile() );
+ for (Artifact a : compileArtifactMap.values()) {
+ classpathElements.add(a.getFile());
}
- if ( additionalDependencies != null )
- {
- for ( Dependency dependency : additionalDependencies )
- {
- Artifact artifact = resolveDependency( dependency );
- getLog().debug( "add additional artifact with path " + artifact.getFile() );
- classpathElements.add( artifact.getFile() );
+ if (additionalDependencies != null) {
+ for (Dependency dependency : additionalDependencies) {
+ Artifact artifact = resolveDependency(dependency);
+ getLog().debug("add additional artifact with path " + artifact.getFile());
+ classpathElements.add(artifact.getFile());
}
}
return classpathElements;
}
- protected ScopeDependencyFilter getDependencyScopeFilter()
- {
- return new ScopeDependencyFilter( Arrays.asList( Artifact.SCOPE_COMPILE,
- Artifact.SCOPE_PROVIDED,
- Artifact.SCOPE_SYSTEM ), null );
+ protected ScopeDependencyFilter getDependencyScopeFilter() {
+ return new ScopeDependencyFilter(
+ Arrays.asList(Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM), null);
}
/**
@@ -2755,58 +2566,46 @@ public abstract class AbstractJavadocMojo
* @return {@link Artifact}
* @throws MavenReportException when artifact could not be resolved
*/
- public Artifact resolveDependency( Dependency dependency )
- throws MavenReportException
- {
- ArtifactTypeRegistry registry = RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager );
- ArtifactRequest req = new ArtifactRequest( RepositoryUtils.toDependency( dependency, registry ).getArtifact(),
- project.getRemoteProjectRepositories(), null );
- try
- {
- ArtifactResult resolutionResult = repoSystem.resolveArtifact( repoSession, req );
- return RepositoryUtils.toArtifact( resolutionResult.getArtifact( ) );
- }
- catch ( ArtifactResolutionException e )
- {
- throw new MavenReportException( "artifact resolver problem - " + e.getMessage(), e );
+ public Artifact resolveDependency(Dependency dependency) throws MavenReportException {
+ ArtifactTypeRegistry registry = RepositoryUtils.newArtifactTypeRegistry(artifactHandlerManager);
+ ArtifactRequest req = new ArtifactRequest(
+ RepositoryUtils.toDependency(dependency, registry).getArtifact(),
+ project.getRemoteProjectRepositories(),
+ null);
+ try {
+ ArtifactResult resolutionResult = repoSystem.resolveArtifact(repoSession, req);
+ return RepositoryUtils.toArtifact(resolutionResult.getArtifact());
+ } catch (ArtifactResolutionException e) {
+ throw new MavenReportException("artifact resolver problem - " + e.getMessage(), e);
}
}
-
- //TODO remove the part with ToolchainManager lookup once we depend on
- //3.0.9 (have it as prerequisite). Define as regular component field then.
- protected final Toolchain getToolchain()
- {
+ // TODO remove the part with ToolchainManager lookup once we depend on
+ // 3.0.9 (have it as prerequisite). Define as regular component field then.
+ protected final Toolchain getToolchain() {
Toolchain tc = null;
- if ( jdkToolchain != null )
- {
+ if (jdkToolchain != null) {
// Maven 3.3.1 has plugin execution scoped Toolchain Support
- try
- {
- Method getToolchainsMethod =
- toolchainManager.getClass().getMethod( "getToolchains", MavenSession.class, String.class,
- Map.class );
+ try {
+ Method getToolchainsMethod = toolchainManager
+ .getClass()
+ .getMethod("getToolchains", MavenSession.class, String.class, Map.class);
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
List<Toolchain> tcs =
- (List<Toolchain>) getToolchainsMethod.invoke( toolchainManager, session, "jdk",
- jdkToolchain );
+ (List<Toolchain>) getToolchainsMethod.invoke(toolchainManager, session, "jdk", jdkToolchain);
- if ( tcs != null && tcs.size() > 0 )
- {
- tc = tcs.get( 0 );
+ if (tcs != null && tcs.size() > 0) {
+ tc = tcs.get(0);
}
- }
- catch ( SecurityException | ReflectiveOperationException e )
- {
+ } catch (SecurityException | ReflectiveOperationException e) {
// ignore
}
}
- if ( tc == null )
- {
- tc = toolchainManager.getToolchainFromBuildContext( "jdk", session );
+ if (tc == null) {
+ tc = toolchainManager.getToolchainFromBuildContext("jdk", session);
}
return tc;
@@ -2819,41 +2618,32 @@ public abstract class AbstractJavadocMojo
* @param artifactList the list of artifacts that will be put in the map
* @throws MavenReportException if any
*/
- private void populateCompileArtifactMap( Map<String, Artifact> compileArtifactMap,
- Collection<Artifact> artifactList )
- throws MavenReportException
- {
- if ( artifactList == null )
- {
+ private void populateCompileArtifactMap(Map<String, Artifact> compileArtifactMap, Collection<Artifact> artifactList)
+ throws MavenReportException {
+ if (artifactList == null) {
return;
}
- for ( Artifact newArtifact : artifactList )
- {
+ for (Artifact newArtifact : artifactList) {
File file = newArtifact.getFile();
- if ( file == null )
- {
+ if (file == null) {
throw new MavenReportException(
- "Error in plugin descriptor - " + "dependency was not resolved for artifact: "
- + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":"
- + newArtifact.getVersion() );
+ "Error in plugin descriptor - " + "dependency was not resolved for artifact: "
+ + newArtifact.getGroupId() + ":" + newArtifact.getArtifactId() + ":"
+ + newArtifact.getVersion());
}
- if ( compileArtifactMap.get( newArtifact.getDependencyConflictId() ) != null )
- {
- Artifact oldArtifact = compileArtifactMap.get( newArtifact.getDependencyConflictId() );
+ if (compileArtifactMap.get(newArtifact.getDependencyConflictId()) != null) {
+ Artifact oldArtifact = compileArtifactMap.get(newArtifact.getDependencyConflictId());
- ArtifactVersion oldVersion = new DefaultArtifactVersion( oldArtifact.getVersion() );
- ArtifactVersion newVersion = new DefaultArtifactVersion( newArtifact.getVersion() );
- if ( newVersion.compareTo( oldVersion ) > 0 )
- {
- compileArtifactMap.put( newArtifact.getDependencyConflictId(), newArtifact );
+ ArtifactVersion oldVersion = new DefaultArtifactVersion(oldArtifact.getVersion());
+ ArtifactVersion newVersion = new DefaultArtifactVersion(newArtifact.getVersion());
+ if (newVersion.compareTo(oldVersion) > 0) {
+ compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
- }
- else
- {
- compileArtifactMap.put( newArtifact.getDependencyConflictId(), newArtifact );
+ } else {
+ compileArtifactMap.put(newArtifact.getDependencyConflictId(), newArtifact);
}
}
}
@@ -2864,51 +2654,42 @@ public abstract class AbstractJavadocMojo
*
* @return a String that contains the text that will be displayed at the bottom of the javadoc
*/
- private String getBottomText()
- {
+ private String getBottomText() {
final String inceptionYear = project.getInceptionYear();
// get Reproducible Builds outputTimestamp date value or the current local date.
- final LocalDate localDate = MavenArchiver.parseBuildOutputTimestamp( outputTimestamp )
- .map( instant -> instant.atZone( ZoneOffset.UTC ).toLocalDate() )
- .orElseGet( LocalDate::now );
-
- final String currentYear = Integer.toString( localDate.getYear() );
-
- String theBottom = StringUtils.replace( this.bottom, "{currentYear}", currentYear );
-
- if ( ( inceptionYear == null ) || inceptionYear.equals( currentYear ) )
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}–", "" );
- }
- else
- {
- theBottom = StringUtils.replace( theBottom, "{inceptionYear}", inceptionYear );
- }
-
- if ( project.getOrganization() == null )
- {
- theBottom = StringUtils.replace( theBottom, " {organizationName}", "" );
- }
- else
- {
- if ( StringUtils.isNotEmpty( project.getOrganization().getName() ) )
- {
- if ( StringUtils.isNotEmpty( project.getOrganization().getUrl() ) )
- {
- theBottom = StringUtils.replace( theBottom, "{organizationName}",
- "<a href=\"" + project.getOrganization().getUrl() + "\">"
- + project.getOrganization().getName() + "</a>" );
+ final LocalDate localDate = MavenArchiver.parseBuildOutputTimestamp(outputTimestamp)
+ .map(instant -> instant.atZone(ZoneOffset.UTC).toLocalDate())
+ .orElseGet(LocalDate::now);
+
+ final String currentYear = Integer.toString(localDate.getYear());
+
+ String theBottom = StringUtils.replace(this.bottom, "{currentYear}", currentYear);
+
+ if ((inceptionYear == null) || inceptionYear.equals(currentYear)) {
+ theBottom = StringUtils.replace(theBottom, "{inceptionYear}–", "");
+ } else {
+ theBottom = StringUtils.replace(theBottom, "{inceptionYear}", inceptionYear);
+ }
+
+ if (project.getOrganization() == null) {
+ theBottom = StringUtils.replace(theBottom, " {organizationName}", "");
+ } else {
+ if (StringUtils.isNotEmpty(project.getOrganization().getName())) {
+ if (StringUtils.isNotEmpty(project.getOrganization().getUrl())) {
+ theBottom = StringUtils.replace(
+ theBottom,
+ "{organizationName}",
+ "<a href=\"" + project.getOrganization().getUrl() + "\">"
+ + project.getOrganization().getName() + "</a>");
+ } else {
+ theBottom = StringUtils.replace(
+ theBottom,
+ "{organizationName}",
+ project.getOrganization().getName());
}
- else
- {
- theBottom =
- StringUtils.replace( theBottom, "{organizationName}", project.getOrganization().getName() );
- }
- }
- else
- {
- theBottom = StringUtils.replace( theBottom, " {organizationName}", "" );
+ } else {
+ theBottom = StringUtils.replace(theBottom, " {organizationName}", "");
}
}
@@ -2930,76 +2711,64 @@ public abstract class AbstractJavadocMojo
* @return the stylesheet file absolute path as String.
* @see #getResource(List, String)
*/
- private Optional<File> getStylesheetFile( final File javadocOutputDirectory )
- {
- if ( StringUtils.isEmpty( stylesheetfile ) )
- {
- if ( "java".equalsIgnoreCase( stylesheet ) )
- {
+ private Optional<File> getStylesheetFile(final File javadocOutputDirectory) {
+ if (StringUtils.isEmpty(stylesheetfile)) {
+ if ("java".equalsIgnoreCase(stylesheet)) {
// use the default Javadoc tool stylesheet
return Optional.empty();
}
- getLog().warn( "Parameter 'stylesheet' is no longer evaluated, rather use 'addStylesheets'"
- + " to customize the CSS!" );
+ getLog().warn("Parameter 'stylesheet' is no longer evaluated, rather use 'addStylesheets'"
+ + " to customize the CSS!");
return Optional.empty();
}
- if ( new File( stylesheetfile ).exists() )
- {
- return Optional.of( new File( stylesheetfile ) );
+ if (new File(stylesheetfile).exists()) {
+ return Optional.of(new File(stylesheetfile));
}
- return getResource( new File( javadocOutputDirectory, DEFAULT_CSS_NAME ), stylesheetfile );
+ return getResource(new File(javadocOutputDirectory, DEFAULT_CSS_NAME), stylesheetfile);
}
- private void addAddStyleSheets( List<String> arguments ) throws MavenReportException
- {
- if ( addStylesheets == null )
- {
+ private void addAddStyleSheets(List<String> arguments) throws MavenReportException {
+ if (addStylesheets == null) {
return;
}
- for ( String addStylesheet : addStylesheets )
- {
- Optional<File> styleSheet = getAddStylesheet( getJavadocDirectory(), addStylesheet );
+ for (String addStylesheet : addStylesheets) {
+ Optional<File> styleSheet = getAddStylesheet(getJavadocDirectory(), addStylesheet);
- if ( styleSheet.isPresent() )
- {
- addArgIfNotEmpty( arguments, "--add-stylesheet",
- JavadocUtil.quotedPathArgument( styleSheet.get().getAbsolutePath() ),
- JavaVersion.parse( "10" ) );
+ if (styleSheet.isPresent()) {
+ addArgIfNotEmpty(
+ arguments,
+ "--add-stylesheet",
+ JavadocUtil.quotedPathArgument(styleSheet.get().getAbsolutePath()),
+ JavaVersion.parse("10"));
}
}
}
-
- private Optional<File> getAddStylesheet( final File javadocOutputDirectory, final String stylesheet )
- throws MavenReportException
- {
- if ( StringUtils.isEmpty( stylesheet ) )
- {
+ private Optional<File> getAddStylesheet(final File javadocOutputDirectory, final String stylesheet)
+ throws MavenReportException {
+ if (StringUtils.isEmpty(stylesheet)) {
return Optional.empty();
}
- File addstylesheetfile = new File( getJavadocDirectory(), stylesheet );
- if ( addstylesheetfile.exists() )
- {
- Optional<File> stylesheetfile = getStylesheetFile( javadocOutputDirectory );
- if ( stylesheetfile.isPresent() )
- {
- if ( stylesheetfile.get().getName().equals( addstylesheetfile.getName() ) )
- {
- throw new MavenReportException( "additional stylesheet must have a different name "
- + "than stylesheetfile: " + stylesheetfile.get().getName() );
+ File addstylesheetfile = new File(getJavadocDirectory(), stylesheet);
+ if (addstylesheetfile.exists()) {
+ Optional<File> stylesheetfile = getStylesheetFile(javadocOutputDirectory);
+ if (stylesheetfile.isPresent()) {
+ if (stylesheetfile.get().getName().equals(addstylesheetfile.getName())) {
+ throw new MavenReportException("additional stylesheet must have a different name "
+ + "than stylesheetfile: " + stylesheetfile.get().getName());
}
}
- return Optional.of( addstylesheetfile );
+ return Optional.of(addstylesheetfile);
}
- throw new MavenReportException( "additional stylesheet file does not exist: "
- + addstylesheetfile.getAbsolutePath() );
+ throw new MavenReportException(
+ "additional stylesheet file does not exist: " + addstylesheetfile.getAbsolutePath());
}
/**
@@ -3014,19 +2783,16 @@ public abstract class AbstractJavadocMojo
* @see #getResource(File, String)
* @since 2.6
*/
- private Optional<File> getHelpFile( final File javadocOutputDirectory )
- {
- if ( StringUtils.isEmpty( helpfile ) )
- {
+ private Optional<File> getHelpFile(final File javadocOutputDirectory) {
+ if (StringUtils.isEmpty(helpfile)) {
return Optional.empty();
}
- if ( new File( helpfile ).exists() )
- {
- return Optional.of( new File( helpfile ) );
+ if (new File(helpfile).exists()) {
+ return Optional.of(new File(helpfile));
}
- return getResource( new File( javadocOutputDirectory, "help-doc.html" ), helpfile );
+ return getResource(new File(javadocOutputDirectory, "help-doc.html"), helpfile);
}
/**
@@ -3036,19 +2802,16 @@ public abstract class AbstractJavadocMojo
*
* @return the access level
*/
- private String getAccessLevel()
- {
+ private String getAccessLevel() {
String accessLevel;
- if ( "public".equalsIgnoreCase( show ) || "protected".equalsIgnoreCase( show ) || "package".equalsIgnoreCase(
- show ) || "private".equalsIgnoreCase( show ) )
- {
+ if ("public".equalsIgnoreCase(show)
+ || "protected".equalsIgnoreCase(show)
+ || "package".equalsIgnoreCase(show)
+ || "private".equalsIgnoreCase(show)) {
accessLevel = "-" + show;
- }
- else
- {
- if ( getLog().isErrorEnabled() )
- {
- getLog().error( "Unrecognized access level to show '" + show + "'. Defaulting to protected." );
+ } else {
+ if (getLog().isErrorEnabled()) {
+ getLog().error("Unrecognized access level to show '" + show + "'. Defaulting to protected.");
}
accessLevel = "-protected";
}
@@ -3064,30 +2827,25 @@ public abstract class AbstractJavadocMojo
* @throws MavenReportException if any
* @see File#pathSeparator
*/
- private String getBootclassPath()
- throws MavenReportException
- {
+ private String getBootclassPath() throws MavenReportException {
Set<BootclasspathArtifact> bootclasspathArtifacts = collectBootClasspathArtifacts();
List<String> bootclassPath = new ArrayList<>();
- for ( BootclasspathArtifact aBootclasspathArtifact : bootclasspathArtifacts )
- {
- if ( ( StringUtils.isNotEmpty( aBootclasspathArtifact.getGroupId() ) ) && ( StringUtils.isNotEmpty(
- aBootclasspathArtifact.getArtifactId() ) ) && ( StringUtils.isNotEmpty(
- aBootclasspathArtifact.getVersion() ) ) )
- {
- bootclassPath.addAll( getArtifactsAbsolutePath( aBootclasspathArtifact ) );
+ for (BootclasspathArtifact aBootclasspathArtifact : bootclasspathArtifacts) {
+ if ((StringUtils.isNotEmpty(aBootclasspathArtifact.getGroupId()))
+ && (StringUtils.isNotEmpty(aBootclasspathArtifact.getArtifactId()))
+ && (StringUtils.isNotEmpty(aBootclasspathArtifact.getVersion()))) {
+ bootclassPath.addAll(getArtifactsAbsolutePath(aBootclasspathArtifact));
}
}
- bootclassPath = JavadocUtil.pruneFiles( bootclassPath );
+ bootclassPath = JavadocUtil.pruneFiles(bootclassPath);
StringBuilder path = new StringBuilder();
- path.append( StringUtils.join( bootclassPath.iterator(), File.pathSeparator ) );
+ path.append(StringUtils.join(bootclassPath.iterator(), File.pathSeparator));
- if ( StringUtils.isNotEmpty( bootclasspath ) )
- {
- path.append( JavadocUtil.unifyPathSeparator( bootclasspath ) );
+ if (StringUtils.isNotEmpty(bootclasspath)) {
+ path.append(JavadocUtil.unifyPathSeparator(bootclasspath));
}
return path.toString();
@@ -3105,31 +2863,25 @@ public abstract class AbstractJavadocMojo
* @throws MavenReportException if any
* @see File#pathSeparator
*/
- private String getDocletPath()
- throws MavenReportException
- {
+ private String getDocletPath() throws MavenReportException {
Set<DocletArtifact> docletArtifacts = collectDocletArtifacts();
List<String> pathParts = new ArrayList<>();
- for ( DocletArtifact docletArtifact : docletArtifacts )
- {
- if ( !isDocletArtifactEmpty( docletArtifact ) )
- {
- pathParts.addAll( getArtifactsAbsolutePath( docletArtifact ) );
+ for (DocletArtifact docletArtifact : docletArtifacts) {
+ if (!isDocletArtifactEmpty(docletArtifact)) {
+ pathParts.addAll(getArtifactsAbsolutePath(docletArtifact));
}
}
... 27118 lines suppressed ...