avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [avro] branch master updated: [AVRO-2228] Bump Apache Velocity to 2.0
Date Thu, 08 Nov 2018 16:01:57 GMT
This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new c4386ad  [AVRO-2228] Bump Apache Velocity to 2.0
c4386ad is described below

commit c4386ad21f16b4fdd761eeb5ac4332f6221aac3f
Author: Fokko Driesprong <fokkodriesprong@godatadriven.com>
AuthorDate: Mon Sep 24 10:07:03 2018 -0700

    [AVRO-2228] Bump Apache Velocity to 2.0
    
    - Remove Slf4jLogChute since 2.0 uses SLF4J itself
    - Update $velocityHasNext to $foreach.hasNext because of deprecation
    - Update $velocityCount to $foreach.count because of deprecation
    - 2.0 does not depend on apache-common collections anymore which
      used to be an old version with security issues
---
 lang/java/compiler/pom.xml                         |   2 +-
 .../avro/compiler/specific/SpecificCompiler.java   | 104 +++------------------
 .../specific/templates/java/classic/enum.vm        |   2 +-
 .../specific/templates/java/classic/protocol.vm    |   4 +-
 .../specific/templates/java/classic/record.vm      |   2 +-
 lang/java/ipc/pom.xml                              |   3 +-
 lang/java/pom.xml                                  |   4 +-
 7 files changed, 20 insertions(+), 101 deletions(-)

diff --git a/lang/java/compiler/pom.xml b/lang/java/compiler/pom.xml
index d236df0..7bee6e3 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 aa7c5c3..5ee2bdc 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.avro.generic.GenericData.StringType;
 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 class SpecificCompiler {
     return dateTimeLogicalTypeImplementation;
   }
 
-  private static String logChuteName = null;
-
   private void initializeVelocity() {
     this.velocityEngine = new VelocityEngine();
 
@@ -286,17 +282,9 @@ public class SpecificCompiler {
     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 @@ public class SpecificCompiler {
     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 class SpecificCompiler {
     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 class SpecificCompiler {
     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 92d0c05..07e6746 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 068bd75..ca5492d 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 5a59a6e..bc0c1d4 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 4358cba..d0767a8 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 eae6899..3b5f67f 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>


Mime
View raw message