You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by tv...@apache.org on 2018/07/28 20:00:52 UTC

svn commit: r1836943 - in /turbine/core/trunk: conf/test/CompleteTurbineResources.properties pom.xml src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java src/test/org/apache/turbine/services/velocity/PathConverterTest.java

Author: tv
Date: Sat Jul 28 20:00:52 2018
New Revision: 1836943

URL: http://svn.apache.org/viewvc?rev=1836943&view=rev
Log:
Preparations for Turbine 4.1
- Move to Velocity 2.0
- Move to Java 1.8

Modified:
    turbine/core/trunk/conf/test/CompleteTurbineResources.properties
    turbine/core/trunk/pom.xml
    turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
    turbine/core/trunk/src/test/org/apache/turbine/services/velocity/PathConverterTest.java

Modified: turbine/core/trunk/conf/test/CompleteTurbineResources.properties
URL: http://svn.apache.org/viewvc/turbine/core/trunk/conf/test/CompleteTurbineResources.properties?rev=1836943&r1=1836942&r2=1836943&view=diff
==============================================================================
--- turbine/core/trunk/conf/test/CompleteTurbineResources.properties (original)
+++ turbine/core/trunk/conf/test/CompleteTurbineResources.properties Sat Jul 28 20:00:52 2018
@@ -537,6 +537,10 @@ services.VelocityService.file.resource.l
 services.VelocityService.file.resource.loader.path  = src/templates/test
 services.VelocityService.file.resource.loader.cache = false
 services.VelocityService.file.resource.loader.modificationCheckInterval = 2
+# backward compatibility with Velocity 1.x
+services.VelocityService.runtime.conversion.handler = none
+services.VelocityService.space.gobbling = bc
+services.VelocityService.directive.if.emptycheck = false
 
 # -------------------------------------------------------------------
 #

Modified: turbine/core/trunk/pom.xml
URL: http://svn.apache.org/viewvc/turbine/core/trunk/pom.xml?rev=1836943&r1=1836942&r2=1836943&view=diff
==============================================================================
--- turbine/core/trunk/pom.xml (original)
+++ turbine/core/trunk/pom.xml Sat Jul 28 20:00:52 2018
@@ -27,7 +27,7 @@
   <groupId>org.apache.turbine</groupId>
   <artifactId>turbine</artifactId>
   <name>Apache Turbine</name>
-  <version>4.0.2-SNAPSHOT</version>
+  <version>4.1-SNAPSHOT</version>
   <description>Turbine is a servlet based framework that allows experienced Java
     developers to quickly build secure web applications. Parts of Turbine
     can also be used independently of the web portion of Turbine as
@@ -857,7 +857,7 @@
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
-      <version>2.5</version><!-- v2.6 requires Java 1.7 -->
+      <version>2.6</version>
     </dependency>
     <!--  TODO requires Java 1.7 :
       <groupId>org.apache.commons</groupId>
@@ -1040,17 +1040,10 @@
       <artifactId>log4j</artifactId>
       <version>1.2.17</version>
     </dependency>
-    <!--  TODO after 4.0.x releases update to
-    
-    <groupId>org.apache.velocity</groupId>
-    <artifactId>velocity-engine-core</artifactId>
-    <version>2.0</version>
-    -->
     <dependency>
       <groupId>org.apache.velocity</groupId>
-      <artifactId>velocity</artifactId>
-      <version>1.7</version>
-      <type>jar</type>
+      <artifactId>velocity-engine-core</artifactId>
+      <version>2.0</version>
     </dependency>
     <dependency>
       <groupId>junit</groupId>
@@ -1078,11 +1071,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-			<groupId>org.apache.fulcrum</groupId>
-			<artifactId>fulcrum-testcontainer</artifactId>
+      <groupId>org.apache.fulcrum</groupId>
+      <artifactId>fulcrum-testcontainer</artifactId>
       <version>1.0.7</version>
-			<scope>test</scope>
-		</dependency>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>
@@ -1144,11 +1137,14 @@
   </profiles>
 
   <properties>
+    <maven.compiler.source>1.8</maven.compiler.source>
+    <maven.compiler.target>1.8</maven.compiler.target>
+    
     <!-- TODO: Change for release -->
     <!--turbine.site.path>turbine/development/turbine-4.1</turbine.site.path-->
     <turbine.site.path>turbine/turbine-4.0</turbine.site.path>
     <fulcrum.intake>1.2.3</fulcrum.intake>
-    <fulcrum.security>1.1.3-SNAPSHOT</fulcrum.security>
+    <fulcrum.security>1.1.2</fulcrum.security>
     <slf4j.version>1.7.25</slf4j.version>
   </properties>
 

Modified: turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java?rev=1836943&r1=1836942&r2=1836943&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/services/velocity/TurbineVelocityService.java Sat Jul 28 20:00:52 2018
@@ -29,12 +29,12 @@ import java.io.Writer;
 import java.util.Iterator;
 import java.util.List;
 
-import org.apache.commons.collections.ExtendedProperties;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.turbine.Turbine;
+import org.apache.turbine.TurbineConstants;
 import org.apache.turbine.pipeline.PipelineData;
 import org.apache.turbine.services.InitializationException;
 import org.apache.turbine.services.TurbineServices;
@@ -48,7 +48,7 @@ import org.apache.velocity.app.event.Eve
 import org.apache.velocity.app.event.MethodExceptionEventHandler;
 import org.apache.velocity.context.Context;
 import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.log.CommonsLogLogChute;
+import org.apache.velocity.util.introspection.Info;
 
 /**
  * This is a Service that can process Velocity templates from within a
@@ -86,9 +86,6 @@ public class TurbineVelocityService
     /** The generic resource loader path property in velocity.*/
     private static final String RESOURCE_LOADER_PATH = ".resource.loader.path";
 
-    /** Default character set to use if not specified in the RunData object. */
-    private static final String DEFAULT_CHAR_SET = "ISO-8859-1";
-
     /** The prefix used for URIs which are of type <code>jar</code>. */
     private static final String JAR_PREFIX = "jar:";
 
@@ -147,7 +144,11 @@ public class TurbineVelocityService
             // Register with the template service.
             registerConfiguration(VelocityService.VELOCITY_EXTENSION);
 
-            defaultInputEncoding = getConfiguration().getString("input.encoding", DEFAULT_CHAR_SET);
+            String turbineInputEncoding = Turbine.getConfiguration().getString(
+                    TurbineConstants.PARAMETER_ENCODING_KEY,
+                    TurbineConstants.PARAMETER_ENCODING_DEFAULT);
+
+            defaultInputEncoding = getConfiguration().getString("input.encoding", turbineInputEncoding);
             defaultOutputEncoding = getConfiguration().getString("output.encoding", defaultInputEncoding);
 
             setInit(true);
@@ -196,28 +197,30 @@ public class TurbineVelocityService
      * MethodException Event Cartridge handler
      * for Velocity.
      *
-     * It logs an execption thrown by the velocity processing
+     * It logs an exception thrown by the velocity processing
      * on error level into the log file
      *
+     * @param context The current context
      * @param clazz The class that threw the exception
      * @param method The Method name that threw the exception
      * @param e The exception that would've been thrown
+     * @param info Information about the template, line and column the exception occurred
      * @return A valid value to be used as Return value
-     * @throws Exception We threw the exception further up
      */
     @Override
-    @SuppressWarnings("rawtypes") // Interface not generified
-	public Object methodException(Class clazz, String method, Exception e)
-            throws Exception
+	public Object methodException(Context context, Class clazz, String method, Exception e, Info info)
     {
         log.error("Class " + clazz.getName() + "." + method + " threw Exception", e);
 
         if (!catchErrors)
         {
-            throw e;
+            throw new RuntimeException(e);
         }
 
-        return "[Turbine caught an Error here. Look into the turbine.log for further information]";
+        return "[Turbine caught an Error in template " + info.getTemplateName()
+            + ", l:" + info.getLine()
+            + ", c:" + info.getColumn()
+            + ". Look into the turbine.log for further information]";
     }
 
     /**
@@ -493,37 +496,29 @@ public class TurbineVelocityService
 
         catchErrors = conf.getBoolean(CATCH_ERRORS_KEY, CATCH_ERRORS_DEFAULT);
 
-        conf.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS,
-                CommonsLogLogChute.class.getName());
-        conf.setProperty(CommonsLogLogChute.LOGCHUTE_COMMONS_LOG_NAME,
-                "velocity");
+        // backward compatibility, can be overridden in the configuration
+        conf.setProperty(RuntimeConstants.RUNTIME_LOG_NAME, "velocity");
 
         velocity = new VelocityEngine();
-        velocity.setExtendedProperties(createVelocityProperties(conf));
+        setVelocityProperties(velocity, conf);
         velocity.init();
     }
 
 
     /**
-     * This method generates the Extended Properties object necessary
+     * This method generates the Properties object necessary
      * for the initialization of Velocity. It also converts the various
      * resource loader pathes into webapp relative pathes. It also
      *
+     * @param velocity The Velocity engine
      * @param conf The Velocity Service configuration
      *
-     * @return An ExtendedProperties Object for Velocity
-     *
      * @throws Exception If a problem occurred while converting the properties.
      */
 
-    public ExtendedProperties createVelocityProperties(Configuration conf)
+    protected void setVelocityProperties(VelocityEngine velocity, Configuration conf)
             throws Exception
     {
-        // This bugger is public, because we want to run some Unit tests
-        // on it.
-
-        ExtendedProperties veloConfig = new ExtendedProperties();
-
         // Fix up all the template resource loader pathes to be
         // webapp relative. Copy all other keys verbatim into the
         // veloConfiguration.
@@ -534,15 +529,16 @@ public class TurbineVelocityService
             if (!key.endsWith(RESOURCE_LOADER_PATH))
             {
                 Object value = conf.getProperty(key);
-                if (value instanceof List<?>) {
+                if (value instanceof List<?>)
+                {
                     for (Iterator<?> itr = ((List<?>)value).iterator(); itr.hasNext();)
                     {
-                        veloConfig.addProperty(key, itr.next());
+                        velocity.addProperty(key, itr.next());
                     }
                 }
                 else
                 {
-                    veloConfig.addProperty(key, value);
+                    velocity.addProperty(key, value);
                 }
                 continue; // for()
             }
@@ -601,10 +597,9 @@ public class TurbineVelocityService
 
                 log.debug("Adding " + key + " -> " + path);
                 // Re-Add this property to the configuration object
-                veloConfig.addProperty(key, path);
+                velocity.addProperty(key, path);
             }
         }
-        return veloConfig;
     }
 
     /**

Modified: turbine/core/trunk/src/test/org/apache/turbine/services/velocity/PathConverterTest.java
URL: http://svn.apache.org/viewvc/turbine/core/trunk/src/test/org/apache/turbine/services/velocity/PathConverterTest.java?rev=1836943&r1=1836942&r2=1836943&view=diff
==============================================================================
--- turbine/core/trunk/src/test/org/apache/turbine/services/velocity/PathConverterTest.java (original)
+++ turbine/core/trunk/src/test/org/apache/turbine/services/velocity/PathConverterTest.java Sat Jul 28 20:00:52 2018
@@ -24,12 +24,14 @@ package org.apache.turbine.services.velo
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import org.apache.commons.collections.ExtendedProperties;
+import java.io.File;
+
 import org.apache.commons.configuration.Configuration;
 import org.apache.turbine.Turbine;
 import org.apache.turbine.services.TurbineServices;
 import org.apache.turbine.test.BaseTestCase;
 import org.apache.turbine.util.TurbineConfig;
+import org.apache.velocity.app.VelocityEngine;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -47,8 +49,6 @@ public class PathConverterTest
 {
     private static TurbineConfig tc = null;
     private static VelocityService vs = null;
-    private static String fileSeperator = System.getProperty("file.separator");
-
 
     @BeforeClass
     public static void setUp() throws Exception {
@@ -77,48 +77,48 @@ public class PathConverterTest
         throws Exception
     {
         Configuration conf = vs.getConfiguration();
-        ExtendedProperties ep = ((TurbineVelocityService) vs).createVelocityProperties(conf);
+        VelocityEngine ve = new VelocityEngine();
+        ((TurbineVelocityService) vs).setVelocityProperties(ve, conf);
 
         String rootPath = Turbine.getRealPath("");
 
-        String [] test1 = ep.getStringArray("test1.resource.loader.path");
-        assertEquals("No Test1 Property found", 1, test1.length);
+        String test1 = (String) ve.getProperty("test1.resource.loader.path");
+        assertNotNull("No Test1 Property found", test1);
         assertEquals("Test1 Path translation failed", rootPath
-                +fileSeperator+"relative"+fileSeperator+"path" , test1[0]);
+                +File.separator+"relative"+File.separator+"path" , test1);
 
-        String [] test2 = ep.getStringArray("test2.resource.loader.path");
-        assertEquals("No Test2 Property found", 1, test2.length);
+        String test2 = (String) ve.getProperty("test2.resource.loader.path");
+        assertNotNull("No Test2 Property found", test2);
         assertEquals("Test2 Path translation failed", rootPath
-                +fileSeperator+"absolute"+fileSeperator+"path" , test2[0]);
+                +File.separator+"absolute"+File.separator+"path" , test2);
 
-        String [] test3 = ep.getStringArray("test3.resource.loader.path");
-        assertEquals("No Test3 Property found", 1, test2.length);
+        String test3 = (String) ve.getProperty("test3.resource.loader.path");
+        assertNotNull("No Test3 Property found", test3);
         assertEquals("Test3 Path translation failed", rootPath
-                +fileSeperator+"jar-file.jar!/", test3[0]);
+                +File.separator+"jar-file.jar!/", test3);
 
-        String [] test4 = ep.getStringArray("test4.resource.loader.path");
-        assertEquals("No Test4 Property found", 1, test4.length);
+        String test4 = (String) ve.getProperty("test4.resource.loader.path");
+        assertNotNull("No Test4 Property found", test4);
         assertEquals("Test4 Path translation failed", rootPath
-                +fileSeperator+"jar-file.jar!/with/some/extensions" , test4[0]);
+                +File.separator+"jar-file.jar!/with/some/extensions" , test4);
 
-        String [] test5 = ep.getStringArray("test5.resource.loader.path");
-        assertEquals("No Test5 Property found", 1, test5.length);
+        String test5 = (String) ve.getProperty("test5.resource.loader.path");
+        assertNotNull("No Test5 Property found", test5);
         assertEquals("Test5 Path translation failed", rootPath
-                +fileSeperator+"jar-file.jar" , test5[0]);
+                +File.separator+"jar-file.jar" , test5);
 
-        String [] test6 = ep.getStringArray("test6.resource.loader.path");
-        assertEquals("No Test6 Property found", 1, test6.length);
-        assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6[0]);
+        String test6 = (String) ve.getProperty("test6.resource.loader.path");
+        assertNotNull("No Test6 Property found", test6);
+        assertEquals("Test6 Path translation failed", "jar:http://jar.on.website/" , test6);
 
-        String [] test7 = ep.getStringArray("test7.resource.loader.path");
-        assertEquals("No Test7 Property found", 1, test7.length);
+        String test7 = (String) ve.getProperty("test7.resource.loader.path");
+        assertNotNull("No Test7 Property found", test7);
         assertEquals("Test7 Path translation failed", rootPath
-                +fileSeperator+"file"+fileSeperator
-                +"system"+fileSeperator+"reference" , test7[0]);
-
-        String [] test8 = ep.getStringArray("test8.resource.loader.path");
-        assertEquals("No Test8 Property found", 1, test8.length);
-        assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8[0]);
+                +File.separator+"file"+File.separator
+                +"system"+File.separator+"reference" , test7);
 
+        String test8 = (String) ve.getProperty("test8.resource.loader.path");
+        assertNotNull("No Test8 Property found", test8);
+        assertEquals("Test8 Path translation failed", "http://reference.on.website/" , test8);
     }
 }