Author: cutting
Date: Tue Nov 5 23:14:36 2013
New Revision: 1539184
URL: http://svn.apache.org/r1539184
Log:
AVRO-1384. Java: Permit Maven to find imports within project. Contributed by
Alexandre Normand.
Added:
avro/trunk/lang/java/maven-plugin/src/test/avro/AvdlClasspathImport.avdl
Modified:
avro/trunk/CHANGES.txt
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
avro/trunk/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLProtocolMojo.java
avro/trunk/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
Modified: avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1539184&r1=1539183&r2=1539184&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Nov 5 23:14:36 2013
@@ -17,6 +17,9 @@ Trunk (not yet released)
AVRO-1387. Java: Add DataFileWriter option to inhibit flush per block.
(Hari Shreedharan via cutting)
+ AVRO-1384. Java: Permit Maven to find imports within project.
+ (Alexandre Normand via cutting)
+
BUG FIXES
AVRO-1368. Fix SpecificDatumWriter to, when writing a string
Modified:
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java?rev=1539184&r1=1539183&r2=1539184&view=diff
==============================================================================
---
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
(original)
+++
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/AbstractAvroMojo.java
Tue Nov 5 23:14:36 2013
@@ -35,6 +35,11 @@ import org.apache.maven.shared.model.fil
*/
public abstract class AbstractAvroMojo extends AbstractMojo {
/**
+ * The source directory of avro files. This directory is added to the
+ * classpath at schema compiling time. All files can therefore be referenced
+ * as classpath resources following the directory structure under the
+ * source directory.
+ *
* @parameter expression="${sourceDirectory}"
* default-value="${basedir}/src/main/avro"
*/
Modified:
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java?rev=1539184&r1=1539183&r2=1539184&view=diff
==============================================================================
---
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
(original)
+++
avro/trunk/lang/java/maven-plugin/src/main/java/org/apache/avro/mojo/IDLProtocolMojo.java
Tue Nov 5 23:14:36 2013
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
+import java.util.ArrayList;
import java.util.List;
import org.apache.avro.Protocol;
@@ -66,19 +67,23 @@ public class IDLProtocolMojo extends Abs
List runtimeClasspathElements = project.getRuntimeClasspathElements();
Idl parser;
+ List<URL> runtimeUrls = new ArrayList<URL>();
+
+ // Add the source directory of avro files to the classpath so that
+ // imports can refer to other idl files as classpath resources
+ runtimeUrls.add(sourceDirectory.toURI().toURL());
+
// If runtimeClasspathElements is not empty values add its values to Idl
path.
- if(runtimeClasspathElements == null ||
runtimeClasspathElements.isEmpty()) {
- parser = new Idl(new File(sourceDirectory, filename));
- } else {
- URL[] runtimeUrls = new URL[runtimeClasspathElements.size()];
- for (int i = 0; i < runtimeClasspathElements.size(); i++) {
- String element = (String) runtimeClasspathElements.get(i);
- runtimeUrls[i] = new File(element).toURI().toURL();
+ if (runtimeClasspathElements != null &&
!runtimeClasspathElements.isEmpty()) {
+ for (Object runtimeClasspathElement : runtimeClasspathElements) {
+ String element = (String) runtimeClasspathElement;
+ runtimeUrls.add(new File(element).toURI().toURL());
+ }
}
+
URLClassLoader projPathLoader = new URLClassLoader
- (runtimeUrls, Thread.currentThread().getContextClassLoader());
+ (runtimeUrls.toArray(new URL[0]),
Thread.currentThread().getContextClassLoader());
parser = new Idl(new File(sourceDirectory, filename), projPathLoader);
- }
Protocol p = parser.CompilationUnit();
String json = p.toString(true);
Added: avro/trunk/lang/java/maven-plugin/src/test/avro/AvdlClasspathImport.avdl
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/maven-plugin/src/test/avro/AvdlClasspathImport.avdl?rev=1539184&view=auto
==============================================================================
--- avro/trunk/lang/java/maven-plugin/src/test/avro/AvdlClasspathImport.avdl
(added)
+++ avro/trunk/lang/java/maven-plugin/src/test/avro/AvdlClasspathImport.avdl
Tue Nov 5 23:14:36 2013
@@ -0,0 +1,26 @@
+/**
+ * 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.
+ */
+@namespace("test")
+protocol IdlClasspathImportTest {
+ import idl "avro/User.avdl";
+
+ record IdlUserWrapper {
+ union { null, test.IdlUser } wrapped;
+ }
+
+}
Modified:
avro/trunk/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLProtocolMojo.java
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLProtocolMojo.java?rev=1539184&r1=1539183&r2=1539184&view=diff
==============================================================================
---
avro/trunk/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLProtocolMojo.java
(original)
+++
avro/trunk/lang/java/maven-plugin/src/test/java/org/apache/avro/mojo/TestIDLProtocolMojo.java
Tue Nov 5 23:14:36 2013
@@ -37,7 +37,7 @@ public class TestIDLProtocolMojo extends
File outputDir = new File(getBasedir(), "target/test-harness/idl/test");
String[] generatedFiles = new String[]{"IdlPrivacy.java",
- "IdlTest.java", "IdlUser.java"};
+ "IdlTest.java", "IdlUser.java", "IdlUserWrapper.java"};
assertFilesExist(outputDir, generatedFiles);
}
Modified: avro/trunk/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
URL:
http://svn.apache.org/viewvc/avro/trunk/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml?rev=1539184&r1=1539183&r2=1539184&view=diff
==============================================================================
--- avro/trunk/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml
(original)
+++ avro/trunk/lang/java/maven-plugin/src/test/resources/unit/idl/pom.xml Tue
Nov 5 23:14:36 2013
@@ -42,7 +42,7 @@
</execution>
</executions>
<configuration>
- <sourceDirectory>${basedir}/src/test/avro</sourceDirectory>
+ <sourceDirectory>${basedir}/src/test</sourceDirectory>
<outputDirectory>${basedir}/target/test-harness/idl</outputDirectory>
<project
implementation="org.apache.maven.plugin.testing.stubs.MavenProjectStub"/>
</configuration>