creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1412678 - in /creadur/whisker/trunk/apache-whisker-velocity/src: main/java/org/apache/creadur/whisker/out/velocity/ main/resources/org/apache/creadur/whisker/template/velocity/ test/java/org/apache/creadur/whisker/out/velocity/
Date Thu, 22 Nov 2012 21:18:12 GMT
Author: rdonkin
Date: Thu Nov 22 21:18:11 2012
New Revision: 1412678

URL: http://svn.apache.org/viewvc?rev=1412678&view=rev
Log:
WHISKER-11 When configured, render source URLs

Added:
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java
  (with props)
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java
  (with props)
Modified:
    creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/RenderingHelper.java
    creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java
    creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java
    creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/license.vm
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/RenderingHelper.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/RenderingHelper.java?rev=1412678&r1=1412677&r2=1412678&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/RenderingHelper.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/RenderingHelper.java
Thu Nov 22 21:18:11 2012
@@ -18,8 +18,11 @@
  */
 package org.apache.creadur.whisker.out.velocity;
 
+import org.apache.commons.lang.StringUtils;
+import org.apache.creadur.whisker.app.Configuration;
 import org.apache.creadur.whisker.model.ByOrganisation;
 import org.apache.creadur.whisker.model.Descriptor;
+import org.apache.creadur.whisker.model.Resource;
 import org.apache.creadur.whisker.model.WithLicense;
 
 /**
@@ -33,12 +36,18 @@ public class RenderingHelper {
     private final Descriptor work;
 
     /**
+     * Configuration for the rendering.
+     */
+    private final Configuration configuration;
+
+    /**
      * Constructs a helper for the given work.
      * @param work not null
      */
-    public RenderingHelper(final Descriptor work) {
+    public RenderingHelper(final Descriptor work, final Configuration configuration) {
         super();
         this.work = work;
+        this.configuration = configuration;
     }
 
     /**
@@ -86,4 +95,22 @@ public class RenderingHelper {
     public boolean isNot(boolean claim) {
         return !claim;
     }
+
+    /**
+     * Renders the resource source URL
+     * based on configuration setting suitable
+     * for the license file.
+     * @param resource not null
+     * @return not null, possible empty string
+     */
+    public String sourceUrl(final Resource resource) {
+        final String result;
+        final String source = resource.getSource();
+        if (StringUtils.isBlank(source) || isNot(configuration.includeSourceURLsInLicense()))
{
+            result = "";
+        } else {
+            result = " from " + source;
+        }
+        return result;
+    }
 }
\ No newline at end of file

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java?rev=1412678&r1=1412677&r2=1412678&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityEngine.java
Thu Nov 22 21:18:11 2012
@@ -124,7 +124,7 @@ public class VelocityEngine extends Abst
             final Descriptor work,
             final ResultWriterFactory writerFactory,
             final Configuration configuration) throws Exception {
-        reporter(writerFactory).generate(work);
+        reporter(writerFactory).generate(work, configuration);
         return this;
     }
 }

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java?rev=1412678&r1=1412677&r2=1412678&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/main/java/org/apache/creadur/whisker/out/velocity/VelocityReports.java
Thu Nov 22 21:18:11 2012
@@ -25,6 +25,7 @@ import java.util.List;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
+import org.apache.creadur.whisker.app.Configuration;
 import org.apache.creadur.whisker.app.ResultWriterFactory;
 import org.apache.creadur.whisker.app.analysis.LicenseAnalyst;
 import org.apache.creadur.whisker.model.Descriptor;
@@ -167,9 +168,11 @@ public class VelocityReports implements 
     /**
      * Reports on work.
      * @param work not null
+     * @param configuration not null
      * @throws Exception when generation fails
      */
-    public final void generate(final Descriptor work) throws Exception {
+    public final void generate(final Descriptor work,
+            final Configuration configuration) throws Exception {
         final List<Product> products = new ArrayList<Product>();
         for (Product product: PRODUCTS_THAT_GENERATE_LICENSING_MATERIALS) {
             switch (product) {
@@ -184,7 +187,7 @@ public class VelocityReports implements 
 
         }
         final Product[] pruductArray = new Product[products.size()];
-        merge(products.toArray(pruductArray), context(work));
+        merge(products.toArray(pruductArray), context(work, configuration));
     }
 
     /**
@@ -218,13 +221,15 @@ public class VelocityReports implements 
     /**
      * Creates a context, and loads it for descriptor work.
      * @param work not null
+     * @param configuration not null
      * @return not null
      */
-    private VelocityContext context(final Descriptor work) {
+    private VelocityContext context(final Descriptor work,
+            final Configuration configuration) {
         final VelocityContext context = new VelocityContext();
         context.put("work", work);
         context.put("indent", new Indentation());
-        context.put("helper", new RenderingHelper(work));
+        context.put("helper", new RenderingHelper(work, configuration));
         return context;
     }
 

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/license.vm
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/license.vm?rev=1412678&r1=1412677&r2=1412678&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/license.vm
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/main/resources/org/apache/creadur/whisker/template/velocity/license.vm
Thu Nov 22 21:18:11 2012
@@ -37,7 +37,7 @@ Within the $directory.Name directory
         by $organisation.Name #if ($organisation.URL) $organisation.URL #end
 
 #foreach( $resource in $organisation.Resources)
-            $resource.Name
+            $resource.Name $helper.sourceUrl($resource)
 #end
 #end
 #end
@@ -56,7 +56,7 @@ $indent.indent(12,$license.CopyrightNoti
         from $organisation.Name #if ($organisation.URL) $organisation.URL #end
 
 #foreach( $resource in $organisation.Resources)
-            $resource.Name
+            $resource.Name $helper.sourceUrl($resource)
 #end
 #end
 #end

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java?rev=1412678&r1=1412677&r2=1412678&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
Thu Nov 22 21:18:11 2012
@@ -49,6 +49,7 @@ public class DescriptorBuilderForTesting
     String secondaryCopyright = null;
     String resourceName;
     String primaryCopyrightNotice = null;
+    public String sourceUrl = "";
 
     public DescriptorBuilderForTesting() {
         resourceName = "resource";
@@ -110,8 +111,7 @@ public class DescriptorBuilderForTesting
         String noticeId = "notice:id";
         notices.put(noticeId, "Some notice text");
         Collection<Resource> resources = new ArrayList<Resource>();
-        String source = "";
-        resources.add(new Resource(resourceName, noticeId, source));
+        resources.add(new Resource(resourceName, noticeId, sourceUrl));
         return resources;
     }
 
@@ -156,4 +156,9 @@ public class DescriptorBuilderForTesting
         return this;
     }
 
+    public DescriptorBuilderForTesting withSourceURL() {
+        sourceUrl = "http://example.org/bogus";
+        return this;
+    }
+
 }

Added: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java?rev=1412678&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java
(added)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java
Thu Nov 22 21:18:11 2012
@@ -0,0 +1,70 @@
+/**
+ * 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.
+ */
+package org.apache.creadur.whisker.out.velocity;
+
+import static org.apache.creadur.whisker.app.ConfigurationBuilder.aConfiguration;
+import junit.framework.TestCase;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.creadur.whisker.app.Result;
+import org.apache.creadur.whisker.model.Descriptor;
+
+public class TestLicenseGenerationSourceURLs extends TestCase {
+
+    StringResultWriterFactory writerFactory;
+    VelocityEngine subject;
+    DescriptorBuilderForTesting builder;
+    Descriptor work;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        writerFactory = new StringResultWriterFactory();
+        subject = new VelocityEngine(new EmptyLog());
+        builder = new DescriptorBuilderForTesting().withSourceURL();
+        work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory(".").build();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testNoSourceUrlsConfiguration() throws Exception {
+        subject.generate(work, writerFactory, aConfiguration().noSourceURLsInLicense().build());
+        assertFalse(failureMessage(), outputContainsSourceUrl());
+
+    }
+
+    private boolean outputContainsSourceUrl() {
+        return StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE),
+                builder.sourceUrl);
+    }
+
+    private String failureMessage() {
+        return "Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE);
+    }
+
+    public void testWithSourceUrlsConfiguration() throws Exception {
+        subject.generate(work, writerFactory, aConfiguration().withSourceURLsInLicense().build());
+
+        assertTrue(failureMessage(), outputContainsSourceUrl());
+
+    }
+}

Propchange: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGenerationSourceURLs.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java?rev=1412678&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java
(added)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java
Thu Nov 22 21:18:11 2012
@@ -0,0 +1,70 @@
+/**
+ * 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.
+ */
+package org.apache.creadur.whisker.out.velocity;
+
+import static org.apache.creadur.whisker.app.ConfigurationBuilder.*;
+
+import org.apache.creadur.whisker.model.Descriptor;
+import org.apache.creadur.whisker.model.Resource;
+
+import junit.framework.TestCase;
+
+public class TestRenderingHelper extends TestCase {
+
+    private static final String A_SOURCE_URL = "http://example.org/sample";
+
+    RenderingHelper subject;
+
+    Resource resourceWithSourceUrl;
+    Resource resourceNoSourceUrl;
+
+    Descriptor work;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        resourceWithSourceUrl = new Resource("a name", "an:id", A_SOURCE_URL);
+        resourceNoSourceUrl = new Resource("a name", "an:id", null);
+    }
+
+    public void testSourceWithSourceUrlsConfiguration() {
+        subject = new RenderingHelper(work,
+                aConfiguration().withSourceURLsInLicense().build());
+        assertEquals(subject.sourceUrl(resourceWithSourceUrl), " from " + A_SOURCE_URL);
+    }
+
+    public void testSourceNoSourceUrlsConfiguration() {
+        subject = new RenderingHelper(work,
+                aConfiguration().noSourceURLsInLicense().build());
+        assertEquals(subject.sourceUrl(resourceWithSourceUrl), "");
+    }
+
+    public void testNoSourceWithSourceUrlsConfiguration() {
+        subject = new RenderingHelper(work,
+                aConfiguration().withSourceURLsInLicense().build());
+        assertEquals(subject.sourceUrl(resourceNoSourceUrl), "");
+    }
+
+    public void testNoSourceNoSourceUrlsConfiguration() {
+        subject = new RenderingHelper(work,
+                aConfiguration().noSourceURLsInLicense().build());
+        assertEquals(subject.sourceUrl(resourceNoSourceUrl), "");
+    }
+
+}

Propchange: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestRenderingHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message