You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/11/08 16:02:00 UTC

[jira] [Commented] (AVRO-2228) Bump Apache Velocity to 2.0

    [ https://issues.apache.org/jira/browse/AVRO-2228?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16679939#comment-16679939 ] 

ASF GitHub Bot commented on AVRO-2228:
--------------------------------------

dkulp closed pull request #332: [AVRO-2228] Bump Apache Velocity to 2.0
URL: https://github.com/apache/avro/pull/332
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/lang/java/compiler/pom.xml b/lang/java/compiler/pom.xml
index d236df0da..7bee6e3c9 100644
--- a/lang/java/compiler/pom.xml
+++ b/lang/java/compiler/pom.xml
@@ -163,7 +163,7 @@
     </dependency>
     <dependency>
       <groupId>org.apache.velocity</groupId>
-      <artifactId>velocity</artifactId>
+      <artifactId>velocity-engine-core</artifactId>
     </dependency>
     <dependency>
       <groupId>com.fasterxml.jackson.core</groupId>
diff --git a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
index aa7c5c3f2..5ee2bdc26 100644
--- a/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
+++ b/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
@@ -52,8 +52,6 @@
 import org.apache.velocity.Template;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.app.VelocityEngine;
-import org.apache.velocity.runtime.RuntimeServices;
-import org.apache.velocity.runtime.log.LogChute;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -271,8 +269,6 @@ public DateTimeLogicalTypeImplementation getDateTimeLogicalTypeImplementation()
     return dateTimeLogicalTypeImplementation;
   }
 
-  private static String logChuteName = null;
-
   private void initializeVelocity() {
     this.velocityEngine = new VelocityEngine();
 
@@ -286,17 +282,9 @@ private void initializeVelocity() {
     velocityEngine.addProperty("file.resource.loader.path", "/, .");
     velocityEngine.setProperty("runtime.references.strict", true);
 
-    // try to use Slf4jLogChute, but if we can't use the null one.
-    if (null == logChuteName) {
-      // multiple threads can get here concurrently, but that's ok.
-      try {
-        new Slf4jLogChute();
-        logChuteName = Slf4jLogChute.class.getName();
-      } catch (Exception e) {
-        logChuteName = "org.apache.velocity.runtime.log.NullLogChute";
-      }
-    }
-    velocityEngine.setProperty("runtime.log.logsystem.class", logChuteName);
+    // Set whitespace gobbling to Backward Compatible (BC)
+    // http://velocity.apache.org/engine/2.0/developer-guide.html#space-gobbling
+    velocityEngine.setProperty("space.gobbling", "bc");
   }
 
   private void initializeSpecificData() {
@@ -490,13 +478,15 @@ protected void validateRecordForCompilation(Schema record) {
     this.createAllArgsConstructor =
         calcAllArgConstructorParameterUnits(record) <= MAX_FIELD_PARAMETER_UNIT_COUNT;
 
-    if (!this.createAllArgsConstructor)
-      new Slf4jLogChute().log(LogChute.WARN_ID, "Record '" + record.getFullName() +
-              "' contains more than " + MAX_FIELD_PARAMETER_UNIT_COUNT +
-              " parameters which exceeds the JVM " +
-              "spec for the number of permitted constructor arguments. Clients must " +
-              "rely on the builder pattern to create objects instead. For more info " +
-              "see JIRA ticket AVRO-1642.");
+    if (!this.createAllArgsConstructor) {
+      Logger logger = LoggerFactory.getLogger(SpecificCompiler.class);
+      logger.warn("Record '" + record.getFullName() +
+        "' contains more than " + MAX_FIELD_PARAMETER_UNIT_COUNT +
+        " parameters which exceeds the JVM " +
+        "spec for the number of permitted constructor arguments. Clients must " +
+        "rely on the builder pattern to create objects instead. For more info " +
+        "see JIRA ticket AVRO-1642.");
+    }
   }
 
   OutputFile compile(Schema schema) {
@@ -1055,75 +1045,6 @@ public static void main(String[] args) throws Exception {
     compileProtocol(new File(args[0]), new File(args[1]));
   }
 
-  public static final class Slf4jLogChute implements LogChute {
-    private Logger logger = LoggerFactory.getLogger("AvroVelocityLogChute");
-    @Override
-    public void init(RuntimeServices rs) throws Exception {
-      // nothing to do
-    }
-
-    @Override
-    public void log(int level, String message) {
-      switch (level) {
-      case LogChute.DEBUG_ID:
-        logger.debug(message);
-        break;
-      case LogChute.TRACE_ID:
-        logger.trace(message);
-        break;
-      case LogChute.WARN_ID:
-        logger.warn(message);
-        break;
-      case LogChute.ERROR_ID:
-        logger.error(message);
-        break;
-      default:
-      case LogChute.INFO_ID:
-        logger.info(message);
-        break;
-      }
-    }
-
-    @Override
-    public void log(int level, String message, Throwable t) {
-      switch (level) {
-      case LogChute.DEBUG_ID:
-        logger.debug(message, t);
-        break;
-      case LogChute.TRACE_ID:
-        logger.trace(message, t);
-        break;
-      case LogChute.WARN_ID:
-        logger.warn(message, t);
-        break;
-      case LogChute.ERROR_ID:
-        logger.error(message, t);
-        break;
-      default:
-      case LogChute.INFO_ID:
-        logger.info(message, t);
-        break;
-      }
-    }
-
-    @Override
-    public boolean isLevelEnabled(int level) {
-      switch (level) {
-      case LogChute.DEBUG_ID:
-        return logger.isDebugEnabled();
-      case LogChute.TRACE_ID:
-        return logger.isTraceEnabled();
-      case LogChute.WARN_ID:
-        return logger.isWarnEnabled();
-      case LogChute.ERROR_ID:
-        return logger.isErrorEnabled();
-      default:
-      case LogChute.INFO_ID:
-        return logger.isInfoEnabled();
-      }
-    }
-  }
-
   /** Sets character encoding for generated java file
   * @param outputCharacterEncoding Character encoding for output files (defaults to system encoding)
   */
@@ -1131,4 +1052,3 @@ public void setOutputCharacterEncoding(String outputCharacterEncoding) {
     this.outputCharacterEncoding = outputCharacterEncoding;
   }
 }
-
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
index 92d0c05c6..07e6746ed 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/enum.vm
@@ -26,7 +26,7 @@ package $schema.getNamespace();
 #end
 @org.apache.avro.specific.AvroGenerated
 public enum ${this.mangle($schema.getName())} {
-  #foreach ($symbol in ${schema.getEnumSymbols()})${this.mangle($symbol)}#if ($velocityHasNext), #end#end
+  #foreach ($symbol in ${schema.getEnumSymbols()})${this.mangle($symbol)}#if ($foreach.hasNext), #end#end
   ;
   public static final org.apache.avro.Schema SCHEMA$ = new org.apache.avro.Schema.Parser().parse("${this.javaEscape($schema.toString())}");
   public static org.apache.avro.Schema getClassSchema() { return SCHEMA$; }
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
index 068bd7514..ca5492de9 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/protocol.vm
@@ -47,7 +47,7 @@ public interface $this.mangle($protocol.getName()) {
   #if ($message.isOneWay())void#else${this.javaUnbox($response)}#end
  ${this.mangle($name)}(##
 #foreach ($p in $message.getRequest().getFields())##
-#*      *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($velocityHasNext), #end
+#*      *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($foreach.hasNext), #end
 #end
 )#if (! $message.isOneWay())
  throws org.apache.avro.AvroRemoteException##
@@ -84,7 +84,7 @@ public interface $this.mangle($protocol.getName()) {
      */
     void ${this.mangle($name)}(##
 #foreach ($p in $message.getRequest().getFields())##
-#*      *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($velocityHasNext), #end
+#*      *#${this.javaUnbox($p.schema())} ${this.mangle($p.name())}#if ($foreach.hasNext), #end
 #end
 #if ($message.getRequest().getFields().size() > 0), #end
 org.apache.avro.ipc.Callback<${this.javaType($response)}> callback) throws java.io.IOException;
diff --git a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
index 5a59a6ee9..bc0c1d421 100644
--- a/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
+++ b/lang/java/compiler/src/main/velocity/org/apache/avro/compiler/specific/templates/java/classic/record.vm
@@ -133,7 +133,7 @@ public class ${this.mangle($schema.getName())}#if ($schema.isError()) extends or
 #end
 #end
    */
-  public ${this.mangle($schema.getName())}(#foreach($field in $schema.getFields())${this.javaType($field.schema())} ${this.mangle($field.name())}#if($velocityCount < $schema.getFields().size()), #end#end) {
+  public ${this.mangle($schema.getName())}(#foreach($field in $schema.getFields())${this.javaType($field.schema())} ${this.mangle($field.name())}#if($foreach.count < $schema.getFields().size()), #end#end) {
 #foreach ($field in $schema.getFields())
     this.${this.mangle($field.name())} = ${this.mangle($field.name())};
 #end
diff --git a/lang/java/ipc/pom.xml b/lang/java/ipc/pom.xml
index 4358cbaa7..d0767a8cd 100644
--- a/lang/java/ipc/pom.xml
+++ b/lang/java/ipc/pom.xml
@@ -136,10 +136,9 @@
     </dependency>
     <dependency>
       <groupId>org.apache.velocity</groupId>
-      <artifactId>velocity</artifactId>
+      <artifactId>velocity-engine-core</artifactId>
     </dependency>
 
   </dependencies>
 
 </project>
-
diff --git a/lang/java/pom.xml b/lang/java/pom.xml
index eae6899de..3b5f67f6d 100644
--- a/lang/java/pom.xml
+++ b/lang/java/pom.xml
@@ -49,7 +49,7 @@
     <thrift.version>0.9.3</thrift.version>
     <slf4j.version>1.7.25</slf4j.version>
     <snappy.version>1.1.7.2</snappy.version>
-    <velocity.version>1.7</velocity.version>
+    <velocity.version>2.0</velocity.version>
     <maven.version>2.0.11</maven.version>
     <ant.version>1.10.0</ant.version>
     <commons-cli.version>1.3.1</commons-cli.version>
@@ -423,7 +423,7 @@
       </dependency>
       <dependency>
         <groupId>org.apache.velocity</groupId>
-        <artifactId>velocity</artifactId>
+        <artifactId>velocity-engine-core</artifactId>
         <version>${velocity.version}</version>
       </dependency>
       <dependency>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


> Bump Apache Velocity to 2.0
> ---------------------------
>
>                 Key: AVRO-2228
>                 URL: https://issues.apache.org/jira/browse/AVRO-2228
>             Project: Apache Avro
>          Issue Type: Improvement
>          Components: java
>    Affects Versions: 1.8.2
>            Reporter: Fokko Driesprong
>            Priority: Major
>
> Apache Velocity 1.7 contains CVE's: CVE-2015-6420, CVE-2017-15708



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)