gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject svn commit: r1476666 - in /gora/trunk: CHANGES.txt gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
Date Sat, 27 Apr 2013 20:41:22 GMT
Author: lewismc
Date: Sat Apr 27 20:41:22 2013
New Revision: 1476666

URL: http://svn.apache.org/r1476666
Log:
GORA-191 Support multiple Avro Schemas within GoraCompiler

Modified:
    gora/trunk/CHANGES.txt
    gora/trunk/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java

Modified: gora/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/gora/trunk/CHANGES.txt?rev=1476666&r1=1476665&r2=1476666&view=diff
==============================================================================
--- gora/trunk/CHANGES.txt (original)
+++ gora/trunk/CHANGES.txt Sat Apr 27 20:41:22 2013
@@ -5,6 +5,9 @@
 Gora Change Log
 
 trunk (current development)
+
+* GORA-191 Support multiple Avro Schemas within GoraCompiler (Udesh Liyanaarachchi, rmarroquin,
lewismc)
+
 * GORA-159 gora-hbase MR tests should use HBaseTestingUtility instead of deprecated HBaseClusterTestCase
via GORA-89 
 
 * GORA-89 Avoid HBase MiniCluster restarts to shorten gora-hbase tests (hsaputra, alfonso,
Ioan eugen Stan)

Modified: gora/trunk/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
URL: http://svn.apache.org/viewvc/gora/trunk/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java?rev=1476666&r1=1476665&r2=1476666&view=diff
==============================================================================
--- gora/trunk/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java (original)
+++ gora/trunk/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java Sat Apr
27 20:41:22 2013
@@ -23,6 +23,7 @@ import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.text.SimpleDateFormat;
+import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -47,6 +48,7 @@ public class GoraCompiler {
   private Set<Schema> queue = new HashSet<Schema>();
   private static final Logger log = LoggerFactory.getLogger(GoraCompiler.class);
   private static LicenseHeaders licenseHeader = new LicenseHeaders(null);
+  private final static String SCHEMA_EXTENTION = ".avsc";
 
   private GoraCompiler(File dest) {
     this.dest = dest;                             // root directory for output
@@ -79,6 +81,19 @@ public class GoraCompiler {
     compiler.enqueue(Schema.parse(src));          // enqueue types
     compiler.compile();                           // generate classes for types
   }
+  
+  /** Generates Java classes for a number of schema files. */
+  public static void compileSchema(File[] srcFiles, File dest) throws IOException {
+  if(licenseHeader != null) {
+  log.info("The generated artifact will be " + licenseHeader.getLicenseName() + " licensed.");
+   }
+       for (File src : srcFiles) {
+        log.info("Compiling Schema: " + src + " to: " + dest);
+        GoraCompiler compiler = new GoraCompiler(dest);
+        compiler.enqueue(Schema.parse(src));          // enqueue types
+        compiler.compile();                           // generate classes for types
+  	  }
+  	}
 
   private static String camelCasify(String s) {
     return s.substring(0, 1).toUpperCase() + s.substring(1);
@@ -472,7 +487,7 @@ public class GoraCompiler {
   public static void main(String[] args) throws Exception {
     if (args.length < 2) {
       System.err.println("Usage: GoraCompiler <schema file> <output dir> [-license
<id>]");
-      System.err.println("  <schema file>     - individual avsc file to be compiled");
+      System.err.println("  <schema file>     - individual avsc file to be compiled
or a directory path containing avsc files");
       System.err.println("  <output dir>      - output directory for generated Java
files");
       System.err.println("  [-license <id>]   - the preferred license header to add
to the\n" +
                                            "\t\t      generated Java file. Current options
include; \n" +
@@ -487,6 +502,12 @@ public class GoraCompiler {
                                               "\t\t  LGPLv3  (GNU Lesser General Public License
v2.1)\n") ;
       System.exit(1);
     }
+    File inputFile = new File(args[0]);
+    File output = new File(args[1]);
+    if(!inputFile.exists() || !output.exists()){
+    	System.err.println("input file path or output file path doesn't exists.");
+    	System.exit(1);
+    }
     for (int i = 1; i < args.length; i++) {
       licenseHeader.setLicenseName("ASLv2");
       if ("-license".equals(args[i])) {
@@ -496,7 +517,19 @@ public class GoraCompiler {
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
     long start = System.currentTimeMillis();
     log.info("GoraCompiler: starting at " + sdf.format(start));
-    compileSchema(new File(args[0]), new File(args[1]));
+    if(inputFile.isDirectory()) {
+    	ArrayList<File> inputSchemas = new ArrayList<File>();
+    	File[] listOfFiles= inputFile.listFiles();
+    	for (File file : listOfFiles) {
+    	    if (file.isFile() && file.exists() && file.getName().endsWith(SCHEMA_EXTENTION))
{
+    	    	inputSchemas.add(file);
+    	    }
+    	}
+    compileSchema(inputSchemas.toArray(new File[inputSchemas.size()]), output);
+    }
+    else if (inputFile.isFile()) {
+    	compileSchema(inputFile, output);	
+    }
     long end = System.currentTimeMillis();
     log.info("GoraCompiler: finished at " + sdf.format(end) + ", elapsed: " + TimingUtil.elapsedTime(start,
end));
     return;



Mime
View raw message