Browse Source

Added an output attribute to <java>.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268135 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
6f18050729
4 changed files with 83 additions and 23 deletions
  1. +4
    -2
      WHATSNEW
  2. +5
    -0
      docs/index.html
  3. +24
    -0
      src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java
  4. +50
    -21
      src/main/org/apache/tools/ant/taskdefs/Java.java

+ 4
- 2
WHATSNEW View File

@@ -4,14 +4,16 @@ Changes from Ant 1.2 to the current sources
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
===============================


+ 5
- 0
docs/index.html View File

@@ -2516,6 +2516,11 @@ the one that is currently running Ant.</p>
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>


+ 24
- 0
src/main/org/apache/tools/ant/taskdefs/ExecuteJava.java View File

@@ -64,16 +64,19 @@ import org.apache.tools.ant.types.Path;

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 @@ public class ExecuteJava {
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 @@ public class ExecuteJava {
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) {
@@ -123,6 +142,11 @@ public class ExecuteJava {
if (sysProperties != null) {
sysProperties.restoreSystem();
}
if (out != null) {
System.setOut(sOut);
System.setErr(sErr);
out.close();
}
}
}
}

+ 50
- 21
src/main/org/apache/tools/ant/taskdefs/Java.java View File

@@ -60,8 +60,7 @@ import org.apache.tools.ant.Project;
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 @@ import java.util.*;
* 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;
/**
@@ -221,6 +222,13 @@ public class Java extends Task {
this.dir = d;
}

/**
* File the output of the process is redirected to.
*/
public void setOutput(File out) {
this.out = out;
}

/**
* -mx or -Xmx depending on VM version
*/
@@ -241,6 +249,13 @@ public class Java extends Task {
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 @@ public class Java extends Task {
* 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) {}
}
}
}



Loading…
Cancel
Save