ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1350461 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/ src/main/org/apache/tools/ant/taskdefs/ src/main/org/apache/tools/ant/taskdefs/launcher/
Date Fri, 15 Jun 2012 04:34:05 GMT
Author: bodewig
Date: Fri Jun 15 04:34:04 2012
New Revision: 1350461

URL: http://svn.apache.org/viewvc?rev=1350461&view=rev
Log:
PR 52706: allow command launcher to be selected via a task.  Submitted by Vimil Saju

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/contributors.xml
    ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/CommandLauncherTask.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/CommandLauncher.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/Java13CommandLauncher.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/PerlScriptCommandLauncher.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/ScriptCommandLauncher.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/VmsCommandLauncher.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/CONTRIBUTORS (original)
+++ ant/core/trunk/CONTRIBUTORS Fri Jun 15 04:34:04 2012
@@ -357,6 +357,7 @@ Trejkaz Xaoza
 Ulrich Schmidt
 Valentino Miazzo
 Victor Toni
+Vimil Saju
 Vincent Legoll
 Volker Leidl
 Waldek Herka

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Fri Jun 15 04:34:04 2012
@@ -1441,6 +1441,10 @@
     <last>Legoll</last>
   </name>
   <name>
+    <first>Vimil</first>
+    <last>Saju</last>
+  </name>
+  <name>
     <first>Volker</first>
     <last>Leidl</last>
   </name>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/MagicNames.java Fri Jun 15 04:34:04 2012
@@ -248,5 +248,33 @@ public final class MagicNames {
      */
     public static final String PROJECT_INVOKED_TARGETS
         = "ant.project.invoked-targets";
+
+    /**
+     * Name of the project reference holding an instance of {@link
+     * org.apache.tools.ant.taskdefs.launcher.CommandLauncher} to use
+     * when executing commands with the help of an external skript.
+     *
+     * <p>Alternatively this is the name of a system property holding
+     * the fully qualified class name of a {@link
+     * org.apache.tools.ant.taskdefs.launcher.CommandLauncher}.</p>
+     *
+     * Value: {@value}
+     * @since Ant 1.9.0
+     */
+    public static final String ANT_SHELL_LAUNCHER_REF_ID = "ant.shellLauncher";
+
+    /**
+     * Name of the project reference holding an instance of {@link
+     * org.apache.tools.ant.taskdefs.launcher.CommandLauncher} to use
+     * when executing commands without the help of an external skript.
+     *
+     * <p>Alternatively this is the name of a system property holding
+     * the fully qualified class name of a {@link
+     * org.apache.tools.ant.taskdefs.launcher.CommandLauncher}.</p>
+     *
+     * Value: {@value}
+     * @since Ant 1.9.0
+     */
+    public static final String ANT_VM_LAUNCHER_REF_ID = "ant.vmLauncher";
 }
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/CommandLauncherTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/CommandLauncherTask.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/CommandLauncherTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/CommandLauncherTask.java Fri Jun
15 04:34:04 2012
@@ -4,6 +4,12 @@ import org.apache.tools.ant.BuildExcepti
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.taskdefs.launcher.CommandLauncher;
 
+/**
+ * Task that configures the {@link
+ * org.apache.tools.ant.taskdefs.launcher.CommandLauncher} to used
+ * when starting external processes.
+ * @since Ant 1.9.0
+ */
 public class CommandLauncherTask extends Task {
     private boolean vmLauncher;
     private CommandLauncher commandLauncher;

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/CommandLauncher.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/CommandLauncher.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/CommandLauncher.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/CommandLauncher.java Fri
Jun 15 04:34:04 2012
@@ -3,6 +3,9 @@ package org.apache.tools.ant.taskdefs.la
 import java.io.File;
 import java.io.IOException;
 
+import static org.apache.tools.ant.MagicNames.ANT_SHELL_LAUNCHER_REF_ID;
+import static org.apache.tools.ant.MagicNames.ANT_VM_LAUNCHER_REF_ID;
+
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.Commandline;
@@ -14,8 +17,6 @@ import org.apache.tools.ant.util.FileUti
  * in the current working directory.
  */
 public class CommandLauncher {
-    private static final String ANT_SHELL_LAUNCHER_REF_ID = "ant.shellLauncher";
-    private static final String ANT_VM_LAUNCHER_REF_ID = "ant.vmLauncher";
 
     protected static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
 
@@ -23,13 +24,8 @@ public class CommandLauncher {
     private static CommandLauncher shellLauncher = null;
 
     static {
-        // Try using a JDK 1.3 launcher
-        try {
-            if(!Os.isFamily("os/2")) {
-                vmLauncher = new Java13CommandLauncher();
-            }
-        } catch(NoSuchMethodException exc) {
-            // Ignore and keep trying
+        if(!Os.isFamily("os/2")) {
+            vmLauncher = new Java13CommandLauncher();
         }
 
         if (Os.isFamily("mac") && !Os.isFamily("unix")) {
@@ -46,23 +42,22 @@ public class CommandLauncher {
                 shellLauncher = new WinNTCommandLauncher(baseLauncher);
             } else {
                 // Windows 98/95 - need to use an auxiliary script
-                shellLauncher = new ScriptCommandLauncher("bin/antRun.bat", baseLauncher);
+                shellLauncher =
+                    new ScriptCommandLauncher("bin/antRun.bat", baseLauncher);
             }
         } else if (Os.isFamily("netware")) {
 
             CommandLauncher baseLauncher = new CommandLauncher();
 
-            shellLauncher = new PerlScriptCommandLauncher("bin/antRun.pl", baseLauncher);
+            shellLauncher =
+                new PerlScriptCommandLauncher("bin/antRun.pl", baseLauncher);
         } else if (Os.isFamily("openvms")) {
             // OpenVMS
-            try {
-                shellLauncher = new VmsCommandLauncher();
-            } catch(NoSuchMethodException exc) {
-                // Ignore and keep trying
-            }
+            shellLauncher = new VmsCommandLauncher();
         } else {
             // Generic
-            shellLauncher = new ScriptCommandLauncher("bin/antRun", new CommandLauncher());
+            shellLauncher = new ScriptCommandLauncher("bin/antRun",
+                new CommandLauncher());
         }
     }
 
@@ -80,9 +75,11 @@ public class CommandLauncher {
      * @throws IOException
      *         if attempting to run a command in a specific directory.
      */
-    public Process exec(Project project, String[] cmd, String[] env) throws IOException {
+    public Process exec(Project project, String[] cmd, String[] env)
+        throws IOException {
         if(project != null) {
-            project.log("Execute:CommandLauncher: " + Commandline.describeCommand(cmd), Project.MSG_DEBUG);
+            project.log("Execute:CommandLauncher: "
+                + Commandline.describeCommand(cmd), Project.MSG_DEBUG);
         }
         return Runtime.getRuntime().exec(cmd, env);
     }
@@ -105,23 +102,22 @@ public class CommandLauncher {
      * @throws IOException
      *         if trying to change directory.
      */
-    public Process exec(Project project, String[] cmd, String[] env, File workingDir) throws
IOException {
-        if(workingDir == null) {
+    public Process exec(Project project, String[] cmd, String[] env,
+                        File workingDir) throws IOException {
+        if (workingDir == null) {
             return exec(project, cmd, env);
         }
         throw new IOException("Cannot execute a process in different "
-                              + "directory under this JVM");
+            + "directory under this JVM");
     }
 
+    /**
+     * Obtains the shell launcher configured for the given project or
+     * the default shell launcher.
+     */
     public static CommandLauncher getShellLauncher(Project project) {
-        CommandLauncher launcher = null;
-        if(project != null) {
-            launcher = (CommandLauncher) project
-                .getReference(ANT_SHELL_LAUNCHER_REF_ID);
-        }
-        if (launcher == null) {
-            launcher = getSystemLauncher(ANT_SHELL_LAUNCHER_REF_ID);
-        }
+        CommandLauncher launcher = extractLauncher(ANT_SHELL_LAUNCHER_REF_ID,
+                                                   project);
         if (launcher == null) {
             launcher = shellLauncher;
         }
@@ -129,17 +125,28 @@ public class CommandLauncher {
         return launcher;
     }
 
+    /**
+     * Obtains the VM launcher configured for the given project or
+     * the default VM launcher.
+     */
     public static CommandLauncher getVMLauncher(Project project) {
+        CommandLauncher launcher = extractLauncher(ANT_VM_LAUNCHER_REF_ID,
+                                                   project);
+        if (launcher == null) {
+            launcher = vmLauncher;
+        }
+        return launcher;
+    }
+
+    private static CommandLauncher extractLauncher(String referenceName,
+                                                   Project project) {
         CommandLauncher launcher = null;
         if (project != null) {
-            launcher = (CommandLauncher)project.getReference(ANT_VM_LAUNCHER_REF_ID);
+            launcher = (CommandLauncher) project.getReference(referenceName);
         }
 
         if (launcher == null) {
-            launcher = getSystemLauncher(ANT_VM_LAUNCHER_REF_ID);
-        }
-        if (launcher == null) {
-            launcher = vmLauncher;
+            launcher = getSystemLauncher(referenceName);
         }
         return launcher;
     }
@@ -169,13 +176,21 @@ public class CommandLauncher {
         return launcher;
     }
 
-    public static void setVMLauncher(Project project, CommandLauncher launcher) {
+    /**
+     * Sets the VM launcher to use for the given project.
+     */
+    public static void setVMLauncher(Project project,
+                                     CommandLauncher launcher) {
         if (project != null) {
             project.addReference(ANT_VM_LAUNCHER_REF_ID, launcher);
         }
     }
 
-    public static void setShellLauncher(Project project, CommandLauncher launcher) {
+    /**
+     * Sets the shell launcher to use for the given project.
+     */
+    public static void setShellLauncher(Project project,
+                                        CommandLauncher launcher) {
         if (project != null) {
             project.addReference(ANT_SHELL_LAUNCHER_REF_ID, launcher);
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/Java13CommandLauncher.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/Java13CommandLauncher.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/Java13CommandLauncher.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/Java13CommandLauncher.java
Fri Jun 15 04:34:04 2012
@@ -13,10 +13,6 @@ import org.apache.tools.ant.types.Comman
  */
 public class Java13CommandLauncher extends CommandLauncher {
 
-    public Java13CommandLauncher() throws NoSuchMethodException {
-        // Used to verify if Java13 is available, is prerequisite in ant 1.8
-    }
-
     /**
      * Launches the given command in a new process, in the given
      * working directory.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/PerlScriptCommandLauncher.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/PerlScriptCommandLauncher.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/PerlScriptCommandLauncher.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/PerlScriptCommandLauncher.java
Fri Jun 15 04:34:04 2012
@@ -38,7 +38,7 @@ public class PerlScriptCommandLauncher e
     public Process exec(Project project, String[] cmd, String[] env,
                         File workingDir) throws IOException {
         if (project == null) {
-            if(workingDir == null) {
+            if (workingDir == null) {
                 return exec(project, cmd, env);
             }
             throw new IOException("Cannot locate antRun script: "

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/ScriptCommandLauncher.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/ScriptCommandLauncher.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/ScriptCommandLauncher.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/ScriptCommandLauncher.java
Fri Jun 15 04:34:04 2012
@@ -46,7 +46,7 @@ public class ScriptCommandLauncher exten
         }
         // Locate the auxiliary script
         String antHome = project.getProperty(MagicNames.ANT_HOME);
-        if(antHome == null) {
+        if (antHome == null) {
             throw new IOException("Cannot locate antRun script: "
                                   + "Property '" + MagicNames.ANT_HOME
                                   + "' not found");
@@ -57,7 +57,7 @@ public class ScriptCommandLauncher exten
 
         // Build the command
         File commandDir = workingDir;
-        if(workingDir == null) {
+        if (workingDir == null) {
             commandDir = project.getBaseDir();
         }
         String[] newcmd = new String[cmd.length + 2];

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/VmsCommandLauncher.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/VmsCommandLauncher.java?rev=1350461&r1=1350460&r2=1350461&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/VmsCommandLauncher.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/launcher/VmsCommandLauncher.java
Fri Jun 15 04:34:04 2012
@@ -15,7 +15,7 @@ import org.apache.tools.ant.util.FileUti
  */
 public class VmsCommandLauncher extends Java13CommandLauncher {
 
-    public VmsCommandLauncher() throws NoSuchMethodException {
+    public VmsCommandLauncher() {
         super();
     }
 



Mime
View raw message