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-ffa450edef68master
| @@ -1,3 +1,4 @@ | |||||
| @echo off | |||||
| cd %1 | cd %1 | ||||
| echo %2 %3 %4 %5 %6 %7 %8 %9 | 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 | |||||
| @@ -140,14 +140,25 @@ public class Main { | |||||
| } else if (arg.startsWith("-D")) { | } else if (arg.startsWith("-D")) { | ||||
| /* Interestingly enough, we get to here when a user | /* 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" | * so instead of parsing on "=", we just make the "-D" | ||||
| * characters go away and skip one argument forward. | * 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 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); | definedProps.put(name, value); | ||||
| } else if (arg.startsWith("-")) { | } else if (arg.startsWith("-")) { | ||||
| // we don't have any more args to recognize! | // we don't have any more args to recognize! | ||||
| @@ -270,6 +270,8 @@ public class Project { | |||||
| } | } | ||||
| log("Detected Java Version: " + javaVersion); | log("Detected Java Version: " + javaVersion); | ||||
| log("Detected OS: " + System.getProperty("os.name"), MSG_VERBOSE); | |||||
| } | } | ||||
| public void addTaskDefinition(String taskName, Class taskClass) { | public void addTaskDefinition(String taskName, Class taskClass) { | ||||
| @@ -97,29 +97,17 @@ public class Exec extends Task { | |||||
| // exec command on system runtime | // exec command on system runtime | ||||
| Process proc = Runtime.getRuntime().exec(command); | 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); | 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(); | proc.waitFor(); | ||||
| // close the output file if required | // close the output file if required | ||||
| @@ -151,4 +139,21 @@ public class Exec extends Task { | |||||
| public void setOutput(String out) { | public void setOutput(String out) { | ||||
| this.out = 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); | |||||
| } | |||||
| } | |||||
| } | } | ||||