Browse Source

bug 7552 audit of <cvs> - ensure command gets reset.

You cannot have an attribute that accepts a boolean or an integer, at
least not the way it has been done - split into two attributes.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272368 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
49ac8075b8
3 changed files with 72 additions and 37 deletions
  1. +10
    -2
      docs/manual/CoreTasks/cvs.html
  2. +56
    -29
      src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java
  3. +6
    -6
      src/main/org/apache/tools/ant/taskdefs/Cvs.java

+ 10
- 2
docs/manual/CoreTasks/cvs.html View File

@@ -27,8 +27,16 @@ preferred over the <i>checkout</i> command, because of speed.</p>
</tr> </tr>
<tr> <tr>
<td valign="top">commpression</td> <td valign="top">commpression</td>
<td valign="top"><code>true</code>, <code>false</code>, or the number 1-9 (corresponding to possible values for CVS&apos; <code>-z#</code> argument). Any other value is treated as false</td>
<td align="center" valign="top">No. Defaults to no compression. if passed <code>true</code>, level 3 compression is assumed.</td>
<td valign="top"><code>true</code> or <code>false</code> - if set
to true, this is the same as copmressionlevel=&quot;3&quot;</td>
<td align="center" valign="top">No. Defaults to false.</td>
</tr>
<tr>
<td valign="top">commpressionlevel</td>
<td valign="top">A number between 1 and 9 (corresponding to
possible values for CVS&apos; <code>-z#</code> argument). Any
other value is treated as compression=&qupt;false&quot;</td>
<td align="center" valign="top">No. Defaults to no compression.</td>
</tr> </tr>


<tr> <tr>


+ 56
- 29
src/main/org/apache/tools/ant/taskdefs/AbstractCvsTask.java View File

@@ -71,18 +71,24 @@ import org.apache.tools.ant.util.StringUtils;
/** /**
* 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
* some customized output processing.
* 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.
* *
* @author costin@dnt.ro * @author costin@dnt.ro
* @author stefano@apache.org * @author stefano@apache.org
* @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a> * @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a>
* @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>
*
* @since Ant 1.5
*/ */
public abstract class AbstractCvsTask extends Task { public abstract class AbstractCvsTask extends Task {
/** Default compression level to use, if compression is enabled via setCompression( true ). */
/**
* Default compression level to use, if compression is enabled via
* setCompression( true ).
*/
public static final int DEFAULT_COMPRESSION_LEVEL = 3; public static final int DEFAULT_COMPRESSION_LEVEL = 3;

private Commandline cmd = new Commandline(); private Commandline cmd = new Commandline();


/** list of Commandline children */ /** list of Commandline children */
@@ -175,7 +181,6 @@ public abstract class AbstractCvsTask extends Task {
} }


public void setExecuteStreamHandler(ExecuteStreamHandler executeStreamHandler){ public void setExecuteStreamHandler(ExecuteStreamHandler executeStreamHandler){

this.executeStreamHandler = executeStreamHandler; this.executeStreamHandler = executeStreamHandler;
} }


@@ -183,7 +188,8 @@ public abstract class AbstractCvsTask extends Task {


if(this.executeStreamHandler == null){ if(this.executeStreamHandler == null){


setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(), getErrorStream()));
setExecuteStreamHandler(new PumpStreamHandler(getOutputStream(),
getErrorStream()));
} }


return this.executeStreamHandler; return this.executeStreamHandler;
@@ -201,13 +207,15 @@ public abstract class AbstractCvsTask extends Task {


if (output != null) { if (output != null) {
try { try {
setOutputStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(output.getPath(), append))));
}
catch (IOException e) {
setOutputStream(new PrintStream(
new BufferedOutputStream(
new FileOutputStream(output
.getPath(),
append))));
} catch (IOException e) {
throw new BuildException(e, location); throw new BuildException(e, location);
} }
}
else {
} else {
setOutputStream(new LogOutputStream(this, Project.MSG_INFO)); setOutputStream(new LogOutputStream(this, Project.MSG_INFO));
} }
} }
@@ -227,13 +235,14 @@ public abstract class AbstractCvsTask extends Task {
if (error != null) { if (error != null) {


try { try {
setErrorStream(new PrintStream(new BufferedOutputStream(new FileOutputStream(error.getPath(), append))));
}
catch (IOException e) {
setErrorStream(new PrintStream(
new BufferedOutputStream(
new FileOutputStream(error.getPath(),
append))));
} catch (IOException e) {
throw new BuildException(e, location); throw new BuildException(e, location);
} }
}
else {
} else {
setErrorStream(new LogOutputStream(this, Project.MSG_WARN)); setErrorStream(new LogOutputStream(this, Project.MSG_WARN));
} }
} }
@@ -246,8 +255,9 @@ public abstract class AbstractCvsTask extends Task {
* @throws BuildException * @throws BuildException
*/ */
protected void runCommand( Commandline toExecute ) throws BuildException { protected void runCommand( Commandline toExecute ) 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).
@@ -262,9 +272,11 @@ public abstract class AbstractCvsTask extends Task {
} }


/** /**
* 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");
@@ -279,7 +291,8 @@ public abstract class AbstractCvsTask extends Task {
var.setKey("CVS_PASSFILE"); var.setKey("CVS_PASSFILE");
var.setValue(String.valueOf(passFile)); var.setValue(String.valueOf(passFile));
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) {
@@ -289,7 +302,6 @@ public abstract class AbstractCvsTask extends Task {
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.
@@ -368,6 +380,7 @@ public abstract class AbstractCvsTask extends Task {


public void execute() throws BuildException { public void execute() throws BuildException {


String savedCommand = getCommand();


if( this.getCommand() == null if( this.getCommand() == null
&& vecCommandlines.size() == 0 ) { && vecCommandlines.size() == 0 ) {
@@ -376,13 +389,22 @@ public abstract class AbstractCvsTask extends Task {
} }


String c = this.getCommand(); String c = this.getCommand();
Commandline cloned = null;
if( c != null ) { if( c != null ) {
this.cmd.createArgument(true).setLine(c);
this.addConfiguredCommandline( this.cmd, true );
cloned = (Commandline) cmd.clone();
cloned.createArgument(true).setLine(c);
this.addConfiguredCommandline(cloned, true);
} }


for( int i = 0; i < vecCommandlines.size(); i++ ) {
this.runCommand( (Commandline)vecCommandlines.elementAt( i ) );
try {
for( int i = 0; i < vecCommandlines.size(); i++ ) {
this.runCommand( (Commandline)vecCommandlines.elementAt( i ) );
}
} finally {
if (cloned != null) {
removeCommandline(cloned);
}
setCommand(savedCommand);
} }
} }


@@ -567,6 +589,10 @@ public abstract class AbstractCvsTask extends Task {
} }
} }


protected void removeCommandline(Commandline c) {
vecCommandlines.removeElement( c );
}

public void addConfiguredCommandline( Commandline c ) { public void addConfiguredCommandline( Commandline c ) {
this.addConfiguredCommandline( c, false ); this.addConfiguredCommandline( c, false );
} }
@@ -575,7 +601,8 @@ public abstract class AbstractCvsTask extends Task {
* Configures and adds the given Commandline. * Configures and adds the given Commandline.
* @param insertAtStart If true, c is * @param insertAtStart If true, c is
*/ */
public void addConfiguredCommandline( Commandline c, boolean insertAtStart ) {
public void addConfiguredCommandline( Commandline c,
boolean insertAtStart ) {
if( c == null ) { return; } if( c == null ) { return; }
this.configureCommandline( c ); this.configureCommandline( c );
if( insertAtStart ) { if( insertAtStart ) {
@@ -590,7 +617,7 @@ public abstract class AbstractCvsTask extends Task {
* If set to a value 1-9 it adds -zN to the cvs command line, else * If set to a value 1-9 it adds -zN to the cvs command line, else
* it disables compression. * it disables compression.
*/ */
public void setCompression( int level ) {
public void setCompressionLevel( int level ) {
this.compression = level; this.compression = level;
} }


@@ -599,7 +626,7 @@ public abstract class AbstractCvsTask extends Task {
* level, AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL. * level, AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL.
*/ */
public void setCompression( boolean usecomp ) { public void setCompression( boolean usecomp ) {
this.setCompression( usecomp ?
setCompressionLevel( usecomp ?
AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL : 0 ); AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL : 0 );
} }




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

@@ -53,11 +53,12 @@
*/ */


package org.apache.tools.ant.taskdefs; package org.apache.tools.ant.taskdefs;

/** /**
* original 1.20 * original 1.20
* *
* NOTE: This implementation has been moved to AbstractCvsTask with the addition of
* some accessors for extensibility.
* NOTE: This implementation has been moved to AbstractCvsTask with
* the addition of some accessors for extensibility.
* *
* *
* @author costin@dnt.ro * @author costin@dnt.ro
@@ -65,14 +66,13 @@ package org.apache.tools.ant.taskdefs;
* @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a> * @author Wolfgang Werner <a href="mailto:wwerner@picturesafe.de">wwerner@picturesafe.de</a>
* @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>
* *
* @since Ant 1.1
*
* @ant.task category="scm" * @ant.task category="scm"
*/ */
public class Cvs extends AbstractCvsTask { public class Cvs extends AbstractCvsTask {


public Cvs(){

public Cvs() {
setTaskName("cvs"); setTaskName("cvs");
} }
} }



Loading…
Cancel
Save