You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gora.apache.org by le...@apache.org on 2013/04/27 22:45:16 UTC
svn commit: r1476668 - in /gora/branches/GORA_174: CHANGES.txt
gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
Author: lewismc
Date: Sat Apr 27 20:45:10 2013
New Revision: 1476668
URL: http://svn.apache.org/r1476668
Log:
GORA-191 Support multiple Avro Schemas within GoraCompiler
Modified:
gora/branches/GORA_174/CHANGES.txt
gora/branches/GORA_174/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
Modified: gora/branches/GORA_174/CHANGES.txt
URL: http://svn.apache.org/viewvc/gora/branches/GORA_174/CHANGES.txt?rev=1476668&r1=1476667&r2=1476668&view=diff
==============================================================================
--- gora/branches/GORA_174/CHANGES.txt (original)
+++ gora/branches/GORA_174/CHANGES.txt Sat Apr 27 20:45:10 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/branches/GORA_174/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java
URL: http://svn.apache.org/viewvc/gora/branches/GORA_174/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java?rev=1476668&r1=1476667&r2=1476668&view=diff
==============================================================================
--- gora/branches/GORA_174/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java (original)
+++ gora/branches/GORA_174/gora-core/src/main/java/org/apache/gora/compiler/GoraCompiler.java Sat Apr 27 20:45:10 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);
@@ -493,7 +508,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" +
@@ -508,6 +523,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])) {
@@ -517,7 +538,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;