You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by br...@apache.org on 2005/08/19 06:08:04 UTC
svn commit: r233427 - in /jakarta/commons/sandbox/exec/trunk/src: bin/
main/java/org/apache/commons/exec/
main/java/org/apache/commons/exec/launcher/
test/java/org/apache/commons/exec/
Author: brett
Date: Thu Aug 18 21:07:50 2005
New Revision: 233427
URL: http://svn.apache.org/viewcvs?rev=233427&view=rev
Log:
PR: 36159
remove support for Java 1.1 to simplify
Removed:
jakarta/commons/sandbox/exec/trunk/src/bin/
Modified:
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java
jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java Thu Aug 18 21:07:50 2005
@@ -46,11 +46,6 @@
private boolean incompatibleWithSpawn = false;
- /**
- * Controls whether the VM (1.3 and above) is used to execute the command.
- */
- private boolean vmLauncher = true;
-
public Exec() {
// default cnstr
}
@@ -300,18 +295,6 @@
*/
/**
- * Sets a flag indicating if we want to launch new process with VM,
- * otherwise use the OS's shell. Default value of the flag is true.
- *
- * @param vmLauncher
- * true if we want to launch new process with VM, false if we
- * want to use the OS's shell.
- */
- public void setVMLauncher(final boolean vmLauncher) {
- this.vmLauncher = vmLauncher;
- }
-
- /**
* Create an Execute instance with the correct working directory set.
*
* @param error
@@ -339,7 +322,6 @@
createWatchdog());
exe.setWorkingDirectory(dir);
- exe.setVMLauncher(vmLauncher);
exe.setNewEnvironment(newEnvironment);
exe.setEnvironment(env.getVariables());
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java Thu Aug 18 21:07:50 2005
@@ -52,17 +52,11 @@
private boolean newEnvironment = false;
- /** Controls whether the VM is used to launch commands, where possible */
- private boolean useVMLauncher = true;
-
private static String userWorkingDirectory = System.getProperty("user.dir");
private static CommandLauncher vmLauncher = CommandLauncherFactory
.createVMLauncher();
- private static CommandLauncher shellLauncher = CommandLauncherFactory
- .createShellLauncher();
-
/** Used to destroy processes when the VM exits. */
private static ProcessDestroyer processDestroyer = new ProcessDestroyer();
@@ -212,20 +206,6 @@
}
/**
- * Launch this execution through the VM, where possible, rather than through
- * the OS's shell. In some cases and operating systems using the shell will
- * allow the shell to perform additional processing such as associating an
- * executable with a script, etc
- *
- * @param useVMLauncher
- * true if exec should launch through the VM, false if the shell
- * should be used to launch the command.
- */
- public void setVMLauncher(final boolean useVMLauncher) {
- this.useVMLauncher = useVMLauncher;
- }
-
- /**
* Creates a process that runs a command.
*
* @param command
@@ -241,18 +221,9 @@
* forwarded from the particular launcher used
*/
public static Process launch(final CommandLine command,
- final Environment env, final File dir, final boolean useVM)
+ final Environment env, final File dir)
throws IOException {
- CommandLauncher launcher;
- if (vmLauncher != null) {
- launcher = vmLauncher;
- } else {
- launcher = shellLauncher;
- }
-
- if (!useVM) {
- launcher = shellLauncher;
- }
+ CommandLauncher launcher = vmLauncher;
if (dir != null && !dir.exists()) {
throw new IOException(dir + " doesn't exist.");
@@ -274,7 +245,7 @@
}
final Process process = launch(getCommandline(), getEnvironment(),
- workingDirectory, useVMLauncher);
+ workingDirectory);
try {
streamHandler.setProcessInputStream(process.getOutputStream());
@@ -327,7 +298,7 @@
throw new ExecuteException(workingDirectory + " doesn't exist.");
}
final Process process = launch(getCommandline(), getEnvironment(),
- workingDirectory, useVMLauncher);
+ workingDirectory);
if (OS.isFamilyWindows()) {
try {
Thread.sleep(1000);
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ProcessDestroyer.java Thu Aug 18 21:07:50 2005
@@ -17,8 +17,6 @@
package org.apache.commons.exec;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Vector;
@@ -27,199 +25,152 @@
*/
class ProcessDestroyer implements Runnable {
- private Vector processes = new Vector();
+ private Vector processes = new Vector();
- // methods to register and unregister shutdown hooks
- private Method addShutdownHookMethod;
+ private ProcessDestroyerImpl destroyProcessThread = null;
- private Method removeShutdownHookMethod;
-
- private ProcessDestroyerImpl destroyProcessThread = null;
-
- // whether or not this ProcessDestroyer has been registered as a
- // shutdown hook
- private boolean added = false;
-
- // whether or not this ProcessDestroyer is currently running as
- // shutdown hook
- private boolean running = false;
-
- private class ProcessDestroyerImpl extends Thread {
- private boolean shouldDestroy = true;
-
- public ProcessDestroyerImpl() {
- super("ProcessDestroyer Shutdown Hook");
- }
-
- public void run() {
- if (shouldDestroy) {
- ProcessDestroyer.this.run();
- }
- }
-
- public void setShouldDestroy(final boolean shouldDestroy) {
- this.shouldDestroy = shouldDestroy;
- }
- }
-
- /**
- * Constructs a <code>ProcessDestroyer</code> and obtains
- * <code>Runtime.addShutdownHook()</code> and
- * <code>Runtime.removeShutdownHook()</code> through reflection. The
- * ProcessDestroyer manages a list of processes to be destroyed when the VM
- * exits. If a process is added when the list is empty, this
- * <code>ProcessDestroyer</code> is registered as a shutdown hook. If
- * removing a process results in an empty list, the
- * <code>ProcessDestroyer</code> is removed as a shutdown hook.
- */
- public ProcessDestroyer() {
- try {
- // check to see if the shutdown hook methods exists
- // (support pre-JDK 1.3 VMs)
- Class[] paramTypes = {Thread.class};
- addShutdownHookMethod = Runtime.class.getMethod("addShutdownHook",
- paramTypes);
-
- removeShutdownHookMethod = Runtime.class.getMethod(
- "removeShutdownHook", paramTypes);
- // wait to add shutdown hook as needed
- } catch (NoSuchMethodException e) {
- // it just won't be added as a shutdown hook... :(
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Registers this <code>ProcessDestroyer</code> as a shutdown hook, uses
- * reflection to ensure pre-JDK 1.3 compatibility.
- */
- private void addShutdownHook() {
- if (addShutdownHookMethod != null && !running) {
- destroyProcessThread = new ProcessDestroyerImpl();
- Object[] args = {destroyProcessThread};
- try {
- addShutdownHookMethod.invoke(Runtime.getRuntime(), args);
- added = true;
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- Throwable t = e.getTargetException();
- if (t != null && t.getClass() == IllegalStateException.class) {
- // shutdown already is in progress
- running = true;
- } else {
- e.printStackTrace();
- }
- }
- }
- }
-
- /**
- * Removes this <code>ProcessDestroyer</code> as a shutdown hook, uses
- * reflection to ensure pre-JDK 1.3 compatibility
- */
- private void removeShutdownHook() {
- if (removeShutdownHookMethod != null && added && !running) {
- Object[] args = {destroyProcessThread};
- try {
- Boolean removed = (Boolean) removeShutdownHookMethod.invoke(
- Runtime.getRuntime(), args);
- if (!removed.booleanValue()) {
- System.err.println("Could not remove shutdown hook");
- }
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- Throwable t = e.getTargetException();
- if (t != null && t.getClass() == IllegalStateException.class) {
- // shutdown already is in progress
- running = true;
- } else {
- e.printStackTrace();
- }
- }
- /*
- * start the hook thread, a unstarted thread may not be
- * eligible for garbage collection
- * Cf.:
- * http://developer.java.sun.com/developer/
- * bugParade/bugs/4533087.html
- */
-
- destroyProcessThread.setShouldDestroy(false);
- destroyProcessThread.start();
- // this should return quickly, since it basically is a NO-OP.
- try {
- destroyProcessThread.join(20000);
- } catch (InterruptedException ie) {
- // the thread didn't die in time
- // it should not kill any processes unexpectedly
- }
- destroyProcessThread = null;
- added = false;
- }
- }
-
- /**
- * Returns whether or not the ProcessDestroyer is registered as as shutdown
- * hook
- *
- * @return true if this is currently added as shutdown hook
- */
- public boolean isAddedAsShutdownHook() {
- return added;
- }
-
- /**
- * Returns <code>true</code> if the specified <code>Process</code> was
- * successfully added to the list of processes to destroy upon VM exit.
- *
- * @param process
- * the process to add
- * @return <code>true</code> if the specified <code>Process</code> was
- * successfully added
- */
- public boolean add(final Process process) {
- synchronized (processes) {
- // if this list is empty, register the shutdown hook
- if (processes.size() == 0) {
- addShutdownHook();
- }
- processes.addElement(process);
- return processes.contains(process);
- }
- }
-
- /**
- * Returns <code>true</code> if the specified <code>Process</code> was
- * successfully removed from the list of processes to destroy upon VM exit.
- *
- * @param process
- * the process to remove
- * @return <code>true</code> if the specified <code>Process</code> was
- * successfully removed
- */
- public boolean remove(final Process process) {
- synchronized (processes) {
- boolean processRemoved = processes.removeElement(process);
- if (processRemoved && processes.size() == 0) {
- removeShutdownHook();
- }
- return processRemoved;
- }
- }
-
- /**
- * Invoked by the VM when it is exiting.
- */
- public void run() {
- synchronized (processes) {
- running = true;
- Enumeration e = processes.elements();
- while (e.hasMoreElements()) {
- ((Process) e.nextElement()).destroy();
- }
- }
- }
+ // whether or not this ProcessDestroyer has been registered as a
+ // shutdown hook
+ private boolean added = false;
+
+ // whether or not this ProcessDestroyer is currently running as
+ // shutdown hook
+ private boolean running = false;
+
+ private class ProcessDestroyerImpl extends Thread {
+ private boolean shouldDestroy = true;
+
+ public ProcessDestroyerImpl() {
+ super("ProcessDestroyer Shutdown Hook");
+ }
+
+ public void run() {
+ if (shouldDestroy) {
+ ProcessDestroyer.this.run();
+ }
+ }
+
+ public void setShouldDestroy(final boolean shouldDestroy) {
+ this.shouldDestroy = shouldDestroy;
+ }
+ }
+
+ /**
+ * Constructs a <code>ProcessDestroyer</code> and obtains
+ * <code>Runtime.addShutdownHook()</code> and
+ * <code>Runtime.removeShutdownHook()</code> through reflection. The
+ * ProcessDestroyer manages a list of processes to be destroyed when the VM
+ * exits. If a process is added when the list is empty, this
+ * <code>ProcessDestroyer</code> is registered as a shutdown hook. If
+ * removing a process results in an empty list, the
+ * <code>ProcessDestroyer</code> is removed as a shutdown hook.
+ */
+ public ProcessDestroyer() {
+ }
+
+ /**
+ * Registers this <code>ProcessDestroyer</code> as a shutdown hook, uses
+ * reflection to ensure pre-JDK 1.3 compatibility.
+ */
+ private void addShutdownHook() {
+ if (!running) {
+ destroyProcessThread = new ProcessDestroyerImpl();
+ Runtime.getRuntime().addShutdownHook(destroyProcessThread);
+ added = true;
+ }
+ }
+
+ /**
+ * Removes this <code>ProcessDestroyer</code> as a shutdown hook, uses
+ * reflection to ensure pre-JDK 1.3 compatibility
+ */
+ private void removeShutdownHook() {
+ if (added && !running) {
+ boolean removed = Runtime.getRuntime().removeShutdownHook(
+ destroyProcessThread);
+ if (!removed) {
+ // System.err.println("Could not remove shutdown hook");
+ // TODO should we just ignore?
+ }
+ /*
+ * start the hook thread, a unstarted thread may not be eligible for
+ * garbage collection Cf.: http://developer.java.sun.com/developer/
+ * bugParade/bugs/4533087.html
+ */
+
+ destroyProcessThread.setShouldDestroy(false);
+ destroyProcessThread.start();
+ // this should return quickly, since it basically is a NO-OP.
+ try {
+ destroyProcessThread.join(20000);
+ } catch (InterruptedException ie) {
+ // the thread didn't die in time
+ // it should not kill any processes unexpectedly
+ }
+ destroyProcessThread = null;
+ added = false;
+ }
+ }
+
+ /**
+ * Returns whether or not the ProcessDestroyer is registered as as shutdown
+ * hook
+ *
+ * @return true if this is currently added as shutdown hook
+ */
+ public boolean isAddedAsShutdownHook() {
+ return added;
+ }
+
+ /**
+ * Returns <code>true</code> if the specified <code>Process</code> was
+ * successfully added to the list of processes to destroy upon VM exit.
+ *
+ * @param process
+ * the process to add
+ * @return <code>true</code> if the specified <code>Process</code> was
+ * successfully added
+ */
+ public boolean add(final Process process) {
+ synchronized (processes) {
+ // if this list is empty, register the shutdown hook
+ if (processes.size() == 0) {
+ addShutdownHook();
+ }
+ processes.addElement(process);
+ return processes.contains(process);
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if the specified <code>Process</code> was
+ * successfully removed from the list of processes to destroy upon VM exit.
+ *
+ * @param process
+ * the process to remove
+ * @return <code>true</code> if the specified <code>Process</code> was
+ * successfully removed
+ */
+ public boolean remove(final Process process) {
+ synchronized (processes) {
+ boolean processRemoved = processes.removeElement(process);
+ if (processRemoved && processes.size() == 0) {
+ removeShutdownHook();
+ }
+ return processRemoved;
+ }
+ }
+
+ /**
+ * Invoked by the VM when it is exiting.
+ */
+ public void run() {
+ synchronized (processes) {
+ running = true;
+ Enumeration e = processes.elements();
+ while (e.hasMoreElements()) {
+ ((Process) e.nextElement()).destroy();
+ }
+ }
+ }
}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import org.apache.commons.exec.OS;
@@ -21,65 +38,13 @@
try {
if (OS.isFamilyOpenVms()) {
launcher = new VmsCommandLauncher();
- } else if (!OS.isFamilyOS2()) {
+ // TODO why not use Java13CommandLauncher on OS2?
+ //} else if (!OS.isFamilyOS2()) {
+ } else {
launcher = new Java13CommandLauncher();
}
} catch (NoSuchMethodException exc) {
// Ignore and keep trying
- }
-
- return launcher;
- }
-
- public static CommandLauncher createShellLauncher() {
- CommandLauncher launcher = null;
-
- if (OS.isFamilyMac() && !OS.isFamilyUnix()) {
- // Mac
- launcher = new MacCommandLauncher(new CommandLauncherImpl());
- } else if (OS.isFamilyOS2()) {
- // OS/2
- launcher = new OS2CommandLauncher(new CommandLauncherImpl());
- } else if (OS.isFamilyWindows()) {
- // Windows. Need to determine which JDK we're running in
-
- CommandLauncher baseLauncher;
- if (System.getProperty("java.version").startsWith("1.1")) {
- // JDK 1.1
- baseLauncher = new Java11CommandLauncher();
- } else {
- // JDK 1.2
- baseLauncher = new CommandLauncherImpl();
- }
-
- if (!OS.isFamilyWin9x()) {
- // Windows XP/2000/NT
- launcher = new WinNTCommandLauncher(baseLauncher);
- } else {
- // Windows 98/95 - need to use an auxiliary script
- launcher = new ScriptCommandLauncher("bin/antRun.bat",
- baseLauncher);
- }
- } else if (OS.isFamilyNetware()) {
- // NetWare. Need to determine which JDK we're running in
- CommandLauncher baseLauncher;
- if (System.getProperty("java.version").startsWith("1.1")) {
- // JDK 1.1
- baseLauncher = new Java11CommandLauncher();
- } else {
- // JDK 1.2
- baseLauncher = new CommandLauncherImpl();
- }
-
- launcher = new PerlScriptCommandLauncher("bin/antRun.pl",
- baseLauncher);
- } else if (OS.isFamilyOpenVms()) {
- // the vmLauncher already uses the shell
- launcher = createVMLauncher();
- } else {
- // Generic
- launcher = new ScriptCommandLauncher("bin/antRun",
- new CommandLauncherImpl());
}
return launcher;
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
@@ -11,7 +28,7 @@
* purpose command launcher which can only launch commands in the current
* working directory.
*/
-public class CommandLauncherImpl implements CommandLauncher {
+public abstract class CommandLauncherImpl implements CommandLauncher {
/*
* (non-Javadoc)
*
@@ -35,12 +52,6 @@
* @see org.apache.commons.exec.launcher.CommandLauncherIn#exec(java.lang.String[],
* java.lang.String[], java.io.File)
*/
- public Process exec(final CommandLine cmd, final Environment env,
- final File workingDir) throws IOException {
- if (workingDir == null) {
- return exec(cmd, env);
- }
- throw new IOException("Cannot execute a process in different "
- + "directory under this JVM");
- }
+ public abstract Process exec(final CommandLine cmd, final Environment env,
+ final File workingDir) throws IOException;
}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.IOException;
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java11CommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,47 +0,0 @@
-package org.apache.commons.exec.launcher;
-
-import java.io.IOException;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.CommandLineImpl;
-import org.apache.commons.exec.environment.Environment;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * A command launcher for JDK/JRE 1.1 under Windows. Fixes quoting problems in
- * Runtime.exec(). Can only launch commands in the current working directory
- */
-public class Java11CommandLauncher extends CommandLauncherImpl {
-
- private static final Log LOG = LogFactory
- .getLog(Java11CommandLauncher.class);
-
- /**
- * Launches the given command in a new process. Needs to quote arguments
- *
- * @param cmd
- * the command line to execute as an array of strings
- * @param env
- * the environment to set as an array of strings
- * @throws IOException
- * probably forwarded from Runtime#exec
- */
- public Process exec(final CommandLine cmd, final Environment env)
- throws IOException {
- // Need to quote arguments with spaces, and to escape
- // quote characters
- CommandLine newCmd = new CommandLineImpl();
- newCmd.setExecutable(
- CommandLineImpl.quoteArgument(cmd.getExecutable()));
-
- String[] args = cmd.getArguments();
- for (int i = 0; i < args.length; i++) {
- newCmd.addArgument(CommandLineImpl.quoteArgument(args[i]));
- }
- LOG.debug("Execute:Java11CommandLauncher: " + newCmd);
-
- return Runtime.getRuntime().exec(newCmd.getCommandline(),
- env.getVariables());
- }
-}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,11 +1,27 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import org.apache.commons.exec.ExecuteException;
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.environment.Environment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -14,53 +30,37 @@
* Runtime.exec() command
*/
public class Java13CommandLauncher extends CommandLauncherImpl {
- private static Log log = LogFactory.getLog(Java13CommandLauncher.class);
+ private static Log log = LogFactory.getLog(Java13CommandLauncher.class);
- public Java13CommandLauncher() throws NoSuchMethodException {
- // Locate method Runtime.exec(String[] cmdarray,
- // String[] envp, File dir)
- myExecWithCWD = Runtime.class.getMethod("exec", new Class[] {
- String[].class, String[].class, File.class});
- }
-
- /**
- * Launches the given command in a new process, in the given working
- * directory
- *
- * @param project
- * the ant project
- * @param cmd
- * the command line to execute as an array of strings
- * @param env
- * the environment to set as an array of strings
- * @param workingDir
- * the working directory where the command should run
- * @throws IOException
- * probably forwarded from Runtime#exec
- */
- public Process exec(final String[] cmd, final String[] env,
- final File workingDir) throws IOException {
- try {
- log.debug("Execute:Java13CommandLauncher: " + cmd);
-
- Object[] arguments = {cmd, env, workingDir};
- return (Process) myExecWithCWD.invoke(Runtime.getRuntime(),
- arguments);
- } catch (InvocationTargetException exc) {
- Throwable realexc = exc.getTargetException();
- if (realexc instanceof ThreadDeath) {
- throw (ThreadDeath) realexc;
- } else if (realexc instanceof IOException) {
- throw (IOException) realexc;
- } else {
- throw new ExecuteException("Unable to execute command",
- realexc);
- }
- } catch (Exception exc) {
- // IllegalAccess, IllegalArgument, ClassCast
- throw new ExecuteException("Unable to execute command", exc);
- }
- }
+ public Java13CommandLauncher() {
+ }
- private Method myExecWithCWD;
+ /**
+ * Launches the given command in a new process, in the given working
+ * directory
+ *
+ * @param project
+ * the ant project
+ * @param cmd
+ * the command line to execute as an array of strings
+ * @param env
+ * the environment to set as an array of strings
+ * @param workingDir
+ * the working directory where the command should run
+ * @throws IOException
+ * probably forwarded from Runtime#exec
+ */
+ public Process exec(final CommandLine cmd, final Environment env,
+ final File workingDir) throws IOException {
+ log.debug("Execute:Java13CommandLauncher: " + cmd);
+
+ String[] envVars = null;
+ if(env != null) {
+ envVars = env.getVariables();
+ }
+
+
+ return (Process) Runtime.getRuntime().exec(cmd.getCommandline(),
+ envVars, workingDir);
+ }
}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/MacCommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,46 +0,0 @@
-package org.apache.commons.exec.launcher;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.environment.Environment;
-
-/**
- * A command launcher for Mac that uses a dodgy mechanism to change working
- * directory before launching commands.
- */
-public class MacCommandLauncher extends CommandLauncherProxy {
- public MacCommandLauncher(final CommandLauncher launcher) {
- super(launcher);
- }
-
- /**
- * Launches the given command in a new process, in the given working
- * directory.
- *
- * @param cmd
- * the command line to execute as an array of strings
- * @param env
- * the environment to set as an array of strings
- * @param workingDir
- * working directory where the command should run
- * @throws IOException
- * forwarded from the exec method of the command launcher
- */
- public Process exec(final CommandLine cmd, final Environment env,
- final File workingDir) throws IOException {
- if (workingDir == null) {
- return exec(cmd, env);
- }
-
- String oldUserDir = System.getProperty("user.dir");
-
- System.getProperties().put("user.dir", workingDir.getAbsolutePath());
- try {
- return exec(cmd, env);
- } finally {
- System.getProperties().put("user.dir", oldUserDir);
- }
- }
-}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
@@ -42,17 +59,9 @@
return exec(cmd, env);
}
- final String cmdDir = workingDir.getAbsolutePath();
-
CommandLine newCmd = new CommandLineImpl();
newCmd.setExecutable("cmd");
newCmd.addArgument("/c");
- // TODO calculate root by walking
- newCmd.addArgument(cmdDir.substring(0, 2));
- newCmd.addArgument("&&");
- newCmd.addArgument("cd");
- newCmd.addArgument(cmdDir.substring(2));
- newCmd.addArgument("&&");
newCmd.addArguments(cmd.getCommandline());
return exec(newCmd, env);
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/PerlScriptCommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,50 +0,0 @@
-package org.apache.commons.exec.launcher;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.CommandLineImpl;
-import org.apache.commons.exec.environment.Environment;
-
-/**
- * A command launcher that uses an auxiliary perl script to launch commands in
- * directories other than the current working directory.
- */
-public class PerlScriptCommandLauncher extends CommandLauncherProxy {
- public PerlScriptCommandLauncher(final String script,
- final CommandLauncher launcher) {
- super(launcher);
- this.script = script;
- }
-
- /**
- * Launches the given command in a new process, in the given working
- * directory
- */
- public Process exec(final CommandLine cmd, final Environment env,
- final File workingDir) throws IOException {
-
- if (workingDir == null) {
- return exec(cmd, env);
- }
-
- // Locate the auxiliary script
- String scriptDir = System.getProperty("org.apache.commons.exec.home", "");
- File scriptFile = new File(scriptDir + File.separator + script);
- if (scriptFile.exists()) {
- throw new IOException("Cannot locate auxiliary script at " +
- scriptFile.getAbsolutePath());
- }
-
- CommandLine newCmd = new CommandLineImpl();
- newCmd.setExecutable("perl");
- newCmd.addArgument(scriptFile.getPath());
- newCmd.addArgument(workingDir.getAbsolutePath());
- newCmd.addArguments(cmd.getCommandline());
-
- return exec(newCmd, env);
- }
-
- private String script;
-}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/ScriptCommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,49 +0,0 @@
-package org.apache.commons.exec.launcher;
-
-import java.io.File;
-import java.io.IOException;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.CommandLineImpl;
-import org.apache.commons.exec.environment.Environment;
-
-/**
- * A command launcher that uses an auxiliary script to launch commands in
- * directories other than the current working directory.
- */
-public class ScriptCommandLauncher extends CommandLauncherProxy {
- public ScriptCommandLauncher(final String script,
- final CommandLauncher launcher) {
- super(launcher);
- this.script = script;
- }
-
- /**
- * Launches the given command in a new process, in the given working
- * directory.
- */
- public Process exec(final CommandLine cmd, final Environment env,
- final File workingDir) throws IOException {
- if (workingDir == null) {
- return exec(cmd, env);
- }
-
- // Locate the auxiliary script
- String scriptDir = System.getProperty("org.apache.commons.exec.home", "");
- File scriptFile = new File(scriptDir + File.separator + script);
- if (scriptFile.exists()) {
- throw new IOException("Cannot locate auxiliary script at " +
- scriptFile.getAbsolutePath());
- }
-
- // Build the command
- CommandLine newCmd = new CommandLineImpl();
- newCmd.setExecutable(scriptFile.getPath());
- newCmd.addArgument(workingDir.getAbsolutePath());
- newCmd.addArguments(cmd.getCommandline());
-
- return exec(newCmd, env);
- }
-
- private String script;
-}
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec.launcher;
import java.io.File;
@@ -40,10 +57,6 @@
CommandLine newCmd = new CommandLineImpl();
newCmd.setExecutable("cmd");
newCmd.addArgument("/c");
- newCmd.addArgument("cd");
- newCmd.addArgument("/d");
- newCmd.addArgument(workingDir.getAbsolutePath());
- newCmd.addArgument("&&");
newCmd.addArguments(cmd.getCommandline());
return exec(newCmd, env);
Modified: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java?rev=233427&r1=233426&r2=233427&view=diff
==============================================================================
--- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java (original)
+++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java Thu Aug 18 21:07:50 2005
@@ -1,3 +1,20 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.commons.exec;
import junit.framework.AssertionFailedError;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org