This is an automated email from the ASF dual-hosted git repository.
michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-tools.git
The following commit(s) were added to refs/heads/master by this push:
new 48d64f35 [VELTOOLS-200] Current Velocity Tools View uses deprecated
Velocity properties
48d64f35 is described below
commit 48d64f351cc5be66c0becec29d2c538e9bbd5e88
Author: Michael Osipov <[email protected]>
AuthorDate: Sat Feb 10 20:01:41 2024 +0100
[VELTOOLS-200] Current Velocity Tools View uses deprecated Velocity
properties
---
.../velocity/tools/generic/BaseTestCase.java | 648 ++++++++++-----------
.../velocity/tools/view/WebappResourceLoader.java | 8 +-
.../apache/velocity/tools/view/velocity.properties | 8 +-
.../src/test/resources/WEB-INF/velocity.properties | 5 +-
4 files changed, 334 insertions(+), 335 deletions(-)
diff --git
a/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
b/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
index 8eb8b2a2..d9cb66f5 100644
---
a/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
+++
b/velocity-tools-generic/src/test/java/org/apache/velocity/tools/generic/BaseTestCase.java
@@ -1,324 +1,324 @@
-package org.apache.velocity.tools.generic;
-
-/*
- * 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.
- */
-
-import java.io.StringWriter;
-import junit.framework.TestCase;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.app.Velocity;
-import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeConstants;
-import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
-import org.apache.velocity.runtime.resource.util.StringResourceRepository;
-
-/**
- * Base test case that provides utility methods for other tests.
- * (Adapted from Velocity Engine's BaseTestCase)
- *
- * @author Nathan Bubna
- * @version $Id: BaseTestCase.java 898032 2010-01-11 19:51:03Z nbubna $
- */
-public abstract class BaseTestCase extends TestCase
-{
- protected VelocityEngine engine;
- protected VelocityContext context;
- protected boolean DEBUG = false;
- protected MockLogger log;
- protected String stringRepoName = "string.repo";
-
- public BaseTestCase(String name)
- {
- super(name);
-
- // if we're just running one case, then have DEBUG
- // automatically set to true
- String testcase = System.getProperty("testcase");
- if (testcase != null)
- {
- DEBUG = testcase.equals(getClass().getName());
- }
- }
-
- protected void setUp() throws Exception
- {
- engine = new VelocityEngine();
-
- //by default, make the engine's log output go to the test-report
- log = new MockLogger(false, false);
- log.setEnabledLevel(MockLogger.LOG_LEVEL_INFO);
- engine.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, log);
-
- // use string resource loader by default, instead of file
- engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,string");
- engine.addProperty("string.resource.loader.class",
StringResourceLoader.class.getName());
- engine.addProperty("string.resource.loader.repository.name",
stringRepoName);
- engine.addProperty("string.resource.loader.repository.static",
"false");
-
- setUpEngine(engine);
-
- context = new VelocityContext();
- setUpContext(context);
- }
-
- protected void setUpEngine(VelocityEngine engine)
- {
- // extension hook
- }
-
- protected void setUpContext(VelocityContext context)
- {
- // extension hook
- }
-
- protected StringResourceRepository getStringRepository()
- {
- StringResourceRepository repo =
-
(StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
- if (repo == null)
- {
- try
- {
- engine.init();
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- repo =
-
(StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
- }
- return repo;
- }
-
- protected void addTemplate(String name, String template)
- {
- info("Template '"+name+"': "+template);
- getStringRepository().putStringResource(name, template);
- }
-
- protected void removeTemplate(String name)
- {
- info("Removed: '"+name+"'");
- getStringRepository().removeStringResource(name);
- }
-
- public void tearDown()
- {
- engine = null;
- context = null;
- }
-
- protected void info(String msg)
- {
- if (DEBUG)
- {
- if (engine == null)
- {
- Velocity.getLog().info(msg);
- }
- else
- {
- engine.getLog().info(msg);
- }
- }
- }
-
- protected void info(String msg, Throwable t)
- {
- if (DEBUG)
- {
- if (engine == null)
- {
- Velocity.getLog().info(msg);
- }
- else
- {
- engine.getLog().info(msg, t);
- }
- }
- }
-
- public void testBase()
- {
- if (DEBUG && engine != null)
- {
- assertSchmoo("");
- assertSchmoo("abc\n123");
- }
- }
-
- /**
- * Compare an expected string with the given loaded template
- */
- protected void assertTmplEquals(String expected, String template)
- {
- info("Expected: " + expected + " from '" + template + "'");
-
- StringWriter writer = new StringWriter();
- try
- {
- engine.mergeTemplate(template, "utf-8", context, writer);
- }
- catch (RuntimeException re)
- {
- info("RuntimeException!", re);
- throw re;
- }
- catch (Exception e)
- {
- info("Exception!", e);
- throw new RuntimeException(e);
- }
-
- info("Result: " + writer.toString());
- assertEquals(expected, writer.toString());
- }
-
- /**
- * Ensure that a context value is as expected.
- */
- protected void assertContextValue(String key, Object expected)
- {
- info("Expected value of '"+key+"': "+expected);
- Object value = context.get(key);
- info("Result: "+value);
- assertEquals(expected, value);
- }
-
- /**
- * Ensure that a template renders as expected.
- */
- protected void assertEvalEquals(String expected, String template)
- {
- info("Expectation: "+expected);
- assertEquals(expected, evaluate(template));
- }
-
- /**
- * Ensure that the given string renders as itself when evaluated.
- */
- protected void assertSchmoo(String templateIsExpected)
- {
- assertEvalEquals(templateIsExpected, templateIsExpected);
- }
-
- /**
- * Ensure that an exception occurs when the string is evaluated.
- */
- protected Exception assertEvalException(String evil)
- {
- return assertEvalException(evil, null);
- }
-
- /**
- * Ensure that a specified type of exception occurs when evaluating the
string.
- */
- protected Exception assertEvalException(String evil, Class exceptionType)
- {
- try
- {
- if (!DEBUG)
- {
- log.off();
- }
- if (exceptionType != null)
- {
- info("Expectation: "+exceptionType.getName());
- }
- evaluate(evil);
- fail("Template '"+evil+"' should have thrown an exception.");
- }
- catch (Exception e)
- {
- if (exceptionType != null &&
!exceptionType.isAssignableFrom(e.getClass()))
- {
- fail("Was expecting template '"+evil+"' to throw
"+exceptionType+" not "+e);
- }
- return e;
- }
- finally
- {
- if (!DEBUG)
- {
- log.on();
- }
- }
- return null;
- }
-
- /**
- * Ensure that the error message of the expected exception has the proper
location info.
- */
- protected Exception assertEvalExceptionAt(String evil, String template,
- int line, int col)
- {
- String loc = template+"[line "+line+", column "+col+"]";
- info("Expectation: Exception at "+loc);
- Exception e = assertEvalException(evil);
-
- info("Result: "+e.getClass().getName()+" - "+e.getMessage());
- if (e.getMessage().indexOf(loc) < 1)
- {
- fail("Was expecting exception at "+loc+" instead of
"+e.getMessage());
- }
- return e;
- }
-
- /**
- * Only ensure that the error message of the expected exception
- * has the proper line and column info.
- */
- protected Exception assertEvalExceptionAt(String evil, int line, int col)
- {
- return assertEvalExceptionAt(evil, "", line, col);
- }
-
- /**
- * Evaluate the specified String as a template and return the result as a
String.
- */
- protected String evaluate(String template)
- {
- StringWriter writer = new StringWriter();
- try
- {
- info("Template: "+template);
-
- // use template as its own name, since our templates are short
- // unless it's not that short, then shorten it...
- String name = (template.length() <= 15) ? template :
template.substring(0,15);
- engine.evaluate(context, writer, name, template);
-
- String result = writer.toString();
- info("Result: "+result);
- return result;
- }
- catch (RuntimeException re)
- {
- info("RuntimeException!", re);
- throw re;
- }
- catch (Exception e)
- {
- info("Exception!", e);
- throw new RuntimeException(e);
- }
- }
-
-}
+package org.apache.velocity.tools.generic;
+
+/*
+ * 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.
+ */
+
+import java.io.StringWriter;
+import junit.framework.TestCase;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.Velocity;
+import org.apache.velocity.app.VelocityEngine;
+import org.apache.velocity.runtime.RuntimeConstants;
+import org.apache.velocity.runtime.resource.loader.StringResourceLoader;
+import org.apache.velocity.runtime.resource.util.StringResourceRepository;
+
+/**
+ * Base test case that provides utility methods for other tests.
+ * (Adapted from Velocity Engine's BaseTestCase)
+ *
+ * @author Nathan Bubna
+ * @version $Id: BaseTestCase.java 898032 2010-01-11 19:51:03Z nbubna $
+ */
+public abstract class BaseTestCase extends TestCase
+{
+ protected VelocityEngine engine;
+ protected VelocityContext context;
+ protected boolean DEBUG = false;
+ protected MockLogger log;
+ protected String stringRepoName = "string.repo";
+
+ public BaseTestCase(String name)
+ {
+ super(name);
+
+ // if we're just running one case, then have DEBUG
+ // automatically set to true
+ String testcase = System.getProperty("testcase");
+ if (testcase != null)
+ {
+ DEBUG = testcase.equals(getClass().getName());
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ engine = new VelocityEngine();
+
+ //by default, make the engine's log output go to the test-report
+ log = new MockLogger(false, false);
+ log.setEnabledLevel(MockLogger.LOG_LEVEL_INFO);
+ engine.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, log);
+
+ // use string resource loader by default, instead of file
+ engine.setProperty(RuntimeConstants.RESOURCE_LOADERS, "file,string");
+ engine.addProperty("resource.loader.string.class",
StringResourceLoader.class.getName());
+ engine.addProperty("resource.loader.string.repository.name",
stringRepoName);
+ engine.addProperty("resource.loader.string.repository.static",
"false");
+
+ setUpEngine(engine);
+
+ context = new VelocityContext();
+ setUpContext(context);
+ }
+
+ protected void setUpEngine(VelocityEngine engine)
+ {
+ // extension hook
+ }
+
+ protected void setUpContext(VelocityContext context)
+ {
+ // extension hook
+ }
+
+ protected StringResourceRepository getStringRepository()
+ {
+ StringResourceRepository repo =
+
(StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
+ if (repo == null)
+ {
+ try
+ {
+ engine.init();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ repo =
+
(StringResourceRepository)engine.getApplicationAttribute(stringRepoName);
+ }
+ return repo;
+ }
+
+ protected void addTemplate(String name, String template)
+ {
+ info("Template '"+name+"': "+template);
+ getStringRepository().putStringResource(name, template);
+ }
+
+ protected void removeTemplate(String name)
+ {
+ info("Removed: '"+name+"'");
+ getStringRepository().removeStringResource(name);
+ }
+
+ public void tearDown()
+ {
+ engine = null;
+ context = null;
+ }
+
+ protected void info(String msg)
+ {
+ if (DEBUG)
+ {
+ if (engine == null)
+ {
+ Velocity.getLog().info(msg);
+ }
+ else
+ {
+ engine.getLog().info(msg);
+ }
+ }
+ }
+
+ protected void info(String msg, Throwable t)
+ {
+ if (DEBUG)
+ {
+ if (engine == null)
+ {
+ Velocity.getLog().info(msg);
+ }
+ else
+ {
+ engine.getLog().info(msg, t);
+ }
+ }
+ }
+
+ public void testBase()
+ {
+ if (DEBUG && engine != null)
+ {
+ assertSchmoo("");
+ assertSchmoo("abc\n123");
+ }
+ }
+
+ /**
+ * Compare an expected string with the given loaded template
+ */
+ protected void assertTmplEquals(String expected, String template)
+ {
+ info("Expected: " + expected + " from '" + template + "'");
+
+ StringWriter writer = new StringWriter();
+ try
+ {
+ engine.mergeTemplate(template, "utf-8", context, writer);
+ }
+ catch (RuntimeException re)
+ {
+ info("RuntimeException!", re);
+ throw re;
+ }
+ catch (Exception e)
+ {
+ info("Exception!", e);
+ throw new RuntimeException(e);
+ }
+
+ info("Result: " + writer.toString());
+ assertEquals(expected, writer.toString());
+ }
+
+ /**
+ * Ensure that a context value is as expected.
+ */
+ protected void assertContextValue(String key, Object expected)
+ {
+ info("Expected value of '"+key+"': "+expected);
+ Object value = context.get(key);
+ info("Result: "+value);
+ assertEquals(expected, value);
+ }
+
+ /**
+ * Ensure that a template renders as expected.
+ */
+ protected void assertEvalEquals(String expected, String template)
+ {
+ info("Expectation: "+expected);
+ assertEquals(expected, evaluate(template));
+ }
+
+ /**
+ * Ensure that the given string renders as itself when evaluated.
+ */
+ protected void assertSchmoo(String templateIsExpected)
+ {
+ assertEvalEquals(templateIsExpected, templateIsExpected);
+ }
+
+ /**
+ * Ensure that an exception occurs when the string is evaluated.
+ */
+ protected Exception assertEvalException(String evil)
+ {
+ return assertEvalException(evil, null);
+ }
+
+ /**
+ * Ensure that a specified type of exception occurs when evaluating the
string.
+ */
+ protected Exception assertEvalException(String evil, Class exceptionType)
+ {
+ try
+ {
+ if (!DEBUG)
+ {
+ log.off();
+ }
+ if (exceptionType != null)
+ {
+ info("Expectation: "+exceptionType.getName());
+ }
+ evaluate(evil);
+ fail("Template '"+evil+"' should have thrown an exception.");
+ }
+ catch (Exception e)
+ {
+ if (exceptionType != null &&
!exceptionType.isAssignableFrom(e.getClass()))
+ {
+ fail("Was expecting template '"+evil+"' to throw
"+exceptionType+" not "+e);
+ }
+ return e;
+ }
+ finally
+ {
+ if (!DEBUG)
+ {
+ log.on();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Ensure that the error message of the expected exception has the proper
location info.
+ */
+ protected Exception assertEvalExceptionAt(String evil, String template,
+ int line, int col)
+ {
+ String loc = template+"[line "+line+", column "+col+"]";
+ info("Expectation: Exception at "+loc);
+ Exception e = assertEvalException(evil);
+
+ info("Result: "+e.getClass().getName()+" - "+e.getMessage());
+ if (e.getMessage().indexOf(loc) < 1)
+ {
+ fail("Was expecting exception at "+loc+" instead of
"+e.getMessage());
+ }
+ return e;
+ }
+
+ /**
+ * Only ensure that the error message of the expected exception
+ * has the proper line and column info.
+ */
+ protected Exception assertEvalExceptionAt(String evil, int line, int col)
+ {
+ return assertEvalExceptionAt(evil, "", line, col);
+ }
+
+ /**
+ * Evaluate the specified String as a template and return the result as a
String.
+ */
+ protected String evaluate(String template)
+ {
+ StringWriter writer = new StringWriter();
+ try
+ {
+ info("Template: "+template);
+
+ // use template as its own name, since our templates are short
+ // unless it's not that short, then shorten it...
+ String name = (template.length() <= 15) ? template :
template.substring(0,15);
+ engine.evaluate(context, writer, name, template);
+
+ String result = writer.toString();
+ info("Result: "+result);
+ return result;
+ }
+ catch (RuntimeException re)
+ {
+ info("RuntimeException!", re);
+ throw re;
+ }
+ catch (Exception e)
+ {
+ info("Exception!", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+}
diff --git
a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
index e20d08b0..e24b63d7 100644
---
a/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
+++
b/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/WebappResourceLoader.java
@@ -39,15 +39,15 @@ import org.apache.velocity.util.ExtProperties;
*
* The default search path is '/' (relative to the webapp root), but
* you can change this behaviour by specifying one or more paths
- * by mean of as many webapp.resource.loader.path properties as needed
+ * by mean of as many resource.loader.webapp.path properties as needed
* in the velocity.properties file.
*
* All paths must be relative to the root of the webapp.
*
- * To enable caching and cache refreshing the webapp.resource.loader.cache and
- * webapp.resource.loader.modificationCheckInterval properties need to be
+ * To enable caching and cache refreshing the resource.loader.webapp.cache and
+ * resource.loader.webapp.modificationCheckInterval properties need to be
* set in the velocity.properties file ... auto-reloading of global macros
- * requires the webapp.resource.loader.cache property to be set to 'false'.
+ * requires the resource.loader.webapp.cache property to be set to 'false'.
*
* @author <a href="mailto:[email protected]">Geir Magnusson Jr.</a>
* @author Nathan Bubna
diff --git
a/velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/velocity.properties
b/velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/velocity.properties
index 3579f9a5..8a86d981 100644
---
a/velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/velocity.properties
+++
b/velocity-tools-view/src/main/resources/org/apache/velocity/tools/view/velocity.properties
@@ -16,13 +16,13 @@
# under the License.
# by default, load resources with webapp resource loader and string resource
loader (in that order)
-resource.loader = webapp,string
-webapp.resource.loader.class =
org.apache.velocity.tools.view.WebappResourceLoader
-string.resource.loader.class =
org.apache.velocity.runtime.resource.loader.StringResourceLoader
+resource.loaders = webapp,string
+resource.loader.webapp.class =
org.apache.velocity.tools.view.WebappResourceLoader
+resource.loader.string.class =
org.apache.velocity.runtime.resource.loader.StringResourceLoader
# allows getting and setting $request, $session and $application attributes
using Velocity syntax,
# like in #set($session.foo = 'bar'), instead of
$session.setAttribute('foo','bar')
-runtime.introspector.uberspect =
org.apache.velocity.util.introspection.UberspectImpl,org.apache.velocity.tools.view.WebappUberspector
+introspector.uberspect.class =
org.apache.velocity.util.introspection.UberspectImpl,org.apache.velocity.tools.view.WebappUberspector
# HTTP charset
output.encoding = UTF-8
diff --git a/velocity-tools-view/src/test/resources/WEB-INF/velocity.properties
b/velocity-tools-view/src/test/resources/WEB-INF/velocity.properties
index f118f56e..78e139a7 100644
--- a/velocity-tools-view/src/test/resources/WEB-INF/velocity.properties
+++ b/velocity-tools-view/src/test/resources/WEB-INF/velocity.properties
@@ -16,6 +16,5 @@
# under the License.
input.encoding=UTF-8
-runtime.log.logsystem.class = org.apache.velocity.runtime.log.NullLogChute
-resource.loader = clazz
-clazz.resource.loader.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
+resource.loaders = clazz
+resource.loader.clazz.class =
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader