Browse Source

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 <jsavage@fisci.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268048 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
37ed344b38
3 changed files with 108 additions and 15 deletions
  1. +10
    -0
      docs/index.html
  2. +94
    -11
      src/main/org/apache/tools/ant/taskdefs/Cvs.java
  3. +4
    -4
      src/main/org/apache/tools/ant/taskdefs/Javac.java

+ 10
- 0
docs/index.html View File

@@ -1372,6 +1372,16 @@ preferred over the <i>checkout</i> command, because of speed.</p>
<td valign="top">report only, don't change any files.</td> <td valign="top">report only, don't change any files.</td>
<td align="center" valign="top">No, default &quot;false&quot;</td> <td align="center" valign="top">No, default &quot;false&quot;</td>
</tr> </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> </table>
<h3>Examples</h3> <h3>Examples</h3>
<pre> &lt;cvs cvsRoot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot; <pre> &lt;cvs cvsRoot=&quot;:pserver:anoncvs@jakarta.apache.org:/home/cvspublic&quot;


+ 94
- 11
src/main/org/apache/tools/ant/taskdefs/Cvs.java View File

@@ -69,21 +69,55 @@ import java.io.*;
public class Cvs extends Task { public class Cvs extends Task {


private Commandline cmd = new Commandline(); private Commandline cmd = new Commandline();
/**
* the CVSROOT variable.
*/
private String cvsRoot; private String cvsRoot;

/**
* the package/module to check out.
*/
private String pack; private String pack;

/**
* the CVS command to execute.
*/
private String command = "checkout"; private String command = "checkout";

/**
* suppress information messages.
*/
private boolean quiet = false; private boolean quiet = false;

/**
* report only, don't change any files.
*/
private boolean noexec = false; private boolean noexec = false;

/**
* the directory where the checked out files should be placed.
*/
private File dest; 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 { 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 // We can't do it ourselves as jCVS is GPLed, a third party task
// outside of jakarta repositories would be possible though (SB). // outside of jakarta repositories would be possible though (SB).
Commandline toExecute = new Commandline(); Commandline toExecute = new Commandline();


toExecute.setExecutable("cvs"); toExecute.setExecutable("cvs");
@@ -100,12 +134,42 @@ public class Cvs extends Task {
toExecute.createArgument().setLine(command); toExecute.createArgument().setLine(command);
toExecute.addArguments(cmd.getCommandline()); toExecute.addArguments(cmd.getCommandline());


if (pack != null) {
if (pack != null) {
toExecute.createArgument().setValue(pack); 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); null);


exe.setAntRun(project); exe.setAntRun(project);
@@ -117,6 +181,17 @@ public class Cvs extends Task {
exe.execute(); exe.execute();
} catch (IOException e) { } catch (IOException e) {
throw new BuildException(e, location); 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 @@ public class Cvs extends Task {
root = null; root = null;
} }


this.cvsRoot = root;
this.cvsRoot = root;
} }


public void setDest(File dest) { public void setDest(File dest) {
@@ -135,7 +210,7 @@ public class Cvs extends Task {
} }


public void setPackage(String p) { public void setPackage(String p) {
this.pack = p;
this.pack = p;
} }


public void setTag(String p) { public void setTag(String p) {
@@ -155,7 +230,7 @@ public class Cvs extends Task {
} }


public void setCommand(String c) { public void setCommand(String c) {
this.command = c;
this.command = c;
} }
public void setQuiet(boolean q) { public void setQuiet(boolean q) {
@@ -165,6 +240,14 @@ public class Cvs extends Task {
public void setNoexec(boolean ne) { public void setNoexec(boolean ne) {
noexec = ne; noexec = ne;
} }

public void setOutput(File output) {
this.output = output;
}
public void setError(File error) {
this.error = error;
}
} }





+ 4
- 4
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -398,7 +398,7 @@ public class Javac extends MatchingTask {
* @param addRuntime Shall <code>rt.jar</code> or * @param addRuntime Shall <code>rt.jar</code> or
* <code>classes.zip</code> be added to the classpath. * <code>classes.zip</code> be added to the classpath.
*/ */
private Path getCompileClasspath(boolean addRuntime) {
protected Path getCompileClasspath(boolean addRuntime) {
Path classpath = new Path(project); Path classpath = new Path(project);


// add dest dir to classpath so that previously compiled and // add dest dir to classpath so that previously compiled and
@@ -598,7 +598,7 @@ public class Javac extends MatchingTask {
* Logs the compilation parameters, adds the files to compile and logs the * Logs the compilation parameters, adds the files to compile and logs the
* &qout;niceSourceList&quot; * &qout;niceSourceList&quot;
*/ */
private void logAndAddFilesToCompile(Commandline cmd) {
protected void logAndAddFilesToCompile(Commandline cmd) {
log("Compilation args: " + cmd.toString(), log("Compilation args: " + cmd.toString(),
Project.MSG_VERBOSE); Project.MSG_VERBOSE);


@@ -742,7 +742,7 @@ public class Javac extends MatchingTask {
* @param args - arguments to pass to process on command line * @param args - arguments to pass to process on command line
* @param firstFileName - index of the first source file in args * @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; String[] commandArray = null;
File tmpFile = null; File tmpFile = null;


@@ -804,7 +804,7 @@ public class Javac extends MatchingTask {
* so that you don't have to specify them all one by one. * so that you don't have to specify them all one by one.
* @param classpath - Path to append files to * @param classpath - Path to append files to
*/ */
private void addExtdirsToClasspath(Path classpath) {
protected void addExtdirsToClasspath(Path classpath) {
if (extdirs == null) { if (extdirs == null) {
String extProp = System.getProperty("java.ext.dirs"); String extProp = System.getProperty("java.ext.dirs");
if (extProp != null) { if (extProp != null) {


Loading…
Cancel
Save