creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pottlin...@apache.org
Subject svn commit: r1679891 - in /creadur/rat/trunk: apache-rat-core/src/main/java/org/apache/rat/config/ apache-rat-core/src/test/java/org/apache/rat/config/ apache-rat-plugin/src/main/java/org/apache/rat/mp/
Date Sun, 17 May 2015 19:24:31 GMT
Author: pottlinger
Date: Sun May 17 19:24:31 2015
New Revision: 1679891

URL: http://svn.apache.org/r1679891
Log:
RAT-179: Add convenience method to extract all available options

* Integrate all available configuration options into static helper method,
  add test and use it RatCheckMojo.

Added:
    creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/config/AddLicenseHeadersTest.java
Modified:
    creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/config/AddLicenseHeaders.java
    creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java

Modified: creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/config/AddLicenseHeaders.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/config/AddLicenseHeaders.java?rev=1679891&r1=1679890&r2=1679891&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/config/AddLicenseHeaders.java
(original)
+++ creadur/rat/trunk/apache-rat-core/src/main/java/org/apache/rat/config/AddLicenseHeaders.java
Sun May 17 19:24:31 2015
@@ -28,5 +28,20 @@ package org.apache.rat.config;
 public enum AddLicenseHeaders {
     TRUE, //
     FALSE, //
-    FORCED
+    FORCED;
+
+    private static final char SEPARATOR = '|';
+
+    /**
+     * @return pretty-printed list of all available options.
+     */
+    public static String getValuesForHelp() {
+        StringBuilder sb = new StringBuilder();
+        for(AddLicenseHeaders headerOption : AddLicenseHeaders.values()) {
+            sb.append(headerOption.name().toLowerCase()).append(SEPARATOR);
+        }
+        // remove last separator
+        sb.setLength(sb.length() - 1);
+        return sb.toString();
+    }
 }

Added: creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/config/AddLicenseHeadersTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/config/AddLicenseHeadersTest.java?rev=1679891&view=auto
==============================================================================
--- creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/config/AddLicenseHeadersTest.java
(added)
+++ creadur/rat/trunk/apache-rat-core/src/test/java/org/apache/rat/config/AddLicenseHeadersTest.java
Sun May 17 19:24:31 2015
@@ -0,0 +1,35 @@
+package org.apache.rat.config;
+/*
+ * 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.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+
+/**
+ * @author pottlinger
+ * @version 2015-05-17, 21:14
+ */
+public class AddLicenseHeadersTest {
+    @Test
+    public void verifyHelpOptions() {
+        String allOptions = AddLicenseHeaders.getValuesForHelp();
+        assertFalse(allOptions, allOptions.isEmpty());
+        assertFalse(allOptions, allOptions.endsWith("|"));
+    }
+}

Modified: creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java?rev=1679891&r1=1679890&r2=1679891&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
(original)
+++ creadur/rat/trunk/apache-rat-plugin/src/main/java/org/apache/rat/mp/RatCheckMojo.java
Sun May 17 19:24:31 2015
@@ -40,14 +40,12 @@ import java.io.InputStream;
 /**
  * Run Rat to perform a violation check.
  */
-@Mojo (name = "check", defaultPhase = LifecyclePhase.VALIDATE)
-public class RatCheckMojo extends AbstractRatMojo
-{
+@Mojo(name = "check", defaultPhase = LifecyclePhase.VALIDATE)
+public class RatCheckMojo extends AbstractRatMojo {
     /**
      * Where to store the report.
-     *
      */
-    @Parameter (property = "rat.outputFile", defaultValue = "${project.build.directory}/rat.txt")
+    @Parameter(property = "rat.outputFile", defaultValue = "${project.build.directory}/rat.txt")
     private File reportFile;
 
     /**
@@ -55,7 +53,6 @@ public class RatCheckMojo extends Abstra
      * report or "xml" for the raw XML report. Alternatively you can give the
      * path of an XSL transformation that will be applied on the raw XML to
      * produce the report written to the output file.
-     *
      */
     @Parameter(property = "rat.outputStyle", defaultValue = "plain")
     private String reportStyle;
@@ -69,7 +66,6 @@ public class RatCheckMojo extends Abstra
     /**
      * Whether to add license headers; possible values are
      * {@code forced}, {@code true}, and {@code false} (default).
-     *
      */
     @Parameter(property = "rat.addLicenseHeaders", defaultValue = "false")
     private String addLicenseHeaders;
@@ -78,7 +74,6 @@ public class RatCheckMojo extends Abstra
      * Copyright message to add to license headers. This option is
      * ignored, unless {@code addLicenseHeaders} is set to {@code true},
      * or {@code forced}.
-     *
      */
     @Parameter(property = "rat.copyrightMessage")
     private String copyrightMessage;
@@ -86,6 +81,7 @@ public class RatCheckMojo extends Abstra
     /**
      * Will ignore rat errors and display a log message if any.
      * Its use is NOT RECOMMENDED, but quite convenient on occasion.
+     *
      * @since 0.9
      */
     @Parameter(property = "rat.ignoreErrors", defaultValue = "false")
@@ -101,53 +97,39 @@ public class RatCheckMojo extends Abstra
     private boolean consoleOutput;
 
     private ClaimStatistic getRawReport()
-        throws MojoExecutionException, MojoFailureException
-    {
+            throws MojoExecutionException, MojoFailureException {
         FileWriter fw = null;
-        try
-        {
-            fw = new FileWriter( reportFile );
-            final ClaimStatistic statistic = createReport( fw, getStyleSheet() );
+        try {
+            fw = new FileWriter(reportFile);
+            final ClaimStatistic statistic = createReport(fw, getStyleSheet());
             fw.close();
             fw = null;
             return statistic;
-        }
-        catch ( IOException e )
-        {
-            throw new MojoExecutionException( e.getMessage(), e );
-        }
-        finally
-        {
-            IOUtils.closeQuietly( fw );
+        } catch (IOException e) {
+            throw new MojoExecutionException(e.getMessage(), e);
+        } finally {
+            IOUtils.closeQuietly(fw);
         }
     }
 
     /**
      * Returns the XSL stylesheet to be used for formatting the report.
      *
-     * @see #reportStyle
      * @return report stylesheet, or <code>null</code> for raw XML
      * @throws MojoExecutionException if the stylesheet can not be found
+     * @see #reportStyle
      */
     private InputStream getStyleSheet() throws MojoExecutionException {
-        if ( reportStyle == null || reportStyle.equals( "plain" ) )
-        {
+        if (reportStyle == null || reportStyle.equals("plain")) {
             return Defaults.getPlainStyleSheet();
-        }
-        else if ( reportStyle.equals( "xml" ) )
-        {
+        } else if (reportStyle.equals("xml")) {
             return null;
-        }
-        else
-        {
-            try
-            {
-                return new FileInputStream( reportStyle );
-            }
-            catch ( FileNotFoundException e )
-            {
+        } else {
+            try {
+                return new FileInputStream(reportStyle);
+            } catch (FileNotFoundException e) {
                 throw new MojoExecutionException(
-                        "Unable to find report stylesheet: " + reportStyle, e );
+                        "Unable to find report stylesheet: " + reportStyle, e);
             }
         }
     }
@@ -155,53 +137,41 @@ public class RatCheckMojo extends Abstra
     /**
      * Invoked by Maven to execute the Mojo.
      *
-     * @throws MojoFailureException
-     *             An error in the plugin configuration was detected.
-     * @throws MojoExecutionException
-     *             Another error occurred while executing the plugin.
-     */
-    public void execute() throws MojoExecutionException, MojoFailureException
-    {
-        if(skip) {
+     * @throws MojoFailureException   An error in the plugin configuration was detected.
+     * @throws MojoExecutionException Another error occurred while executing the plugin.
+     */
+    public void execute() throws MojoExecutionException, MojoFailureException {
+        if (skip) {
             getLog().info("RAT will not execute since it is configured to be skipped via
system property 'rat.skip'.");
             return;
         }
 
         final File parent = reportFile.getParentFile();
-        if(!parent.mkdirs() && !parent.isDirectory()) {
+        if (!parent.mkdirs() && !parent.isDirectory()) {
             throw new MojoExecutionException("Could not create report parent directory "
+ parent);
         }
 
         final ClaimStatistic report = getRawReport();
-        check( report );
+        check(report);
     }
 
-    protected void check( ClaimStatistic statistics )
-        throws MojoFailureException
-    {
+    protected void check(ClaimStatistic statistics)
+            throws MojoFailureException {
         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." );
+        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 )
-            {
-                throw new RatCheckException( "Too many files with unapproved license: " +
statistics.getNumUnApproved() + seeReport);
-            }
-            else
-            {
-                getLog().warn( "Rat check: " + statistics.getNumUnApproved() + " files with
unapproved licenses." + seeReport);
+            if (!ignoreErrors) {
+                throw new RatCheckException("Too many files with unapproved license: " +
statistics.getNumUnApproved() + seeReport);
+            } else {
+                getLog().warn("Rat check: " + statistics.getNumUnApproved() + " files with
unapproved licenses." + seeReport);
             }
         }
     }
@@ -221,7 +191,7 @@ public class RatCheckMojo extends Abstra
         } else if (AddLicenseHeaders.FALSE.name().equalsIgnoreCase(addLicenseHeaders)) {
             // Nothing to do
         } else {
-            throw new MojoFailureException("Invalid value for addLicenseHeaders: Expected
forced|true|false, got "
+            throw new MojoFailureException("Invalid value for addLicenseHeaders: Expected
" + AddLicenseHeaders.getValuesForHelp() + ", got "
                     + addLicenseHeaders);
         }
         return configuration;



Mime
View raw message