You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by be...@apache.org on 2008/11/08 00:59:37 UTC
svn commit: r712313 - in
/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site:
pom.xml src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java
src/main/java/org/apache/maven/plugin/coreit/InfoReport.java
Author: bentmann
Date: Fri Nov 7 15:59:37 2008
New Revision: 712313
URL: http://svn.apache.org/viewvc?rev=712313&view=rev
Log:
o Added mojo to generate reports
o Added report mojo
Added:
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java (with props)
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java (with props)
Modified:
maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/pom.xml
Modified: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/pom.xml?rev=712313&r1=712312&r2=712313&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/pom.xml (original)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/pom.xml Fri Nov 7 15:59:37 2008
@@ -33,7 +33,7 @@
<name>Maven Integration Test Plugin :: Site</name>
<description>
- A test plugin that requires reports for its execution.
+ A test plugin that works with reports.
</description>
<inceptionYear>2008</inceptionYear>
@@ -47,5 +47,21 @@
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-api</artifactId>
+ <version>2.0</version>
+ <exclusions>
+ <exclusion>
+ <groupId>doxia</groupId>
+ <artifactId>doxia-sink-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.doxia</groupId>
+ <artifactId>doxia-sink-api</artifactId>
+ <version>1.0-alpha-11</version>
+ </dependency>
</dependencies>
</project>
Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java?rev=712313&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java Fri Nov 7 15:59:37 2008
@@ -0,0 +1,132 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.plugin.MojoFailureException;
+import org.apache.maven.reporting.MavenReport;
+import org.codehaus.doxia.sink.Sink;
+
+import java.io.File;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * Generates the available/configured reports.
+ *
+ * @goal generate
+ * @phase site
+ * @requiresReports true
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class GenerateMojo
+ extends AbstractMojo
+{
+
+ /**
+ * The path to the output directory of the site.
+ *
+ * @parameter default-value="${project.reporting.outputDirectory}"
+ */
+ private File outputDirectory;
+
+ /**
+ * The language for the reports.
+ *
+ * @parameter default-value="en"
+ */
+ private String language = "en";
+
+ /**
+ * A flag whether to ignore errors from reports and continue the generation.
+ *
+ * @parameter default-value="false"
+ */
+ private boolean ignoreErrors;
+
+ /**
+ * The reports configured for the current build.
+ *
+ * @parameter expression="${reports}"
+ * @required
+ * @readonly
+ */
+ private List reports;
+
+ /**
+ * Runs this mojo.
+ *
+ * @throws MojoExecutionException If the output file could not be created.
+ */
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Using output directory " + outputDirectory );
+
+ Locale locale = new Locale( language );
+ getLog().info( "[MAVEN-CORE-IT-LOG] Using locale " + locale );
+
+ InvocationHandler handler = new InvocationHandler()
+ {
+
+ public Object invoke( Object proxy, Method method, Object[] args )
+ throws Throwable
+ {
+ return null;
+ }
+
+ };
+ Sink sink = (Sink) Proxy.newProxyInstance( getClass().getClassLoader(), new Class[] { Sink.class }, handler );
+
+ for ( int i = 0; i < reports.size(); i++ )
+ {
+ MavenReport report = (MavenReport) reports.get( i );
+
+ if ( report.canGenerateReport() )
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Generating report " + report );
+ try
+ {
+ report.setReportOutputDirectory( outputDirectory );
+ report.generate( sink, locale );
+ }
+ catch ( Throwable e )
+ {
+ getLog().warn( "[MAVEN-CORE-IT-LOG] " + e, e );
+ if ( !ignoreErrors )
+ {
+ throw new MojoExecutionException( "Failed to generate report " + report, e );
+ }
+ }
+ }
+ else
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Skipping report " + report );
+ }
+ }
+ }
+
+}
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/GenerateMojo.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java?rev=712313&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java (added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java Fri Nov 7 15:59:37 2008
@@ -0,0 +1,201 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.plugin.MojoFailureException;
+import org.apache.maven.reporting.MavenReport;
+import org.apache.maven.reporting.MavenReportException;
+
+import org.codehaus.doxia.sink.Sink;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Locale;
+import java.util.Properties;
+
+/**
+ * Creates a properties file in the site output directory.
+ *
+ * @goal info
+ *
+ * @author Benjamin Bentmann
+ * @version $Id$
+ */
+public class InfoReport
+ extends AbstractMojo
+ implements MavenReport
+{
+
+ /**
+ * The base directory of the current Maven project.
+ *
+ * @parameter default-value="${basedir}"
+ * @required
+ * @readonly
+ */
+ private File basedir;
+
+ /**
+ * The path to the properties file, relative to the output directory of the site. The keys
+ * <code>locale.language</code>, <code>locale.country</code> and <code>locale.variant</code> indicate the report's
+ * locale.
+ *
+ * @parameter default-value="info.properties"
+ */
+ private String infoFile = "info.properties";
+
+ /**
+ * The path to the output directory of the site.
+ *
+ * @parameter default-value="${project.reporting.outputDirectory}"
+ */
+ private File outputDirectory;
+
+ /**
+ * The locale for the report.
+ */
+ private Locale locale;
+
+ /**
+ * Runs this mojo.
+ *
+ * @throws MojoExecutionException If the output file could not be created.
+ * @throws MojoFailureException If the output file has not been set.
+ */
+ public void execute()
+ throws MojoExecutionException, MojoFailureException
+ {
+ getLog().info( "[MAVEN-CORE-IT-LOG] Using output file path: " + infoFile );
+
+ if ( infoFile == null || infoFile.length() <= 0 )
+ {
+ throw new MojoFailureException( "Path name for output file has not been specified" );
+ }
+
+ File outputFile = new File( outputDirectory, infoFile );
+ if ( !outputFile.isAbsolute() )
+ {
+ outputFile = new File( new File( basedir, outputDirectory.getPath() ), infoFile ).getAbsoluteFile();
+ }
+
+ Properties props = new Properties();
+ props.setProperty( "site.output.directory", outputDirectory.getPath() );
+ if ( locale != null )
+ {
+ props.setProperty( "locale.language", locale.getLanguage() );
+ props.setProperty( "locale.country", locale.getCountry() );
+ props.setProperty( "locale.variant", locale.getVariant() );
+ }
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file: " + outputFile );
+
+ OutputStream out = null;
+ try
+ {
+ outputFile.getParentFile().mkdirs();
+ out = new FileOutputStream( outputFile );
+ props.store( out, "MAVEN-CORE-IT-LOG" );
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( "Output file could not be created: " + outputFile, e );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ try
+ {
+ out.close();
+ }
+ catch ( IOException e )
+ {
+ // just ignore
+ }
+ }
+ }
+
+ getLog().info( "[MAVEN-CORE-IT-LOG] Created output file: " + outputFile );
+ }
+
+ /**
+ * Runs this report.
+ *
+ * @throws MavenReportException If the report could not be created.
+ */
+ public void generate( Sink sink, Locale locale )
+ throws MavenReportException
+ {
+ this.locale = locale;
+ try
+ {
+ execute();
+ }
+ catch ( Exception e )
+ {
+ throw new MavenReportException( "Report could not be created", e );
+ }
+ }
+
+ public String getOutputName()
+ {
+ return "info";
+ }
+
+ public String getCategoryName()
+ {
+ return "Project Reports";
+ }
+
+ public String getName( Locale locale )
+ {
+ return "name";
+ }
+
+ public String getDescription( Locale locale )
+ {
+ return "description";
+ }
+
+ public void setReportOutputDirectory( File outputDirectory )
+ {
+ this.outputDirectory = outputDirectory;
+ }
+
+ public File getReportOutputDirectory()
+ {
+ return outputDirectory;
+ }
+
+ public boolean isExternalReport()
+ {
+ return true;
+ }
+
+ public boolean canGenerateReport()
+ {
+ return true;
+ }
+
+}
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-site/src/main/java/org/apache/maven/plugin/coreit/InfoReport.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision