[jboss-cvs] JBossAS SVN: r104244 - projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 25 20:57:27 EDT 2010


Author: jeff.zhang
Date: 2010-04-25 20:57:26 -0400 (Sun, 25 Apr 2010)
New Revision: 104244

Modified:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
Log:
[JBJCA-306] support -o to redirect output directory

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-04-25 21:51:11 UTC (rev 104243)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-04-26 00:57:26 UTC (rev 104244)
@@ -38,7 +38,8 @@
  */
 public class Main
 {
-
+   private static final int OTHER = 2;
+   
    /**
     * Code generator standalone tool
     * 
@@ -46,11 +47,37 @@
     */
    public static void main(String[] args)
    {
-      Locale locale = Locale.getDefault();
-      
+      String outputDir = ".";
+      int arg = 0;
+ 
+      if (args.length > 0)
+      {
+         while (args.length > arg + 1)
+         {
+            if (args[arg].startsWith("-"))
+            {
+               if (args[arg].equals("-o"))
+               {
+                  arg++;
+                  if (arg >= args.length)
+                  {
+                     usage();
+                     System.exit(OTHER);
+                  }
+                  outputDir = args[arg];
+               }
+            } 
+            else
+            {
+               usage();
+               System.exit(OTHER);
+            }
+            arg++;
+         }
+      }
       try 
       {
-         ResourceBundle dbconf = ResourceBundle.getBundle("codegenerator", locale);
+         ResourceBundle dbconf = ResourceBundle.getBundle("codegenerator", Locale.getDefault());
 
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          System.out.print(dbconf.getString("package.name"));
@@ -82,13 +109,9 @@
             props.add(config);
          }
          def.setRaConfigProps(props);
+
          
-         System.out.print(dbconf.getString("output.dir"));
-         String output = in.readLine();
-         if (output == null || output.equals(""))
-            output = ".";
-         
-         File outDir = new File(output);
+         File outDir = new File(outputDir);
          outDir.mkdirs();
          
          File report = new File(outDir, className + ".java");
@@ -103,4 +126,12 @@
       }
    }
 
+   /**
+    * Tool usage
+    */
+   private static void usage()
+   {
+      System.out.println("Usage: codegenerator [-o directory]");
+   }
+
 }




More information about the jboss-cvs-commits mailing list