You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ch...@apache.org on 2018/05/21 19:23:11 UTC

[2/4] commons-release-plugin git commit: COMMONSSITE-108: finishing up the velocity delegates

COMMONSSITE-108: finishing up the velocity delegates


Project: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/commit/34bf87ee
Tree: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/tree/34bf87ee
Diff: http://git-wip-us.apache.org/repos/asf/commons-release-plugin/diff/34bf87ee

Branch: refs/heads/master
Commit: 34bf87ee58e6856266006051eb7e6d7d179986f0
Parents: 0cbef20
Author: Rob Tompkins <ch...@gmail.com>
Authored: Mon May 21 09:06:38 2018 -0400
Committer: Rob Tompkins <ch...@gmail.com>
Committed: Mon May 21 09:06:38 2018 -0400

----------------------------------------------------------------------
 .../velocity/HeaderHtmlVelocityDelegate.java    | 36 ++++++++++-------
 .../velocity/ReadmeHtmlVelocityDelegate.java    | 17 +++++---
 .../resources/META-INF/plexus/components.xml    | 42 --------------------
 .../HeaderHtmlVelocityDelegateTest.java         | 22 ++++++++++
 .../ReadmeHtmlVelocityDelegateTest.java         |  2 +-
 5 files changed, 55 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/34bf87ee/src/main/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegate.java b/src/main/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegate.java
index acdad16..3852451 100644
--- a/src/main/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegate.java
+++ b/src/main/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegate.java
@@ -16,11 +16,12 @@
  */
 package org.apache.commons.release.plugin.velocity;
 
+import java.io.Writer;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-
-import java.io.Writer;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 
 /**
  * This class' purpose is to generate the <code>HEADER.html</code> that moves along with the
@@ -30,15 +31,10 @@ import java.io.Writer;
  * @since 1.3
  */
 public class HeaderHtmlVelocityDelegate {
-
-    /**
-     * The location of the velocity tempate for this class.
-     */
-    private static final String TEMPLATE = "HEADER.vm";
-
-    /**
-     * The private constructor to be used by the {@link HeaderHtmlVelocityDelegateBuilder}.
-     */
+    /** The location of the velocity tempate for this class. */
+    private static final String TEMPLATE = "resources/org/apache/commons/release/plugin"
+                                         + "/velocity/HEADER.vm";
+    /** The private constructor to be used by the {@link HeaderHtmlVelocityDelegateBuilder}. */
     private HeaderHtmlVelocityDelegate() {
         super();
     }
@@ -59,8 +55,11 @@ public class HeaderHtmlVelocityDelegate {
      * @return the {@link Writer} that we've filled out the template into.
      */
     public Writer render(Writer writer) {
-        Velocity.init();
-        Template template = Velocity.getTemplate(TEMPLATE);
+        VelocityEngine ve = new VelocityEngine();
+        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
+        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
+        ve.init();
+        Template template = ve.getTemplate(TEMPLATE);
         VelocityContext context = new VelocityContext();
         template.merge(context, writer);
         return writer;
@@ -69,7 +68,14 @@ public class HeaderHtmlVelocityDelegate {
     /**
      * A builder class for instantiation of the {@link HeaderHtmlVelocityDelegate}.
      */
-    private static class HeaderHtmlVelocityDelegateBuilder {
+    public static class HeaderHtmlVelocityDelegateBuilder {
+
+        /**
+         * Private constructor so that we can have a proper builder pattern.
+         */
+        private HeaderHtmlVelocityDelegateBuilder() {
+            super();
+        }
 
         /**
          * Builds up the {@link ReadmeHtmlVelocityDelegate} from the previously set parameters.

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/34bf87ee/src/main/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegate.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegate.java b/src/main/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegate.java
index 6910323..2524a11 100644
--- a/src/main/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegate.java
+++ b/src/main/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegate.java
@@ -16,12 +16,13 @@
  */
 package org.apache.commons.release.plugin.velocity;
 
+import java.io.Writer;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-
-import java.io.Writer;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 
 /**
  * This class' purpose is to generate the <code>README.html</code> that moves along with the
@@ -32,7 +33,8 @@ import java.io.Writer;
  */
 public class ReadmeHtmlVelocityDelegate {
     /** The location of the velocity template for this class. */
-    private static final String TEMPLATE = "README.vm";
+    private static final String TEMPLATE = "resources/org/apache/commons/release/plugin"
+                                         + "/velocity/README.vm";
     /** This is supposed to represent the maven artifactId. */
     private String artifactId;
     /** This is supposed to represent the maven version of the release. */
@@ -70,6 +72,11 @@ public class ReadmeHtmlVelocityDelegate {
      * @return a reference to the {@link Writer} passed in.
      */
     public Writer render(Writer writer) {
+        VelocityEngine ve = new VelocityEngine();
+        ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
+        ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
+        ve.init();
+        Template template = ve.getTemplate(TEMPLATE);
         String[] splitArtifactId = artifactId.split("-");
         String wordCommons = splitArtifactId[0];
         String artifactShortName = splitArtifactId[1];
@@ -77,8 +84,6 @@ public class ReadmeHtmlVelocityDelegate {
                 StringUtils.capitalize(wordCommons)
                         + "-"
                         + artifactShortName.toUpperCase();
-        Velocity.init();
-        Template template = Velocity.getTemplate(TEMPLATE);
         VelocityContext context = new VelocityContext();
         context.internalPut("artifactIdWithFirstLetterscapitalized", artifactIdWithFirstLetterscapitalized);
         context.internalPut("artifactShortName", artifactShortName.toUpperCase());

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/34bf87ee/src/main/resources/META-INF/plexus/components.xml
----------------------------------------------------------------------
diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml
deleted file mode 100644
index e58557c..0000000
--- a/src/main/resources/META-INF/plexus/components.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
-<!--
-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.
--->
-<component-set>
-  <components>
-    <component>
-      <role>org.codehaus.plexus.velocity.VelocityComponent</role>
-      <role-hint>maven-changes-plugin</role-hint>
-      <implementation>org.codehaus.plexus.velocity.DefaultVelocityComponent</implementation>
-      <configuration>
-        <properties>
-          <property>
-            <name>resource.loader</name>
-            <value>file,class</value>
-          </property>
-          <property>
-            <name>class.resource.loader.class</name>
-            <value>org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</value>
-          </property>
-          <property>
-            <name>file.resource.loader.class</name>
-            <value>org.apache.maven.plugins.resource.loader.ProjectResourceLoader</value>
-          </property>
-        </properties>
-      </configuration>
-    </component>
-  </components>
-</component-set>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/34bf87ee/src/test/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegateTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegateTest.java b/src/test/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegateTest.java
new file mode 100644
index 0000000..6da2c53
--- /dev/null
+++ b/src/test/java/org/apache/commons/release/plugin/velocity/HeaderHtmlVelocityDelegateTest.java
@@ -0,0 +1,22 @@
+package org.apache.commons.release.plugin.velocity;
+
+import static junit.framework.TestCase.assertTrue;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import org.junit.Test;
+
+/**
+ * Unit tests for {@link HeaderHtmlVelocityDelegate}
+ */
+public class HeaderHtmlVelocityDelegateTest {
+
+    @Test
+    public void testSuccess() {
+        HeaderHtmlVelocityDelegate subject = HeaderHtmlVelocityDelegate.builder().build();
+        Writer writer = new StringWriter();
+        writer = subject.render(writer);
+        assertTrue(writer.toString().contains("<h2>Apache Commons Project Distributions</h2>"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-release-plugin/blob/34bf87ee/src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java b/src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java
index 0e7c15f..b005d3f 100644
--- a/src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java
+++ b/src/test/java/org/apache/commons/release/plugin/velocity/ReadmeHtmlVelocityDelegateTest.java
@@ -40,6 +40,6 @@ public class ReadmeHtmlVelocityDelegateTest {
         Writer writer = new StringWriter();
         writer = delegate.render(writer);
         String filledOutTemplate = writer.toString();
-        assertTrue(filledOutTemplate.contains(""));
+        assertTrue(filledOutTemplate.contains("<h1>Commons-TEXT v1.4.</h1>"));
     }
 }