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 2002/01/05 04:09:24 UTC

cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers Resources.properties DefaultCommandLauncher.java

donaldp     02/01/04 19:09:24

  Modified:    proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers
                        DefaultCommandLauncher.java
  Added:       proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers
                        Resources.properties
  Log:
  Made sure that setting of environment variables for the native exec calls occurs accoridng to epectations.
  
  If no properties are specified then null is passed to underlying exec call.
  
  if some properties are set and environment is additive then the native environment is added to environment object
  
  Revision  Changes    Path
  1.5       +35 -5     jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java
  
  Index: DefaultCommandLauncher.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/DefaultCommandLauncher.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultCommandLauncher.java	23 Dec 2001 02:54:35 -0000	1.4
  +++ DefaultCommandLauncher.java	5 Jan 2002 03:09:24 -0000	1.5
  @@ -11,7 +11,11 @@
   import java.io.IOException;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  +import java.util.Properties;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
   import org.apache.myrmidon.framework.exec.CommandLauncher;
  +import org.apache.myrmidon.framework.exec.Environment;
   import org.apache.myrmidon.framework.exec.ExecException;
   import org.apache.myrmidon.framework.exec.ExecMetaData;
   
  @@ -22,11 +26,14 @@
    *
    * @author <a href="mailto:peter@apache.org">Peter Donald</a>
    * @author <a href="mailto:thomas.haas@softwired-inc.com">Thomas Haas</a>
  - * @version $Revision: 1.4 $ $Date: 2001/12/23 02:54:35 $
  + * @version $Revision: 1.5 $ $Date: 2002/01/05 03:09:24 $
    */
   public class DefaultCommandLauncher
       implements CommandLauncher
   {
  +    private static final Resources REZ =
  +        ResourceManager.getPackageResources( DefaultCommandLauncher.class );
  +
       private static final Method c_execWithCWD;
   
       static
  @@ -64,13 +71,12 @@
       {
           if( ExecUtil.isCwd( metaData.getWorkingDirectory() ) )
           {
  -            final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
  +            final String[] env = getEnvironmentSpec( metaData );
               return Runtime.getRuntime().exec( metaData.getCommand(), env );
           }
           else if( null == c_execWithCWD )
           {
  -            final String message = "Unable to launch native command in a " +
  -                "working directory other than \".\"";
  +            final String message = REZ.getString( "default.bad-dir.error" );
               throw new ExecException( message );
           }
           else
  @@ -79,6 +85,30 @@
           }
       }
   
  +    private String[] getEnvironmentSpec( final ExecMetaData metaData )
  +        throws ExecException, IOException
  +    {
  +        final Properties environment = metaData.getEnvironment();
  +        if( 0 == environment.size() )
  +        {
  +            return null;
  +        }
  +        else
  +        {
  +            if( metaData.isEnvironmentAdditive() )
  +            {
  +                final Properties newEnvironment = new Properties();
  +                newEnvironment.putAll( environment );
  +                newEnvironment.putAll( Environment.getNativeEnvironment() );
  +                return ExecUtil.toNativeEnvironment( newEnvironment );
  +            }
  +            else
  +            {
  +                return ExecUtil.toNativeEnvironment( environment );
  +            }
  +        }
  +    }
  +
       /**
        * Execute the Java1.3 Runtime.exec() 3 parame method that sets working
        * directory. This needs to be done via reflection so that it can compile
  @@ -87,7 +117,7 @@
       private Process execJava13( final ExecMetaData metaData )
           throws IOException, ExecException
       {
  -        final String[] env = ExecUtil.toNativeEnvironment( metaData.getEnvironment() );
  +        final String[] env = getEnvironmentSpec( metaData );
           final Object[] args =
               {metaData.getCommand(),
                env,
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/myrmidon/framework/exec/launchers/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  default.bad-dir.error=Unable to launch native command in a working directory other than "." on Java 1.2 JVMs.
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>