[jboss-cvs] JBossAS SVN: r104258 - in projects/jboss-jca/trunk/codegenerator/src/main: resources and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 27 00:44:08 EDT 2010


Author: jeff.zhang
Date: 2010-04-27 00:44:07 -0400 (Tue, 27 Apr 2010)
New Revision: 104258

Added:
   projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Utils.java
   projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template
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/SimpleTemplate.java
Log:
[JBJCA-308] generate build.xml file for building and package rar file

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-27 01:47:43 UTC (rev 104257)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Main.java	2010-04-27 04:44:07 UTC (rev 104258)
@@ -26,6 +26,7 @@
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -48,7 +49,7 @@
     */
    public static void main(String[] args)
    {
-      String outputDir = ".";
+      String outputDir = "out"; //default output directory
       int arg = 0;
  
       if (args.length > 0)
@@ -111,9 +112,17 @@
          }
          def.setRaConfigProps(props);
 
-         FileWriter fw = createFile(className, packageName, outputDir);
+         FileWriter fw = createSrcFile(className + ".java", packageName, outputDir);
          template.process(def, fw);
          fw.close();
+         
+         //ant build.xml
+         FileWriter antfw = createFile("build.xml", outputDir);
+         URL headerFile = SimpleTemplate.class.getResource("/build.xml.template");
+         String headerString = Utils.readFileIntoString(headerFile);
+         antfw.write(headerString);
+         antfw.close();
+         
          System.out.println(dbconf.getString("java.wrote"));
       }
       catch (Exception e)
@@ -121,30 +130,51 @@
          e.printStackTrace();
       }
    }
+   
    /**
-    * Create file
+    * Create source file
     * @param name The name of the class
     * @param packageName The package name
     * @param outDir output directory
     * @return The file
     * @exception IOException Thrown if an error occurs 
     */
-   public static FileWriter createFile(String name, String packageName, String outDir) throws IOException
+   private static FileWriter createSrcFile(String name, String packageName, String outDir) throws IOException
    {
-      File path = new File(".");
+      String directory = "src";
 
       if (packageName != null && !packageName.trim().equals(""))
       {
-         String directory = packageName.replace('.', File.separatorChar);
-         directory += File.separatorChar;
+         directory = directory + File.separatorChar +
+                     packageName.replace('.', File.separatorChar);
+      }
 
-         path = new File(outDir, directory);
+      File path = new File(outDir, directory);
+      if (!path.exists())
+         path.mkdirs();
+      
+      File file = new File(path.getAbsolutePath() + File.separatorChar + name);
 
-         if (!path.exists())
-            path.mkdirs();
-      }
+      if (file.exists())
+         file.delete();
 
-      File file = new File(path.getAbsolutePath() + File.separatorChar + name + ".java");
+      return new FileWriter(file);
+   }
+   
+   /**
+    * Create file
+    * @param name The name of the class
+    * @param outDir output directory
+    * @return The file
+    * @exception IOException Thrown if an error occurs 
+    */
+   private static FileWriter createFile(String name, String outDir) throws IOException
+   {
+      File path = new File(outDir);
+      if (!path.exists())
+         path.mkdirs();
+      
+      File file = new File(path.getAbsolutePath() + File.separatorChar + name);
 
       if (file.exists())
          file.delete();

Modified: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java	2010-04-27 01:47:43 UTC (rev 104257)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/SimpleTemplate.java	2010-04-27 04:44:07 UTC (rev 104258)
@@ -22,9 +22,6 @@
 package org.jboss.jca.codegenerator;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.Reader;
 import java.io.Writer;
 import java.net.URL;
 
@@ -88,7 +85,7 @@
    private void writeheader(Definition def, Writer out) throws IOException
    {
       URL headerFile = SimpleTemplate.class.getResource("/header.template");
-      String headerString = readFileIntoString(headerFile);
+      String headerString = Utils.readFileIntoString(headerFile);
       out.write(headerString);
       writeEol(out);
    }
@@ -392,7 +389,7 @@
       out.write("public void endpointDeactivation(MessageEndpointFactory endpointFactory,");
       writeEol(out);
       writeIndent(out, indent + 1);
-      out.write("ActivationSpec spec) throws ResourceException");
+      out.write("ActivationSpec spec)");
       writeLeftCurlyBracket(out, indent);
       writeIndent(out, indent + 1);
       out.write("log.debug(\"call endpointDeactivation\");");
@@ -400,54 +397,4 @@
       writeEol(out);
    }
 
-
-   /**
-    *  Reads the contents of a file into a string variable.
-    * 
-    * @param input
-    * @return
-    * @throws IOException ioException
-    */
-   private String readFileIntoString(URL input) throws IOException
-   {
-      
-      InputStream stream = null;
-      InputStreamReader reader = null;
-      try
-      {
-         stream = input.openStream();
-         reader = new InputStreamReader(stream);
-         return readStreamIntoString(reader);
-      }
-      finally
-      {
-         if (reader != null)
-            reader.close();
-         if (stream != null)
-            stream.close();
-      }
-   }
-
-   /**
-    *  Reads the contents of a stream into a string variable.
-    * 
-    * @param reader
-    * @return
-    * @throws IOException ioException
-    */
-   private String readStreamIntoString(Reader reader) throws IOException
-   {
-      StringBuilder s = new StringBuilder();
-      char a[] = new char[0x10000];
-      while (true)
-      {
-         int l = reader.read(a);
-         if (l == -1)
-            break;
-         if (l <= 0)
-            throw new IOException();
-         s.append(a, 0, l);
-      }
-      return s.toString();
-   }
 }

Added: projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Utils.java
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Utils.java	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/java/org/jboss/jca/codegenerator/Utils.java	2010-04-27 04:44:07 UTC (rev 104258)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.jca.codegenerator;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
+/**
+ * A Utils.
+ * @version $Revision: $
+ */
+public class Utils
+{
+   /**
+    *  Reads the contents of a file into a string variable.
+    * 
+    * @param input url 
+    * @return string of return
+    * @throws IOException ioException
+    */
+   public static String readFileIntoString(URL input) throws IOException
+   {
+      
+      InputStream stream = null;
+      InputStreamReader reader = null;
+      try
+      {
+         stream = input.openStream();
+         reader = new InputStreamReader(stream);
+         return readStreamIntoString(reader);
+      }
+      finally
+      {
+         if (reader != null)
+            reader.close();
+         if (stream != null)
+            stream.close();
+      }
+   }
+
+   /**
+    *  Reads the contents of a stream into a string variable.
+    * 
+    * @param reader url
+    * @return string of return
+    * @throws IOException ioException
+    */
+   private static String readStreamIntoString(Reader reader) throws IOException
+   {
+      StringBuilder s = new StringBuilder();
+      char a[] = new char[0x10000];
+      while (true)
+      {
+         int l = reader.read(a);
+         if (l == -1)
+            break;
+         if (l <= 0)
+            throw new IOException();
+         s.append(a, 0, l);
+      }
+      return s.toString();
+   }
+}

Added: projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template
===================================================================
--- projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template	                        (rev 0)
+++ projects/jboss-jca/trunk/codegenerator/src/main/resources/build.xml.template	2010-04-27 04:44:07 UTC (rev 104258)
@@ -0,0 +1,36 @@
+<project name="jca-test" basedir="." default="rar">
+
+  <!-- ================================= 
+       Properties              
+       ================================= -->
+  <property name="target.dir" value="${basedir}/target" />
+  <property name="lib.dir" value="${basedir}/../../../lib" />
+
+  <path id="lib.path.id">
+    <fileset dir="${lib.dir}">
+      <include name="**/*.jar"/>
+    </fileset>
+  </path>
+  
+  <!-- ================================= 
+       Target: compile
+       ================================= -->
+  <target name="compile">
+    <mkdir dir="${target.dir}" />
+
+    <javac srcdir="${basedir}/src"
+           destdir="${target.dir}"
+           classpathref="lib.path.id">
+    </javac> 
+  </target>
+  
+  <!-- ================================= 
+       Target: rar
+       ================================= -->
+  <target name="rar" depends="compile">
+    <mkdir dir="${basedir}/rar" />
+
+    <jar destfile="${basedir}/rar/jca-test.rar"
+         basedir="${basedir}/target"/>
+  </target>
+</project>
\ No newline at end of file




More information about the jboss-cvs-commits mailing list