You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2014/12/07 17:52:03 UTC

svn commit: r1643698 - in /maven/shared/trunk/maven-reporting-impl/src/it: setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ use-as-direct-mojo/ use-as-site-report/

Author: hboutemy
Date: Sun Dec  7 16:52:02 2014
New Revision: 1643698

URL: http://svn.apache.org/r1643698
Log:
[MSHARED-389] created an IT to show how to implement a report that uses an external tool to generate the report

Added:
    maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java   (with props)
Modified:
    maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/invoker.properties
    maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/verify.groovy
    maven/shared/trunk/maven-reporting-impl/src/it/use-as-site-report/verify.groovy

Added: maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java?rev=1643698&view=auto
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java (added)
+++ maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java Sun Dec  7 16:52:02 2014
@@ -0,0 +1,96 @@
+package org.apache.maven.reporting.its.custom;
+
+/*
+ * 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 java.io.IOException;
+import java.io.File;
+import java.util.Locale;
+
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.apache.maven.shared.utils.io.FileUtils;
+
+/**
+ * Typical code to copy as an external reporting plugin start: choose the goal name, then implement getOutputName(),
+ * getName( Locale ), getDescription( Locale ) and of course executeReport( Locale ).
+ */
+@Mojo( name = "external" )
+public class ExternalReport
+    extends AbstractMavenReport
+{
+    /**
+     * The name of the destination directory inside the site.
+     */
+    @Parameter( property = "destDir", defaultValue = "external" )
+    private String destDir;
+
+    public String getOutputName()
+    {
+        return destDir + "/report";
+    }
+
+    public String getName( Locale locale )
+    {
+        return "External Maven Report";
+    }
+
+    public String getDescription( Locale locale )
+    {
+        return "External Maven Report Description";
+    }
+
+    public boolean isExternalReport()
+    {
+        return true;
+    }
+
+    @Override
+    protected void executeReport( Locale locale )
+        throws MavenReportException
+    {
+        try
+        {
+            executeExternalTool( getOutputDirectory() + '/' + destDir );
+        }
+        catch ( IOException ioe )
+        {
+            throw new MavenReportException( "IO exception while executing external reporting tool", ioe );
+        }
+    }
+
+    /**
+     * Invoke the external tool to generate report.
+     *
+     * @param destination destination directory
+     */
+    private void executeExternalTool( String destination )
+        throws IOException
+    {
+        // demo implementation, to be replaced with effective tool
+        File dest = new File( destination );
+
+        dest.mkdirs();
+
+        File report = new File( dest, "report.html" );
+        FileUtils.fileWrite( report, "UTF-8", "<html><body><h1>External Report</h1></body></html>" );
+    }
+}

Propchange: maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: maven/shared/trunk/maven-reporting-impl/src/it/setup-reporting-plugin/src/main/java/org/apache/maven/reporting/its/custom/ExternalReport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/invoker.properties
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/invoker.properties?rev=1643698&r1=1643697&r2=1643698&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/invoker.properties (original)
+++ maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/invoker.properties Sun Dec  7 16:52:02 2014
@@ -17,3 +17,4 @@
 
 invoker.goals.1 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:custom
 invoker.goals.2 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:custom-renderer
+invoker.goals.3 = org.apache.maven.reporting.its:custom-reporting-plugin:1.0-SNAPSHOT:external

Modified: maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/verify.groovy
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/verify.groovy?rev=1643698&r1=1643697&r2=1643698&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/verify.groovy (original)
+++ maven/shared/trunk/maven-reporting-impl/src/it/use-as-direct-mojo/verify.groovy Sun Dec  7 16:52:02 2014
@@ -27,4 +27,8 @@ f = new File( site, 'custom-report-with-
 assert f.exists();
 assert f.text.contains( 'Custom Maven Report with Renderer content.' );
 
+f = new File( site, 'external/report.html' );
+assert f.exists();
+assert f.text.contains( '<h1>External Report</h1>' );
+
 return true;
\ No newline at end of file

Modified: maven/shared/trunk/maven-reporting-impl/src/it/use-as-site-report/verify.groovy
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-reporting-impl/src/it/use-as-site-report/verify.groovy?rev=1643698&r1=1643697&r2=1643698&view=diff
==============================================================================
--- maven/shared/trunk/maven-reporting-impl/src/it/use-as-site-report/verify.groovy (original)
+++ maven/shared/trunk/maven-reporting-impl/src/it/use-as-site-report/verify.groovy Sun Dec  7 16:52:02 2014
@@ -27,4 +27,8 @@ f = new File( site, 'custom-report-with-
 assert f.exists();
 assert f.text.contains( 'Custom Maven Report with Renderer content.' );
 
+f = new File( site, 'external/report.html' );
+assert f.exists();
+assert f.text.contains( '<h1>External Report</h1>' );
+
 return true;
\ No newline at end of file