ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@locus.apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecuteJava.java Java.java
Date Tue, 31 Oct 2000 12:13:14 GMT
bodewig     00/10/31 04:13:14

  Modified:    .        WHATSNEW
               docs     index.html
               src/main/org/apache/tools/ant/taskdefs ExecuteJava.java
                        Java.java
  Log:
  Added an output attribute to <java>.
  
  Revision  Changes    Path
  1.40      +4 -2      jakarta-ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- WHATSNEW	2000/10/27 15:23:26	1.39
  +++ WHATSNEW	2000/10/31 12:13:11	1.40
  @@ -4,14 +4,16 @@
   Other changes:
   --------------
   
  -* New tasks: propertyfile
  +* New tasks: propertyfile, depend
   
  +* Added output attribute to <java>.
  +
   Fixed bugs:
   -----------
   
   * <signjar> doesn't use deprectated methods anymore.
   
  -* documentation of javadoc has been corrected.
  +* javadoc's failonerror attribute works again
   
   Changes from Ant 1.1 to Ant 1.2
   ===============================
  
  
  
  1.140     +5 -0      jakarta-ant/docs/index.html
  
  Index: index.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/index.html,v
  retrieving revision 1.139
  retrieving revision 1.140
  diff -u -r1.139 -r1.140
  --- index.html	2000/10/31 11:11:59	1.139
  +++ index.html	2000/10/31 12:13:13	1.140
  @@ -2516,6 +2516,11 @@
         fork is disabled)</td>
       <td align="center" valign="top">No</td>
     </tr>
  +  <tr>
  +    <td valign="top">output</td>
  +    <td valign="top">Name of a file to write the output to.</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
   </table>
   <h3>Parameters specified as nested elements</h3>
   <h4>arg and jvmarg</h4>
  
  
  
  1.6       +24 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  
  Index: ExecuteJava.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ExecuteJava.java	2000/10/12 16:09:49	1.5
  +++ ExecuteJava.java	2000/10/31 12:13:13	1.6
  @@ -64,16 +64,19 @@
   
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  +import java.io.*;
   
   /*
    *
    * @author thomas.haas@softwired-inc.com
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
   public class ExecuteJava {
   
       private Commandline javaCommand = null;
       private Path classpath = null;
       private CommandlineJava.SysProperties sysProperties = null;
  +    private PrintStream out;
   
       public void setJavaCommand(Commandline javaCommand) {
           this.javaCommand = javaCommand;
  @@ -87,7 +90,18 @@
           sysProperties = s;
       }
   
  +    /**
  +     * All output (System.out as well as System.err) will be written
  +     * to this Stream.
  +     */
  +    public void setOutput(PrintStream out) {
  +        this.out = out;
  +    }
  +
       public void execute(Project project) throws BuildException{
  +        PrintStream sOut = System.out;
  +        PrintStream sErr = System.err;
  +
           final String classname = javaCommand.getExecutable();
           final Object[] argument = { javaCommand.getArguments() };
           try {
  @@ -95,6 +109,11 @@
                   sysProperties.setSystem();
               }
   
  +            if (out != null) {
  +                System.setErr(out);
  +                System.setOut(out);
  +            }
  +
               final Class[] param = { Class.forName("[Ljava.lang.String;") };
               Class target = null;
               if (classpath == null) {
  @@ -122,6 +141,11 @@
           } finally {
               if (sysProperties != null) {
                   sysProperties.restoreSystem();
  +            }
  +            if (out != null) {
  +                System.setOut(sOut);
  +                System.setErr(sErr);
  +                out.close();
               }
           }
       }
  
  
  
  1.23      +50 -21    jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java
  
  Index: Java.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Java.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Java.java	2000/10/12 15:59:16	1.22
  +++ Java.java	2000/10/31 12:13:14	1.23
  @@ -60,8 +60,7 @@
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.types.*;
   
  -import java.io.File;
  -import java.io.IOException;
  +import java.io.*;
   import java.lang.reflect.*;
   import java.util.*;
   
  @@ -70,12 +69,14 @@
    * for the called application thus resulting in much faster operation.
    *
    * @author Stefano Mazzocchi <a href="mailto:stefano@apache.org">stefano@apache.org</a>
  + * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
    */
   public class Java extends Task {
   
       private CommandlineJava cmdl = new CommandlineJava();
       private boolean fork = false;
       private File dir = null;
  +    private File out;
       private boolean failOnError = false;
       
       /**
  @@ -222,6 +223,13 @@
       }
   
       /**
  +     * File the output of the process is redirected to.
  +     */
  +    public void setOutput(File out) {
  +        this.out = out;
  +    }
  +
  +    /**
        * -mx or -Xmx depending on VM version
        */
       public void setMaxmemory(String max){
  @@ -241,6 +249,13 @@
           exe.setJavaCommand(command.getJavaCommand());
           exe.setClasspath(command.getClasspath());
           exe.setSystemProperties(command.getSystemProperties());
  +        if (out != null) {
  +            try {
  +                exe.setOutput(new PrintStream(new FileOutputStream(out)));
  +            } catch (IOException io) {
  +                throw new BuildException(io, location);
  +            }
  +        }
           
           exe.execute(project);
       }
  @@ -249,27 +264,41 @@
        * Executes the given classname with the given arguments in a separate VM.
        */
       private int run(String[] command) throws BuildException {
  -        Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
  +        FileOutputStream fos = null;
  +        try {
  +            Execute exe = null;
  +            if (out == null) {
  +                exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
                                                          Project.MSG_WARN), 
                                     null);
  -        
  -        
  -        exe.setAntRun(project);
  -
  -        if (dir == null) {
  -            dir = project.getBaseDir();
  -        } else if (!dir.exists() || !dir.isDirectory()) {
  -            throw new BuildException(dir.getAbsolutePath()+" is not a valid directory",
  -                                     location);
  -        }
  -
  -        exe.setWorkingDirectory(dir);
  -
  -        exe.setCommandline(command);
  -        try {
  -            return exe.execute();
  -        } catch (IOException e) {
  -            throw new BuildException(e, location);
  +            } else {
  +                fos = new FileOutputStream(out);
  +                exe = new Execute(new PumpStreamHandler(fos), null);
  +            }
  +            
  +            exe.setAntRun(project);
  +            
  +            if (dir == null) {
  +                dir = project.getBaseDir();
  +            } else if (!dir.exists() || !dir.isDirectory()) {
  +                throw new BuildException(dir.getAbsolutePath()+" is not a valid directory",
  +                                         location);
  +            }
  +            
  +            exe.setWorkingDirectory(dir);
  +            
  +            exe.setCommandline(command);
  +            try {
  +                return exe.execute();
  +            } catch (IOException e) {
  +                throw new BuildException(e, location);
  +            }
  +        } catch (IOException io) {
  +            throw new BuildException(io, location);
  +        } finally {
  +            if (fos != null) {
  +                try {fos.close();} catch (IOException io) {}
  +            }
           }
       }
   
  
  
  

Mime
View raw message