You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by do...@apache.org on 2001/12/19 12:48:26 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec PerlScriptCommandLauncher.java MacCommandLauncher.java
donaldp 01/12/19 03:48:26
Added: proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec
PerlScriptCommandLauncher.java
MacCommandLauncher.java
Log:
Move command launchers to top level classes. Inner classes are evil.
Revision Changes Path
1.1 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/PerlScriptCommandLauncher.java
Index: PerlScriptCommandLauncher.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.exec;
import org.apache.tools.ant.Project;
import org.apache.myrmidon.api.TaskException;
import org.apache.avalon.excalibur.io.FileUtil;
import java.io.File;
import java.io.IOException;
/**
* A command launcher that uses an auxiliary perl script to launch commands
* in directories other than the current working directory.
*/
class PerlScriptCommandLauncher
extends CommandLauncherProxy
{
private String _script;
PerlScriptCommandLauncher( String script, CommandLauncher launcher )
{
super( launcher );
_script = script;
}
/**
* Launches the given command in a new process, in the given working
* directory
*
* @param project Description of Parameter
* @param cmd Description of Parameter
* @param env Description of Parameter
* @param workingDir Description of Parameter
* @return Description of the Returned Value
* @exception IOException Description of Exception
*/
public Process exec( Project project, String[] cmd, String[] env, File workingDir )
throws IOException, TaskException
{
if( project == null )
{
if( workingDir == null )
{
return exec( project, cmd, env );
}
throw new IOException( "Cannot locate antRun script: No project provided" );
}
// Locate the auxiliary script
String antHome = project.getProperty( "ant.home" );
if( antHome == null )
{
throw new IOException( "Cannot locate antRun script: Property 'ant.home' not found" );
}
String antRun = FileUtil.
resolveFile( project.getBaseDir(), antHome + File.separator + _script ).toString();
// Build the command
File commandDir = workingDir;
if( workingDir == null && project != null )
{
commandDir = project.getBaseDir();
}
String[] newcmd = new String[ cmd.length + 3 ];
newcmd[ 0 ] = "perl";
newcmd[ 1 ] = antRun;
newcmd[ 2 ] = commandDir.getAbsolutePath();
System.arraycopy( cmd, 0, newcmd, 3, cmd.length );
return exec( project, newcmd, env );
}
}
1.1 jakarta-ant/proposal/myrmidon/src/main/org/apache/tools/ant/taskdefs/exec/MacCommandLauncher.java
Index: MacCommandLauncher.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.tools.ant.taskdefs.exec;
import org.apache.tools.ant.Project;
import org.apache.myrmidon.api.TaskException;
import java.io.File;
import java.io.IOException;
/**
* A command launcher for Mac that uses a dodgy mechanism to change working
* directory before launching commands.
*/
class MacCommandLauncher
extends CommandLauncherProxy
{
MacCommandLauncher( CommandLauncher launcher )
{
super( launcher );
}
/**
* Launches the given command in a new process, in the given working
* directory
*
* @param project Description of Parameter
* @param cmd Description of Parameter
* @param env Description of Parameter
* @param workingDir Description of Parameter
* @return Description of the Returned Value
* @exception IOException Description of Exception
*/
public Process exec( Project project, String[] cmd, String[] env, File workingDir )
throws IOException, TaskException
{
if( workingDir == null )
{
return exec( project, cmd, env );
}
System.getProperties().put( "user.dir", workingDir.getAbsolutePath() );
try
{
return exec( project, cmd, env );
}
finally
{
System.getProperties().put( "user.dir", Execute.antWorkingDirectory );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>