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/21 14:16:39 UTC
cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers ExecUtil.java
donaldp 01/12/21 05:16:39
Added: proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers
ExecUtil.java
Log:
Added a utility class to hold util functions for implementing Launchers.
Revision Changes Path
1.1 jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ExecUtil.java
Index: ExecUtil.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.myrmidon.framework.exec.launchers;
import java.io.File;
import java.io.IOException;
import org.apache.myrmidon.framework.exec.ExecMetaData;
/**
* A set of utility functions useful when writing CommandLaunchers.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2001/12/21 13:16:39 $
*/
class ExecUtil
{
/**
* The file representing the current working directory.
*/
private static final File c_cwd;
static
{
try
{
c_cwd = ( new File( "." ) ).getCanonicalFile();
}
catch( final IOException ioe )
{
//Should never happen
throw new IllegalStateException();
}
}
/**
* Private constructor to block instantiation.
*/
private ExecUtil()
{
}
/**
* Create a new ExecMetaData representing the same command with the specified
* prefix. This is useful when you are launching the native executable via a
* script of some sort.
*/
protected static ExecMetaData prepend( final ExecMetaData metaData,
final String[] prefix )
{
final String[] original = metaData.getCommand();
final String[] command = new String[ original.length + prefix.length ];
System.arraycopy( prefix, 0, command, 0, prefix.length );
System.arraycopy( original, 0, command, prefix.length, original.length );
return new ExecMetaData( command,
metaData.getEnvironment(),
metaData.getWorkingDirectory(),
metaData.isEnvironmentAdditive() );
}
/**
* Utility method to check if specified file is equal
* to the current working directory.
*/
protected static boolean isCwd( final File file )
throws IOException
{
return file.getCanonicalFile().equals( getCwd() );
}
/**
* Return the current working directory of the JVM.
* This value is initialized when this class is first loaded.
*/
protected static File getCwd()
{
return c_cwd;
}
/**
* Retrieve the directory in which Myrmidon is installed.
* This is used to determine the locaiton of scripts in various launchers.
*/
protected static File getAntHomeDirectory()
{
final String antHome = System.getProperty( "ant.home" );
if( null == antHome )
{
final String message =
"Cannot locate antRun script: Property 'ant.home' not specified";
throw new IllegalStateException( message );
}
return new File( antHome );
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>