lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [lucene-solr] 01/01: SOLR-13335: Upgrade to velocity 2.0 and velocity-tools 3.0
Date Tue, 19 Mar 2019 20:17:58 GMT
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch jira/solr-13335
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 927ab0b700882b5798dfdb39e94070158f5147d7
Author: Kevin Risden <krisden@apache.org>
AuthorDate: Tue Mar 19 13:08:26 2019 -0400

    SOLR-13335: Upgrade to velocity 2.0 and velocity-tools 3.0
    
    Signed-off-by: Kevin Risden <krisden@apache.org>
---
 lucene/ivy-versions.properties                     |   9 +-
 solr/contrib/velocity/ivy.xml                      |  10 +-
 .../solr/response/SolrParamResourceLoader.java     |  15 ++-
 .../apache/solr/response/SolrVelocityLogger.java   | 114 ---------------------
 .../solr/response/SolrVelocityResourceLoader.java  |  12 ++-
 .../solr/response/VelocityResponseWriter.java      |  26 +----
 solr/licenses/velocity-1.7.jar.sha1                |   1 -
 solr/licenses/velocity-engine-core-2.0.jar.sha1    |   1 +
 ...SL.txt => velocity-engine-core-LICENSE-ASL.txt} |   0
 ...-NOTICE.txt => velocity-engine-core-NOTICE.txt} |   0
 solr/licenses/velocity-tools-2.0.jar.sha1          |   1 -
 solr/licenses/velocity-tools-generic-3.0.jar.sha1  |   1 +
 ....txt => velocity-tools-generic-LICENSE-ASL.txt} |   0
 ...OTICE.txt => velocity-tools-generic-NOTICE.txt} |   0
 solr/licenses/velocity-tools-view-3.0.jar.sha1     |   1 +
 ...ASL.txt => velocity-tools-view-LICENSE-ASL.txt} |   0
 ...s-NOTICE.txt => velocity-tools-view-NOTICE.txt} |   0
 solr/licenses/velocity-tools-view-jsp-3.0.jar.sha1 |   1 +
 ...txt => velocity-tools-view-jsp-LICENSE-ASL.txt} |   0
 ...TICE.txt => velocity-tools-view-jsp-NOTICE.txt} |   0
 20 files changed, 35 insertions(+), 157 deletions(-)

diff --git a/lucene/ivy-versions.properties b/lucene/ivy-versions.properties
index 51f05c4..2c83f4a 100644
--- a/lucene/ivy-versions.properties
+++ b/lucene/ivy-versions.properties
@@ -191,8 +191,13 @@ org.apache.tika.version = 1.19.1
 /org.apache.tika/tika-parsers = ${org.apache.tika.version}
 /org.apache.tika/tika-xmp = ${org.apache.tika.version}
 
-/org.apache.velocity/velocity = 1.7
-/org.apache.velocity/velocity-tools = 2.0
+org.apache.velocity.tools.version = 3.0
+/org.apache.velocity.tools/velocity-tools-generic = ${org.apache.velocity.tools.version}
+/org.apache.velocity.tools/velocity-tools-view = ${org.apache.velocity.tools.version}
+/org.apache.velocity.tools/velocity-tools-view-jsp = ${org.apache.velocity.tools.version}
+
+/org.apache.velocity/velocity-engine-core = 2.0
+
 /org.apache.xmlbeans/xmlbeans = 3.0.1
 /org.apache.zookeeper/zookeeper = 3.4.13
 
diff --git a/solr/contrib/velocity/ivy.xml b/solr/contrib/velocity/ivy.xml
index 561492d..ab8758b 100644
--- a/solr/contrib/velocity/ivy.xml
+++ b/solr/contrib/velocity/ivy.xml
@@ -23,9 +23,13 @@
     <conf name="test" transitive="false"/>
   </configurations>
   <dependencies>
-    <dependency org="commons-collections" name="commons-collections" rev="${/commons-collections/commons-collections}"
conf="compile"/>
-    <dependency org="org.apache.velocity" name="velocity" rev="${/org.apache.velocity/velocity}"
conf="compile"/>
-    <dependency org="org.apache.velocity" name="velocity-tools" rev="${/org.apache.velocity/velocity-tools}"
conf="compile"/>
+    <dependency org="org.apache.commons" name="commons-lang3" rev="${/org.apache.commons/commons-lang3}"
conf="compile"/>
+
+    <dependency org="org.apache.velocity" name="velocity-engine-core" rev="${/org.apache.velocity/velocity-engine-core}"
conf="compile"/>
+
+    <dependency org="org.apache.velocity.tools" name="velocity-tools-generic" rev="${/org.apache.velocity.tools/velocity-tools-generic}"
conf="compile"/>
+    <dependency org="org.apache.velocity.tools" name="velocity-tools-view" rev="${/org.apache.velocity.tools/velocity-tools-view}"
conf="compile"/>
+    <dependency org="org.apache.velocity.tools" name="velocity-tools-view-jsp" rev="${/org.apache.velocity.tools/velocity-tools-view-jsp}"
conf="compile"/>
 
     <exclude org="*" ext="*" matcher="regexp" type="${ivy.exclude.types}"/>
   </dependencies>
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java
b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java
index 17b2878..53e03d7 100644
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java
+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrParamResourceLoader.java
@@ -20,11 +20,10 @@ import org.apache.solr.request.SolrQueryRequest;
 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
 import org.apache.velocity.runtime.resource.Resource;
 import org.apache.velocity.exception.ResourceNotFoundException;
-import org.apache.commons.collections.ExtendedProperties;
+import org.apache.velocity.util.ExtProperties;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -52,13 +51,13 @@ public class SolrParamResourceLoader extends ResourceLoader {
   }
 
   @Override
-  public void init(ExtendedProperties extendedProperties) {
+  public void init(ExtProperties extendedProperties) {
   }
 
   @Override
-  public InputStream getResourceStream(String s) throws ResourceNotFoundException {
-    String template = templates.get(s);
-    return template == null ? null : new ByteArrayInputStream(template.getBytes(StandardCharsets.UTF_8));
+  public Reader getResourceReader(String source, String encoding) throws ResourceNotFoundException
{
+    String template = templates.get(source);
+    return template == null ? null : new StringReader(template);
   }
 
   @Override
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityLogger.java
b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityLogger.java
deleted file mode 100644
index 00f817f..0000000
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityLogger.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.solr.response;
-
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.log.LogChute;
-import org.slf4j.Logger;
-
-public class SolrVelocityLogger implements LogChute {
-  private final Logger log;
-
-  public SolrVelocityLogger(Logger log) {
-    this.log = log;
-  }
-
-  @Override
-  public void init(RuntimeServices runtimeServices) throws Exception {
-  }
-
-  @Override
-  public void log(int level, String message) {
-    switch(level) {
-      case LogChute.TRACE_ID:
-        log.trace(message);
-        break;
-
-      case LogChute.DEBUG_ID:
-        log.debug(message);
-        break;
-
-      case LogChute.INFO_ID:
-        log.info(message);
-        break;
-
-      case LogChute.WARN_ID:
-        log.warn(message);
-        break;
-
-      case LogChute.ERROR_ID:
-        log.error(message);
-        break;
-
-      default: // unknown logging level, use warn
-        log.warn(message);
-        break;
-    }
-  }
-
-  @Override
-  public void log(int level, String message, Throwable throwable) {
-    switch(level) {
-      case LogChute.TRACE_ID:
-        log.trace(message, throwable);
-        break;
-
-      case LogChute.DEBUG_ID:
-        log.debug(message, throwable);
-        break;
-
-      case LogChute.INFO_ID:
-        log.info(message, throwable);
-        break;
-
-      case LogChute.WARN_ID:
-        log.warn(message, throwable);
-        break;
-
-      case LogChute.ERROR_ID:
-        log.error(message, throwable);
-        break;
-
-      default: // unknown logging level, use warn
-        log.warn(message, throwable);
-        break;
-    }
-  }
-
-  @Override
-  public boolean isLevelEnabled(int level) {
-    switch(level) {
-      case LogChute.TRACE_ID:
-        return log.isTraceEnabled();
-
-      case LogChute.DEBUG_ID:
-        return log.isDebugEnabled();
-
-      case LogChute.INFO_ID:
-        return log.isInfoEnabled();
-
-      case LogChute.WARN_ID:
-        return log.isWarnEnabled();
-
-      case LogChute.ERROR_ID:
-        return log.isErrorEnabled();
-
-      default:
-        return false;
-    }
-  }
-}
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
index c83a5a7..4fbbba0 100644
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/SolrVelocityResourceLoader.java
@@ -17,13 +17,15 @@
 package org.apache.solr.response;
 
 import java.io.IOException;
-import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
 
-import org.apache.commons.collections.ExtendedProperties;
 import org.apache.solr.core.SolrResourceLoader;
 import org.apache.velocity.exception.ResourceNotFoundException;
 import org.apache.velocity.runtime.resource.Resource;
 import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+import org.apache.velocity.util.ExtProperties;
 
 /**
   * Velocity resource loader wrapper around Solr resource loader
@@ -37,13 +39,13 @@ public class SolrVelocityResourceLoader extends ResourceLoader {
   }
 
   @Override
-  public void init(ExtendedProperties extendedProperties) {
+  public void init(ExtProperties extendedProperties) {
   }
 
   @Override
-  public InputStream getResourceStream(String template_name) throws ResourceNotFoundException
{
+  public Reader getResourceReader(String source, String encoding) throws ResourceNotFoundException
{
     try {
-      return loader.openResource("velocity/" + template_name);
+      return new InputStreamReader(loader.openResource("velocity/" + source), StandardCharsets.UTF_8);
     } catch (IOException ioe) {
       throw new ResourceNotFoundException(ioe);
     }
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
index ad1ee39..5aa4afa 100644
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
@@ -26,7 +26,6 @@ import java.lang.invoke.MethodHandles;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 import java.util.ResourceBundle;
@@ -46,16 +45,14 @@ import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import org.apache.velocity.tools.ConversionUtils;
+import org.apache.velocity.tools.generic.CollectionTool;
 import org.apache.velocity.tools.generic.ComparisonDateTool;
 import org.apache.velocity.tools.generic.DisplayTool;
 import org.apache.velocity.tools.generic.EscapeTool;
-import org.apache.velocity.tools.generic.ListTool;
 import org.apache.velocity.tools.generic.LocaleConfig;
 import org.apache.velocity.tools.generic.MathTool;
 import org.apache.velocity.tools.generic.NumberTool;
 import org.apache.velocity.tools.generic.ResourceTool;
-import org.apache.velocity.tools.generic.SortTool;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -87,7 +84,6 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
   private String initPropertiesFileName;  // used just to hold from init() to inform()
 
   private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-  private static final SolrVelocityLogger velocityLogger = new SolrVelocityLogger(log);
   private Properties velocityInitProps = new Properties();
   private Map<String,String> customTools = new HashMap<String,String>();
 
@@ -211,8 +207,7 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
     context.put("log", log);   // TODO: add test; TODO: should this be overridable with a
custom "log" named tool?
     context.put("esc", new EscapeTool());
     context.put("date", new ComparisonDateTool());
-    context.put("list", new ListTool());
-    context.put(SORT, new SortTool());
+    context.put(SORT, new CollectionTool());
 
     MathTool mathTool = new MathTool();
     mathTool.configure(toolConfig);
@@ -285,9 +280,6 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
   private VelocityEngine createEngine(SolrQueryRequest request) {
     VelocityEngine engine = new VelocityEngine();
 
-    // route all Velocity logging through Solr's logging facility
-    engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM, velocityLogger);
-
     // Set some engine properties that improve the experience
     //   - these could be considered in the future for parameterization, but can also be
overridden by using
     //     the init.properties.file setting.  (TODO: add a test for this properties set here
overridden)
@@ -381,7 +373,7 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
     return "{\"result\":\"" + replaced + "\"}";
   }
 
-  // see: http://svn.apache.org/repos/asf/velocity/tools/branches/2.0.x/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
+  // see: https://github.com/apache/velocity-tools/blob/trunk/velocity-tools-generic/src/main/java/org/apache/velocity/tools/generic/ResourceTool.java
   private static class SolrVelocityResourceTool extends ResourceTool {
 
     private ClassLoader solrClassLoader;
@@ -398,17 +390,5 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
           (loc == null) ? this.getLocale() : this.toLocale(loc),
           solrClassLoader);
     }
-
-    // Why did Velocity Tools make this private?  Copied from ResourceTools.java
-    private Locale toLocale(Object obj) {
-      if (obj == null) {
-        return null;
-      }
-      if (obj instanceof Locale) {
-        return (Locale) obj;
-      }
-      String s = String.valueOf(obj);
-      return ConversionUtils.toLocale(s);
-    }
   }
 }
diff --git a/solr/licenses/velocity-1.7.jar.sha1 b/solr/licenses/velocity-1.7.jar.sha1
deleted file mode 100644
index e522a85..0000000
--- a/solr/licenses/velocity-1.7.jar.sha1
+++ /dev/null
@@ -1 +0,0 @@
-2ceb567b8f3f21118ecdec129fe1271dbc09aa7a
diff --git a/solr/licenses/velocity-engine-core-2.0.jar.sha1 b/solr/licenses/velocity-engine-core-2.0.jar.sha1
new file mode 100644
index 0000000..9cbf13d
--- /dev/null
+++ b/solr/licenses/velocity-engine-core-2.0.jar.sha1
@@ -0,0 +1 @@
+6e5f29e1237b1764a4ce769feeffb85b0b19cfa7
diff --git a/solr/licenses/velocity-LICENSE-ASL.txt b/solr/licenses/velocity-engine-core-LICENSE-ASL.txt
similarity index 100%
rename from solr/licenses/velocity-LICENSE-ASL.txt
rename to solr/licenses/velocity-engine-core-LICENSE-ASL.txt
diff --git a/solr/licenses/velocity-NOTICE.txt b/solr/licenses/velocity-engine-core-NOTICE.txt
similarity index 100%
rename from solr/licenses/velocity-NOTICE.txt
rename to solr/licenses/velocity-engine-core-NOTICE.txt
diff --git a/solr/licenses/velocity-tools-2.0.jar.sha1 b/solr/licenses/velocity-tools-2.0.jar.sha1
deleted file mode 100644
index 579b5fc..0000000
--- a/solr/licenses/velocity-tools-2.0.jar.sha1
+++ /dev/null
@@ -1 +0,0 @@
-69936384de86857018b023a8c56ae0635c56b6a0
diff --git a/solr/licenses/velocity-tools-generic-3.0.jar.sha1 b/solr/licenses/velocity-tools-generic-3.0.jar.sha1
new file mode 100644
index 0000000..018c1b3
--- /dev/null
+++ b/solr/licenses/velocity-tools-generic-3.0.jar.sha1
@@ -0,0 +1 @@
+e789f6ec06f9a69ccb8956f407fb685b2938e74b
diff --git a/solr/licenses/velocity-tools-LICENSE-ASL.txt b/solr/licenses/velocity-tools-generic-LICENSE-ASL.txt
similarity index 100%
copy from solr/licenses/velocity-tools-LICENSE-ASL.txt
copy to solr/licenses/velocity-tools-generic-LICENSE-ASL.txt
diff --git a/solr/licenses/velocity-tools-NOTICE.txt b/solr/licenses/velocity-tools-generic-NOTICE.txt
similarity index 100%
copy from solr/licenses/velocity-tools-NOTICE.txt
copy to solr/licenses/velocity-tools-generic-NOTICE.txt
diff --git a/solr/licenses/velocity-tools-view-3.0.jar.sha1 b/solr/licenses/velocity-tools-view-3.0.jar.sha1
new file mode 100644
index 0000000..67cf265
--- /dev/null
+++ b/solr/licenses/velocity-tools-view-3.0.jar.sha1
@@ -0,0 +1 @@
+2f72ca8eb2bcb8af2c5fab826d64add20ab70a2e
diff --git a/solr/licenses/velocity-tools-LICENSE-ASL.txt b/solr/licenses/velocity-tools-view-LICENSE-ASL.txt
similarity index 100%
copy from solr/licenses/velocity-tools-LICENSE-ASL.txt
copy to solr/licenses/velocity-tools-view-LICENSE-ASL.txt
diff --git a/solr/licenses/velocity-tools-NOTICE.txt b/solr/licenses/velocity-tools-view-NOTICE.txt
similarity index 100%
copy from solr/licenses/velocity-tools-NOTICE.txt
copy to solr/licenses/velocity-tools-view-NOTICE.txt
diff --git a/solr/licenses/velocity-tools-view-jsp-3.0.jar.sha1 b/solr/licenses/velocity-tools-view-jsp-3.0.jar.sha1
new file mode 100644
index 0000000..45dd7f8
--- /dev/null
+++ b/solr/licenses/velocity-tools-view-jsp-3.0.jar.sha1
@@ -0,0 +1 @@
+27f6a21c7973ffb75001b3e9ac4731facf5757b4
diff --git a/solr/licenses/velocity-tools-LICENSE-ASL.txt b/solr/licenses/velocity-tools-view-jsp-LICENSE-ASL.txt
similarity index 100%
rename from solr/licenses/velocity-tools-LICENSE-ASL.txt
rename to solr/licenses/velocity-tools-view-jsp-LICENSE-ASL.txt
diff --git a/solr/licenses/velocity-tools-NOTICE.txt b/solr/licenses/velocity-tools-view-jsp-NOTICE.txt
similarity index 100%
rename from solr/licenses/velocity-tools-NOTICE.txt
rename to solr/licenses/velocity-tools-view-jsp-NOTICE.txt


Mime
View raw message