public class JavadocUtil
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
JavadocUtil.JavadocOutputStreamConsumer
Ignores line like 'Picked up JAVA_TOOL_OPTIONS: ...' as can happen on CI servers.
|
private static class |
JavadocUtil.PathTokenizer
A Path tokenizer takes a path and returns the components that make up that path.
|
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_TIMEOUT
The default timeout used when fetching url, i.e.
|
protected static java.lang.String |
ERROR_INIT_VM
Error message when VM could not be started using invoker.
|
| Constructor and Description |
|---|
JavadocUtil() |
| Modifier and Type | Method and Description |
|---|---|
protected static void |
addFilesFromSource(java.util.List<java.lang.String> files,
java.io.File sourceDirectory,
java.util.List<java.lang.String> sourceFileIncludes,
java.util.List<java.lang.String> sourceFileExcludes,
java.lang.String[] excludePackages)
Convenience method that gets the files to be included in the javadoc.
|
protected static void |
copyJavadocResources(java.io.File outputDirectory,
java.io.File javadocDir,
java.lang.String excludedocfilessubdir)
Convenience method that copy all
doc-files directories from javadocDir to the
outputDirectory. |
protected static void |
copyResource(java.net.URL url,
java.io.File file)
Copy the given url to the given file.
|
private static org.apache.http.client.HttpClient |
createHttpClient(org.apache.maven.settings.Settings settings,
java.net.URL url)
Creates a new
HttpClient instance. |
(package private) static boolean |
equals(java.lang.String value,
java.lang.String... strings) |
(package private) static boolean |
equalsIgnoreCase(java.lang.String value,
java.lang.String... strings) |
protected static java.lang.String |
extractJavadocVersion(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.List<java.lang.String> |
getExcludedNames(java.util.Collection<java.lang.String> sourcePaths,
java.lang.String[] subpackagesList,
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> |
getExcludedPackages(java.lang.String sourceDirectory,
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> |
getIncludedFiles(java.io.File sourceDirectory,
java.lang.String[] fileList,
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.JavaVersion |
getJavadocVersion(java.io.File javadocExe)
Call the Javadoc tool and parse its output to find its version, i.e.:
|
private static java.io.File |
getJavaHome(org.apache.maven.plugin.logging.Log log) |
private static java.lang.String |
getJavaOpts(org.apache.maven.plugin.logging.Log log) |
private static java.lang.String |
getMavenHome(org.apache.maven.plugin.logging.Log log) |
private static java.lang.String |
getMavenOpts(org.apache.maven.plugin.logging.Log log) |
protected static java.net.URL |
getRedirectUrl(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 of
com.sun.tools.doclets.Taglet class from a given
jar file. |
protected static java.lang.String |
hideProxyPassword(java.lang.String cmdLine,
org.apache.maven.settings.Settings settings)
For security reasons, if an active proxy is defined and needs an authentication by username/password, hide the
proxy password in the command line.
|
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) |
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)
Invoke Maven for the given project file with a list of goals and properties, the output will be in the invokerlog
file.
|
static boolean |
isEmpty(java.util.Collection<?> collection)
Convenience method to determine that a collection is empty or null.
|
static boolean |
isNotEmpty(java.util.Collection<?> collection)
Convenience method to determine that a collection is not empty or null.
|
private static boolean |
isValidClassName(java.lang.String str) |
protected static boolean |
isValidPackageList(java.net.URL url,
org.apache.maven.settings.Settings settings,
boolean validateContent)
Validates an
URL to point to a valid package-list resource. |
private static boolean |
isValidPackageName(java.lang.String str) |
protected static java.lang.String |
parseJavadocMemory(java.lang.String memory)
Parse a memory string which be used in the JVM arguments
-Xms or -Xmx. |
static java.util.Collection<java.lang.String> |
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.String |
quotedArgument(java.lang.String value)
Convenience method to wrap an argument value in single quotes (i.e.
|
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.
|
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.
|
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.
|
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.String |
toRelative(java.io.File basedir,
java.lang.String absolutePath) |
protected static java.lang.String |
unifyPathSeparator(java.lang.String path)
Unify the given path with the current System path separator, to be platform independent.
|
protected static boolean |
validateEncoding(java.lang.String charsetName)
Validate if a charset is supported on this platform.
|
public static final int DEFAULT_TIMEOUT
protected static final java.lang.String ERROR_INIT_VM
public static java.util.Collection<java.lang.String> pruneDirs(org.apache.maven.project.MavenProject project,
java.util.Collection<java.lang.String> dirs)
dirs could be an absolute or relative against the project's base directory String path.project - the current Maven project not nulldirs - the collection of String directories path that will be validated.String directories absolute paths.protected static java.util.List<java.lang.String> pruneFiles(java.util.Collection<java.lang.String> files)
files
should be an absolute String path.files - the list of String files paths that will be validated.File objects.public static boolean shouldPruneFile(java.lang.String f,
java.util.List<java.lang.String> pruned)
f - The files.pruned - The list of pruned files..protected static java.util.List<java.lang.String> getExcludedNames(java.util.Collection<java.lang.String> sourcePaths,
java.lang.String[] subpackagesList,
java.lang.String[] excludedPackages)
sourcePaths - the path to the source filessubpackagesList - list of subpackages to be included in the javadocexcludedPackages - the package names to be excluded in the javadocprotected static java.lang.String quotedArgument(java.lang.String value)
'). Intended for values which
may contain whitespaces. \n) are skipped.value - the argument value.protected static java.lang.String quotedPathArgument(java.lang.String value)
value - the argument value.protected static void copyJavadocResources(java.io.File outputDirectory,
java.io.File javadocDir,
java.lang.String excludedocfilessubdir)
throws java.io.IOException
doc-files directories from javadocDir to the
outputDirectory.outputDirectory - the output directoryjavadocDir - the javadoc directoryexcludedocfilessubdir - the excludedocfilessubdir parameterjava.io.IOException - if anyprotected static java.util.List<java.lang.String> getIncludedFiles(java.io.File sourceDirectory,
java.lang.String[] fileList,
java.lang.String[] excludePackages)
sourceDirectory - the directory where the source files are locatedfileList - the list of all files found in the sourceDirectoryexcludePackages - package names to be excluded in the javadocprotected static java.util.List<java.lang.String> getExcludedPackages(java.lang.String sourceDirectory,
java.lang.String[] excludePackagenames)
sourceDirectory - the directory where the source files are locatedexcludePackagenames - package names to be excluded in the javadocprotected static void addFilesFromSource(java.util.List<java.lang.String> files,
java.io.File sourceDirectory,
java.util.List<java.lang.String> sourceFileIncludes,
java.util.List<java.lang.String> sourceFileExcludes,
java.lang.String[] excludePackages)
sourceDirectory - the directory where the source files are locatedfiles - the variable that contains the appended filenames of the files to be included in the javadocexcludePackages - the packages to be excluded in the javadocssourceFileIncludes - files to include.sourceFileExcludes - files to exclude.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.IllegalArgumentException
javadoc.exe( or.sh ) - J - version
javadocExe - not null filejava.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.extractJavadocVersion(String)protected static java.lang.String extractJavadocVersion(java.lang.String output)
throws java.lang.IllegalArgumentException
| 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" |
output - for 'javadoc -J-version'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 nullprotected static java.lang.String parseJavadocMemory(java.lang.String memory)
throws java.lang.IllegalArgumentException
-Xms or -Xmx. | JDK | Memory argument support for -Xms or -Xmx |
|---|---|
| SUN | 1024k | 128m | 1g | 1t |
| IBM | 1024k | 1024b | 128m | 128mb | 1g | 1gb |
| BEA | 1024k | 1024kb | 128m | 128mb | 1g | 1gb |
memory - the memory to be parsed, not null.memory parameter, the
default unit is m. The units g | gb or t | tb will be converted in
m.java.lang.IllegalArgumentException - if the memory parameter is null or doesn't match any pattern.protected static boolean validateEncoding(java.lang.String charsetName)
charsetName - the charsetName to be check.true if the given charset is supported by the JVM, false otherwise.protected static java.lang.String hideProxyPassword(java.lang.String cmdLine,
org.apache.maven.settings.Settings settings)
cmdLine - a command line, not nullsettings - the user settingsprotected static java.util.List<java.lang.String> getTagletClassNames(java.io.File jarFile)
throws java.io.IOException,
java.lang.ClassNotFoundException,
java.lang.NoClassDefFoundError
com.sun.tools.doclets.Taglet class from a given
jar file. JAVA_HOME/lib/tools.jar is a requirement to find
com.sun.tools.doclets.Taglet class.jarFile - not nullcom.sun.tools.doclets.Taglet class names from a given jarFile.java.io.IOException - if jarFile is invalid or not found, or if the JAVA_HOME/lib/tools.jar is not
found.java.lang.ClassNotFoundException - if anyjava.lang.NoClassDefFoundError - if anyprotected static void copyResource(java.net.URL url,
java.io.File file)
throws java.io.IOException
url - not null urlfile - not null file where the url will be createdjava.io.IOException - if anyprotected 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)
throws org.apache.maven.shared.invoker.MavenInvocationException
maven.home Java system property or defined in
M2_HOME system env variables.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 using System.out.org.apache.maven.shared.invoker.MavenInvocationException - if anyprotected static java.lang.String readFile(java.io.File javaFile,
java.lang.String encoding)
javaFile - not nullencoding - could be nullFileUtils.fileRead(File, String)protected static java.lang.String[] splitPath(java.lang.String path)
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"]
path - which can contain multiple paths separated with a colon (:) or a semi-colon
(;), platform independent. Could be null.null if path was null.protected static java.lang.String unifyPathSeparator(java.lang.String path)
unifyPathSeparator( "/home:/tmp" ) = "/home:/tmp" (Solaris box) unifyPathSeparator( "/home:/tmp" ) = "/home;/tmp" (Windows box)
path - which can contain multiple paths by separating them with a colon (:) or a semi-colon
(;), platform independent. Could be null.null if path was
null.splitPath(String),
File.pathSeparatorprivate static java.util.List<java.lang.String> getClassNamesFromJar(java.io.File jarFile)
throws java.io.IOException
jarFile - not nulljava.io.IOException - if any or if the jarFile is null or doesn't exist.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
log - could be nullinvoker - not nullrequest - not nullinvokerLog - not nullgoals - not nullproperties - could be nullmavenOpts - could be nullorg.apache.maven.shared.invoker.MavenInvocationException - if anyprivate static java.lang.String getMavenHome(org.apache.maven.plugin.logging.Log log)
log - a logger could be nullmaven.home system property or defined in M2_HOME
system env variables or null if never set.private static java.lang.String getMavenOpts(org.apache.maven.plugin.logging.Log log)
log - a logger could be nullMAVEN_OPTS env variable valueprivate static java.io.File getJavaHome(org.apache.maven.plugin.logging.Log log)
log - a logger could be nullJAVA_HOME from System.getProperty( "java.home" ) By default,
System.getProperty( "java.home" ) = JRE_HOME and JRE_HOME should be in the
JDK_HOMEprivate static java.lang.String getJavaOpts(org.apache.maven.plugin.logging.Log log)
log - a logger could be nullJAVA_OPTS env variable valuestatic java.util.List<java.lang.String> toList(java.lang.String src)
static java.util.List<java.lang.String> toList(java.lang.String src,
java.lang.String elementPrefix,
java.lang.String elementSuffix)
static <T> java.util.List<T> toList(T[] multiple)
static <T> java.util.List<T> toList(T single,
T[] multiple)
public static java.lang.String toRelative(java.io.File basedir,
java.lang.String absolutePath)
public static boolean isNotEmpty(java.util.Collection<?> collection)
collection - the collection to verifytrue if not null and not empty, otherwise falsepublic static boolean isEmpty(java.util.Collection<?> collection)
collection - the collection to verifytrue if null or empty, otherwise falseprotected static java.net.URL getRedirectUrl(java.net.URL url,
org.apache.maven.settings.Settings settings)
throws java.io.IOException
url - URL.settings - Maven settings.java.io.IOException - if there was an error during the Http request.protected static boolean isValidPackageList(java.net.URL url,
org.apache.maven.settings.Settings settings,
boolean validateContent)
throws java.io.IOException
URL to point to a valid package-list resource.url - The URL to validate.settings - The user settings used to configure the connection to the URL or null.validateContent - true to validate the content of the package-list resource;
false to only check the existence of the package-list resource.true if url points to a valid package-list resource;
false else.java.io.IOException - if reading the resource fails.createHttpClient(org.apache.maven.settings.Settings, java.net.URL)private static boolean isValidPackageName(java.lang.String str)
private static boolean isValidClassName(java.lang.String str)
private static org.apache.http.client.HttpClient createHttpClient(org.apache.maven.settings.Settings settings,
java.net.URL url)
HttpClient instance.settings - The settings to use for setting up the client or null.url - The URL to use for setting up the client or null.HttpClient instance.DEFAULT_TIMEOUTstatic boolean equalsIgnoreCase(java.lang.String value,
java.lang.String... strings)
static boolean equals(java.lang.String value,
java.lang.String... strings)