You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by rd...@apache.org on 2011/08/07 20:21:48 UTC

svn commit: r1154742 - in /incubator/rat/whisker/trunk/legacy/src: main/java/org/apache/rat/whisker/legacy/app/ main/java/org/apache/rat/whisker/legacy/cli/ test/java/org/apache/rat/whisker/legacy/cli/

Author: rdonkin
Date: Sun Aug  7 18:21:47 2011
New Revision: 1154742

URL: http://svn.apache.org/viewvc?rev=1154742&view=rev
Log:
Validate that source is set when audit is selected.

Modified:
    incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java
    incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java
    incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java
    incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java

Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java?rev=1154742&r1=1154741&r2=1154742&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Act.java Sun Aug  7 18:21:47 2011
@@ -23,9 +23,18 @@ package org.apache.rat.whisker.legacy.ap
  */
 public enum Act {
     
-    GENERATE,
-    AUDIT,
-    REPORT,
-    TEMPLATE
+    GENERATE(false),
+    AUDIT(true),
+    REPORT(true),
+    TEMPLATE(true);
 
+    private final boolean isSourceRequired;
+
+    private Act(boolean isSourceRequired) {
+        this.isSourceRequired = isSourceRequired;
+    }
+
+    public boolean isSourceRequired() {
+        return isSourceRequired;
+    }
 }

Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java?rev=1154742&r1=1154741&r2=1154742&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/Whisker.java Sun Aug  7 18:21:47 2011
@@ -29,10 +29,10 @@ import org.apache.rat.whisker.legacy.sca
  * 
  */
 public class Whisker {
-
-    private Act act = Act.TEMPLATE;
-    private String source = "app";
-    private String licenseDescriptor = "org/apache/rat/whisker/samples/james/james.xml";
+    
+    private Act act;
+    private String source;
+    private String licenseDescriptor;
 
     /**
      * @return the base

Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java?rev=1154742&r1=1154741&r2=1154742&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/cli/Main.java Sun Aug  7 18:21:47 2011
@@ -22,6 +22,7 @@ import org.apache.commons.cli.CommandLin
 import org.apache.commons.cli.CommandLineParser;
 import org.apache.commons.cli.GnuParser;
 import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.MissingOptionException;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.rat.whisker.legacy.app.Act;
@@ -79,8 +80,9 @@ public class Main {
      * Configures the application from the command line given.
      * @param parse commandLine not null
      * @return not null
+     * @throws MissingOptionException 
      */
-    private Whisker configure(final CommandLine commandLine) {
+    private Whisker configure(final CommandLine commandLine) throws MissingOptionException {
         whisker.setSource(CommandLineOption.SOURCE.getOptionValue(commandLine));
         whisker.setLicenseDescriptor(CommandLineOption.LICENSE_DESCRIPTION.getOptionValue(commandLine));
         if (CommandLineOption.ACT_TO_AUDIT.isSetOn(commandLine)) {
@@ -88,6 +90,10 @@ public class Main {
         } else if (CommandLineOption.ACT_TO_GENERATE.isSetOn(commandLine)) {
             whisker.setAct(Act.GENERATE);
         }
+        
+        if (whisker.getSource() == null && whisker.getAct().isSourceRequired()) {
+            throw new MissingOptionException("-" + CommandLineOption.SOURCE.getShortName() + " " + CommandLineOption.SOURCE.getDescription());
+        }
         return whisker;
     }
 

Modified: incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java?rev=1154742&r1=1154741&r2=1154742&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/test/java/org/apache/rat/whisker/legacy/cli/TestCommandParsing.java Sun Aug  7 18:21:47 2011
@@ -74,9 +74,11 @@ public class TestCommandParsing extends 
     private void checkSetActForOption(Act act, CommandLineOption option)
             throws ParseException {
         assertEquals(act + " arg should set property on Whisker", act, subject.configure(
-                args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", longOpt(option.getLongName()))).getAct());
+                args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", 
+                        shortOpt(CommandLineOption.SOURCE.getShortName()), "path", longOpt(option.getLongName()))).getAct());
         assertEquals(act + "Audit arg should set property on Whisker", act, subject.configure(
-                args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", shortOpt(option.getShortName()))).getAct());
+                args(longOpt(CommandLineOption.LICENSE_DESCRIPTION.getLongName()), "PATH", 
+                        shortOpt(CommandLineOption.SOURCE.getShortName()), "path", shortOpt(option.getShortName()))).getAct());
     }
 
     public void testSetSourceByCli() throws Exception {
@@ -85,6 +87,17 @@ public class TestCommandParsing extends 
         checkSourceWithPath("relative");
     }
     
+    public void testAuditRequiresSource() throws Exception {
+        try {
+            subject.configure(args( 
+                    longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()),
+                    shortOpt(CommandLineOption.LICENSE_DESCRIPTION.getShortName()), "some/path"));
+            fail("Audit requires source");
+        } catch (ParseException e) {
+            // Expected
+        }
+    }
+    
     /**
      * @param aPath
      */
@@ -158,7 +171,8 @@ public class TestCommandParsing extends 
      */
     private void exerciseLicenseDescriptor(String aPath, String arg)
             throws ParseException {
-        assertEquals("License descriptor arg should set property on Whisker", aPath, subject.configure(args(arg, aPath, longOpt(CommandLineOption.ACT_TO_AUDIT.getLongName()))).getLicenseDescriptor());
+        assertEquals("License descriptor arg should set property on Whisker", aPath, 
+                subject.configure(args(arg, aPath, longOpt(CommandLineOption.ACT_TO_GENERATE.getLongName()))).getLicenseDescriptor());
     }
     
     private String[] args(String ...strings) {