Package org.apache.maven.plugins.javadoc
Class JavadocUtil
- java.lang.Object
-
- org.apache.maven.plugins.javadoc.JavadocUtil
-
public class JavadocUtil extends java.lang.ObjectSet of utilities methods for Javadoc.- Since:
- 2.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classJavadocUtil.JavadocOutputStreamConsumerIgnores line like 'Picked up JAVA_TOOL_OPTIONS: ...' as can happen on CI servers.private static classJavadocUtil.PathTokenizerA Path tokenizer takes a path and returns the components that make up that path.
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_TIMEOUTThe default timeout used when fetching url, i.e.protected static java.lang.StringERROR_INIT_VMError message when VM could not be started using invoker.
-
Constructor Summary
Constructors Constructor Description JavadocUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static voidcopyJavadocResources(java.io.File outputDirectory, java.io.File javadocDir, java.lang.String excludedocfilessubdir)Convenience method that copy alldoc-filesdirectories fromjavadocDirto theoutputDirectory.protected static voidcopyResource(java.net.URL url, java.io.File file)Copy the given url to the given file.private static org.apache.http.impl.client.CloseableHttpClientcreateHttpClient(org.apache.maven.settings.Settings settings, java.net.URL url)Creates a newHttpClientinstance.(package private) static booleanequals(java.lang.String value, java.lang.String... strings)(package private) static booleanequalsIgnoreCase(java.lang.String value, java.lang.String... strings)protected static java.lang.StringextractJavadocVersion(java.lang.String output)Parse the output for 'javadoc -J-version' and return the javadoc version recognized.private static java.util.List<java.lang.String>getClassNamesFromJar(java.io.File jarFile)protected static java.util.Collection<java.lang.String>getExcludedPackages(java.nio.file.Path sourceDirectory, java.util.Collection<java.lang.String> excludePackagenames)Method that gets the complete package names (including subpackages) of the packages that were defined in the excludePackageNames parameter.protected static java.util.List<java.lang.String>getExcludedPackages(java.util.Collection<java.nio.file.Path> sourcePaths, java.util.Collection<java.lang.String> excludedPackages)Method that gets all the source files to be excluded from the javadoc on the given source paths.protected static java.util.List<java.lang.String>getFilesFromSource(java.io.File sourceDirectory, java.util.List<java.lang.String> sourceFileIncludes, java.util.List<java.lang.String> sourceFileExcludes, java.util.Collection<java.lang.String> excludePackages)Convenience method that gets the files to be included in the javadoc.protected static java.util.List<java.lang.String>getIncludedFiles(java.io.File sourceDirectory, java.lang.String[] fileList, java.util.Collection<java.lang.String> excludePackages)Method that gets the files or classes that would be included in the javadocs using the subpackages parameter.protected static org.codehaus.plexus.languages.java.version.JavaVersiongetJavadocVersion(java.io.File javadocExe)Call the Javadoc tool and parse its output to find its version, i.e.:private static java.io.FilegetJavaHome(org.apache.maven.plugin.logging.Log log)private static java.lang.StringgetJavaOpts(org.apache.maven.plugin.logging.Log log)private static java.lang.StringgetMavenHome(org.apache.maven.plugin.logging.Log log)private static java.lang.StringgetMavenOpts(org.apache.maven.plugin.logging.Log log)private static java.io.BufferedReadergetReader(java.net.URL url, org.apache.maven.settings.Settings settings)protected static java.net.URLgetRedirectUrl(java.net.URL url, org.apache.maven.settings.Settings settings)Execute an Http request at the given URL, follows redirects, and returns the last redirect locations.protected static java.util.List<java.lang.String>getTagletClassNames(java.io.File jarFile)Auto-detect the class names of the implementation ofcom.sun.tools.doclets.Tagletclass from a given jar file.private static org.apache.maven.shared.invoker.InvocationResultinvoke(org.apache.maven.plugin.logging.Log log, org.apache.maven.shared.invoker.Invoker invoker, org.apache.maven.shared.invoker.InvocationRequest request, java.io.File invokerLog, java.util.List<java.lang.String> goals, java.util.Properties properties, java.lang.String mavenOpts)protected static voidinvokeMaven(org.apache.maven.plugin.logging.Log log, java.io.File localRepositoryDir, java.io.File projectFile, java.util.List<java.lang.String> goals, java.util.Properties properties, java.io.File invokerLog, java.io.File globalSettingsFile)Invoke Maven for the given project file with a list of goals and properties, the output will be in the invokerlog file.static booleanisEmpty(java.util.Collection<?> collection)Convenience method to determine that a collection is empty or null.static booleanisNotEmpty(java.util.Collection<?> collection)Convenience method to determine that a collection is not empty or null.private static booleanisValidClassName(java.lang.String str)protected static booleanisValidElementList(java.net.URL url, org.apache.maven.settings.Settings settings, boolean validateContent)protected static booleanisValidPackageList(java.net.URL url, org.apache.maven.settings.Settings settings, boolean validateContent)Validates anURLto point to a validpackage-listresource.private static booleanisValidPackageName(java.lang.String str)protected static java.lang.StringparseJavadocMemory(java.lang.String memory)Parse a memory string which be used in the JVM arguments-Xmsor-Xmx.static java.util.Collection<java.nio.file.Path>pruneDirs(org.apache.maven.project.MavenProject project, java.util.Collection<java.lang.String> dirs)Method that removes the invalid directories in the specified directories.protected static java.util.List<java.lang.String>pruneFiles(java.util.Collection<java.lang.String> files)Method that removes the invalid files in the specified files.protected static java.lang.StringquotedArgument(java.lang.String value)Convenience method to wrap an argument value in single quotes (i.e.protected static java.lang.StringquotedPathArgument(java.lang.String value)Convenience method to format a path argument so that it is properly interpreted by the javadoc tool.protected static java.lang.StringreadFile(java.io.File javaFile, java.lang.String encoding)Read the given file and return the content or null if an IOException occurs.static booleanshouldPruneFile(java.lang.String f, java.util.List<java.lang.String> pruned)Determine whether a file should be excluded from the provided list of paths, based on whether it exists and is already present in the list.protected static java.lang.String[]splitPath(java.lang.String path)Split the given path with colon and semi-colon, to support Solaris and Windows path.(package private) static java.util.List<java.lang.String>toList(java.lang.String src)(package private) static java.util.List<java.lang.String>toList(java.lang.String src, java.lang.String elementPrefix, java.lang.String elementSuffix)(package private) static <T> java.util.List<T>toList(T[] multiple)(package private) static <T> java.util.List<T>toList(T single, T[] multiple)static java.lang.StringtoRelative(java.io.File basedir, java.lang.String absolutePath)protected static java.lang.StringunifyPathSeparator(java.lang.String path)Unify the given path with the current System path separator, to be platform independent.protected static booleanvalidateEncoding(java.lang.String charsetName)Validate if a charset is supported on this platform.
-
-
-
Field Detail
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUT
The default timeout used when fetching url, i.e. 2000.- See Also:
- Constant Field Values
-
ERROR_INIT_VM
protected static final java.lang.String ERROR_INIT_VM
Error message when VM could not be started using invoker.- See Also:
- Constant Field Values
-
-
Method Detail
-
pruneDirs
public static java.util.Collection<java.nio.file.Path> pruneDirs(org.apache.maven.project.MavenProject project, java.util.Collection<java.lang.String> dirs)Method that removes the invalid directories in the specified directories. Note: All elements indirscould be an absolute or relative against the project's base directoryStringpath.- Parameters:
project- the current Maven project not nulldirs- the collection ofStringdirectories path that will be validated.- Returns:
- a List of valid
Stringdirectories absolute paths.
-
pruneFiles
protected static java.util.List<java.lang.String> pruneFiles(java.util.Collection<java.lang.String> files)
Method that removes the invalid files in the specified files. Note: All elements infilesshould be an absoluteStringpath.- Parameters:
files- the list ofStringfiles paths that will be validated.- Returns:
- a List of valid
Fileobjects.
-
shouldPruneFile
public static boolean shouldPruneFile(java.lang.String f, java.util.List<java.lang.String> pruned)Determine whether a file should be excluded from the provided list of paths, based on whether it exists and is already present in the list.- Parameters:
f- The files.pruned- The list of pruned files..- Returns:
- true if the file could be pruned false otherwise.
-
getExcludedPackages
protected static java.util.List<java.lang.String> getExcludedPackages(java.util.Collection<java.nio.file.Path> sourcePaths, java.util.Collection<java.lang.String> excludedPackages)Method that gets all the source files to be excluded from the javadoc on the given source paths.- Parameters:
sourcePaths- the path to the source filesexcludedPackages- the package names to be excluded in the javadoc- Returns:
- a List of the packages to be excluded in the generated javadoc
-
quotedArgument
protected static java.lang.String quotedArgument(java.lang.String value)
Convenience method to wrap an argument value in single quotes (i.e.'). Intended for values which may contain whitespaces.
To prevent javadoc error, the line separator (i.e.\n) are skipped.- Parameters:
value- the argument value.- Returns:
- argument with quote
-
quotedPathArgument
protected static java.lang.String quotedPathArgument(java.lang.String value)
Convenience method to format a path argument so that it is properly interpreted by the javadoc tool. Intended for path values which may contain whitespaces.- Parameters:
value- the argument value.- Returns:
- path argument with quote
-
copyJavadocResources
protected static void copyJavadocResources(java.io.File outputDirectory, java.io.File javadocDir, java.lang.String excludedocfilessubdir) throws java.io.IOExceptionConvenience method that copy alldoc-filesdirectories fromjavadocDirto theoutputDirectory.- Parameters:
outputDirectory- the output directoryjavadocDir- the javadoc directoryexcludedocfilessubdir- the excludedocfilessubdir parameter- Throws:
java.io.IOException- if any- Since:
- 2.5
-
getIncludedFiles
protected static java.util.List<java.lang.String> getIncludedFiles(java.io.File sourceDirectory, java.lang.String[] fileList, java.util.Collection<java.lang.String> excludePackages)Method that gets the files or classes that would be included in the javadocs using the subpackages parameter.- Parameters:
sourceDirectory- the directory where the source files are locatedfileList- the list of all relative files found in the sourceDirectoryexcludePackages- package names to be excluded in the javadoc- Returns:
- a StringBuilder that contains the appended file names of the files to be included in the javadoc
-
getExcludedPackages
protected static java.util.Collection<java.lang.String> getExcludedPackages(java.nio.file.Path sourceDirectory, java.util.Collection<java.lang.String> excludePackagenames)Method that gets the complete package names (including subpackages) of the packages that were defined in the excludePackageNames parameter.- Parameters:
sourceDirectory- the directory where the source files are locatedexcludePackagenames- package names to be excluded in the javadoc- Returns:
- a List of the packagenames to be excluded
-
getFilesFromSource
protected static java.util.List<java.lang.String> getFilesFromSource(java.io.File sourceDirectory, java.util.List<java.lang.String> sourceFileIncludes, java.util.List<java.lang.String> sourceFileExcludes, java.util.Collection<java.lang.String> excludePackages)Convenience method that gets the files to be included in the javadoc.- Parameters:
sourceDirectory- the directory where the source files are locatedexcludePackages- the packages to be excluded in the javadocssourceFileIncludes- files to include.sourceFileExcludes- files to exclude.
-
getJavadocVersion
protected static org.codehaus.plexus.languages.java.version.JavaVersion getJavadocVersion(java.io.File javadocExe) throws java.io.IOException, org.codehaus.plexus.util.cli.CommandLineException, java.lang.IllegalArgumentExceptionCall the Javadoc tool and parse its output to find its version, i.e.:javadoc.exe( or.sh ) - J - version
- Parameters:
javadocExe- not null file- Returns:
- the javadoc version as float
- Throws:
java.io.IOException- if javadocExe is null, doesn't exist or is not a fileorg.codehaus.plexus.util.cli.CommandLineException- if anyjava.lang.IllegalArgumentException- if no output was found in the command linejava.util.regex.PatternSyntaxException- if the output contains a syntax error in the regular-expression pattern.- See Also:
extractJavadocVersion(String)
-
extractJavadocVersion
protected static java.lang.String extractJavadocVersion(java.lang.String output) throws java.lang.IllegalArgumentExceptionParse the output for 'javadoc -J-version' and return the javadoc version recognized.
Here are some output for 'javadoc -J-version' depending the JDK used:JDK Output for 'javadoc -J-version' Sun 1.4 java full version "1.4.2_12-b03" Sun 1.5 java full version "1.5.0_07-164" IBM 1.4 javadoc full version "J2RE 1.4.2 IBM Windows 32 build cn1420-20040626" IBM 1.5 (French JVM) javadoc version complète de "J2RE 1.5.0 IBM Windows 32 build pwi32pdev-20070426a" FreeBSD 1.5 java full version "diablo-1.5.0-b01" BEA jrockit 1.5 java full version "1.5.0_11-b03" - Parameters:
output- for 'javadoc -J-version'- Returns:
- the version of the javadoc for the output, only digits and dots
- Throws:
java.util.regex.PatternSyntaxException- if the output doesn't match with the output pattern (?s).*?[^a-zA-Z]([0-9]+\\.?[0-9]*)(\\.([0-9]+))?.*.java.lang.IllegalArgumentException- if the output is null
-
parseJavadocMemory
protected static java.lang.String parseJavadocMemory(java.lang.String memory) throws java.lang.IllegalArgumentExceptionParse a memory string which be used in the JVM arguments-Xmsor-Xmx.
Here are some supported memory string depending the JDK used:JDK Memory argument support for -Xmsor-XmxSUN 1024k | 128m | 1g | 1t IBM 1024k | 1024b | 128m | 128mb | 1g | 1gb BEA 1024k | 1024kb | 128m | 128mb | 1g | 1gb - Parameters:
memory- the memory to be parsed, not null.- Returns:
- the memory parsed with a supported unit. If no unit specified in the
memoryparameter, the default unit ism. The unitsg | gbort | tbwill be converted inm. - Throws:
java.lang.IllegalArgumentException- if thememoryparameter is null or doesn't match any pattern.
-
validateEncoding
protected static boolean validateEncoding(java.lang.String charsetName)
Validate if a charset is supported on this platform.- Parameters:
charsetName- the charsetName to be check.- Returns:
trueif the given charset is supported by the JVM,falseotherwise.
-
getTagletClassNames
protected static java.util.List<java.lang.String> getTagletClassNames(java.io.File jarFile) throws java.io.IOException, java.lang.ClassNotFoundException, java.lang.NoClassDefFoundErrorAuto-detect the class names of the implementation ofcom.sun.tools.doclets.Tagletclass from a given jar file.
Note:JAVA_HOME/lib/tools.jaris a requirement to findcom.sun.tools.doclets.Tagletclass.- Parameters:
jarFile- not null- Returns:
- the list of
com.sun.tools.doclets.Tagletclass names from a given jarFile. - Throws:
java.io.IOException- if jarFile is invalid or not found, or if theJAVA_HOME/lib/tools.jaris not found.java.lang.ClassNotFoundException- if anyjava.lang.NoClassDefFoundError- if any
-
copyResource
protected static void copyResource(java.net.URL url, java.io.File file) throws java.io.IOExceptionCopy the given url to the given file.- Parameters:
url- not null urlfile- not null file where the url will be created- Throws:
java.io.IOException- if any- Since:
- 2.6
-
invokeMaven
protected static void invokeMaven(org.apache.maven.plugin.logging.Log log, java.io.File localRepositoryDir, java.io.File projectFile, java.util.List<java.lang.String> goals, java.util.Properties properties, java.io.File invokerLog, java.io.File globalSettingsFile) throws org.apache.maven.shared.invoker.MavenInvocationExceptionInvoke Maven for the given project file with a list of goals and properties, the output will be in the invokerlog file.
Note: the Maven Home should be defined in themaven.homeJava system property or defined inM2_HOMEsystem env variables.- Parameters:
log- a logger could be null.localRepositoryDir- the localRepository not null.projectFile- a not null project file.goals- a not null goals list.properties- the properties for the goals, could be null.invokerLog- the log file where the invoker will be written, if null usingSystem.out.globalSettingsFile- reference to settings file, could be null.- Throws:
org.apache.maven.shared.invoker.MavenInvocationException- if any- Since:
- 2.6
-
readFile
protected static java.lang.String readFile(java.io.File javaFile, java.lang.String encoding)Read the given file and return the content or null if an IOException occurs.- Parameters:
javaFile- not nullencoding- could be null- Returns:
- the content with unified line separator of the given javaFile using the given encoding.
- Since:
- 2.6.1
- See Also:
FileUtils.fileRead(File, String)
-
splitPath
protected static java.lang.String[] splitPath(java.lang.String path)
Split the given path with colon and semi-colon, to support Solaris and Windows path. Examples:splitPath( "/home:/tmp" ) = ["/home", "/tmp"] splitPath( "/home;/tmp" ) = ["/home", "/tmp"] splitPath( "C:/home:C:/tmp" ) = ["C:/home", "C:/tmp"] splitPath( "C:/home;C:/tmp" ) = ["C:/home", "C:/tmp"]
- Parameters:
path- which can contain multiple paths separated with a colon (:) or a semi-colon (;), platform independent. Could be null.- Returns:
- the path splitted by colon or semi-colon or
nullif path wasnull. - Since:
- 2.6.1
-
unifyPathSeparator
protected static java.lang.String unifyPathSeparator(java.lang.String path)
Unify the given path with the current System path separator, to be platform independent. Examples:unifyPathSeparator( "/home:/tmp" ) = "/home:/tmp" (Solaris box) unifyPathSeparator( "/home:/tmp" ) = "/home;/tmp" (Windows box)
- Parameters:
path- which can contain multiple paths by separating them with a colon (:) or a semi-colon (;), platform independent. Could be null.- Returns:
- the same path but separated with the current System path separator or
nullif path wasnull. - Since:
- 2.6.1
- See Also:
splitPath(String),File.pathSeparator
-
getClassNamesFromJar
private static java.util.List<java.lang.String> getClassNamesFromJar(java.io.File jarFile) throws java.io.IOException- Parameters:
jarFile- not null- Returns:
- all class names from the given jar file.
- Throws:
java.io.IOException- if any or if the jarFile is null or doesn't exist.
-
invoke
private static org.apache.maven.shared.invoker.InvocationResult invoke(org.apache.maven.plugin.logging.Log log, org.apache.maven.shared.invoker.Invoker invoker, org.apache.maven.shared.invoker.InvocationRequest request, java.io.File invokerLog, java.util.List<java.lang.String> goals, java.util.Properties properties, java.lang.String mavenOpts) throws org.apache.maven.shared.invoker.MavenInvocationException- Parameters:
log- could be nullinvoker- not nullrequest- not nullinvokerLog- not nullgoals- not nullproperties- could be nullmavenOpts- could be null- Returns:
- the invocation result
- Throws:
org.apache.maven.shared.invoker.MavenInvocationException- if any- Since:
- 2.6
-
getMavenHome
private static java.lang.String getMavenHome(org.apache.maven.plugin.logging.Log log)
- Parameters:
log- a logger could be null- Returns:
- the Maven home defined in the
maven.homesystem property or defined inM2_HOMEsystem env variables or null if never set. - Since:
- 2.6
-
getMavenOpts
private static java.lang.String getMavenOpts(org.apache.maven.plugin.logging.Log log)
- Parameters:
log- a logger could be null- Returns:
- the
MAVEN_OPTSenv variable value - Since:
- 2.6
-
getJavaHome
private static java.io.File getJavaHome(org.apache.maven.plugin.logging.Log log)
- Parameters:
log- a logger could be null- Returns:
- the
JAVA_HOMEfrom System.getProperty( "java.home" ) By default,System.getProperty( "java.home" ) = JRE_HOMEandJRE_HOMEshould be in theJDK_HOME - Since:
- 2.6
-
getJavaOpts
private static java.lang.String getJavaOpts(org.apache.maven.plugin.logging.Log log)
- Parameters:
log- a logger could be null- Returns:
- the
JAVA_OPTSenv variable value - Since:
- 2.6
-
toList
static java.util.List<java.lang.String> toList(java.lang.String src)
-
toList
static java.util.List<java.lang.String> toList(java.lang.String src, java.lang.String elementPrefix, java.lang.String elementSuffix)
-
toList
static <T> java.util.List<T> toList(T[] multiple)
-
toList
static <T> java.util.List<T> toList(T single, T[] multiple)
-
toRelative
public static java.lang.String toRelative(java.io.File basedir, java.lang.String absolutePath)
-
isNotEmpty
public static boolean isNotEmpty(java.util.Collection<?> collection)
Convenience method to determine that a collection is not empty or null.- Parameters:
collection- the collection to verify- Returns:
trueif notnulland not empty, otherwisefalse
-
isEmpty
public static boolean isEmpty(java.util.Collection<?> collection)
Convenience method to determine that a collection is empty or null.- Parameters:
collection- the collection to verify- Returns:
trueifnullor empty, otherwisefalse
-
getRedirectUrl
protected static java.net.URL getRedirectUrl(java.net.URL url, org.apache.maven.settings.Settings settings) throws java.io.IOExceptionExecute an Http request at the given URL, follows redirects, and returns the last redirect locations. For URLs that aren't http/https, this does nothing and simply returns the given URL unchanged.- Parameters:
url- URL.settings- Maven settings.- Returns:
- Last redirect location.
- Throws:
java.io.IOException- if there was an error during the Http request.
-
isValidPackageList
protected static boolean isValidPackageList(java.net.URL url, org.apache.maven.settings.Settings settings, boolean validateContent) throws java.io.IOExceptionValidates anURLto point to a validpackage-listresource.- Parameters:
url- The URL to validate.settings- The user settings used to configure the connection to the URL ornull.validateContent-trueto validate the content of thepackage-listresource;falseto only check the existence of thepackage-listresource.- Returns:
trueifurlpoints to a validpackage-listresource;falseelse.- Throws:
java.io.IOException- if reading the resource fails.- Since:
- 2.8
- See Also:
createHttpClient(org.apache.maven.settings.Settings, java.net.URL)
-
isValidElementList
protected static boolean isValidElementList(java.net.URL url, org.apache.maven.settings.Settings settings, boolean validateContent) throws java.io.IOException- Throws:
java.io.IOException
-
getReader
private static java.io.BufferedReader getReader(java.net.URL url, org.apache.maven.settings.Settings settings) throws java.io.IOException- Throws:
java.io.IOException
-
isValidPackageName
private static boolean isValidPackageName(java.lang.String str)
-
isValidClassName
private static boolean isValidClassName(java.lang.String str)
-
createHttpClient
private static org.apache.http.impl.client.CloseableHttpClient createHttpClient(org.apache.maven.settings.Settings settings, java.net.URL url)Creates a newHttpClientinstance.- Parameters:
settings- The settings to use for setting up the client ornull.url- TheURLto use for setting up the client ornull.- Returns:
- A new
HttpClientinstance. - Since:
- 2.8
- See Also:
DEFAULT_TIMEOUT
-
equalsIgnoreCase
static boolean equalsIgnoreCase(java.lang.String value, java.lang.String... strings)
-
equals
static boolean equals(java.lang.String value, java.lang.String... strings)
-
-