Skip to content

Commit

Permalink
AVRO-3403: Create and use ANTLR to parse IDL files (#1588)
Browse files Browse the repository at this point in the history
This large change encompasses a new avro-idl module, a shared ANTLR
grammar to allow implementations in other languages, and uses (copies
of) all existing IDL tests.
  • Loading branch information
opwvhk authored Sep 11, 2023
1 parent 6f188f8 commit cae0cb1
Show file tree
Hide file tree
Showing 101 changed files with 5,342 additions and 270 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ indent_style = space
indent_size = 2
trim_trailing_whitespace=true

ij_continuation_indent_size = 4
ij_java_wrap_comments = true
ij_any_indent_case_from_switch = false

[*.{avsc,avpr,avdl}]
indent_style = space
indent_size = 2
trim_trailing_whitespace=true

ij_continuation_indent_size = 4
ij_json_space_after_colon = true
ij_json_space_before_colon = true
ij_json_spaces_within_brackets = true
ij_any_array_initializer_wrap = off

[*.{ps1}]
indent_style = space
indent_size = 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<name>Simple Avro Ordering Service</name>

<properties>
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
<project.build.sourceEncoding>${project.build.sourceEncoding}</project.build.sourceEncoding>
<avro.version>${project.version}</avro.version>
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
Expand Down
2 changes: 1 addition & 1 deletion lang/java/avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
<version>1.12.0-SNAPSHOT</version>
<relativePath>../</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>avro</artifactId>
Expand Down
67 changes: 38 additions & 29 deletions lang/java/compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,37 +183,8 @@
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>exec</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>


<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -242,4 +213,42 @@
</dependency>
</dependencies>

<profiles>
<profile>
<id>m2e</id>
<activation>
<property><name>m2e.version</name></property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>exec</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,14 @@ public SpecificCompiler(Protocol protocol) {
}

public SpecificCompiler(Schema schema) {
this(Collections.singleton(schema));
}

public SpecificCompiler(Collection<Schema> schemas) {
this();
enqueue(schema);
for (Schema schema : schemas) {
enqueue(schema);
}
this.protocol = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ import org.apache.commons.text.StringEscapeUtils;
*
* Note: each instance is not thread-safe, but multiple separate
* instances are safely independent.
*
* @deprecated Use the new org.apache.avro.idl.IdlReader from avro-idl instead.
*/
@Deprecated
public class Idl implements Closeable {
static JsonNodeFactory FACTORY = JsonNodeFactory.instance;
private static final String OPTIONAL_NULLABLE_TYPE_PROPERTY = "org.apache.avro.compiler.idl.Idl.NullableType.optional";
Expand Down
2 changes: 1 addition & 1 deletion lang/java/grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>org.apache.avro</groupId>
<artifactId>avro-parent</artifactId>
<version>1.12.0-SNAPSHOT</version>
<relativePath>../</relativePath>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>avro-grpc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion lang/java/grpc/src/test/avro/TestService.avdl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* 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
Expand Down
172 changes: 172 additions & 0 deletions lang/java/idl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?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
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
https://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.
-->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>avro-parent</artifactId>
<groupId>org.apache.avro</groupId>
<version>1.12.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>avro-idl</artifactId>

<name>Apache Avro IDL</name>
<packaging>bundle</packaging>
<url>https://avro.apache.org</url>
<description>Compilers for Avro IDL and Avro Specific Java API</description>

<properties>
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<osgi.import>
!org.apache.avro.idl*,
org.apache.avro*;version="${project.version}",
org.apache.commons.text*,
*
</osgi.import>
<osgi.export>org.apache.avro.idl*;version="${project.version}"</osgi.export>
<antlr.version>4.9.3</antlr.version>
</properties>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/idl</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>org.apache.avro.idl</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>prepare-test-jar</id>
<phase>generate-test-resources</phase>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<classifier>test-resource</classifier>
<testClassesDirectory>src/test/idl/putOnClassPath</testClassesDirectory>
<finalName>putOnClassPath</finalName>
<outputDirectory>${project.build.testOutputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>${antlr.version}</version>
<executions>
<execution>
<id>antlr</id>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>${project.basedir}/../../../share/idl_grammar</sourceDirectory>
<libDirectory>${project.basedir}/../../../share/idl_grammar/imports</libDirectory>
<listener>true</listener>
<visitor>false</visitor>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>avro</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>

<profiles>
<profile>
<id>m2e</id>
<activation>
<property><name>m2e.version</name></property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<versionRange>[1.0,)</versionRange>
<goals>
<goal>exec</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute/>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
</project>
Loading

0 comments on commit cae0cb1

Please sign in to comment.