hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ph...@apache.org
Subject svn commit: r679901 - in /hadoop/zookeeper/trunk/src/java/main/org/apache: jute/compiler/ jute/compiler/generated/ zookeeper/version/util/
Date Fri, 25 Jul 2008 21:19:48 GMT
Author: phunt
Date: Fri Jul 25 14:19:47 2008
New Revision: 679901

URL: http://svn.apache.org/viewvc?rev=679901&view=rev
Log:
Addresses ZOOKEEPER-97 supports optional output directory in code generator

Modified:
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CGenerator.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CppGenerator.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JFile.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JRecord.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JavaGenerator.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/Rcc.java
    hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/rcc.jj
    hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/version/util/VerGen.java

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CGenerator.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CGenerator.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CGenerator.java Fri Jul
25 14:19:47 2008
@@ -34,15 +34,18 @@
     private String mName;
     private ArrayList mInclFiles;
     private ArrayList mRecList;
+    private final File outputDirectory;
     
     /** Creates a new instance of CppGenerator
      *
      * @param name possibly full pathname to the file
      * @param ilist included files (as JFile)
      * @param rlist List of records defined within this file
+     * @param outputDirectory 
      */
-    CGenerator(String name, ArrayList ilist, ArrayList rlist) {
+    CGenerator(String name, ArrayList ilist, ArrayList rlist, File outputDirectory) {
         mFullName = name;
+        this.outputDirectory = outputDirectory;
         mName = (new File(name)).getName();
         mInclFiles = ilist;
         mRecList = rlist;
@@ -54,8 +57,9 @@
      * record-level code is generated by JRecord.
      */
     void genCode() throws IOException {
-        FileWriter c = new FileWriter(mName+".c");
-        FileWriter h = new FileWriter(mName+".h");
+        outputDirectory.mkdirs();
+        FileWriter c = new FileWriter(new File(outputDirectory, mName+".c"));
+        FileWriter h = new FileWriter(new File(outputDirectory, mName+".h"));
         h.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
         h.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
         

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CppGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CppGenerator.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CppGenerator.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/CppGenerator.java Fri Jul
25 14:19:47 2008
@@ -34,15 +34,18 @@
     private String mName;
     private ArrayList mInclFiles;
     private ArrayList mRecList;
+    private final File outputDirectory;
     
     /** Creates a new instance of CppGenerator
      *
      * @param name possibly full pathname to the file
      * @param ilist included files (as JFile)
      * @param rlist List of records defined within this file
+     * @param outputDirectory 
      */
-    CppGenerator(String name, ArrayList ilist, ArrayList rlist) {
+    CppGenerator(String name, ArrayList ilist, ArrayList rlist, File outputDirectory) {
         mFullName = name;
+        this.outputDirectory = outputDirectory;
         mName = (new File(name)).getName();
         mInclFiles = ilist;
         mRecList = rlist;
@@ -54,8 +57,9 @@
      * record-level code is generated by JRecord.
      */
     void genCode() throws IOException {
-        FileWriter cc = new FileWriter(mName+".cc");
-        FileWriter hh = new FileWriter(mName+".hh");
+        outputDirectory.mkdirs();
+        FileWriter cc = new FileWriter(new File(outputDirectory, mName+".cc"));
+        FileWriter hh = new FileWriter(new File(outputDirectory, mName+".hh"));
         hh.write("#ifndef __"+mName.toUpperCase().replace('.','_')+"__\n");
         hh.write("#define __"+mName.toUpperCase().replace('.','_')+"__\n");
         

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JFile.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JFile.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JFile.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JFile.java Fri Jul 25 14:19:47
2008
@@ -18,6 +18,7 @@
 
 package org.apache.jute.compiler;
 
+import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 
@@ -54,16 +55,17 @@
     
     /** Generate record code in given language. Language should be all
      *  lowercase.
+     * @param outputDirectory 
      */
-    public void genCode(String language) throws IOException {
+    public void genCode(String language, File outputDirectory) throws IOException {
         if ("c++".equals(language)) {
-            CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords);
+            CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords, outputDirectory);
             gen.genCode();
         } else if ("java".equals(language)) {
-            JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords);
+            JavaGenerator gen = new JavaGenerator(mName, mInclFiles, mRecords, outputDirectory);
             gen.genCode();
         } else if ("c".equals(language)) {
-        	CGenerator gen = new CGenerator(mName, mInclFiles, mRecords);
+        	CGenerator gen = new CGenerator(mName, mInclFiles, mRecords, outputDirectory);
         	gen.genCode();
         } else {
             System.out.println("Cannnot recognize language:"+language);

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JRecord.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JRecord.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JRecord.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JRecord.java Fri Jul 25
14:19:47 2008
@@ -357,10 +357,10 @@
         
     }
     
-    public void genJavaCode() throws IOException {
+    public void genJavaCode(File outputDirectory) throws IOException {
         String pkg = getJavaPackage();
         String pkgpath = pkg.replaceAll("\\.", "/");
-        File pkgdir = new File(pkgpath);
+        File pkgdir = new File(outputDirectory, pkgpath);
         if (!pkgdir.exists()) {
             // create the pkg directory
             boolean ret = pkgdir.mkdirs();

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JavaGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JavaGenerator.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JavaGenerator.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/JavaGenerator.java Fri Jul
25 14:19:47 2008
@@ -33,17 +33,20 @@
     private String mName;
     private ArrayList mInclFiles;
     private ArrayList mRecList;
+    private final File outputDirectory;
     
     /** Creates a new instance of JavaGenerator
      *
      * @param name possibly full pathname to the file
      * @param incl included files (as JFile)
      * @param records List of records defined within this file
+     * @param outputDirectory 
      */
-    JavaGenerator(String name, ArrayList incl, ArrayList records) {
+    JavaGenerator(String name, ArrayList incl, ArrayList records, File outputDirectory) {
         mName = name;
         mInclFiles = incl;
         mRecList = records;
+        this.outputDirectory = outputDirectory;
     }
     
     /**
@@ -53,7 +56,7 @@
     void genCode() throws IOException {
         for (Iterator i = mRecList.iterator(); i.hasNext(); ) {
             JRecord rec = (JRecord) i.next();
-            rec.genJavaCode();
+            rec.genJavaCode(outputDirectory);
         }
     }
 }

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/Rcc.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/Rcc.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/Rcc.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/Rcc.java Fri Jul
25 14:19:47 2008
@@ -29,15 +29,16 @@
 import java.io.IOException;
 
 public class Rcc implements RccConstants {
-    private static String language = "java";
-    private static ArrayList recFiles = new ArrayList();
-    private static JFile curFile;
-    private static Hashtable recTab;
+    private static Hashtable recTab = new Hashtable();
     private static String curDir = System.getProperty("user.dir");
     private static String curFileName;
     private static String curModuleName;
 
     public static void main(String args[]) {
+        String language = "java";
+        ArrayList recFiles = new ArrayList();
+        JFile curFile=null;
+
         for (int i=0; i<args.length; i++) {
             if ("-l".equalsIgnoreCase(args[i]) ||
                 "--language".equalsIgnoreCase(args[i])) {
@@ -57,30 +58,19 @@
         }
         for (int i=0; i<recFiles.size(); i++) {
             curFileName = (String) recFiles.get(i);
-            File file = new File(curDir, curFileName);
+            File file = new File(curFileName);
             try {
-                FileReader reader = new FileReader(file);
-                Rcc parser = new Rcc(reader);
-                try {
-                    recTab = new Hashtable();
-                    curFile = parser.Input();
-                    System.out.println((String) recFiles.get(i) +
-                        " Parsed Successfully");
-                } catch (ParseException e) {
-                    System.out.println(e.toString());
-                    System.exit(1);
-                }
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                }
+                curFile = parseFile(file);
             } catch (FileNotFoundException e) {
-                System.out.println("File " + (String) recFiles.get(i) +
-                    " Not found.");
+                System.out.println("File " + (String) recFiles.get(i) + " Not found.");
+                System.exit(1);
+            } catch (ParseException e) {
+                System.out.println(e.toString());
                 System.exit(1);
             }
+            System.out.println((String) recFiles.get(i) + " Parsed Successfully");
             try {
-                curFile.genCode(language);
+                curFile.genCode(language, new File("."));
             } catch (IOException e) {
                 System.out.println(e.toString());
                 System.exit(1);
@@ -88,6 +78,22 @@
         }
     }
 
+    public static JFile parseFile(File file) throws FileNotFoundException, ParseException
{
+        curDir = file.getParent();
+        curFileName = file.getName();
+        FileReader reader = new FileReader(file);
+        try {
+            Rcc parser = new Rcc(reader);
+            recTab = new Hashtable();
+            return parser.Input();
+        } finally {
+            try {
+                reader.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+
   final public JFile Input() throws ParseException {
     ArrayList ilist = new ArrayList();
     ArrayList rlist = new ArrayList();

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/rcc.jj
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/rcc.jj?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/rcc.jj (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/jute/compiler/generated/rcc.jj Fri Jul
25 14:19:47 2008
@@ -33,15 +33,16 @@
 import java.io.IOException;
 
 public class Rcc {
-    private static String language = "java";
-    private static ArrayList recFiles = new ArrayList();
-    private static JFile curFile;
-    private static Hashtable recTab;
+    private static Hashtable recTab = new Hashtable();
     private static String curDir = System.getProperty("user.dir");
     private static String curFileName;
     private static String curModuleName;
 
     public static void main(String args[]) {
+        String language = "java";
+        ArrayList recFiles = new ArrayList();
+        JFile curFile=null;
+        
         for (int i=0; i<args.length; i++) {
             if ("-l".equalsIgnoreCase(args[i]) ||
                 "--language".equalsIgnoreCase(args[i])) {
@@ -61,36 +62,41 @@
         }
         for (int i=0; i<recFiles.size(); i++) {
             curFileName = (String) recFiles.get(i);
-            File file = new File(curDir, curFileName);
+            File file = new File(curFileName);
             try {
-                FileReader reader = new FileReader(file);
-                Rcc parser = new Rcc(reader);
-                try {
-                    recTab = new Hashtable();
-                    curFile = parser.Input();
-                    System.out.println((String) recFiles.get(i) +
-                        " Parsed Successfully");
-                } catch (ParseException e) {
-                    System.out.println(e.toString());
-                    System.exit(1);
-                }
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                }
+                curFile = parseFile(file);
             } catch (FileNotFoundException e) {
-                System.out.println("File " + (String) recFiles.get(i) +
-                    " Not found.");
+                System.out.println("File " + (String) recFiles.get(i) + " Not found.");
+                System.exit(1);
+            } catch (ParseException e) {
+                System.out.println(e.toString());
                 System.exit(1);
             }
+            System.out.println((String) recFiles.get(i) + " Parsed Successfully");
             try {
-                curFile.genCode(language);
+                curFile.genCode(language, new File("."));
             } catch (IOException e) {
                 System.out.println(e.toString());
                 System.exit(1);
             }
         }
     }
+
+    public static JFile parseFile(File file) throws FileNotFoundException, ParseException
{
+        curDir = file.getParent();
+        curFileName = file.getName();
+        FileReader reader = new FileReader(file);
+        try {
+            Rcc parser = new Rcc(reader);
+            recTab = new Hashtable();
+            return parser.Input();
+        } finally {
+            try {
+                reader.close();
+            } catch (IOException e) {
+            }
+        }
+    }
 }
 
 PARSER_END(Rcc)

Modified: hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/version/util/VerGen.java
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/version/util/VerGen.java?rev=679901&r1=679900&r2=679901&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/version/util/VerGen.java (original)
+++ hadoop/zookeeper/trunk/src/java/main/org/apache/zookeeper/version/util/VerGen.java Fri
Jul 25 14:19:47 2008
@@ -32,10 +32,10 @@
         System.exit(1);
     }
 
-    static void generateFile(int maj, int min, int micro, int rev,
+    static void generateFile(File outputDir, int maj, int min, int micro, int rev,
             String buildDate) {
         String path = PACKAGE_NAME.replaceAll("\\.", "/");
-        File pkgdir = new File(path);
+        File pkgdir = new File(outputDir, path);
         if (!pkgdir.exists()) {
             // create the pkg directory
             boolean ret = pkgdir.mkdirs();
@@ -100,7 +100,7 @@
             int min = Integer.parseInt(v[1]);
             int micro = Integer.parseInt(v[2]);
             int rev = Integer.parseInt(args[1]);
-            generateFile(maj, min, micro, rev, args[2]);
+            generateFile(new File("."), maj, min, micro, rev, args[2]);
         } catch (NumberFormatException e) {
             System.err
                 .println("All version-related parameters must be valid integers!");



Mime
View raw message