You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2012/02/25 00:47:16 UTC

svn commit: r1293481 - in /avro/trunk: ./ lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/ lang/java/compiler/src/test/idl/input/ lang/java/compiler/src/test/idl/output/ lang/java/compiler/src/test/idl/putOnClassPath/

Author: cutting
Date: Fri Feb 24 23:47:15 2012
New Revision: 1293481

URL: http://svn.apache.org/viewvc?rev=1293481&view=rev
Log:
AVRO-1036.  Fix a regression in IDL imports created by AVRO-971.

Added:
    avro/trunk/lang/java/compiler/src/test/idl/input/nestedimport.avdl
    avro/trunk/lang/java/compiler/src/test/idl/output/nestedimport.avpr
    avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/nestedtypes.avdl
Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
    avro/trunk/lang/java/compiler/src/test/idl/input/import.avdl
    avro/trunk/lang/java/compiler/src/test/idl/output/import.avpr
    avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/OnTheClasspath.avdl

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1293481&r1=1293480&r2=1293481&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Fri Feb 24 23:47:15 2012
@@ -12,6 +12,9 @@ Avro 1.6.3 (unreleased)
 
     AVRO-1037. Problems using Avro 1.6.2 with Hadoop (CDH3 or 1.0) (scottcarey)
 
+    AVRO-1036. Fix a regression in IDL imports created by AVRO-971.
+    (George Fletcher & cutting)
+
 Avro 1.6.2 (13 February 2012)
 
   NEW FEATURES

Modified: avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj?rev=1293481&r1=1293480&r2=1293481&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj (original)
+++ avro/trunk/lang/java/compiler/src/main/javacc/org/apache/avro/compiler/idl/idl.jj Fri Feb 24 23:47:15 2012
@@ -66,6 +66,7 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.net.URL;
 
 import org.apache.avro.Schema;
 import org.apache.avro.Schema.*;
@@ -83,8 +84,7 @@ import org.apache.commons.lang.StringEsc
  * Note: each instance is not thread-safe, but multiple separate
  * instances are safely independent.
  */
-public class Idl
-{
+public class Idl implements Closeable {
   static JsonNodeFactory FACTORY = JsonNodeFactory.instance;
 
   File inputDir = new File(".");
@@ -110,6 +110,18 @@ public class Idl
     this.resourceLoader = resourceLoader;
   }
   
+  private Idl(URL input, Idl parent) throws IOException {
+    this(input.openStream(), "UTF-8");
+    this.inputDir = "file".equals(input.getProtocol())
+      ? new File(input.getPath()).getParentFile()
+      : parent.inputDir;
+    this.resourceLoader = parent.resourceLoader;
+  }
+  
+  public void close() throws IOException {
+    jj_input_stream.inputStream.close();
+  }
+
   private ParseException error(String message, Token token) {
     return new ParseException
       (message+", at line "+token.beginLine+", column "+token.beginColumn);
@@ -137,22 +149,16 @@ public class Idl
     return values;
   }
   
-  private InputStream findFile(String importFile) throws IOException {
-    InputStream stream = null;
-    //Load the file if it exist in the inputDir
+  private URL findFile(String importFile) throws IOException {
     File file = new File(this.inputDir, importFile);
-    if (file.exists()) {
-      stream = new FileInputStream(file);
-    }
-    else if (this.resourceLoader != null) {
-      //Otherwise look for it using the provided ClassLoader.
-      stream = this.resourceLoader.getResourceAsStream(importFile);
-    }
-
-    if (stream == null) {
+    URL result = null;
+    if (file.exists())
+      result = file.toURL();
+    else if (this.resourceLoader != null)
+      result = this.resourceLoader.getResource(importFile);
+    if (result == null)
       throw new FileNotFoundException(importFile);
-    }
-    return stream;
+    return result;
   }
 
 }
@@ -1163,11 +1169,11 @@ Protocol ImportIdl() : {
   <IDL> importFile = JsonString() ";"
     {
       try {
-        InputStream stream = findFile(importFile); 
+        Idl idl = new Idl(findFile(importFile), this); 
         try {
-          return new Idl(stream).CompilationUnit();
+          return idl.CompilationUnit();
         } finally {
-          stream.close();
+          idl.close();
         }
       } catch (IOException e) {
         throw error("Error importing "+importFile+": "+e, token);
@@ -1183,7 +1189,7 @@ Protocol ImportProtocol() : {
     {
 
       try {
-        InputStream stream = findFile(importFile);
+        InputStream stream = findFile(importFile).openStream();
         try {
           return Protocol.parse(stream);
         } finally {
@@ -1204,7 +1210,7 @@ Schema ImportSchema() : {
       try {
         Parser parser = new Schema.Parser();
         parser.addTypes(names);                   // inherit names
-        InputStream stream = findFile(importFile);
+        InputStream stream = findFile(importFile).openStream();
         try {
           Schema value = parser.parse(stream);
           names = parser.getTypes();                // update names

Modified: avro/trunk/lang/java/compiler/src/test/idl/input/import.avdl
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/input/import.avdl?rev=1293481&r1=1293480&r2=1293481&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/input/import.avdl (original)
+++ avro/trunk/lang/java/compiler/src/test/idl/input/import.avdl Fri Feb 24 23:47:15 2012
@@ -19,7 +19,8 @@
 @namespace("org.foo")
 protocol Import {
   import idl "reservedwords.avdl";
-  
+  import idl "nestedimport.avdl";
+
   //Note that this import is resolve via the classpath, not relative path.
   import idl "OnTheClasspath.avdl";
   import protocol "OnTheClasspath.avpr";

Added: avro/trunk/lang/java/compiler/src/test/idl/input/nestedimport.avdl
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/input/nestedimport.avdl?rev=1293481&view=auto
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/input/nestedimport.avdl (added)
+++ avro/trunk/lang/java/compiler/src/test/idl/input/nestedimport.avdl Fri Feb 24 23:47:15 2012
@@ -0,0 +1,31 @@
+/**
+ * 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.
+ */
+
+@version("1.0.5")
+@namespace("org.apache.avro.ipc.specific")
+protocol nestedimport {
+    import idl "reservedwords.avdl";
+    import protocol "bar.avpr";
+    import schema "position.avsc";
+    import schema "player.avsc";
+
+    record ImportBar {
+        avro.examples.baseball.Player  foo;
+    }
+
+}
\ No newline at end of file

Modified: avro/trunk/lang/java/compiler/src/test/idl/output/import.avpr
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/output/import.avpr?rev=1293481&r1=1293480&r2=1293481&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/output/import.avpr (original)
+++ avro/trunk/lang/java/compiler/src/test/idl/output/import.avpr Fri Feb 24 23:47:15 2012
@@ -3,6 +3,44 @@
   "namespace" : "org.foo",
   "doc" : "* Licensed to the Apache Software Foundation (ASF) under one\n * or more contributor license agreements.  See the NOTICE file\n * distributed with this work for additional information\n * regarding copyright ownership.  The ASF licenses this file\n * to you under the Apache License, Version 2.0 (the\n * \"License\"); you may not use this file except in compliance\n * with the License.  You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.",
   "types" : [ {
+    "type" : "enum",
+    "name" : "Position",
+    "namespace" : "avro.examples.baseball",
+    "symbols" : [ "P", "C", "B1", "B2", "B3", "SS", "LF", "CF", "RF", "DH" ]
+  }, {
+    "type" : "record",
+    "name" : "Player",
+    "namespace" : "avro.examples.baseball",
+    "fields" : [ {
+      "name" : "number",
+      "type" : "int"
+    }, {
+      "name" : "first_name",
+      "type" : "string"
+    }, {
+      "name" : "last_name",
+      "type" : "string"
+    }, {
+      "name" : "position",
+      "type" : {
+        "type" : "array",
+        "items" : "Position"
+      }
+    } ]
+  }, {
+    "type" : "record",
+    "name" : "ImportBar",
+    "namespace" : "org.apache.avro.ipc.specific",
+    "fields" : [ {
+      "name" : "foo",
+      "type" : "avro.examples.baseball.Player"
+    } ]
+  }, {
+    "type" : "record",
+    "name" : "NestedType",
+    "namespace" : "org.on.the.classpath",
+    "fields" : [ ]
+  }, {
     "type" : "record",
     "name" : "FromAfar",
     "namespace" : "org.on.the.classpath",

Added: avro/trunk/lang/java/compiler/src/test/idl/output/nestedimport.avpr
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/output/nestedimport.avpr?rev=1293481&view=auto
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/output/nestedimport.avpr (added)
+++ avro/trunk/lang/java/compiler/src/test/idl/output/nestedimport.avpr Fri Feb 24 23:47:15 2012
@@ -0,0 +1,53 @@
+{
+  "protocol" : "nestedimport",
+  "namespace" : "org.apache.avro.ipc.specific",
+  "doc" : "* Licensed to the Apache Software Foundation (ASF) under one\n * or more contributor license agreements.  See the NOTICE file\n * distributed with this work for additional information\n * regarding copyright ownership.  The ASF licenses this file\n * to you under the Apache License, Version 2.0 (the\n * \"License\"); you may not use this file except in compliance\n * with the License.  You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.",
+  "version" : "1.0.5",
+  "types" : [ {
+    "type" : "enum",
+    "name" : "Position",
+    "namespace" : "avro.examples.baseball",
+    "symbols" : [ "P", "C", "B1", "B2", "B3", "SS", "LF", "CF", "RF", "DH" ]
+  }, {
+    "type" : "record",
+    "name" : "Player",
+    "namespace" : "avro.examples.baseball",
+    "fields" : [ {
+      "name" : "number",
+      "type" : "int"
+    }, {
+      "name" : "first_name",
+      "type" : "string"
+    }, {
+      "name" : "last_name",
+      "type" : "string"
+    }, {
+      "name" : "position",
+      "type" : {
+        "type" : "array",
+        "items" : "Position"
+      }
+    } ]
+  }, {
+    "type" : "record",
+    "name" : "ImportBar",
+    "fields" : [ {
+      "name" : "foo",
+      "type" : "avro.examples.baseball.Player"
+    } ]
+  } ],
+  "messages" : {
+    "error" : {
+      "request" : [ ],
+      "response" : "null"
+    },
+    "void" : {
+      "request" : [ ],
+      "response" : "null"
+    },
+    "bar" : {
+      "request" : [ ],
+      "response" : "null"
+    }
+  }
+}
\ No newline at end of file

Modified: avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/OnTheClasspath.avdl
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/OnTheClasspath.avdl?rev=1293481&r1=1293480&r2=1293481&view=diff
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/OnTheClasspath.avdl (original)
+++ avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/OnTheClasspath.avdl Fri Feb 24 23:47:15 2012
@@ -18,6 +18,7 @@
 
 @namespace("org.on.the.classpath")
 protocol OnTheClasspath {
+    import idl "nestedtypes.avdl";
 	record FromAfar {
 	}
 }

Added: avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/nestedtypes.avdl
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/nestedtypes.avdl?rev=1293481&view=auto
==============================================================================
--- avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/nestedtypes.avdl (added)
+++ avro/trunk/lang/java/compiler/src/test/idl/putOnClassPath/nestedtypes.avdl Fri Feb 24 23:47:15 2012
@@ -0,0 +1,23 @@
+/**
+ * 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("org.on.the.classpath")
+protocol OnTheClasspathTypes {
+	record NestedType {
+	}
+}