From c94f06426355f244dc6c34d926d83fd643274a41 Mon Sep 17 00:00:00 2001 From: Peter Donald Date: Sat, 22 Dec 2001 12:38:54 +0000 Subject: [PATCH] Made it possible for the script to consist of multiple parts so that you could possible do something like perl bin/antRun.pl python bin/antRun.py etc This resulted in removal of file resolving and pushing that back into the Execute task git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270303 13f79535-47bb-0310-9956-ffa450edef68 --- .../exec/launchers/ScriptCommandLauncher.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java index 81ff04dfb..af064637d 100644 --- a/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java +++ b/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ScriptCommandLauncher.java @@ -8,15 +8,15 @@ package org.apache.myrmidon.framework.exec.launchers; import java.io.IOException; -import java.io.File; import org.apache.myrmidon.api.TaskException; import org.apache.myrmidon.framework.exec.CommandLauncher; import org.apache.myrmidon.framework.exec.ExecMetaData; -import org.apache.avalon.excalibur.io.FileUtil; /** * A command launcher that uses an auxiliary script to launch commands in - * directories other than the current working directory. + * directories other than the current working directory. The script specified + * in the constructor is invoked with the directory passed as second argument + * and the actual command as subsequent arguments. * * @author Peter Donald * @author Thomas Haas @@ -25,11 +25,33 @@ import org.apache.avalon.excalibur.io.FileUtil; public class ScriptCommandLauncher implements CommandLauncher { - private String m_script; + private String[] m_script; + /** + * Create a command launcher whos script is a single + * command. An example would be "bin/antRun.bat". + */ public ScriptCommandLauncher( final String script ) + { + this( new String[]{script} ); + } + + /** + * Create a command launcher whos script takes multiple + * commands. Examples would be "perl bin/antRun.pl", + * "python bin/antRun.py", ""tcl8 bin/antRun.tcl" etc + */ + public ScriptCommandLauncher( final String[] script ) { m_script = script; + if( null == m_script ) + { + throw new NullPointerException( "script" ); + } + if( 0 == m_script.length ) + { + throw new IllegalArgumentException( "script" ); + } } /** @@ -39,13 +61,13 @@ public class ScriptCommandLauncher public Process exec( final ExecMetaData metaData ) throws IOException, TaskException { - final File homeDir = ExecUtil.getAntHomeDirectory(); - final String script = FileUtil.resolveFile( homeDir, m_script ).toString(); - // Build the command - final String[] prefix = new String[ 2 ]; - prefix[ 0 ] = script; - prefix[ 1 ] = metaData.getWorkingDirectory().getCanonicalPath(); + final String[] prefix = new String[ m_script.length + 1 ]; + for( int i = 0; i < m_script.length; i++ ) + { + prefix[ i ] = m_script[ i ]; + } + prefix[ m_script.length ] = metaData.getWorkingDirectory().getCanonicalPath(); final ExecMetaData newMetaData = ExecUtil.prepend( metaData, prefix ); return Runtime.getRuntime().