{
buildJavadocOptions();
}
catch ( IOException e )
{
throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );
}
List<String> sourcePaths = getSourcePaths();
List<String> files = getFiles( sourcePaths );
if ( !canGenerateReport( files ) )
{
return;
}
List<String> packageNames = getPackageNames( sourcePaths, files );
List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( sourcePaths, files );
// ----------------------------------------------------------------------
// Find the javadoc executable and version
// ----------------------------------------------------------------------
String jExecutable;
try
{
jExecutable = getJavadocExecutable();
}
catch ( IOException e )
{
throw new MavenReportException( "Unable to find javadoc command: " + e.getMessage(), e );
}
setFJavadocVersion( new File( jExecutable ) );
// ----------------------------------------------------------------------
// Javadoc output directory as File
// ----------------------------------------------------------------------
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." );
}
javadocOutputDirectory.mkdirs();
// ----------------------------------------------------------------------
// Copy all resources
// ----------------------------------------------------------------------
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 );
// ----------------------------------------------------------------------
// Wrap Javadoc JVM args
// ----------------------------------------------------------------------
addMemoryArg( cmd, "-Xmx", this.maxmemory );
addMemoryArg( cmd, "-Xms", this.minmemory );
addProxyArg( cmd );
if ( StringUtils.isNotEmpty( additionalJOption ) )
{
cmd.createArg().setValue( additionalJOption );
}
if ( additionalJOptions != null && additionalJOptions.length != 0 )
{
for ( String jo : additionalJOptions )
{
cmd.createArg().setValue( jo );
}
}
List<String> arguments = new ArrayList<String>();
// ----------------------------------------------------------------------
// Wrap Javadoc options
// ----------------------------------------------------------------------
addJavadocOptions( arguments, sourcePaths );
// ----------------------------------------------------------------------
// Wrap Standard doclet Options
// ----------------------------------------------------------------------
if ( StringUtils.isEmpty( doclet ) || useStandardDocletOptions )
{
addStandardDocletOptions( javadocOutputDirectory, arguments );
}
// ----------------------------------------------------------------------
// Write options file and include it in the command line
// ----------------------------------------------------------------------
if ( arguments.size() > 0 )
{
addCommandLineOptions( cmd, arguments, javadocOutputDirectory );
}
// ----------------------------------------------------------------------
// Write packages file and include it in the command line
// ----------------------------------------------------------------------
if ( !packageNames.isEmpty() )
{
addCommandLinePackages( cmd, javadocOutputDirectory, packageNames );
// ----------------------------------------------------------------------
// Write argfile file and include it in the command line
// ----------------------------------------------------------------------
if ( !filesWithUnnamedPackages.isEmpty() )
{
addCommandLineArgFile( cmd, javadocOutputDirectory, filesWithUnnamedPackages );
}
}
else
{
// ----------------------------------------------------------------------
// Write argfile file and include it in the command line
// ----------------------------------------------------------------------
if ( !files.isEmpty() )
{
addCommandLineArgFile( cmd, javadocOutputDirectory, files );
}
}
// ----------------------------------------------------------------------
// Execute command line
// ----------------------------------------------------------------------
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++ )
{
String arg = cmd.getArguments()[i].trim();
if ( !arg.startsWith( "@" ) )
{
continue;
}
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() )
{
scriptFile.delete();
}
}
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 ) );
}
}
catch ( IOException e )
{
throw new MavenReportException( "Failed to patch javadocs vulnerability: " + e.getMessage(), e );
}
}
else
{
getLog().info( "applying javadoc security fix has been disabled" );