You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@locus.apache.org on 2000/09/29 17:40:35 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Cvs.java Javac.java
bodewig 00/09/29 08:40:34
Modified: docs index.html
src/main/org/apache/tools/ant/taskdefs Cvs.java Javac.java
Log:
Enable redirecting either the output or error or both from a cvs command to a file.
Example usage:
<target name="diff">
<cvs command="diff" output="patch.txt"/>
</target>
Submitted by: Julian M. Savage <js...@fisci.com>
Revision Changes Path
1.120 +10 -0 jakarta-ant/docs/index.html
Index: index.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/index.html,v
retrieving revision 1.119
retrieving revision 1.120
diff -u -r1.119 -r1.120
--- index.html 2000/09/28 13:46:29 1.119
+++ index.html 2000/09/29 15:40:29 1.120
@@ -1372,6 +1372,16 @@
<td valign="top">report only, don't change any files.</td>
<td align="center" valign="top">No, default "false"</td>
</tr>
+ <tr>
+ <td valign="top">output</td>
+ <td valign="top">the file to direct standard output from the command.</td>
+ <td align="center" valign="top">No, default output to ANT Log as MSG_INFO.</td>
+ </tr>
+ <tr>
+ <td valign="top">error</td>
+ <td valign="top">the file to direct standard error from the command.</td>
+ <td align="center" valign="top">No, default error to ANT Log as MSG_WARN.</td>
+ </tr>
</table>
<h3>Examples</h3>
<pre> <cvs cvsRoot=":pserver:anoncvs@jakarta.apache.org:/home/cvspublic"
1.11 +94 -11 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java
Index: Cvs.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Cvs.java 2000/09/11 10:33:49 1.10
+++ Cvs.java 2000/09/29 15:40:32 1.11
@@ -69,21 +69,55 @@
public class Cvs extends Task {
private Commandline cmd = new Commandline();
+
+ /**
+ * the CVSROOT variable.
+ */
private String cvsRoot;
+
+ /**
+ * the package/module to check out.
+ */
private String pack;
+
+ /**
+ * the CVS command to execute.
+ */
private String command = "checkout";
+
+ /**
+ * suppress information messages.
+ */
private boolean quiet = false;
+
+ /**
+ * report only, don't change any files.
+ */
private boolean noexec = false;
+
+ /**
+ * the directory where the checked out files should be placed.
+ */
private File dest;
-
+
+ /**
+ * the file to direct standard output from the command.
+ */
+ private File output;
+
+ /**
+ * the file to direct standard error from the command.
+ */
+ private File error;
+
public void execute() throws BuildException {
- // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
- // execution so that we don't rely on having native CVS stuff around (SM)
+ // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
+ // execution so that we don't rely on having native CVS stuff around (SM)
// We can't do it ourselves as jCVS is GPLed, a third party task
// outside of jakarta repositories would be possible though (SB).
-
+
Commandline toExecute = new Commandline();
toExecute.setExecutable("cvs");
@@ -100,12 +134,42 @@
toExecute.createArgument().setLine(command);
toExecute.addArguments(cmd.getCommandline());
- if (pack != null) {
+ if (pack != null) {
toExecute.createArgument().setValue(pack);
- }
+ }
+
+ ExecuteStreamHandler streamhandler = null;
+ OutputStream outputstream = null;
+ OutputStream errorstream = null;
+ if (error == null && output == null) {
+ streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
+ Project.MSG_WARN);
+ }
+ else {
+ if (output != null) {
+ try {
+ outputstream = new PrintStream(new BufferedOutputStream(new FileOutputStream(output)));
+ } catch (IOException e) {
+ throw new BuildException(e, location);
+ }
+ }
+ else {
+ outputstream = new LogOutputStream(this, Project.MSG_INFO);
+ }
+ if (error != null) {
+ try {
+ errorstream = new PrintStream(new BufferedOutputStream(new FileOutputStream(error)));
+ } catch (IOException e) {
+ throw new BuildException(e, location);
+ }
+ }
+ else {
+ errorstream = new LogOutputStream(this, Project.MSG_WARN);
+ }
+ streamhandler = new PumpStreamHandler(outputstream, errorstream);
+ }
- Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
- Project.MSG_WARN),
+ Execute exe = new Execute(streamhandler,
null);
exe.setAntRun(project);
@@ -117,6 +181,17 @@
exe.execute();
} catch (IOException e) {
throw new BuildException(e, location);
+ } finally {
+ if (output != null) {
+ try {
+ outputstream.close();
+ } catch (IOException e) {}
+ }
+ if (error != null) {
+ try {
+ errorstream.close();
+ } catch (IOException e) {}
+ }
}
}
@@ -127,7 +202,7 @@
root = null;
}
- this.cvsRoot = root;
+ this.cvsRoot = root;
}
public void setDest(File dest) {
@@ -135,7 +210,7 @@
}
public void setPackage(String p) {
- this.pack = p;
+ this.pack = p;
}
public void setTag(String p) {
@@ -155,7 +230,7 @@
}
public void setCommand(String c) {
- this.command = c;
+ this.command = c;
}
public void setQuiet(boolean q) {
@@ -164,6 +239,14 @@
public void setNoexec(boolean ne) {
noexec = ne;
+ }
+
+ public void setOutput(File output) {
+ this.output = output;
+ }
+
+ public void setError(File error) {
+ this.error = error;
}
}
1.45 +4 -4 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
Index: Javac.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- Javac.java 2000/09/29 15:28:12 1.44
+++ Javac.java 2000/09/29 15:40:33 1.45
@@ -398,7 +398,7 @@
* @param addRuntime Shall <code>rt.jar</code> or
* <code>classes.zip</code> be added to the classpath.
*/
- private Path getCompileClasspath(boolean addRuntime) {
+ protected Path getCompileClasspath(boolean addRuntime) {
Path classpath = new Path(project);
// add dest dir to classpath so that previously compiled and
@@ -598,7 +598,7 @@
* Logs the compilation parameters, adds the files to compile and logs the
* &qout;niceSourceList"
*/
- private void logAndAddFilesToCompile(Commandline cmd) {
+ protected void logAndAddFilesToCompile(Commandline cmd) {
log("Compilation args: " + cmd.toString(),
Project.MSG_VERBOSE);
@@ -742,7 +742,7 @@
* @param args - arguments to pass to process on command line
* @param firstFileName - index of the first source file in args
*/
- private int executeJikesCompile(String[] args, int firstFileName) {
+ protected int executeJikesCompile(String[] args, int firstFileName) {
String[] commandArray = null;
File tmpFile = null;
@@ -804,7 +804,7 @@
* so that you don't have to specify them all one by one.
* @param classpath - Path to append files to
*/
- private void addExtdirsToClasspath(Path classpath) {
+ protected void addExtdirsToClasspath(Path classpath) {
if (extdirs == null) {
String extProp = System.getProperty("java.ext.dirs");
if (extProp != null) {