Package org.apache.maven.plugins.javadoc
Class AbstractJavadocMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- org.apache.maven.plugins.javadoc.AbstractJavadocMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled,org.apache.maven.plugin.Mojo
- Direct Known Subclasses:
JavadocJar,JavadocReport,ResourcesBundleMojo
public abstract class AbstractJavadocMojo extends org.apache.maven.plugin.AbstractMojoBase class with majority of Javadoc functionalities.- Since:
- 2.0
- Author:
- Brett Porter, Vincent Siveton
- See Also:
- The javadoc Command
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringARGFILE_FILE_NAMETheargfilefile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @filesprotected static StringDEBUG_JAVADOC_SCRIPT_NAMEThe Javadoc script file name whendebugparameter is on, i.e.protected booleanfailOnErrorSpecifies if the build will fail if there are errors during javadoc execution or not.protected booleanfailOnWarningsSpecifies if the build will fail if there are warning during javadoc execution or not.protected static StringFILES_FILE_NAMEThefilesfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @filesstatic StringJAVADOC_RESOURCES_ATTACHMENT_CLASSIFIERClassifier used in the name of the javadoc-options XML file, and in the resources bundle artifact that gets attached to the project.protected ArrayList<String>linksCreates links to existing javadoc-generated documentation of external referenced classes.protected org.apache.maven.plugin.MojoExecutionmojoExecutionprotected static StringOPTIONS_FILE_NAMETheoptionsfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @filesprotected FileoutputDirectorySpecifies the destination directory where javadoc saves the generated HTML files.protected StringoutputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).protected static StringPACKAGES_FILE_NAMEThepackagesfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @filesprotected org.apache.maven.project.MavenProjectprojectThe Maven Project Objectprotected List<org.apache.maven.project.MavenProject>reactorProjectsThe projects in the reactor for aggregation report.protected org.apache.maven.execution.MavenSessionsessionThe current build session instance.protected booleanskipSpecifies whether the Javadoc generation should be skipped.static StringTEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIERClassifier used in the name of the javadoc-options XML file, and in the resources bundle artifact that gets attached to the project.protected booleanuseStandardDocletOptionsSpecifies to use the options provided by the Standard Doclet for a custom doclet.
-
Constructor Summary
Constructors Constructor Description AbstractJavadocMojo()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected JavadocOptionsbuildJavadocOptions()Generate a javadoc-options XML file, for either bundling with a javadoc-resources artifact OR supplying to a distro module in a includeDependencySources configuration, so the javadoc options from this execution can be reconstructed and merged in the distro build.protected booleancanGenerateReport(Map<Path,Collection<String>> files)Method that indicates whether the javadoc can be generated or not.protected SourceResolverConfigconfigureDependencySourceResolution(SourceResolverConfig config)Override this method to customize the configuration for resolving dependency sources.voidexecute()protected voidexecuteReport(Locale unusedLocale)The package documentation details the Javadoc Options used by this Plugin.protected voidfailOnError(String prefix, Exception e)protected StringgetAttachmentClassifier()Override this if you need to provide a bundle attachment classifier, as in the case of test javadocs.protected FilegetClassesFile(org.apache.maven.project.MavenProject project)protected OfflineLinkgetDefaultJavadocApiLink()protected org.eclipse.aether.util.filter.ScopeDependencyFiltergetDependencyScopeFilter()protected Collection<JavadocModule>getDependencySourcePaths()Resolve dependency sources so they can be included directly in the javadoc process.protected StringgetDoclint()protected StringgetDoctitle()protected List<String>getExecutionProjectSourceRoots(org.apache.maven.project.MavenProject p)protected Map<Path,Collection<String>>getFiles(Collection<Path> sourcePaths)Method to get the files on the specified source pathsprotected FilegetJavadocDirectory()protected FilegetJavadocOptionsFile()Construct the output file for the generated javadoc-options XML file, after creating the javadocOptionsDir if necessary.protected StringgetOutputDirectory()protected FilegetOverview()protected org.apache.maven.project.MavenProjectgetProject()protected List<File>getProjectBuildOutputDirs(org.apache.maven.project.MavenProject p)protected List<String>getProjectSourceRoots(org.apache.maven.project.MavenProject p)protected List<org.apache.maven.project.MavenProject>getReactorProjects()protected Collection<JavadocModule>getSourcePaths()Method to get the source paths per reactorProject.protected org.apache.maven.toolchain.ToolchaingetToolchain()protected StringgetWindowtitle()protected booleanisAggregator()Indicates whether this goal is flagged with@aggregator.protected booleanisSkippedJavadoc(org.apache.maven.project.MavenProject mavenProject)protected booleanisSkippedModule(org.apache.maven.project.MavenProject mavenProject)protected booleanisTest()Indicates whether this goal generates documentation for theJava Test code.protected booleanisValidJavadocLink(String link, boolean detecting)protected voidlogError(String message, Throwable t)Logs an error with throwable content only if in debug.org.apache.maven.artifact.ArtifactresolveDependency(org.apache.maven.model.Dependency dependency)protected voidverifyRemovedParameter(String paramName)
-
-
-
Field Detail
-
JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER
public static final String JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER
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.- Since:
- 2.7
- See Also:
TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, Constant Field Values
-
TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER
public static final String TEST_JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER
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 test-javadocs.- Since:
- 2.7
- See Also:
JAVADOC_RESOURCES_ATTACHMENT_CLASSIFIER, Constant Field Values
-
DEBUG_JAVADOC_SCRIPT_NAME
protected static final String DEBUG_JAVADOC_SCRIPT_NAME
The Javadoc script file name whendebugparameter is on, i.e. javadoc.bat or javadoc.sh
-
OPTIONS_FILE_NAME
protected static final String OPTIONS_FILE_NAME
Theoptionsfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @files- See Also:
- Constant Field Values
-
PACKAGES_FILE_NAME
protected static final String PACKAGES_FILE_NAME
Thepackagesfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @files- See Also:
- Constant Field Values
-
ARGFILE_FILE_NAME
protected static final String ARGFILE_FILE_NAME
Theargfilefile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @files- See Also:
- Constant Field Values
-
FILES_FILE_NAME
protected static final String FILES_FILE_NAME
Thefilesfile name in the output directory when calling:javadoc.exe(or .sh) @options @packages | @argfile | @files- See Also:
- Constant Field Values
-
session
@Parameter(defaultValue="${session}", readonly=true, required=true) protected org.apache.maven.execution.MavenSession sessionThe current build session instance. This is used for toolchain manager API calls.
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) protected org.apache.maven.project.MavenProject projectThe Maven Project Object
-
mojoExecution
@Parameter(defaultValue="${mojoExecution}", readonly=true, required=true) protected org.apache.maven.plugin.MojoExecution mojoExecution
-
reactorProjects
@Parameter(defaultValue="${reactorProjects}", required=true, readonly=true) protected List<org.apache.maven.project.MavenProject> reactorProjectsThe projects in the reactor for aggregation report.
-
skip
@Parameter(property="maven.javadoc.skip", defaultValue="false") protected boolean skipSpecifies whether the Javadoc generation should be skipped.- Since:
- 2.5
-
failOnError
@Parameter(property="maven.javadoc.failOnError", defaultValue="true") protected boolean failOnErrorSpecifies if the build will fail if there are errors during javadoc execution or not.- Since:
- 2.5
-
failOnWarnings
@Parameter(property="maven.javadoc.failOnWarnings", defaultValue="false") protected boolean failOnWarningsSpecifies if the build will fail if there are warning during javadoc execution or not.- Since:
- 3.0.1
-
useStandardDocletOptions
@Parameter(property="useStandardDocletOptions", defaultValue="true") protected boolean useStandardDocletOptionsSpecifies to use the options provided by the Standard Doclet for a custom doclet.
Example:<docletArtifacts> <docletArtifact> <groupId>com.sun.tools.doclets</groupId> <artifactId>doccheck</artifactId> <version>1.2b2</version> </docletArtifact> </docletArtifacts> <useStandardDocletOptions>true</useStandardDocletOptions>- Since:
- 2.5
-
links
@Parameter(property="links") protected ArrayList<String> links
Creates links to existing javadoc-generated documentation of external referenced classes.Notes:
- This option is ignored if the plugin is run in offline mode (using the
<offline>setting or specifying-o, --offlineor-Dmaven.javadoc.offline=trueon the command line. - all given links should have a fetchable
/package-listor/element-list(since Java 10). For instance:<links> <link>https://docs.oracle.com/en/java/javase/17/docs/api</link> <links>
will be used becausehttps://docs.oracle.com/en/java/javase/17/docs/api/element-listexists. - If
detectLinksis defined, the links between the project dependencies are automatically added. - If
detectJavaApiLinkis defined, a Java API link, based on the Java version of the project's sources, will be added automatically.
- See Also:
- Doclet option link
- This option is ignored if the plugin is run in offline mode (using the
-
outputDirectory
@Parameter(property="destDir", alias="destDir", defaultValue="${project.build.directory}/apidocs", required=true) protected File outputDirectorySpecifies the destination directory where javadoc saves the generated HTML files.- See Also:
- Doclet option d
-
outputTimestamp
@Parameter(defaultValue="${project.build.outputTimestamp}") protected String outputTimestampTimestamp for reproducible output archive entries, either formatted as ISO 8601yyyy-MM-dd'T'HH:mm:ssXXXor as an int representing seconds since the epoch (like SOURCE_DATE_EPOCH).- Since:
- 3.2.0
-
-
Method Detail
-
isAggregator
protected boolean isAggregator()
Indicates whether this goal is flagged with@aggregator.- Returns:
trueif the goal is designed as an aggregator,falseotherwise.- See Also:
AggregatorJavadocReport,AggregatorTestJavadocReport
-
isTest
protected boolean isTest()
Indicates whether this goal generates documentation for theJava Test code.- Returns:
trueif the goal generates Test Javadocs,falseotherwise.
-
getOutputDirectory
protected String getOutputDirectory()
- Returns:
- the output directory
-
getProject
protected org.apache.maven.project.MavenProject getProject()
-
getProjectBuildOutputDirs
protected List<File> getProjectBuildOutputDirs(org.apache.maven.project.MavenProject p)
- Parameters:
p- not null maven project- Returns:
- the list of directories where compiled classes are placed for the given project. These dirs are added to the javadoc classpath.
-
getClassesFile
protected File getClassesFile(org.apache.maven.project.MavenProject project)
- Parameters:
project- the project in which to find a classes file- Returns:
- null, the attached artifact file, or outputDirectory.
-
getProjectSourceRoots
protected List<String> getProjectSourceRoots(org.apache.maven.project.MavenProject p)
- Parameters:
p- not null maven project- Returns:
- the list of source paths for the given project
-
getExecutionProjectSourceRoots
protected List<String> getExecutionProjectSourceRoots(org.apache.maven.project.MavenProject p)
- Parameters:
p- not null maven project- Returns:
- the list of source paths for the execution project of the given project
-
getJavadocDirectory
protected File getJavadocDirectory()
- Returns:
- the current javadoc directory
-
getDoclint
protected String getDoclint()
- Returns:
- the doclint specific checks configuration
-
getDoctitle
protected String getDoctitle()
- Returns:
- the title to be placed near the top of the overview summary file
-
getOverview
protected File getOverview()
- Returns:
- the overview documentation file from the user parameter or from the
javadocdirectory
-
getWindowtitle
protected String getWindowtitle()
- Returns:
- the title to be placed in the HTML title tag
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException- Throws:
org.apache.maven.plugin.MojoExecutionExceptionorg.apache.maven.plugin.MojoFailureException
-
verifyRemovedParameter
protected final void verifyRemovedParameter(String paramName)
-
executeReport
protected void executeReport(Locale unusedLocale) throws org.apache.maven.reporting.MavenReportException
The package documentation details the Javadoc Options used by this Plugin.- Parameters:
unusedLocale- the wanted locale (actually unused).- Throws:
org.apache.maven.reporting.MavenReportException- if any
-
getFiles
protected Map<Path,Collection<String>> getFiles(Collection<Path> sourcePaths) throws org.apache.maven.reporting.MavenReportException
Method to get the files on the specified source paths- Parameters:
sourcePaths- a Collection that contains the paths to the source files- Returns:
- a List that contains the specific path for every source file
- Throws:
org.apache.maven.reporting.MavenReportException-MavenReportExceptionissue while generating report
-
getSourcePaths
protected Collection<JavadocModule> getSourcePaths() throws org.apache.maven.reporting.MavenReportException
Method to get the source paths per reactorProject. If no source path is specified in the parameter, the compile source roots of the project will be used.- Returns:
- a Map of the project absolute source paths per projects key (G:A)
- Throws:
org.apache.maven.reporting.MavenReportException-MavenReportExceptionissue while generating report- See Also:
JavadocUtil.pruneDirs(MavenProject, Collection)
-
configureDependencySourceResolution
protected SourceResolverConfig configureDependencySourceResolution(SourceResolverConfig config)
Override this method to customize the configuration for resolving dependency sources. The default behavior enables the resolution of -sources jar files.- Parameters:
config-SourceResolverConfig- Returns:
SourceResolverConfig
-
getDependencySourcePaths
protected final Collection<JavadocModule> getDependencySourcePaths() throws org.apache.maven.reporting.MavenReportException
Resolve dependency sources so they can be included directly in the javadoc process. To customize this, overrideconfigureDependencySourceResolution(SourceResolverConfig).- Returns:
- List of source paths.
- Throws:
org.apache.maven.reporting.MavenReportException-MavenReportException
-
canGenerateReport
protected boolean canGenerateReport(Map<Path,Collection<String>> files)
Method that indicates whether the javadoc can be generated or not. If the project does not contain any source files and no subpackages are specified, the plugin will terminate.- Parameters:
files- the project files- Returns:
- a boolean that indicates whether javadoc report can be generated or not
-
getDependencyScopeFilter
protected org.eclipse.aether.util.filter.ScopeDependencyFilter getDependencyScopeFilter()
-
resolveDependency
public org.apache.maven.artifact.Artifact resolveDependency(org.apache.maven.model.Dependency dependency) throws org.apache.maven.reporting.MavenReportException- Parameters:
dependency-Dependency- Returns:
Artifact- Throws:
org.apache.maven.reporting.MavenReportException- when artifact could not be resolved
-
getToolchain
protected final org.apache.maven.toolchain.Toolchain getToolchain()
-
getDefaultJavadocApiLink
protected final OfflineLink getDefaultJavadocApiLink()
- Returns:
- if
detectJavaApiLink, the Java API link based on thejavaApiLinksproperties and the value of thesourceparameter in theorg.apache.maven.plugins:maven-compiler-plugindefined in${project.build.plugins}or in${project.build.pluginManagement}, or thejavadocRuntimeVersion, ornullif not defined. - Since:
- 2.6
- See Also:
- source parameter
-
isValidJavadocLink
protected boolean isValidJavadocLink(String link, boolean detecting)
- Parameters:
link- not nulldetecting-trueif the link is generated bydetectLinks, orfalseotherwise- Returns:
trueif the link has a/package-list,falseotherwise.- Since:
- 2.6
- See Also:
- package-list spec
-
getJavadocOptionsFile
protected final File getJavadocOptionsFile()
Construct the output file for the generated javadoc-options XML file, after creating the javadocOptionsDir if necessary. This method does NOT write to the file in question.- Returns:
- The options
Filefile. - Since:
- 2.7
-
buildJavadocOptions
protected final JavadocOptions buildJavadocOptions() throws IOException
Generate a javadoc-options XML file, for either bundling with a javadoc-resources artifact OR supplying to a distro module in a includeDependencySources configuration, so the javadoc options from this execution can be reconstructed and merged in the distro build.- Returns:
JavadocOptions- Throws:
IOException-IOException- Since:
- 2.7
-
getAttachmentClassifier
protected String getAttachmentClassifier()
Override this if you need to provide a bundle attachment classifier, as in the case of test javadocs.- Returns:
- The attachment classifier.
-
logError
protected void logError(String message, Throwable t)
Logs an error with throwable content only if in debug.- Parameters:
message- The message which should be announced.t- The throwable part of the message.
-
getReactorProjects
protected List<org.apache.maven.project.MavenProject> getReactorProjects()
-
failOnError
protected void failOnError(String prefix, Exception e) throws org.apache.maven.plugin.MojoExecutionException
- Parameters:
prefix- The prefix of the exception.e- The exception.- Throws:
org.apache.maven.plugin.MojoExecutionException-MojoExecutionExceptionissue while generating report
-
isSkippedModule
protected boolean isSkippedModule(org.apache.maven.project.MavenProject mavenProject)
- Parameters:
mavenProject- the project that might be skipped- Returns:
trueif the project needs to be skipped from aggregate generation
-
isSkippedJavadoc
protected boolean isSkippedJavadoc(org.apache.maven.project.MavenProject mavenProject)
- Parameters:
mavenProject- the project that might be skipped- Returns:
trueif the pom configuration skips javadoc generation for the project
-
-