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/12/25 18:24:08 UTC

svn commit: r1224612 - in /incubator/rat/whisker/trunk: apache-whisker-app/src/main/java/org/apache/rat/whisker/app/ apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/ apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/ apache-w...

Author: rdonkin
Date: Sun Dec 25 17:24:08 2011
New Revision: 1224612

URL: http://svn.apache.org/viewvc?rev=1224612&view=rev
Log:
Switch from string name to StreamableResource, allowing alternative sources to be loaded.

Modified:
    incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/Whisker.java
    incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableClassPathResource.java
    incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableFileNameResource.java
    incubator/rat/whisker/trunk/apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/Main.java
    incubator/rat/whisker/trunk/apache-whisker-cli/src/test/java/org/apache/rat/whisker/cli/TestCommandParsing.java

Modified: incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/Whisker.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/Whisker.java?rev=1224612&r1=1224611&r2=1224612&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/Whisker.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/Whisker.java Sun Dec 25 17:24:08 2011
@@ -22,11 +22,11 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collection;
 
-import org.apache.rat.whisker.app.load.StreamableResourceFactory;
 import org.apache.rat.whisker.fromxml.JDomBuilder;
 import org.apache.rat.whisker.model.Work;
 import org.apache.rat.whisker.scan.Directory;
 import org.apache.rat.whisker.scan.FromFileSystem;
+import org.jdom.JDOMException;
 
 
 /**
@@ -36,7 +36,7 @@ public class Whisker {
     
     private Act act;
     private String source;
-    private String licenseDescriptor;
+    private StreamableResource licenseDescriptor;
     
     private AbstractEngine engine;
 
@@ -76,14 +76,14 @@ public class Whisker {
     /**
      * @return the licenseDescriptor
      */
-    public String getLicenseDescriptor() {
+    public StreamableResource getLicenseDescriptor() {
         return licenseDescriptor;
     }
 
     /**
      * @param licenseDescriptor the licenseDescriptor to set
      */
-    public Whisker setLicenseDescriptor(String licenseDescriptor) {
+    public Whisker setLicenseDescriptor(StreamableResource licenseDescriptor) {
         this.licenseDescriptor = licenseDescriptor;
         return this;
     }
@@ -174,8 +174,8 @@ public class Whisker {
      * @return
      * @throws IOException 
      */
-    private InputStream resourceAsStream(final String resource) throws IOException {
-        return new StreamableResourceFactory().streamFromClassPathResource(resource).open();
+    private InputStream resourceAsStream(final StreamableResource resource) throws IOException {
+        return resource.open();
     }
     
     
@@ -185,7 +185,7 @@ public class Whisker {
      * @throws JDOMException
      * @throws IOException
      */
-    private Work load(final String resource) throws Exception {
+    private Work load(final StreamableResource resource) throws Exception {
         final InputStream resourceAsStream = resourceAsStream(resource);
         if (resourceAsStream == null) {
             throw new IllegalArgumentException("Cannot load " + resource);

Modified: incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableClassPathResource.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableClassPathResource.java?rev=1224612&r1=1224611&r2=1224612&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableClassPathResource.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableClassPathResource.java Sun Dec 25 17:24:08 2011
@@ -30,7 +30,7 @@ public class StreamableClassPathResource
 
     /** The full name <strong>including path</strong> of a resource on the class path */
     private final String name;
-    
+  
     /**
      * Constructs an instance that streams the given class path resource
      * on demand.
@@ -43,6 +43,16 @@ public class StreamableClassPathResource
         this.name = name;
     }
 
+    
+    /**
+     * Gets the location on the class path of the resource to be streamed.
+     * @return not null
+     */
+    public String getName() {
+        return name;
+    }
+
+
 
     /**
      * @see org.apache.rat.whisker.app.StreamableResource#open()

Modified: incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableFileNameResource.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableFileNameResource.java?rev=1224612&r1=1224611&r2=1224612&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableFileNameResource.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-app/src/main/java/org/apache/rat/whisker/app/load/StreamableFileNameResource.java Sun Dec 25 17:24:08 2011
@@ -43,6 +43,14 @@ public class StreamableFileNameResource 
         this.fileName = fileName;
     }
 
+    /**    
+     * Gets the file name of the resource to be streamed.
+     * @return full file name, not null
+     */
+    public String getFileName() {
+        return fileName;
+    }
+
     /**
      * @see org.apache.rat.whisker.app.StreamableResource#open()
      */

Modified: incubator/rat/whisker/trunk/apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/Main.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/Main.java?rev=1224612&r1=1224611&r2=1224612&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/Main.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-cli/src/main/java/org/apache/rat/whisker/cli/Main.java Sun Dec 25 17:24:08 2011
@@ -27,6 +27,7 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.rat.whisker.app.Act;
 import org.apache.rat.whisker.app.Whisker;
+import org.apache.rat.whisker.app.load.StreamableResourceFactory;
 import org.apache.rat.whisker.out.velocity.VelocityEngine;
 
 /**
@@ -85,7 +86,9 @@ public class Main {
     private Whisker configure(final CommandLine commandLine) throws MissingOptionException {
         whisker.setEngine(new VelocityEngine());
         whisker.setSource(CommandLineOption.SOURCE.getOptionValue(commandLine));
-        whisker.setLicenseDescriptor(CommandLineOption.LICENSE_DESCRIPTION.getOptionValue(commandLine));
+        whisker.setLicenseDescriptor(
+                new StreamableResourceFactory().streamFromClassPathResource(
+                        CommandLineOption.LICENSE_DESCRIPTION.getOptionValue(commandLine)));
         if (CommandLineOption.ACT_TO_AUDIT.isSetOn(commandLine)) {
             whisker.setAct(Act.AUDIT);
         } else if (CommandLineOption.ACT_TO_GENERATE.isSetOn(commandLine)) {

Modified: incubator/rat/whisker/trunk/apache-whisker-cli/src/test/java/org/apache/rat/whisker/cli/TestCommandParsing.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/apache-whisker-cli/src/test/java/org/apache/rat/whisker/cli/TestCommandParsing.java?rev=1224612&r1=1224611&r2=1224612&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/apache-whisker-cli/src/test/java/org/apache/rat/whisker/cli/TestCommandParsing.java (original)
+++ incubator/rat/whisker/trunk/apache-whisker-cli/src/test/java/org/apache/rat/whisker/cli/TestCommandParsing.java Sun Dec 25 17:24:08 2011
@@ -24,6 +24,7 @@ import org.apache.commons.cli.AlreadySel
 import org.apache.commons.cli.ParseException;
 import org.apache.rat.whisker.app.Act;
 import org.apache.rat.whisker.app.Whisker;
+import org.apache.rat.whisker.app.load.StreamableClassPathResource;
 
 /**
  *
@@ -172,7 +173,9 @@ 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_GENERATE.getLongName()))).getLicenseDescriptor());
+                ((StreamableClassPathResource)subject.configure(
+                        args(arg, aPath, longOpt(CommandLineOption.ACT_TO_GENERATE.getLongName())))
+                            .getLicenseDescriptor()).getName());
     }
     
     private String[] args(String ...strings) {