[jboss-cvs] JBossAS SVN: r70891 - projects/ejb3/trunk/installer/src/main/java/org/jboss/ejb3/installer.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Mar 15 20:27:42 EDT 2008


Author: ALRubinger
Date: 2008-03-15 20:27:42 -0400 (Sat, 15 Mar 2008)
New Revision: 70891

Modified:
   projects/ejb3/trunk/installer/src/main/java/org/jboss/ejb3/installer/Installer.java
Log:
[EJBTHREE-1205] Change detection of Ant Process to creation of actual Process, not presence of a path

Modified: projects/ejb3/trunk/installer/src/main/java/org/jboss/ejb3/installer/Installer.java
===================================================================
--- projects/ejb3/trunk/installer/src/main/java/org/jboss/ejb3/installer/Installer.java	2008-03-15 23:41:07 UTC (rev 70890)
+++ projects/ejb3/trunk/installer/src/main/java/org/jboss/ejb3/installer/Installer.java	2008-03-16 00:27:42 UTC (rev 70891)
@@ -69,6 +69,7 @@
     * Environment Property key for ANT_HOME 
     */
    private static final String ENV_PROPERTY_ANT_HOME = "ANT_HOME";
+
    /*
     * Environment Property key for ANT_CMD 
     */
@@ -320,30 +321,85 @@
     */
    private void runAnt()
    {
+
+      try
+      {
+         // Get the Process
+         Process antProcess = this.getAntProcess();
+
+         // Capture the output
+         Thread captureProcess = new CaptureProcess(antProcess);
+         captureProcess.start();
+
+         // Ensure proper completion, block until done
+         int exitValue = antProcess.waitFor();
+         if (exitValue == 0)
+         {
+            this.getPrintStream().println("Ant Build Completed");
+         }
+         else
+         {
+            throw new RuntimeException("Ant Process completed improperly with Exit Value " + exitValue);
+         }
+      }
+      catch (IOException ioe)
+      {
+         // Other I/O Error
+         throw new RuntimeException(ioe);
+      }
+      catch (InterruptedException ie)
+      {
+         throw new RuntimeException(ie);
+      }
+
+   }
+
+   /**
+    * Obtains the Ant Process
+    * 
+    * @return
+    * @throws IOException
+    */
+   private Process getAntProcess() throws IOException
+   {
+      return this.getAntProcess(false);
+   }
+
+   /**
+    * Obtains the Ant Process.  If "useBatchExtension" is false, no extension will 
+    * be added on first attempt, but the batch extension will be tried if the first 
+    * try without it fails.
+    * 
+    * @param useBatchExtension
+    * @return
+    * @throws IOException
+    */
+   private Process getAntProcess(boolean useBatchExtension) throws IOException
+   {
       // Initialize
       Process antProcess = null;
       String buildfile = this.getInstallationDirectory() + File.separator + Installer.FILENAME_BUILDFILE;
 
       // Try
       String antCommandPath = System.getenv(Installer.ENV_PROPERTY_ANT_CMD);
-      if(antCommandPath == null)
+      if (antCommandPath == null)
       {
          // Obtain ANT_HOME and ensure specified
          String antHome = System.getenv(Installer.ENV_PROPERTY_ANT_HOME);
          if (antHome == null || "".equals(antHome))
          {
-            throw new RuntimeException("Environment Variable '" + Installer.ENV_PROPERTY_ANT_HOME + "' must be specified.");
+            throw new RuntimeException("Environment Variable '" + Installer.ENV_PROPERTY_ANT_HOME
+                  + "' must be specified.");
          }
          this.getPrintStream().println("Using ANT_HOME: " + antHome);
-   
+
          // Construct "ant" command path
          antCommandPath = antHome + File.separator + "bin" + File.separator + Installer.COMMAND_ANT;
       }
 
-      // If "ant" doesn't exist
-      if (!new File(antCommandPath).exists())
+      // If we should use the batch extension
+      if (useBatchExtension)
       {
-         this.getPrintStream().println(antCommandPath+" does not exist, trying .bat extension");
          // Add batch extension
          antCommandPath = antCommandPath + Installer.COMMAND_EXTENSION_BATCH;
       }
@@ -362,39 +418,29 @@
          this.getPrintStream().println(
                "Starting Ant> " + antCommandPath + " " + Installer.SWITCH_ANT_BUILDFILE + " " + buildfile);
          antProcess = antProcessBuilder.start();
-
-         // Capture the output
-         Thread captureProcess = new CaptureProcess(antProcess);
-         captureProcess.start();
-
-         // Ensure proper completion, block until done
-         int exitValue = antProcess.waitFor();
-         if (exitValue == 0)
-         {
-            this.getPrintStream().println("Ant Build Completed");
-         }
-         else
-         {
-            throw new RuntimeException("Ant Process completed improperly with Exit Value " + exitValue);
-         }
       }
       catch (IOException ioe)
       {
-         // The command could not be found
-         if (antProcess == null)
+         // The command could not be found, and we've tried the batch extension
+         if (antProcess == null && useBatchExtension)
          {
             throw new RuntimeException(
                   "Ensure Apache Ant is properly installed and Environment Variable ANT_HOME is set", ioe);
          }
-
-         // Other I/O Error
-         throw new RuntimeException(ioe);
+         // The command could not be found, but we haven't yet tried the batch extension
+         else if (antProcess == null && !useBatchExtension)
+         {
+            return this.getAntProcess(true);
+         }
+         // Miscellaneous IOException
+         else
+         {
+            throw ioe;
+         }
       }
-      catch (InterruptedException ie)
-      {
-         throw new RuntimeException(ie);
-      }
 
+      // Return
+      return antProcess;
    }
 
    /**




More information about the jboss-cvs-commits mailing list