0) {
addCommandArgument("-D");
@@ -465,6 +514,9 @@ public abstract class AbstractCvsTask extends Task {
public void setCommand(String c) {
this.command = c;
}
+ public String getCommand() {
+ return this.command;
+ }
public void setQuiet(boolean q) {
quiet = q;
@@ -489,6 +541,66 @@ public abstract class AbstractCvsTask extends Task {
public void setFailOnError(boolean failOnError) {
this.failOnError = failOnError;
}
-}
+ /**
+ * Configure a commandline element for things like cvsRoot, quiet, etc.
+ */
+ protected void configureCommandline( Commandline c ) {
+ if( c == null ) {
+ return;
+ }
+ c.setExecutable( "cvs" );
+ if (cvsPackage != null) {
+ c.createArgument(true).setLine(cvsPackage);
+ }
+ if ( this.compression > 0 && this.compression < 10 ) {
+ c.createArgument(true).setValue("-z"+this.compression);
+ }
+ if (quiet) {
+ c.createArgument(true).setValue("-q");
+ }
+ if (noexec) {
+ c.createArgument(true).setValue("-n");
+ }
+ if (cvsRoot != null) {
+ c.createArgument(true).setLine("-d"+cvsRoot);
+ }
+ }
+ public void addConfiguredCommandline( Commandline c ) {
+ this.addConfiguredCommandline( c, false );
+ }
+
+ /**
+ * Configures and adds the given Commandline.
+ * @param insertAtStart If true, c is
+ */
+ public void addConfiguredCommandline( Commandline c, boolean insertAtStart ) {
+ if( c == null ) { return; }
+ this.configureCommandline( c );
+ if( insertAtStart ) {
+ vecCommandlines.insertElementAt( c, 0 );
+ }
+ else {
+ vecCommandlines.addElement( c );
+ }
+ }
+
+ /**
+ * If set to a value 1-9 it adds -zN to the cvs command line, else
+ * it disables compression.
+ */
+ public void setCompression( int level ) {
+ this.compression = level;
+ }
+
+ /**
+ * @param usecomp If true, turns on compression using default
+ * level, AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL.
+ */
+ public void setCompression( boolean usecomp ) {
+ this.setCompression( usecomp ?
+ AbstractCvsTask.DEFAULT_COMPRESSION_LEVEL : 0 );
+ }
+
+}
diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java
index 1875faaf0..17d52e50d 100644
--- a/src/main/org/apache/tools/ant/types/Commandline.java
+++ b/src/main/org/apache/tools/ant/types/Commandline.java
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2000-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -80,7 +80,7 @@ import java.util.StringTokenizer;
* createAcommandline
which returns an instance of this class.
*
* @author thomas.haas@softwired-inc.com
- * @author Stefan Bodewig
+ * @author Stefan Bodewig
*/
public class Commandline implements Cloneable {
@@ -124,6 +124,9 @@ public class Commandline implements Cloneable {
* @param line line to split into several commandline arguments
*/
public void setLine(String line) {
+ if( line == null ) {
+ return;
+ }
parts = translateCommandline(line);
}
@@ -132,7 +135,7 @@ public class Commandline implements Cloneable {
* PATH - ensures the right separator for the local platform
* is used.
*
- * @param value a single commandline argument.
+ * @param value a single commandline argument.
*/
public void setPath(Path value) {
parts = new String[] {value.toString()};
@@ -140,9 +143,9 @@ public class Commandline implements Cloneable {
/**
* Sets a single commandline argument to the absolute filename
- * of the given file.
+ * of the given file.
*
- * @param value a single commandline argument.
+ * @param value a single commandline argument.
*/
public void setFile(File value) {
parts = new String[] {value.getAbsolutePath()};
@@ -191,16 +194,37 @@ public class Commandline implements Cloneable {
/**
* Creates an argument object.
- * Each commandline object has at most one instance of the argument class.
+ *
+ * Each commandline object has at most one instance of the
+ * argument class. This method calls
+ * this.createArgument(false)
.
+ *
+ * @see #createArgument(boolean)
* @return the argument object.
*/
public Argument createArgument() {
+ return this.createArgument( false );
+ }
+
+ /**
+ * Creates an argument object and adds it to our list of args.
+ *
+ * Each commandline object has at most one instance of the
+ * argument class.
+ *
+ * @param insertAtStart if true, the argument is inserted at the
+ * beginning of the list of args, otherwise it is appended.
+ */
+ public Argument createArgument( boolean insertAtStart ) {
Argument argument = new Argument();
- arguments.addElement(argument);
+ if(insertAtStart) {
+ arguments.insertElementAt(argument,0);
+ } else {
+ arguments.addElement(argument);
+ }
return argument;
}
-
/**
* Sets the executable to run.
*/
@@ -248,11 +272,13 @@ public class Commandline implements Cloneable {
for (int i=0; i
*
* @exception BuildException if the argument contains both, single
- * and double quotes.
+ * and double quotes.
*/
public static String quoteArgument(String argument) {
if (argument.indexOf("\"") > -1) {
@@ -310,7 +336,7 @@ public class Commandline implements Cloneable {
}
// parse with a simple finite state machine
-
+
final int normal = 0;
final int inQuote = 1;
final int inDoubleQuote = 2;
@@ -390,7 +416,7 @@ public class Commandline implements Cloneable {
public void clearArgs() {
arguments.removeAllElements();
}
-
+
/**
* Return a marker.
*
@@ -401,4 +427,5 @@ public class Commandline implements Cloneable {
public Marker createMarker() {
return new Marker(arguments.size());
}
+
}