avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1161756 - in /avro/branches/branch-1.5: ./ lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/ lang/java/tools/src/main/java/org/apache/avro/tool/ lang/java/tools/src/test/compiler/ lang/java/tools/src/test/compiler/input/ ...
Date Thu, 25 Aug 2011 20:52:58 GMT
Author: cutting
Date: Thu Aug 25 20:52:57 2011
New Revision: 1161756

URL: http://svn.apache.org/viewvc?rev=1161756&view=rev
Log:
Merge -c 1161755 from trunk to 1.5 branch.  Fixes: AVRO-877.

Added:
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/
      - copied from r1161755, avro/trunk/lang/java/tools/src/test/compiler/
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/input/
      - copied from r1161755, avro/trunk/lang/java/tools/src/test/compiler/input/
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/input/player.avsc
      - copied unchanged from r1161755, avro/trunk/lang/java/tools/src/test/compiler/input/player.avsc
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/input/position.avsc
      - copied unchanged from r1161755, avro/trunk/lang/java/tools/src/test/compiler/input/position.avsc
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/output/
      - copied from r1161755, avro/trunk/lang/java/tools/src/test/compiler/output/
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/output/Player.java
      - copied unchanged from r1161755, avro/trunk/lang/java/tools/src/test/compiler/output/Player.java
    avro/branches/branch-1.5/lang/java/tools/src/test/compiler/output/Position.java
      - copied unchanged from r1161755, avro/trunk/lang/java/tools/src/test/compiler/output/Position.java
    avro/branches/branch-1.5/lang/java/tools/src/test/java/org/apache/avro/tool/TestSpecificCompilerTool.java
      - copied unchanged from r1161755, avro/trunk/lang/java/tools/src/test/java/org/apache/avro/tool/TestSpecificCompilerTool.java
Modified:
    avro/branches/branch-1.5/   (props changed)
    avro/branches/branch-1.5/CHANGES.txt
    avro/branches/branch-1.5/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
    avro/branches/branch-1.5/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java

Propchange: avro/branches/branch-1.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 25 20:52:57 2011
@@ -1 +1 @@
-/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1079680,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1099257,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729,1129856,1130503,1136342,1141619,1141677,1141685,1141979-1141980,1142057,1142063,1151660,1151983,1157245,1161743
+/avro/trunk:1075938,1075993,1078917,1079055,1079060,1079063,1079680,1083246,1085921,1086727,1086730,1086866,1087076,1087129,1087136,1087439-1087440,1087463,1087472,1087792,1089128,1089131,1089550,1094812,1095206-1095208,1095493,1095529,1095548,1095550,1096798,1097916,1097927,1097968,1097974,1099257,1102332,1102335,1124127,1124971,1129053,1129071,1129697-1129706,1129729,1129856,1130503,1136342,1141619,1141677,1141685,1141979-1141980,1142057,1142063,1151660,1151983,1157245,1161743,1161755

Modified: avro/branches/branch-1.5/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/CHANGES.txt?rev=1161756&r1=1161755&r2=1161756&view=diff
==============================================================================
--- avro/branches/branch-1.5/CHANGES.txt (original)
+++ avro/branches/branch-1.5/CHANGES.txt Thu Aug 25 20:52:57 2011
@@ -7,6 +7,9 @@ Avro 1.5.3 (unreleased)
     AVRO-874. Java: Improved Schema parsing API and permit IDL imports
     to depend on names defined in prior imports. (cutting)
 
+    AVRO-877. Java: Add support for compiling multiple, dependent
+    schemas. (Bill Graham via cutting)
+
   BUG FIXES
 
 Avro 1.5.2 (12 August 2011)

Modified: avro/branches/branch-1.5/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java?rev=1161756&r1=1161755&r2=1161756&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
(original)
+++ avro/branches/branch-1.5/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java
Thu Aug 25 20:52:57 2011
@@ -153,16 +153,36 @@ public class SpecificCompiler {
    * @param dest the directory to place generated files in
    */
   public static void compileProtocol(File src, File dest) throws IOException {
-    Protocol protocol = Protocol.parse(src);
-    SpecificCompiler compiler = new SpecificCompiler(protocol);
-    compiler.compileToDestination(src, dest);
+    compileProtocol(new File[] {src}, dest);
+  }
+
+  /**
+   * Generates Java interface and classes for a number of protocol files.
+   * @param srcFiles the source Avro protocol files
+   * @param dest the directory to place generated files in
+   */
+  public static void compileProtocol(File[] srcFiles, File dest) throws IOException {
+    for (File src : srcFiles) {
+      Protocol protocol = Protocol.parse(src);
+      SpecificCompiler compiler = new SpecificCompiler(protocol);
+      compiler.compileToDestination(src, dest);
+    }
   }
 
   /** Generates Java classes for a schema. */
   public static void compileSchema(File src, File dest) throws IOException {
-    Schema schema = Schema.parse(src);
-    SpecificCompiler compiler = new SpecificCompiler(schema);
-    compiler.compileToDestination(src, dest);
+    compileSchema(new File[] {src}, dest);
+  }
+
+  /** Generates Java classes for a number of schema files. */
+  public static void compileSchema(File[] srcFiles, File dest) throws IOException {
+    Schema.Parser parser = new Schema.Parser();
+
+    for (File src : srcFiles) {
+      Schema schema = parser.parse(src);
+      SpecificCompiler compiler = new SpecificCompiler(schema);
+      compiler.compileToDestination(src, dest);
+    }
   }
 
   /** Recursively enqueue schemas that need a class generated. */

Modified: avro/branches/branch-1.5/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.5/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java?rev=1161756&r1=1161755&r2=1161756&view=diff
==============================================================================
--- avro/branches/branch-1.5/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
(original)
+++ avro/branches/branch-1.5/lang/java/tools/src/main/java/org/apache/avro/tool/SpecificCompilerTool.java
Thu Aug 25 20:52:57 2011
@@ -18,8 +18,12 @@
 package org.apache.avro.tool;
 
 import java.io.File;
+import java.io.FilenameFilter;
 import java.io.InputStream;
 import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.LinkedHashSet;
 import java.util.List;
 
 import org.apache.avro.compiler.specific.SpecificCompiler;
@@ -33,18 +37,27 @@ public class SpecificCompilerTool implem
   @Override
   public int run(InputStream in, PrintStream out, PrintStream err,
       List<String> args) throws Exception {
-    if (args.size() != 3) {
+    if (args.size() < 3) {
       System.err
-          .println("Expected 3 arguments: (schema|protocol) inputfile outputdir");
+          .println("Need at least 3 arguments: (schema|protocol) input... outputdir");
+      System.err
+          .println(" input - input files or directories");
+      System.err
+          .println(" outputdir - directory to write generated java");
       return 1;
     }
     String method = args.get(0);
-    File input = new File(args.get(1));
-    File output = new File(args.get(2));
+    List<File> inputs = new ArrayList<File>();
+    File output = new File(args.get(args.size() - 1));
+
+    for (int i = 1; i < args.size() - 1; i++) {
+      inputs.add(new File(args.get(i)));
+    }
+
     if ("schema".equals(method)) {
-      SpecificCompiler.compileSchema(input, output);
+      SpecificCompiler.compileSchema(determineInputs(inputs, SCHEMA_FILTER), output);
     } else if ("protocol".equals(method)) {
-      SpecificCompiler.compileProtocol(input, output);
+      SpecificCompiler.compileProtocol(determineInputs(inputs, PROTOCOL_FILTER), output);
     } else {
       System.err.println("Expected \"schema\" or \"protocol\".");
       return 1;
@@ -61,4 +74,59 @@ public class SpecificCompilerTool implem
   public String getShortDescription() {
     return "Generates Java code for the given schema.";
   }
+
+  /**
+   * For a List of files or directories, returns a File[] containing each file
+   * passed as well as each file with a matching extension found in the directory.
+   *
+   * @param inputs List of File objects that are files or directories
+   * @param filter File extension filter to match on when fetching files from a directory
+   * @return Unique array of files
+   */
+  private static File[] determineInputs(List<File> inputs, FilenameFilter filter) {
+    Set<File> fileSet = new LinkedHashSet<File>(); // preserve order and uniqueness
+
+    for (File file : inputs) {
+      // if directory, look at contents to see what files match extension
+      if (file.isDirectory()) {
+        for (File f : file.listFiles(filter)) {
+          fileSet.add(f);
+        }
+      }
+      // otherwise, just add the file.
+      else {
+        fileSet.add(file);
+      }
+    }
+
+    if (fileSet.size() > 0) {
+      System.err.println("Input files to compile:");
+      for (File file : fileSet) {
+        System.err.println("  " + file);
+      }
+    }
+    else {
+      System.err.println("No input files found.");
+    }
+
+    return fileSet.toArray((new File[fileSet.size()]));
+  }
+
+  private static final FileExtensionFilter SCHEMA_FILTER =
+    new FileExtensionFilter("avsc");
+  private static final FileExtensionFilter PROTOCOL_FILTER =
+    new FileExtensionFilter("avpr");
+
+  private static class FileExtensionFilter implements FilenameFilter {
+    private String extension;
+
+    private FileExtensionFilter(String extension) {
+      this.extension = extension;
+    }
+
+    @Override
+    public boolean accept(File dir, String name) {
+      return name.endsWith(this.extension);
+    }
+  }
 }



Mime
View raw message