You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by rs...@apache.org on 2022/02/07 18:53:29 UTC

[avro] 01/02: AVRO-3285: Upgrade JavaCC plugin and library (#1447)

This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 34e75a3995feb26721ecb90e89023392e27d9f8b
Author: Oscar Westra van Holthe - Kind <op...@users.noreply.github.com>
AuthorDate: Thu Jan 13 14:39:43 2022 +0100

    AVRO-3285: Upgrade JavaCC plugin and library (#1447)
    
    Also resolve IDE warnings for idl.jj, which was previously impossible.
---
 lang/java/compiler/pom.xml                         | 30 ++++----
 .../javacc/org/apache/avro/compiler/idl/idl.jj     | 83 ++++++++--------------
 lang/java/pom.xml                                  | 31 ++++----
 3 files changed, 63 insertions(+), 81 deletions(-)

diff --git a/lang/java/compiler/pom.xml b/lang/java/compiler/pom.xml
index e5f4756..380b526 100644
--- a/lang/java/compiler/pom.xml
+++ b/lang/java/compiler/pom.xml
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
    Licensed to the Apache Software Foundation (ASF) under one or more
-   contributor license agreements.  See the NOTICE file distributed with
+   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
+   the License. You may obtain a copy of the License at:
 
        https://www.apache.org/licenses/LICENSE-2.0
 
@@ -24,7 +24,7 @@
     <artifactId>avro-parent</artifactId>
     <groupId>org.apache.avro</groupId>
     <version>1.11.1-SNAPSHOT</version>
-    <relativePath>../</relativePath>
+    <relativePath>../pom.xml</relativePath>
   </parent>
 
   <artifactId>avro-compiler</artifactId>
@@ -93,7 +93,7 @@
         and outputs to target/generated-sources/javacc See http://mojo.codehaus.org/javacc-maven-plugin/javacc-mojo.html
         for more info on using this plugin. -->
       <plugin>
-        <groupId>org.codehaus.mojo</groupId>
+        <groupId>org.javacc.plugin</groupId>
         <artifactId>javacc-maven-plugin</artifactId>
         <executions>
           <execution>
@@ -133,11 +133,11 @@
               <classpathScope>test</classpathScope>
               <arguments>
                 <argument>-classpath</argument>
-                <classpath></classpath>
+                <classpath/>
                 <argument>org.apache.avro.compiler.specific.SchemaTask</argument>
                 <argument>${project.basedir}/src/test/resources/full_record_v1.avsc</argument>
                 <argument>${project.basedir}/src/test/resources/full_record_v2.avsc</argument>
-                <argument>${project.basedir}/target/generated-test-sources</argument>
+                <argument>${project.basedir}/target/generated-test-sources/javacc</argument>
               </arguments>
             </configuration>
           </execution>
@@ -149,10 +149,8 @@
         <executions>
           <execution>
             <!--
-              Usually code is generated using a special-purpose maven plugin and the plugin
-              automatically adds the generated sources into project.
-              Here since general-purpose exec plugin is used for generating code, we need to manually
-              add the sources.
+              Special-purpose maven plugins that generate code usually add the generated sources into the project.
+              But because the general-purpose exec plugin above generated code, we need to manually add the generated sources.
             -->
             <id>add-test-source</id>
             <phase>generate-test-sources</phase>
@@ -161,16 +159,14 @@
             </goals>
             <configuration>
               <sources>
-                <source>${project.basedir}/target/generated-test-sources</source>
+                <source>${project.basedir}/target/generated-test-sources/javacc</source>
               </sources>
             </configuration>
           </execution>
           <execution>
             <!--
-              Usually code is generated using a special-purpose maven plugin and the plugin
-              automatically adds the generated sources into project.
-              Here since general-purpose exec plugin is used for generating code, we need to manually
-              add the sources.
+              Special-purpose maven plugins that generate code usually add the generated sources into the project.
+              But because the general-purpose exec plugin above generated code, we need to manually add the generated sources.
             -->
             <id>add-source</id>
             <phase>generate-sources</phase>
@@ -225,8 +221,8 @@
     </dependency>
     <dependency>
       <groupId>org.apache.commons</groupId>
-      <artifactId>commons-lang3</artifactId>
-      <version>${commons-lang.version}</version>
+      <artifactId>commons-text</artifactId>
+      <version>${commons-text.version}</version>
     </dependency>
     <dependency>
       <groupId>org.apache.velocity</groupId>
diff --git a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
index 5fe7871..ee467ff 100644
--- a/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
+++ b/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
@@ -81,7 +81,7 @@ import org.apache.avro.util.internal.Accessor;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.node.*;
 
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.text.StringEscapeUtils;
 
 /**
  * Grammar to parse a higher-level language into an Avro Schema.
@@ -96,7 +96,7 @@ public class Idl implements Closeable {
   URI inputDir;
   ClassLoader resourceLoader = null;
   String namespace;
-  Map<String,Schema> names = new LinkedHashMap<String,Schema>();
+  Map<String,Schema> names = new LinkedHashMap<>();
 
   private List<String> parserWarnings = Collections.emptyList();
   /**
@@ -137,6 +137,7 @@ public class Idl implements Closeable {
     this.resourceLoader = parent.resourceLoader;
   }
 
+  @SuppressWarnings("RedundantThrows")
   public void close() throws IOException {
     jj_input_stream.inputStream.close();
   }
@@ -159,7 +160,7 @@ public class Idl implements Closeable {
     JsonNode value = props.get(key);
     if (!value.isArray())
       throw error(key+" property must be array: "+value, token);
-    List<String> values = new ArrayList<String>();
+    List<String> values = new ArrayList<>();
     for (JsonNode n : value)
       if (n.isTextual())
         values.add(n.textValue());
@@ -209,7 +210,6 @@ public class Idl implements Closeable {
     }
     return schema;
   }
-
 }
 
 PARSER_END(Idl)
@@ -248,13 +248,13 @@ MORE :
 <DOC_COMMENT>
 SPECIAL_TOKEN :
 {
-  <"*/" > {DocCommentHelper.setDoc(matchedToken);} : DEFAULT
+  "*/" {DocCommentHelper.setDoc(matchedToken);} : DEFAULT
 }
 
 <MULTI_LINE_COMMENT>
 SKIP :
 {
-  <"*/" > : DEFAULT
+  "*/" : DEFAULT
 }
 
 /* RESERVED WORDS AND LITERALS */
@@ -1053,7 +1053,7 @@ Protocol CompilationUnit():
 }
 {
   p = ProtocolDeclaration()
-  ( < "\u001a" > )?
+  ( "\u001a" )?
   ( <STUFF_TO_IGNORE: ~[]> )?
   <EOF>
   {
@@ -1102,7 +1102,7 @@ private Schema NamedSchemaDeclaration(Map<String, JsonNode> props):
 Schema UnionDefinition():
 {
   Schema s;
-  List<Schema> schemata = new ArrayList<Schema>();
+  List<Schema> schemata = new ArrayList<>();
 }
 {
   // Don't disallow unions here: its constructor disallows nested unions and throws a descriptive exception.
@@ -1127,7 +1127,7 @@ Protocol ProtocolDeclaration():
 {
   String name;
   Protocol p;
-  Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
+  Map<String, JsonNode> props = new LinkedHashMap<>();
 }
 {
   ( SchemaProperty(props) )*
@@ -1164,8 +1164,7 @@ Schema EnumDeclaration():
   symbols = EnumBody()
       [ <EQUALS> defaultSymbol=Identifier() <SEMICOLON>]
   {
-    Schema s = Schema.createEnum(name, doc, this.namespace, symbols,
-                                 defaultSymbol);
+    Schema s = Schema.createEnum(name, doc, namespace, symbols, defaultSymbol);
     names.put(s.getFullName(), s);
     return s;
   }
@@ -1173,7 +1172,7 @@ Schema EnumDeclaration():
 
 List<String> EnumBody():
 {
-  List<String> symbols = new ArrayList<String>();
+  List<String> symbols = new ArrayList<>();
 }
 {
   "{"
@@ -1197,7 +1196,7 @@ void ProtocolBody(Protocol p):
   Schema schema;
   Message message;
   Protocol importProtocol;
-  Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
+  Map<String, JsonNode> props = new LinkedHashMap<>();
 }
 {
   "{"
@@ -1234,13 +1233,8 @@ Protocol ImportIdl() : {
 {
   <IDL> importFile = JsonString() ";"
     {
-      try {
-        Idl idl = new Idl(findFile(importFile), this);
-        try {
-          return idl.CompilationUnit();
-        } finally {
-          idl.close();
-        }
+      try (Idl idl=new Idl(findFile(importFile), this)){
+        return idl.CompilationUnit();
       } catch (IOException e) {
         throw error("Error importing "+importFile+": "+e, token);
       }
@@ -1253,14 +1247,8 @@ Protocol ImportProtocol() : {
 {
   <PROTOCOL> importFile = JsonString() ";"
     {
-
-      try {
-        InputStream stream = findFile(importFile).openStream();
-        try {
-          return Protocol.parse(stream);
-        } finally {
-          stream.close();
-        }
+      try (InputStream stream=findFile(importFile).openStream()) {
+        return Protocol.parse(stream);
       } catch (IOException e) {
         throw error("Error importing "+importFile+": "+e, token);
       }
@@ -1273,17 +1261,12 @@ Schema ImportSchema() : {
 {
   <SCHEMA> importFile = JsonString() ";"
     {
-      try {
+      try (InputStream stream=findFile(importFile).openStream()){
         Parser parser = new Schema.Parser();
         parser.addTypes(names);                   // inherit names
-        InputStream stream = findFile(importFile).openStream();
-        try {
-          Schema value = parser.parse(stream);
-          names = parser.getTypes();                // update names
-          return value;
-        } finally {
-          stream.close();
-        }
+        Schema value = parser.parse(stream);
+        names = parser.getTypes();                // update names
+        return value;
       } catch (IOException e) {
         throw error("Error importing "+importFile+": "+e, token);
       }
@@ -1309,7 +1292,7 @@ Schema FixedDeclaration():
 Schema RecordDeclaration():
 {
   String name;
-  List<Field> fields = new ArrayList<Field>();
+  List<Field> fields = new ArrayList<>();
   boolean isError;
 }
 {
@@ -1361,7 +1344,7 @@ void VariableDeclarator(Schema type, List<Field> fields):
 {
   String name;
   JsonNode defaultValue = null;
-  Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
+  Map<String, JsonNode> props = new LinkedHashMap<>();
 }
 {
     ( SchemaProperty(props) )*
@@ -1408,7 +1391,7 @@ private Message MessageDeclaration(Protocol p, Map<String, JsonNode> props):
   Schema request;
   Schema response;
   boolean oneWay = false;
-  List<Schema> errorSchemata = new ArrayList<Schema>();
+  List<Schema> errorSchemata = new ArrayList<>();
   errorSchemata.add(Protocol.SYSTEM_ERROR);
 }
 {
@@ -1440,14 +1423,12 @@ void ErrorList(List<Schema> errors):
 
 Schema FormalParameters():
 {
-  List<Field> fields = new ArrayList<Field>();
+  List<Field> fields = new ArrayList<>();
 }
 {
-  (
-    "(" [ FormalParameter(fields) ( "," FormalParameter(fields) )* ] ")"
-  )
+  "(" [ FormalParameter(fields) ( "," FormalParameter(fields) )* ] ")"
   {
-    return Schema.createRecord(fields);
+    return Schema.createRecord(null, null, null, false, fields);
   }
 }
 
@@ -1463,7 +1444,7 @@ void FormalParameter(List<Field> fields):
 Schema Type():
 {
   Schema s;
-  Map<String, JsonNode> props = new LinkedHashMap<String, JsonNode>();
+  Map<String, JsonNode> props = new LinkedHashMap<>();
 }
 {
     ( SchemaProperty(props) )*
@@ -1557,10 +1538,8 @@ Schema ReferenceType():
   StringBuilder sb = new StringBuilder();
 }
 {
-  (
-    part = Identifier() { sb.append(part); }
-    ("." tok = AnyIdentifier() { sb.append(".").append(tok.image); })*
-    )
+  part = Identifier() { sb.append(part); }
+  ("." tok = AnyIdentifier() { sb.append(".").append(tok.image); })*
   {
     String name = sb.toString();
     if ((name.indexOf('.') == -1) && namespace != null)
@@ -1575,7 +1554,7 @@ Schema ReferenceType():
 }
 
 Schema PrimitiveType():
-{}
+{ Schema s; }
 {
   "boolean" { return Schema.create(Type.BOOLEAN); }
 | "bytes" { return Schema.create(Type.BYTES); }
@@ -1589,7 +1568,7 @@ Schema PrimitiveType():
 | "time_ms" { return LogicalTypes.timeMillis().addToSchema(Schema.create(Type.INT)); }
 | "timestamp_ms" { return LogicalTypes.timestampMillis().addToSchema(Schema.create(Type.LONG)); }
 | "local_timestamp_ms" { return LogicalTypes.localTimestampMillis().addToSchema(Schema.create(Type.LONG)); }
-| "decimal" { return DecimalTypeProperties(); }
+| "decimal" s = DecimalTypeProperties() { return s; }
 | "uuid" {return LogicalTypes.uuid().addToSchema(Schema.create(Type.STRING));}
 }
 
diff --git a/lang/java/pom.xml b/lang/java/pom.xml
index 14b7f11..7223740 100644
--- a/lang/java/pom.xml
+++ b/lang/java/pom.xml
@@ -23,7 +23,7 @@
     <groupId>org.apache.avro</groupId>
     <artifactId>avro-toplevel</artifactId>
     <version>1.11.1-SNAPSHOT</version>
-    <relativePath>../../</relativePath>
+    <relativePath>../../pom.xml</relativePath>
   </parent>
 
   <artifactId>avro-parent</artifactId>
@@ -44,28 +44,28 @@
     <jopt-simple.version>5.0.4</jopt-simple.version>
     <junit.version>4.13.2</junit.version>
     <netty.version>4.1.72.Final</netty.version>
-    <protobuf.version>3.19.4</protobuf.version>
+    <protobuf.version>3.19.1</protobuf.version>
     <thrift.version>0.15.0</thrift.version>
-    <slf4j.version>1.7.33</slf4j.version>
-    <reload4j.version>1.2.18.0</reload4j.version>
+    <slf4j.version>1.7.32</slf4j.version>
     <snappy.version>1.1.8.4</snappy.version>
     <velocity.version>2.3</velocity.version>
-    <maven-core.version>3.3.9</maven-core.version>
+    <maven.version>3.8.4</maven.version>
     <ant.version>1.10.12</ant.version>
-    <commons-cli.version>1.5.0</commons-cli.version>
+    <commons-cli.version>1.4</commons-cli.version>
     <commons-compress.version>1.21</commons-compress.version>
-    <commons-lang.version>3.12.0</commons-lang.version>
+    <commons-text.version>1.9</commons-text.version>
     <tukaani.version>1.9</tukaani.version>
     <mockito.version>4.2.0</mockito.version>
     <hamcrest.version>2.2</hamcrest.version>
-    <grpc.version>1.44.0</grpc.version>
+    <grpc.version>1.43.1</grpc.version>
     <zstd-jni.version>1.5.1-1</zstd-jni.version>
     <!-- version properties for plugins -->
-    <archetype-plugin.version>3.2.1</archetype-plugin.version>
+    <archetype-plugin.version>3.2.0</archetype-plugin.version>
     <bundle-plugin-version>5.1.4</bundle-plugin-version>
     <exec-plugin.version>3.0.0</exec-plugin.version>
     <file-management.version>3.0.0</file-management.version>
-    <javacc-plugin.version>2.6</javacc-plugin.version>
+    <javacc-plugin.version>3.0.3</javacc-plugin.version>
+    <javacc.version>7.0.10</javacc.version>
   </properties>
 
   <modules>
@@ -96,7 +96,7 @@
         <plugin>
           <groupId>org.codehaus.mojo</groupId>
           <artifactId>build-helper-maven-plugin</artifactId>
-          <version>3.3.0</version>
+          <version>3.2.0</version>
         </plugin>
         <plugin>
           <groupId>org.apache.maven.plugins</groupId>
@@ -211,9 +211,16 @@
           </configuration>
         </plugin>
         <plugin>
-          <groupId>org.codehaus.mojo</groupId>
+          <groupId>org.javacc.plugin</groupId>
           <artifactId>javacc-maven-plugin</artifactId>
           <version>${javacc-plugin.version}</version>
+          <dependencies>
+            <dependency>
+              <groupId>net.java.dev.javacc</groupId>
+              <artifactId>javacc</artifactId>
+              <version>${javacc.version}</version>
+            </dependency>
+          </dependencies>
         </plugin>
         <plugin>
           <groupId>org.codehaus.mojo</groupId>