Browse Source

Added a utility class to hold util functions for implementing Launchers.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270279 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Donald 24 years ago
parent
commit
d0225d0b52
1 changed files with 102 additions and 0 deletions
  1. +102
    -0
      proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ExecUtil.java

+ 102
- 0
proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/ExecUtil.java View File

@@ -0,0 +1,102 @@
/*
* 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$ $Date$
*/
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 );
}
}

Loading…
Cancel
Save