From 304543331b48f1922682a301536d50cf8ed53659 Mon Sep 17 00:00:00 2001 From: Emmanuel Venisse Date: Thu, 19 May 2005 16:53:27 +0000 Subject: [PATCH] Add a little javadoc report git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@170966 13f79535-47bb-0310-9956-ffa450edef68 --- maven-reports/maven-javadoc-plugin/pom.xml | 23 +++ .../maven/plugin/javadoc/JavadocReport.java | 188 ++++++++++++++++++ .../plugin/javadoc/JavadocReportMojo.java | 138 +++++++++++++ 3 files changed, 349 insertions(+) create mode 100644 maven-reports/maven-javadoc-plugin/pom.xml create mode 100644 maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReport.java create mode 100644 maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReportMojo.java diff --git a/maven-reports/maven-javadoc-plugin/pom.xml b/maven-reports/maven-javadoc-plugin/pom.xml new file mode 100644 index 0000000000..5f514e9719 --- /dev/null +++ b/maven-reports/maven-javadoc-plugin/pom.xml @@ -0,0 +1,23 @@ + + 4.0.0 + + org.apache.maven.plugins + maven-report-parent + 2.0-SNAPSHOT + + maven-javadoc-plugin + 2.0-SNAPSHOT + maven-plugin + Maven Javadoc Plugin + + + evenisse + Emmanuel Venisse + evenisse@apache.org + Apache Software Foundation + + Creator + + + + diff --git a/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReport.java b/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReport.java new file mode 100644 index 0000000000..008c216294 --- /dev/null +++ b/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReport.java @@ -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 Emmanuel Venisse + * @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 © " + 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"; + } +} \ No newline at end of file diff --git a/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReportMojo.java b/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReportMojo.java new file mode 100644 index 0000000000..f97073d35c --- /dev/null +++ b/maven-reports/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/JavadocReportMojo.java @@ -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 Brett Porter + * @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( "\n" ); + buffer.append( " \n"); + buffer.append( " \n" ); + + buffer.append( " \n" ); + + buffer.append( " \n" ); + buffer.append( "\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 ); + } +}