Add a little javadoc report

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@170966 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Emmanuel Venisse 2005-05-19 16:53:27 +00:00
parent a1ab59106e
commit 304543331b
3 changed files with 349 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-report-parent</artifactId>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<name>Maven Javadoc Plugin</name>
<developers>
<developer>
<id>evenisse</id>
<name>Emmanuel Venisse</name>
<email>evenisse@apache.org</email>
<organization>Apache Software Foundation</organization>
<roles>
<role>Creator</role>
</roles>
</developer>
</developers>
</project>

View File

@ -0,0 +1,188 @@
package org.apache.maven.plugin.javadoc;
/*
* Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed 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 java.io.File;
import java.util.Calendar;
import java.util.Iterator;
import org.apache.maven.reporting.AbstractMavenReport;
import org.apache.maven.reporting.MavenReportException;
import org.codehaus.doxia.sink.Sink;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
import org.codehaus.plexus.util.cli.DefaultConsumer;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: DependenciesReport.java,v 1.2 2005/02/23 00:08:02 brett Exp $
*/
public class JavadocReport
extends AbstractMavenReport
{
/**
* @see org.apache.maven.reporting.AbstractMavenReport#generate(org.codehaus.doxia.sink.Sink)
*/
public void generate( Sink sink )
throws MavenReportException
{
if ( getConfiguration() == null )
{
throw new MavenReportException( "You must specify a report configuration." );
}
execute();
}
/**
* @see org.apache.maven.reporting.AbstractMavenReport#execute()
*/
protected void execute()
throws MavenReportException
{
try
{
File outputDir = new File( getConfiguration().getReportOutputDirectory().getAbsolutePath() + "/apidocs" );
outputDir.mkdirs();
int actualYear = Calendar.getInstance().get( Calendar.YEAR );
String year;
if ( getConfiguration().getModel().getInceptionYear() != null
&& Integer.valueOf( getConfiguration().getModel().getInceptionYear() ).intValue() == actualYear )
{
year = getConfiguration().getModel().getInceptionYear();
}
else
{
year = getConfiguration().getModel().getInceptionYear() + "-" + String.valueOf( actualYear );
}
StringBuffer classpath = new StringBuffer();
for ( Iterator i = getConfiguration().getProject().getCompileClasspathElements().iterator(); i.hasNext(); )
{
classpath.append( (String) i.next() );
if ( i.hasNext() )
{
classpath.append( ";" );
}
}
StringBuffer sourcePath = new StringBuffer();
String[] fileList = new String[1];
for ( Iterator i = getConfiguration().getCompileSourceRoots().iterator(); i.hasNext(); )
{
String sourceDirectory = (String) i.next();
fileList = FileUtils.getFilesFromExtension( sourceDirectory, new String[] { "java" } );
sourcePath.append( sourceDirectory );
}
File javadocDirectory = new File( getConfiguration().getProject().getBuild().getDirectory() + "/javadoc" );
if ( fileList != null && fileList.length != 0 )
{
StringBuffer files = new StringBuffer();
for ( int i = 0; i < fileList.length; i++ )
{
files.append( fileList[i] );
files.append( "\n" );
}
javadocDirectory.mkdirs();
FileUtils.fileWrite( new File( javadocDirectory, "files" ).getAbsolutePath(), files.toString() );
}
else
{
return;
}
Commandline cl = new Commandline();
cl.setWorkingDirectory( javadocDirectory.getAbsolutePath() );
cl.setExecutable( getJavadocPath() );
cl.createArgument().setValue( "-use" );
cl.createArgument().setValue( "-version" );
cl.createArgument().setValue( "-author" );
cl.createArgument().setValue( "-windowtitle" );
cl.createArgument().setValue(
getConfiguration().getModel().getName() + " "
+ getConfiguration().getModel().getVersion() );
cl.createArgument().setValue( "-bottom" );
cl.createArgument().setValue( "Copyright &copy; " + year + " "
+ getConfiguration().getModel().getOrganization().getName()
+ ". All Rights Reserved." );
cl.createArgument().setValue( "-sourcePath" );
cl.createArgument().setValue( sourcePath.toString() );
cl.createArgument().setValue( "-d" );
cl.createArgument().setValue( outputDir.getAbsolutePath() );
cl.createArgument().setValue( "-classpath" );
cl.createArgument().setValue( classpath.toString() );
cl.createArgument().setValue( "@files" );
System.out.println( Commandline.toString( cl.getCommandline() ) );
System.out.println( cl.getWorkingDirectory() );
CommandLineUtils.executeCommandLine( cl, new DefaultConsumer(), new DefaultConsumer() );
}
catch ( Exception e )
{
throw new MavenReportException( "An error is occurred in javadoc report generation.", e );
}
}
/**
* @see org.apache.maven.reporting.MavenReport#getDescription()
*/
public String getDescription()
{
return "JavaDoc API documentation.";
}
/**
* @see org.apache.maven.reporting.MavenReport#getName()
*/
public String getName()
{
return "JavaDocs";
}
/**
* @see org.apache.maven.reporting.MavenReport#getOutputName()
*/
public String getOutputName()
{
return "apidocs/index";
}
/**
* Return path of javadoc tool.
*
* @return path of javadoc tool
*/
private String getJavadocPath()
{
String osName = System.getProperty( "os.name" );
String jdkPath;
if ( osName.startsWith( "Windows" ) )
{
jdkPath = "%JAVA_HOME%";
}
else
{
jdkPath = "$JAVA_HOME";
}
String fileSeparator = System.getProperty( "file.separator" );
return jdkPath + fileSeparator + "bin" + fileSeparator + "javadoc";
}
}

View File

@ -0,0 +1,138 @@
package org.apache.maven.plugin.javadoc;
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed 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 org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.reporting.MavenReportConfiguration;
import org.codehaus.doxia.site.renderer.SiteRenderer;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.StringInputStream;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
/**
* @goal javadoc
* @description A Maven2 plugin which generates a Javadoc report
* @requiresDependencyResolution compile
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id: PmdReportMojo.java,v 1.4 2005/02/23 00:08:54 brett Exp $
*/
public class JavadocReportMojo
extends AbstractMojo
{
/**
* @parameter expression="${basedir}/src/site"
* @required
*/
private String siteDirectory;
/**
* @parameter expression="${project.build.directory}/site"
* @required
*/
private String outputDirectory;
/**
* @parameter expression="${component.org.codehaus.doxia.site.renderer.SiteRenderer}"
* @required
* @readonly
*/
private SiteRenderer siteRenderer;
/**
* @parameter expression="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute()
throws MojoExecutionException
{
MavenReportConfiguration config = new MavenReportConfiguration();
config.setProject( project );
config.setReportOutputDirectory( new File( outputDirectory ) );
MavenReport report = new JavadocReport();
report.setConfiguration( config );
try
{
report.generate( null );
}
catch ( Exception e )
{
throw new MojoExecutionException( "An error is occurred in the PMD report generation.", e );
}
}
private String getReportsMenu()
{
StringBuffer buffer = new StringBuffer();
buffer.append( "<menu name=\"Project Documentation\">\n" );
buffer.append( " <item name=\"About " + project.getName() + "\" href=\"/index.html\"/>\n");
buffer.append( " <item name=\"Project reports\" href=\"/maven-reports.html\" collapse=\"true\">\n" );
buffer.append( " <item name=\"PMD report\" href=\"/pmd.html\"/>\n" );
buffer.append( " </item>\n" );
buffer.append( "</menu>\n" );
return buffer.toString();
}
private InputStream getSiteDescriptor()
throws MojoExecutionException
{
File siteDescriptor = new File( siteDirectory, "site.xml" );
if ( !siteDescriptor.exists() )
{
throw new MojoExecutionException( "The site descriptor is not present!" );
}
String siteDescriptorContent = "";
try
{
siteDescriptorContent = FileUtils.fileRead( siteDescriptor );
}
catch( IOException e )
{
throw new MojoExecutionException( "The site descriptor cannot be read!", e );
}
Map props = new HashMap();
props.put( "reports", getReportsMenu() );
siteDescriptorContent = StringUtils.interpolate( siteDescriptorContent, props );
return new StringInputStream( siteDescriptorContent );
}
}