Browse Source

Main: fixed a pb with the -D parameter

Project: prints the os as well as jdk version
taskdefs.Exec: Fixed issues with Win95
Submitted by: Ludovic Claude <lc@websitewatchers.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267560 13f79535-47bb-0310-9956-ffa450edef68
master
Sam Ruby 25 years ago
parent
commit
b139901cab
4 changed files with 42 additions and 23 deletions
  1. +2
    -1
      src/bin/antRun.bat
  2. +14
    -3
      src/main/org/apache/tools/ant/Main.java
  3. +2
    -0
      src/main/org/apache/tools/ant/Project.java
  4. +24
    -19
      src/main/org/apache/tools/ant/taskdefs/Exec.java

+ 2
- 1
src/bin/antRun.bat View File

@@ -1,3 +1,4 @@
@echo off
cd %1
echo %2 %3 %4 %5 %6 %7 %8 %9
%2 %3 %4 %5 %6 %7 %8 %9 2>&1
%2 %3 %4 %5 %6 %7 %8 %9

+ 14
- 3
src/main/org/apache/tools/ant/Main.java View File

@@ -140,14 +140,25 @@ public class Main {
} else if (arg.startsWith("-D")) {

/* Interestingly enough, we get to here when a user
* uses -Dname=value. However, the JDK goes ahead
* and parses this out to args {"-Dname", "value"}
* uses -Dname=value. However, in some cases, the JDK
* goes ahead * and parses this out to args
* {"-Dname", "value"}
* so instead of parsing on "=", we just make the "-D"
* characters go away and skip one argument forward.
*
* I don't know how to predict when the JDK is going
* to help or not, so we simply look for the equals sign.
*/

String name = arg.substring(2, arg.length());
String value = args[++i];
String value = null;
int posEq = name.indexOf("=");
if (posEq > 0) {
value = name.substring(posEq+1);
name = name.substring(0, posEq);
} else if (i < args.length)
value = args[++i];

definedProps.put(name, value);
} else if (arg.startsWith("-")) {
// we don't have any more args to recognize!


+ 2
- 0
src/main/org/apache/tools/ant/Project.java View File

@@ -270,6 +270,8 @@ public class Project {
}

log("Detected Java Version: " + javaVersion);

log("Detected OS: " + System.getProperty("os.name"), MSG_VERBOSE);
}

public void addTaskDefinition(String taskName, Class taskClass) {


+ 24
- 19
src/main/org/apache/tools/ant/taskdefs/Exec.java View File

@@ -97,29 +97,17 @@ public class Exec extends Task {

// exec command on system runtime
Process proc = Runtime.getRuntime().exec(command);
// get process response
BufferedReader din = new BufferedReader(new InputStreamReader(proc.getInputStream()));

// if "out" attribute is present, redirect to it
PrintWriter fos = null;
if (out != null) {
fos = new PrintWriter(new FileWriter(out));
PrintWriter fos=null;
if( out!=null ) {
fos=new PrintWriter( new FileWriter( out ) );
project.log("Output redirected to " + out, Project.MSG_VERBOSE);
}
pipeOutput(proc.getInputStream(), "exec", fos);
pipeOutput(proc.getErrorStream(), "error", fos);
if (null != fos)
fos.close();


// pipe the process output
String line;
while((line = din.readLine()) != null) {
if (fos == null) {
project.log(line, "exec", Project.MSG_INFO);
} else {
fos.println(line);
}
}

// wait until the process is finished
proc.waitFor();
// close the output file if required
@@ -151,4 +139,21 @@ public class Exec extends Task {
public void setOutput(String out) {
this.out = out;
}

private void pipeOutput(InputStream is, String name, PrintWriter fos)
throws IOException
{
project.log("pipeOutput", name, Project.MSG_INFO);
InputStreamReader isr=new InputStreamReader(is);
BufferedReader din = new BufferedReader(isr);

// pipe output to STDOUT
String line;
while((line = din.readLine()) != null) {
if( fos==null)
project.log(line, name, Project.MSG_INFO);
else
fos.println(line);
}
}
}

Loading…
Cancel
Save