From b139901cab374b10e2f73a58769fb4ef1c2837bd Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Tue, 25 Jan 2000 23:03:22 +0000 Subject: [PATCH] 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 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267560 13f79535-47bb-0310-9956-ffa450edef68 --- src/bin/antRun.bat | 3 +- src/main/org/apache/tools/ant/Main.java | 17 ++++++-- src/main/org/apache/tools/ant/Project.java | 2 + .../org/apache/tools/ant/taskdefs/Exec.java | 43 +++++++++++-------- 4 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/bin/antRun.bat b/src/bin/antRun.bat index b6dc95e6e..8216d1847 100755 --- a/src/bin/antRun.bat +++ b/src/bin/antRun.bat @@ -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 diff --git a/src/main/org/apache/tools/ant/Main.java b/src/main/org/apache/tools/ant/Main.java index b89e00a9e..f044aa0c0 100644 --- a/src/main/org/apache/tools/ant/Main.java +++ b/src/main/org/apache/tools/ant/Main.java @@ -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! diff --git a/src/main/org/apache/tools/ant/Project.java b/src/main/org/apache/tools/ant/Project.java index e6354346d..da967622c 100644 --- a/src/main/org/apache/tools/ant/Project.java +++ b/src/main/org/apache/tools/ant/Project.java @@ -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) { diff --git a/src/main/org/apache/tools/ant/taskdefs/Exec.java b/src/main/org/apache/tools/ant/taskdefs/Exec.java index cae95b36a..37c1e6507 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Exec.java +++ b/src/main/org/apache/tools/ant/taskdefs/Exec.java @@ -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); + } + } }