@@ -1,7 +1,7 @@
/*
/*
* The Apache Software License, Version 1.1
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2000- 2001 The Apache Software Foundation. All rights
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* Redistribution and use in source and binary forms, with or without
@@ -69,8 +69,8 @@ import org.apache.tools.ant.types.Environment;
/**
/**
* original Cvs.java 1.20
* original Cvs.java 1.20
*
*
* NOTE: This implementation has been moved here from Cvs.java with the addition of
* some accessors for extensibility. Another task can extend this with
* NOTE: This implementation has been moved here from Cvs.java with the addition of
* some accessors for extensibility. Another task can extend this with
* some customized output processing.
* some customized output processing.
*
*
* @author costin@dnt.ro
* @author costin@dnt.ro
@@ -79,107 +79,107 @@ import org.apache.tools.ant.types.Environment;
* @author Kevin Ross <a href="mailto:kevin.ross@bredex.com">kevin.ross@bredex.com</a>
* @author Kevin Ross <a href="mailto:kevin.ross@bredex.com">kevin.ross@bredex.com</a>
*/
*/
public abstract class AbstractCvsTask extends Task {
public abstract class AbstractCvsTask extends Task {
private Commandline cmd = new Commandline();
private Commandline cmd = new Commandline();
/**
/**
* the CVSROOT variable.
* the CVSROOT variable.
*/
*/
private String cvsRoot;
private String cvsRoot;
/**
/**
* the CVS_RSH variable.
* the CVS_RSH variable.
*/
*/
private String cvsRsh;
private String cvsRsh;
/**
/**
* the package/module to check out.
* the package/module to check out.
*/
*/
private String cvsPackage;
private String cvsPackage;
/**
/**
* the CVS command to execute.
* the CVS command to execute.
*/
*/
private String command = "checkout";
private String command = "checkout";
/**
/**
* suppress information messages.
* suppress information messages.
*/
*/
private boolean quiet = false;
private boolean quiet = false;
/**
/**
* report only, don't change any files.
* report only, don't change any files.
*/
*/
private boolean noexec = false;
private boolean noexec = false;
/**
/**
* CVS port
* CVS port
*/
*/
private int port = 0;
private int port = 0;
/**
/**
* CVS password file
* CVS password file
*/
*/
private File passFile = null;
private File passFile = null;
/**
/**
* the directory where the checked out files should be placed.
* the directory where the checked out files should be placed.
*/
*/
private File dest;
private File dest;
/** whether or not to append stdout/stderr to existing files */
/** whether or not to append stdout/stderr to existing files */
private boolean append = false;
private boolean append = false;
/**
/**
* the file to direct standard output from the command.
* the file to direct standard output from the command.
*/
*/
private File output;
private File output;
/**
/**
* the file to direct standard error from the command.
* the file to direct standard error from the command.
*/
*/
private File error;
private File error;
/**
/**
* If true it will stop the build if cvs exits with error.
* If true it will stop the build if cvs exits with error.
* Default is false. (Iulian)
* Default is false. (Iulian)
*/
*/
private boolean failOnError = false;
private boolean failOnError = false;
/**
/**
* Create accessors for the following, to allow different handling of
* Create accessors for the following, to allow different handling of
* the output.
* the output.
*/
*/
private ExecuteStreamHandler executeStreamHandler;
private ExecuteStreamHandler executeStreamHandler;
private OutputStream outputStream;
private OutputStream outputStream;
private OutputStream errorStream;
private OutputStream errorStream;
public void setExecuteStreamHandler(ExecuteStreamHandler executeStreamHandler){
public void setExecuteStreamHandler(ExecuteStreamHandler executeStreamHandler){
this.executeStreamHandler = executeStreamHandler;
this.executeStreamHandler = executeStreamHandler;
}
}
protected ExecuteStreamHandler getExecuteStreamHandler(){
protected ExecuteStreamHandler getExecuteStreamHandler(){
if(this.executeStreamHandler == null){
if(this.executeStreamHandler == null){
setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(), getErrorStream()));
setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(), getErrorStream()));
}
}
return this.executeStreamHandler;
return this.executeStreamHandler;
}
}
protected void setOutputStream(OutputStream outputStream){
protected void setOutputStream(OutputStream outputStream){
this.outputStream = outputStream;
this.outputStream = outputStream;
}
}
protected OutputStream getOutputStream(){
protected OutputStream getOutputStream(){
if(this.outputStream == null){
if(this.outputStream == null){
if (output != null) {
if (output != null) {
try {
try {
setOutputStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(output.getPath(), append))));
setOutputStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(output.getPath(), append))));
@@ -192,21 +192,21 @@ public abstract class AbstractCvsTask extends Task {
setOutputStream(new LogOutputStream(this, Project.MSG_INFO));
setOutputStream(new LogOutputStream(this, Project.MSG_INFO));
}
}
}
}
return this.outputStream;
return this.outputStream;
}
}
protected void setErrorStream(OutputStream errorStream){
protected void setErrorStream(OutputStream errorStream){
this.errorStream = errorStream;
this.errorStream = errorStream;
}
}
protected OutputStream getErrorStream(){
protected OutputStream getErrorStream(){
if(this.errorStream == null){
if(this.errorStream == null){
if (error != null) {
if (error != null) {
try {
try {
setErrorStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(error.getPath(), append))));
setErrorStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(error.getPath(), append))));
}
}
@@ -218,20 +218,20 @@ public abstract class AbstractCvsTask extends Task {
setErrorStream(new LogOutputStream(this, Project.MSG_WARN));
setErrorStream(new LogOutputStream(this, Project.MSG_WARN));
}
}
}
}
return this.errorStream;
return this.errorStream;
}
}
public void execute() throws BuildException {
public void execute() throws BuildException {
// XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
// 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)
// 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");
if (cvsRoot != null) {
if (cvsRoot != null) {
toExecute.createArgument().setValue("-d");
toExecute.createArgument().setValue("-d");
@@ -243,40 +243,40 @@ public abstract class AbstractCvsTask extends Task {
if (quiet) {
if (quiet) {
toExecute.createArgument().setValue("-q");
toExecute.createArgument().setValue("-q");
}
}
toExecute.createArgument().setLine(command);
toExecute.createArgument().setLine(command);
//
//
// get the other arguments.
// get the other arguments.
//
//
toExecute.addArguments(cmd.getCommandline());
toExecute.addArguments(cmd.getCommandline());
if (cvsPackage != null) {
if (cvsPackage != null) {
toExecute.createArgument().setLine(cvsPackage);
toExecute.createArgument().setLine(cvsPackage);
}
}
Environment env = new Environment();
Environment env = new Environment();
if(port>0){
if(port>0){
Environment.Variable var = new Environment.Variable();
Environment.Variable var = new Environment.Variable();
var.setKey("CVS_CLIENT_PORT");
var.setKey("CVS_CLIENT_PORT");
var.setValue(String.valueOf(port));
var.setValue(String.valueOf(port));
env.addVariable(var);
env.addVariable(var);
}
}
/**
/**
* Need a better cross platform integration with <cvspass>, so use the same filename.
* Need a better cross platform integration with <cvspass>, so use the same filename.
*/
*/
/* But currently we cannot because 'cvs log' is not working with a pass file.
/* But currently we cannot because 'cvs log' is not working with a pass file.
if(passFile == null){
if(passFile == null){
File defaultPassFile = new File(System.getProperty("user.home") + File.separatorChar + ".cvspass");
File defaultPassFile = new File(System.getProperty("user.home") + File.separatorChar + ".cvspass");
if(defaultPassFile.exists())
if(defaultPassFile.exists())
this.setPassfile(defaultPassFile);
this.setPassfile(defaultPassFile);
}
}
*/
*/
if(passFile!=null){
if(passFile!=null){
Environment.Variable var = new Environment.Variable();
Environment.Variable var = new Environment.Variable();
var.setKey("CVS_PASSFILE");
var.setKey("CVS_PASSFILE");
@@ -284,21 +284,21 @@ public abstract class AbstractCvsTask extends Task {
env.addVariable(var);
env.addVariable(var);
log("Using cvs passfile: " + String.valueOf(passFile), Project.MSG_INFO);
log("Using cvs passfile: " + String.valueOf(passFile), Project.MSG_INFO);
}
}
if(cvsRsh!=null){
if(cvsRsh!=null){
Environment.Variable var = new Environment.Variable();
Environment.Variable var = new Environment.Variable();
var.setKey("CVS_RSH");
var.setKey("CVS_RSH");
var.setValue(String.valueOf(cvsRsh));
var.setValue(String.valueOf(cvsRsh));
env.addVariable(var);
env.addVariable(var);
}
}
//
//
// Just call the getExecuteStreamHandler() and let it handle
// Just call the getExecuteStreamHandler() and let it handle
// the semantics of instantiation or retrieval.
// the semantics of instantiation or retrieval.
//
//
Execute exe = new Execute(getExecuteStreamHandler(), null);
Execute exe = new Execute(getExecuteStreamHandler(), null);
exe.setAntRun(project);
exe.setAntRun(project);
if (dest == null) {
if (dest == null) {
dest = project.getBaseDir();
dest = project.getBaseDir();
@@ -310,16 +310,16 @@ public abstract class AbstractCvsTask extends Task {
try {
try {
log("Executing: " + executeToString(exe), Project.MSG_DEBUG);
log("Executing: " + executeToString(exe), Project.MSG_DEBUG);
int retCode = exe.execute();
int retCode = exe.execute();
/*Throw an exception if cvs exited with error. (Iulian)*/
/*Throw an exception if cvs exited with error. (Iulian)*/
if(failOnError && retCode != 0) {
if(failOnError && retCode != 0) {
throw new BuildException("cvs exited with error code "+ retCode);
throw new BuildException("cvs exited with error code "+ retCode);
}
}
}
}
catch (IOException e) {
catch (IOException e) {
throw new BuildException(e, location);
throw new BuildException(e, location);
}
}
finally {
finally {
//
//
// condition used to be if(output == null) outputStream.close(). This is
// condition used to be if(output == null) outputStream.close(). This is
@@ -330,7 +330,7 @@ public abstract class AbstractCvsTask extends Task {
outputStream.close();
outputStream.close();
} catch (IOException e) {}
} catch (IOException e) {}
}
}
if (errorStream != null) {
if (errorStream != null) {
try {
try {
errorStream.close();
errorStream.close();
@@ -338,13 +338,13 @@ public abstract class AbstractCvsTask extends Task {
}
}
}
}
}
}
private String executeToString(Execute execute){
private String executeToString(Execute execute){
StringBuffer stringBuffer = new StringBuffer(250);
StringBuffer stringBuffer = new StringBuffer(250);
String[] commandLine = execute.getCommandline();
String[] commandLine = execute.getCommandline();
for(int i=0; i<commandLine.length; i++){
for(int i=0; i<commandLine.length; i++){
stringBuffer.append(commandLine[i]);
stringBuffer.append(commandLine[i]);
stringBuffer.append(" ");
stringBuffer.append(" ");
}
}
@@ -353,8 +353,8 @@ public abstract class AbstractCvsTask extends Task {
stringBuffer.append(newLine);
stringBuffer.append(newLine);
stringBuffer.append("environment:");
stringBuffer.append("environment:");
stringBuffer.append(newLine);
stringBuffer.append(newLine);
String[] variableArray = execute.getEnvironment();
String[] variableArray = execute.getEnvironment();
if(variableArray != null){
if(variableArray != null){
@@ -368,24 +368,24 @@ public abstract class AbstractCvsTask extends Task {
return stringBuffer.toString();
return stringBuffer.toString();
}
}
public void setCvsRoot(String root) {
public void setCvsRoot(String root) {
// Check if not real cvsroot => set it to null
// Check if not real cvsroot => set it to null
if (root != null) {
if (root != null) {
if (root.trim().equals("")) {
if (root.trim().equals("")) {
root = null;
root = null;
}
}
}
}
this.cvsRoot = root;
this.cvsRoot = root;
}
}
public String getCvsRoot(){
public String getCvsRoot(){
return this.cvsRoot;
return this.cvsRoot;
}
}
public void setCvsRsh(String rsh) {
public void setCvsRsh(String rsh) {
// Check if not real cvsrsh => set it to null
// Check if not real cvsrsh => set it to null
if (rsh != null) {
if (rsh != null) {
@@ -393,51 +393,51 @@ public abstract class AbstractCvsTask extends Task {
rsh = null;
rsh = null;
}
}
}
}
this.cvsRsh = rsh;
this.cvsRsh = rsh;
}
}
public String getCvsRsh(){
public String getCvsRsh(){
return this.cvsRsh;
return this.cvsRsh;
}
}
public void setPort(int port){
public void setPort(int port){
this.port = port;
this.port = port;
}
}
public int getPort(){
public int getPort(){
return this.port;
return this.port;
}
}
public void setPassfile(File passFile){
public void setPassfile(File passFile){
this.passFile = passFile;
this.passFile = passFile;
}
}
public File getPassFile(){
public File getPassFile(){
return this.passFile;
return this.passFile;
}
}
public void setDest(File dest) {
public void setDest(File dest) {
this.dest = dest;
this.dest = dest;
}
}
public File getDest(){
public File getDest(){
return this.dest;
return this.dest;
}
}
public void setPackage(String p) {
public void setPackage(String p) {
this.cvsPackage = p;
this.cvsPackage = p;
}
}
public String getPackage(){
public String getPackage(){
return this.cvsPackage;
return this.cvsPackage;
}
}
public void setTag(String p) {
public void setTag(String p) {
// Check if not real tag => set it to null
// Check if not real tag => set it to null
if (p != null && p.trim().length() > 0) {
if (p != null && p.trim().length() > 0) {
@@ -445,47 +445,47 @@ public abstract class AbstractCvsTask extends Task {
addCommandArgument(p);
addCommandArgument(p);
}
}
}
}
/**
/**
* This needs to be public to allow configuration
* This needs to be public to allow configuration
* of commands externally.
* of commands externally.
*/
*/
public void addCommandArgument(String arg){
public void addCommandArgument(String arg){
this.cmd.createArgument().setValue(arg);
this.cmd.createArgument().setValue(arg);
}
}
public void setDate(String p) {
public void setDate(String p) {
if(p != null && p.trim().length() > 0) {
if(p != null && p.trim().length() > 0) {
addCommandArgument("-D");
addCommandArgument("-D");
addCommandArgument(p);
addCommandArgument(p);
}
}
}
}
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) {
quiet = q;
quiet = q;
}
}
public void setNoexec(boolean ne) {
public void setNoexec(boolean ne) {
noexec = ne;
noexec = ne;
}
}
public void setOutput(File output) {
public void setOutput(File output) {
this.output = output;
this.output = output;
}
}
public void setError(File error) {
public void setError(File error) {
this.error = error;
this.error = error;
}
}
public void setAppend(boolean value){
public void setAppend(boolean value){
this.append = value;
this.append = value;
}
}
public void setFailOnError(boolean failOnError) {
public void setFailOnError(boolean failOnError) {
this.failOnError = failOnError;
this.failOnError = failOnError;
}
}