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 22:08:20 UTC

svn commit: r1154758 - in /incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy: app/WhiskerVelocity.java out/Engine.java

Author: rdonkin
Date: Sun Aug  7 20:08:20 2011
New Revision: 1154758

URL: http://svn.apache.org/viewvc?rev=1154758&view=rev
Log:
Move resource loading from Engine

Modified:
    incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/WhiskerVelocity.java
    incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Engine.java

Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/WhiskerVelocity.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/WhiskerVelocity.java?rev=1154758&r1=1154757&r2=1154758&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/WhiskerVelocity.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/app/WhiskerVelocity.java Sun Aug  7 20:08:20 2011
@@ -19,7 +19,13 @@
 package org.apache.rat.whisker.legacy.app;
 
 
+import java.io.IOException;
+
 import org.apache.rat.whisker.legacy.out.Engine;
+import org.apache.rat.whisker.legacy.out.LicenseAnalyst;
+import org.apache.rat.whisker.legacy.out.Work;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
 
 /**
  * 
@@ -27,7 +33,18 @@ import org.apache.rat.whisker.legacy.out
 public class WhiskerVelocity extends Whisker {
 
     protected void doGenerate() throws Exception {
-        new Engine().write(getLicenseDescriptor());
+        new Engine().merge(new LicenseAnalyst().validate(load(getLicenseDescriptor())));
+    }
+    
+    /**
+     * @param resource
+     * @return
+     * @throws JDOMException
+     * @throws IOException
+     */
+    private Work load(final String resource) throws JDOMException,
+            IOException {
+        return new Work(new SAXBuilder().build(getClass().getClassLoader().getResourceAsStream(resource)));
     }
     
     /**
@@ -35,7 +52,7 @@ public class WhiskerVelocity extends Whi
      */
     @Override
     protected void doValidate() throws Exception {
-        new Engine().check(getLicenseDescriptor(), directories());
+        new Engine().merge(new LicenseAnalyst(directories()).analyse(load(getLicenseDescriptor())));
     }
 
     /**

Modified: incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Engine.java
URL: http://svn.apache.org/viewvc/incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Engine.java?rev=1154758&r1=1154757&r2=1154758&view=diff
==============================================================================
--- incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Engine.java (original)
+++ incubator/rat/whisker/trunk/legacy/src/main/java/org/apache/rat/whisker/legacy/out/Engine.java Sun Aug  7 20:08:20 2011
@@ -22,7 +22,6 @@ import java.io.IOException;
 import java.io.StringWriter;
 import java.util.Collection;
 
-
 import org.apache.rat.whisker.legacy.out.LicenseAnalyst.ResourceDefinitionException;
 import org.apache.rat.whisker.legacy.scan.Directory;
 import org.apache.velocity.VelocityContext;
@@ -33,7 +32,6 @@ import org.apache.velocity.exception.Res
 import org.apache.velocity.runtime.RuntimeServices;
 import org.apache.velocity.runtime.log.LogChute;
 import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
 
 /**
  * Wraps velocity engine.
@@ -90,8 +88,8 @@ public class Engine implements LogChute 
     /**
      * 
      */
-    public void write(final String resource) throws Exception {
-        merge(TEMPLATES, context(resource));
+    public void merge(final Work work) throws Exception {
+        merge(TEMPLATES, context(work));
     }
 
     private void merge(final String[] names, final VelocityContext context) throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, JDOMException, IOException {
@@ -122,24 +120,13 @@ public class Engine implements LogChute 
      * @throws JDOMException 
      * @throws ResourceDefinitionException 
      */
-    private VelocityContext context(final String resource) throws JDOMException, IOException, ResourceDefinitionException {
-        final Work work = new LicenseAnalyst().validate(load(resource));
+    private VelocityContext context(final Work work) throws JDOMException, IOException, ResourceDefinitionException {
         VelocityContext context = new VelocityContext();
         context.put("work", work);
         context.put("indent", new Indentation());
         return context;
     }
 
-    /**
-     * @param resource
-     * @return
-     * @throws JDOMException
-     * @throws IOException
-     */
-    private Work load(final String resource) throws JDOMException,
-            IOException {
-        return new Work(new SAXBuilder().build(getClass().getClassLoader().getResourceAsStream(resource)));
-    }
 
     /**
      * Returns full template path.
@@ -171,8 +158,8 @@ public class Engine implements LogChute 
      * @param withBase
      * @throws Exception 
      */
-    public void check(String licenseDescriptor, Collection<Directory> withBase) throws Exception {
-        merge(MISSING_LICENSE_REPORT_TEMPLATE, context(new LicenseAnalyst(withBase).analyse(load(licenseDescriptor))));
+    public void merge(LicenseAnalyst analyst) throws Exception {
+        merge(MISSING_LICENSE_REPORT_TEMPLATE, context(analyst));
     }
 
     /**