You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2003/02/11 11:08:40 UTC

cvs commit: ant/src/main/org/apache/tools/ant/taskdefs Execute.java

bodewig     2003/02/11 02:08:40

  Modified:    src/main/org/apache/tools/ant/taskdefs Execute.java
  Log:
  Don't use "cd /d" on OS/2.
  
  PR: 16924
  Submitted by:	Zdenek Wagner <wagner at cesnet dot cz>
  
  Revision  Changes    Path
  1.50      +50 -4     ant/src/main/org/apache/tools/ant/taskdefs/Execute.java
  
  Index: Execute.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Execute.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- Execute.java	10 Feb 2003 14:13:34 -0000	1.49
  +++ Execute.java	11 Feb 2003 10:08:39 -0000	1.50
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -118,8 +118,8 @@
               // Mac
               shellLauncher = new MacCommandLauncher(new CommandLauncher());
           } else if (Os.isFamily("os/2")) {
  -            // OS/2 - use same mechanism as Windows 2000
  -            shellLauncher = new WinNTCommandLauncher(new CommandLauncher());
  +            // OS/2
  +            shellLauncher = new OS2CommandLauncher(new CommandLauncher());
           } else if (Os.isFamily("windows")) {
               // Windows.  Need to determine which JDK we're running in
   
  @@ -688,6 +688,52 @@
           }
   
           private CommandLauncher _launcher;
  +    }
  +
  +    /**
  +     * A command launcher for OS/2 that uses 'cmd.exe' when launching
  +     * commands in directories other than the current working
  +     * directory.
  +     *
  +     * <p>Unlike Windows NT and friends, OS/2's cd doesn't support the
  +     * /d switch to change drives and directories in one go.</p>
  +     */
  +    private static class OS2CommandLauncher extends CommandLauncherProxy {
  +        OS2CommandLauncher(CommandLauncher launcher) {
  +            super(launcher);
  +        }
  +
  +        /**
  +         * Launches the given command in a new process, in the given working
  +         * directory.
  +         */
  +        public Process exec(Project project, String[] cmd, String[] env,
  +                            File workingDir) throws IOException {
  +            File commandDir = workingDir;
  +            if (workingDir == null) {
  +                if (project != null) {
  +                    commandDir = project.getBaseDir();
  +                } else {
  +                    return exec(project, cmd, env);
  +                }
  +            }
  +
  +            // Use cmd.exe to change to the specified drive and
  +            // directory before running the command
  +            final int preCmdLength = 7;
  +            final String cmdDir = commandDir.getAbsolutePath();
  +            String[] newcmd = new String[cmd.length + preCmdLength];
  +            newcmd[0] = "cmd";
  +            newcmd[1] = "/c";
  +            newcmd[2] = cmdDir.substring(0, 2);
  +            newcmd[3] = "&&";
  +            newcmd[4] = "cd";
  +            newcmd[5] = cmdDir.substring(2);
  +            newcmd[6] = "&&";
  +            System.arraycopy(cmd, 0, newcmd, preCmdLength, cmd.length);
  +
  +            return exec(project, newcmd, env);
  +        }
       }
   
       /**