[RAT-61] List files with unapproved licenses in Maven output

git-svn-id: https://svn.apache.org/repos/asf/creadur/rat/trunk@1636753 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 4f72a0d..bafc8b1 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -13,6 +13,7 @@
     * [RAT-175] - SourceCodeManagementSystems.hasIgnoreFile() should return boolean
     * [RAT-177] - final arrays should be private
    Improvement
+    * [RAT-61]  - List files with unapproved licenses in Maven output
     * [RAT-170] - RAT should use itself during build and site generation
     * [RAT-181] - BinaryGuesser should treat *.truststore as binary
     * [RAT-184] - Add DEPENDENCIES to the list of ignored files in NoteGuesser.
diff --git a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
index 683ba5b..c3c21e3 100644
--- a/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
+++ b/apache-rat-core/src/main/java/org/apache/rat/Defaults.java
@@ -67,12 +67,18 @@
                     new CDDL1License()));
     
     public static final String PLAIN_STYLESHEET = "org/apache/rat/plain-rat.xsl";
-    
+    public static final String UNAPPROVED_LICENSES_STYLESHEET = "org/apache/rat/unapproved-licenses.xsl";
+
     public static InputStream getPlainStyleSheet() {
         InputStream result = Defaults.class.getClassLoader().getResourceAsStream(Defaults.PLAIN_STYLESHEET);
         return result;
     }
     
+    public static InputStream getUnapprovedLicensesStyleSheet() {
+        InputStream result = Defaults.class.getClassLoader().getResourceAsStream(Defaults.UNAPPROVED_LICENSES_STYLESHEET);
+        return result;
+    }
+
     public static InputStream getDefaultStyleSheet() {
         InputStream result = getPlainStyleSheet();
         return result;
diff --git a/apache-rat-core/src/main/resources/org/apache/rat/unapproved-licenses.xsl b/apache-rat-core/src/main/resources/org/apache/rat/unapproved-licenses.xsl
new file mode 100644
index 0000000..040909b
--- /dev/null
+++ b/apache-rat-core/src/main/resources/org/apache/rat/unapproved-licenses.xsl
@@ -0,0 +1,31 @@
+<?xml version='1.0' ?>
+<!--
+ 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.                                           *
+-->
+<xsl:stylesheet version="1.0"
+                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method='text'/>
+<xsl:template match='/'>Files with unapproved licenses:
+<xsl:for-each select='descendant::resource[license-approval/@name="false"]'>
+  <xsl:text>  </xsl:text>
+  <xsl:value-of select='@name'/>
+  <xsl:text>
+</xsl:text>
+</xsl:for-each>
+</xsl:template>
+</xsl:stylesheet>
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
index 0a00d7f..648abc4 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/AbstractRatMojo.java
@@ -40,6 +40,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.io.Writer;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.util.ArrayList;
@@ -378,6 +380,63 @@
     }
 
     /**
+     * Creates the report as a string.
+     *
+     * @param styleSheet The style sheet to use when formatting the report
+     * @throws MojoFailureException
+     *             An error in the plugin configuration was detected.
+     * @throws MojoExecutionException
+     *             An error occurred while creating the report.
+     * @return Report contents
+     */
+    protected String createReport( InputStream styleSheet )
+        throws MojoExecutionException, MojoFailureException
+    {
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = null;
+        try
+        {
+            pw = new PrintWriter( sw );
+            createReport( new PrintWriter( sw ), styleSheet );
+            final String result = sw.toString();
+            pw.close();
+            pw = null;
+            sw.close();
+            sw = null;
+            return result;
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( e.getMessage(), e );
+        }
+        finally
+        {
+            if ( pw != null )
+            {
+                try
+                {
+                    pw.close();
+                }
+                catch ( Throwable t )
+                {
+                    // Ignore me
+                }
+            }
+            if ( sw != null )
+            {
+                try
+                {
+                    sw.close();
+                }
+                catch ( Throwable t )
+                {
+                    // Ignore me
+                }
+            }
+        }
+    }
+
+    /**
      * Writes the report to the given stream.
      *
      * @param out
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
index 010c177..6cca222 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
@@ -89,6 +89,15 @@
     @Parameter(property = "rat.ignoreErrors", defaultValue = "false")
     private boolean ignoreErrors;
 
+    /**
+     * Whether to output the names of files that have unapproved licenses to the
+     * console.
+     *
+     * @since 0.12
+     */
+    @Parameter(property = "rat.consoleOutput", defaultValue = "false")
+    private boolean consoleOutput;
+
     private ClaimStatistic getRawReport()
         throws MojoExecutionException, MojoFailureException
     {
@@ -181,6 +190,18 @@
         getLog().info("Rat check: Summary of files. Unapproved: " + statistics.getNumUnApproved() + " unknown: " + statistics.getNumUnknown() + " generated: " + statistics.getNumGenerated() + " approved: " + statistics.getNumApproved() + " licence.");
         if ( numUnapprovedLicenses < statistics.getNumUnApproved() )
         {
+            if ( consoleOutput )
+            {
+                try
+                {
+                    getLog().warn( createReport( Defaults.getUnapprovedLicensesStyleSheet() ).trim() );
+                }
+                catch( MojoExecutionException e )
+                {
+                    getLog().warn( "Unable to print the files with unapproved licenses to the console." );
+                }
+            }
+
             final String seeReport = " See RAT report in: " + reportFile;
             if ( !ignoreErrors )
             {
diff --git a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
index 361c43e..0b1f439 100644
--- a/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
+++ b/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatReportMojo.java
@@ -22,8 +22,6 @@
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.io.Writer;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -129,61 +127,6 @@
     }
 
     /**
-     * Creates the report as a string. Currently, this string will be embedded verbatimly into the report document.
-     *
-     * @throws MojoFailureException
-     *             An error in the plugin configuration was detected.
-     * @throws MojoExecutionException
-     *             An error occurred while creating the report.
-     * @return Report contents
-     */
-    private String createReport() throws MojoExecutionException, MojoFailureException
-    {
-        StringWriter sw = new StringWriter();
-        PrintWriter pw = null;
-        try
-        {
-            pw = new PrintWriter( sw );
-            createReport( new PrintWriter( sw ), Defaults.getDefaultStyleSheet() );
-            final String result = sw.toString();
-            pw.close();
-            pw = null;
-            sw.close();
-            sw = null;
-            return result;
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
-        }
-        finally
-        {
-            if ( pw != null )
-            {
-                try
-                {
-                    pw.close();
-                }
-                catch ( Throwable t )
-                {
-                    // Ignore me
-                }
-            }
-            if ( sw != null )
-            {
-                try
-                {
-                    sw.close();
-                }
-                catch ( Throwable t )
-                {
-                    // Ignore me
-                }
-            }
-        }
-    }
-
-    /**
      * Called from Maven to invoke the plugin.
      *
      * @throws MojoFailureException
@@ -313,7 +256,7 @@
         sink.verbatim( true );
         try
         {
-            sink.text( createReport() );
+            sink.text( createReport( Defaults.getDefaultStyleSheet() ) );
         }
         catch ( MojoExecutionException e )
         {