remainders : mostly instance variables which should be private but are protected or public git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274820 13f79535-47bb-0310-9956-ffa450edef68master
@@ -58,9 +58,9 @@ import org.apache.oro.text.perl.Perl5Util; | |||
import java.util.ArrayList; | |||
/** | |||
/** | |||
* FStatP4OutputHandler - spezialied Perforce output handler | |||
* able to sort files recognized as managed by Perforce and files not | |||
* able to sort files recognized as managed by Perforce and files not | |||
* managed by Perforce in the output | |||
* | |||
* @author <A HREF="mailto:miha@softhome.net">Miha</A> | |||
@@ -83,7 +83,7 @@ class FStatP4OutputHandler extends P4HandlerAdapter { | |||
String f = util.group(1); | |||
nonExisting.add(f); | |||
} | |||
parent.log(parent.util.substitute("s/^.*: //", line), | |||
parent.log(parent.util.substitute("s/^.*: //", line), | |||
Project.MSG_VERBOSE); | |||
} | |||
@@ -72,9 +72,16 @@ import org.apache.tools.ant.types.FileSet; | |||
* <b>Example Usage:</b> | |||
* <table border="1"> | |||
* <th>Function</th><th>Command</th> | |||
* <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings specified</td><td><P4add <br>P4view="//projects/foo/main/source/..." <br>P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient"><br><fileset basedir="dir" includes="**/*.java"><br></p4add></td></tr> | |||
* <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings defined in environment</td><td><P4add P4view="//projects/foo/main/source/..." /><br><fileset basedir="dir" includes="**/*.java"><br></p4add></td></tr> | |||
* <tr><td>Specify the length of command line arguments to pass to each invocation of p4</td><td><p4add Commandlength="450"></td></tr> | |||
* <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings specified</td> | |||
* <td><P4add <br>P4view="//projects/foo/main/source/..." <br>P4User="fbloggs" | |||
* <br>P4Port="km01:1666" | |||
* <br>P4Client="fbloggsclient"><br><fileset basedir="dir" includes="**/*.java"><br> | |||
* </p4add></td></tr> | |||
* <tr><td>Add files using P4USER, P4PORT and P4CLIENT settings defined in environment</td><td> | |||
* <P4add P4view="//projects/foo/main/source/..." /><br><fileset basedir="dir" | |||
* includes="**/*.java"><br></p4add></td></tr> | |||
* <tr><td>Specify the length of command line arguments to pass to each invocation of p4</td> | |||
* <td><p4add Commandlength="450"></td></tr> | |||
* </table> | |||
* | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
@@ -83,17 +90,19 @@ import org.apache.tools.ant.types.FileSet; | |||
* @ant.task category="scm" | |||
*/ | |||
public class P4Add extends P4Base { | |||
private static final int DEFAULT_CMD_LENGTH = 450; | |||
private int changelist; | |||
private String addCmd = ""; | |||
private Vector filesets = new Vector(); | |||
private int cmdLength = 450; | |||
private int cmdLength = DEFAULT_CMD_LENGTH; | |||
/** | |||
* positive integer specifying the maximum length | |||
* of the commandline when calling Perforce to add the files. | |||
* Defaults to 450, higher values mean faster execution, | |||
* but also possible failures. | |||
* @param len maximum length of command line default is 450. | |||
* @throws BuildException if trying to set the command line length to 0 or less. | |||
*/ | |||
public void setCommandlength(int len) throws BuildException { | |||
@@ -107,6 +116,10 @@ public class P4Add extends P4Base { | |||
* If specified the open files are associated with the | |||
* specified pending changelist number; otherwise the open files are | |||
* associated with the default changelist. | |||
* | |||
* @param changelist the change list number | |||
* | |||
* @throws BuildException if trying to set a change list number <=0. | |||
*/ | |||
public void setChangelist(int changelist) throws BuildException { | |||
if (changelist <= 0) { | |||
@@ -118,11 +131,18 @@ public class P4Add extends P4Base { | |||
/** | |||
* files to add | |||
* | |||
* @param set the FileSet that one wants to add to Perforce Source Control | |||
*/ | |||
public void addFileset(FileSet set) { | |||
filesets.addElement(set); | |||
} | |||
/** | |||
* run the task. | |||
* | |||
* @throws BuildException if the execution of the Perforce command fails. | |||
*/ | |||
public void execute() throws BuildException { | |||
if (P4View != null) { | |||
@@ -75,7 +75,7 @@ import org.apache.tools.ant.types.Commandline; | |||
* @see P4Edit | |||
* @see P4Submit | |||
* @see P4Label | |||
* @see org.apache.tools.ant.taskdefs.Exec | |||
* @see org.apache.tools.ant.taskdefs.Execute | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
*/ | |||
public abstract class P4Base extends org.apache.tools.ant.Task { | |||
@@ -112,6 +112,8 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
/** | |||
* The p4d server and port to connect to; | |||
* optional, default "perforce:1666" | |||
* | |||
* @param P4Port the port one wants to set such as localhost:1666 | |||
*/ | |||
public void setPort(String P4Port) { | |||
this.P4Port = "-p" + P4Port; | |||
@@ -120,6 +122,8 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
/** | |||
* The p4 client spec to use; | |||
* optional, defaults to the current user | |||
* | |||
* @param P4Client the name of the Perforce client spec | |||
*/ | |||
public void setClient(String P4Client) { | |||
this.P4Client = "-c" + P4Client; | |||
@@ -128,22 +132,34 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
/** | |||
* The p4 username; | |||
* optional, defaults to the current user | |||
* | |||
* @param P4User the user name | |||
*/ | |||
public void setUser(String P4User) { | |||
this.P4User = "-u" + P4User; | |||
} | |||
/** | |||
* Set global P4 options; Used on all | |||
* of the Perforce tasks. | |||
*/ | |||
* | |||
* @param P4Opts global options, to use a specific P4Config file for instance | |||
*/ | |||
public void setGlobalopts(String P4Opts) { | |||
this.P4Opts = P4Opts; | |||
} | |||
/** | |||
* The client, branch or label view to operate upon; | |||
* optional default "//..." | |||
* optional default "//...". | |||
* | |||
* the view is required for the following tasks : | |||
* <ul> | |||
* <li>p4delete</li> | |||
* <li>p4edit</li> | |||
* <li>p4reopen</li> | |||
* <li>p4resolve</li> | |||
* </ul> | |||
* | |||
* @param P4View the view one wants to use | |||
*/ | |||
public void setView(String P4View) { | |||
this.P4View = P4View; | |||
@@ -152,6 +168,9 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
/** | |||
* Set extra command options; only used on some | |||
* of the Perforce tasks. | |||
* | |||
* @param P4CmdOpts command line options going after the particular | |||
* Perforce command | |||
*/ | |||
public void setCmdopts(String P4CmdOpts) { | |||
this.P4CmdOpts = P4CmdOpts; | |||
@@ -160,11 +179,24 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
/** | |||
* whether to stop the build (true, default) | |||
* or keep going if an error is returned from the p4 command | |||
* @param fail indicates whether one wants to fail the build if an error comes from the | |||
* Perforce command | |||
*/ | |||
public void setFailonerror(boolean fail) { | |||
failOnError = fail; | |||
} | |||
/** | |||
* sets attributes Port, Client, User from properties | |||
* if these properties are defined. | |||
* Called automatically by UnknownElement | |||
* @see org.apache.tools.ant.UnknownElement | |||
* <table> | |||
* <tr><th>Property</th><th>Attribute</th></tr> | |||
* <tr><td>p4.port</td><td>Port</td></tr> | |||
* <tr><td>p4.client</td><td>Client</td></tr> | |||
* <tr><td>p4.user</td><td>User</td></tr> | |||
* </table> | |||
*/ | |||
public void init() { | |||
util = new Perl5Util(); | |||
@@ -182,14 +214,23 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
setUser(tmpprop); | |||
} | |||
} | |||
/** | |||
* no usages found for this method | |||
* runs a Perforce command without a handler | |||
* @param command the command that one wants to execute | |||
* @throws BuildException if failonerror is set and the command fails | |||
*/ | |||
protected void execP4Command(String command) throws BuildException { | |||
execP4Command(command, null); | |||
} | |||
/** Execute P4 command assembled by subclasses. | |||
@param command The command to run | |||
@param handler A P4Handler to process any input and output | |||
/** | |||
* Execute P4 command assembled by subclasses. | |||
* | |||
* @param command The command to run | |||
* @param handler A P4Handler to process any input and output | |||
* | |||
* @throws BuildException if failonerror has been set to true | |||
*/ | |||
protected void execP4Command(String command, P4Handler handler) throws BuildException { | |||
try { | |||
@@ -232,6 +273,7 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||
try { | |||
handler.stop(); | |||
} catch (Exception e) { | |||
log(e.toString(), Project.MSG_ERR); | |||
} | |||
} | |||
@@ -81,7 +81,9 @@ public class P4Change extends P4Base { | |||
protected String description = "AutoSubmit By Ant"; | |||
/** | |||
* throw all immutability rules to the wind | |||
* creates a new Perforce change list | |||
* sets the p4.change property to the number of the new change list | |||
* @throws BuildException if the word error appears in the output coming from Perforce | |||
*/ | |||
public void execute() throws BuildException { | |||
@@ -113,7 +115,12 @@ public class P4Change extends P4Base { | |||
execP4Command("change -i", handler); | |||
} | |||
/** | |||
* returns the text of an empty change list | |||
* @return the text of an empty change list | |||
* @throws BuildException if the text error is displayed | |||
* in the Perforce output outside of a comment line | |||
*/ | |||
public String getEmptyChangeList() throws BuildException { | |||
final StringBuffer stringbuf = new StringBuffer(); | |||
@@ -121,28 +128,23 @@ public class P4Change extends P4Base { | |||
public void process(String line) { | |||
if (!util.match("/^#/", line)) { | |||
if (util.match("/error/", line)) { | |||
log("Client Error", Project.MSG_VERBOSE); | |||
throw new BuildException("Perforce Error, check client settings and/or server"); | |||
throw new BuildException("Perforce Error, " | |||
+ "check client settings and/or server"); | |||
} else if (util.match("/<enter description here>/", line)) { | |||
// we need to escape the description in case there are / | |||
description = backslash(description); | |||
line = util.substitute("s/<enter description here>/" + description + "/", line); | |||
line = util.substitute("s/<enter description here>/" | |||
+ description + "/", line); | |||
} else if (util.match("/\\/\\//", line)) { | |||
//Match "//" for begining of depot filespec | |||
return; | |||
} | |||
stringbuf.append(line); | |||
stringbuf.append("\n"); | |||
} | |||
} | |||
}); | |||
return stringbuf.toString(); | |||
} | |||
@@ -152,7 +154,8 @@ public class P4Change extends P4Base { | |||
* always backslashes in a string unless they escape the delimiter. | |||
* @param value the string to backslash for slashes | |||
* @return the backslashed string | |||
* @see < a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html#substitute(java.lang.String,%20java.lang.String)">Oro</a> | |||
* @see <a href="http://jakarta.apache.org/oro/api/org/apache/oro/text/perl/Perl5Util.html | |||
* #substitute(java.lang.String,%20java.lang.String)">Oro</a> | |||
*/ | |||
public static final String backslash(String value) { | |||
final StringBuffer buf = new StringBuffer(value.length()); | |||
@@ -170,6 +173,7 @@ public class P4Change extends P4Base { | |||
/** | |||
* Description for ChangeList;optional. | |||
* If none is specified, it will default to "AutoSubmit By Ant" | |||
* @param desc description for the change list | |||
*/ | |||
public void setDescription(String desc) { | |||
this.description = desc; | |||
@@ -86,14 +86,30 @@ import org.apache.tools.ant.Project; | |||
*/ | |||
public class P4Counter extends P4Base { | |||
/** | |||
* name of the counter | |||
*/ | |||
public String counter = null; | |||
/** | |||
* name of an optional property | |||
*/ | |||
public String property = null; | |||
/** | |||
* flag telling whether the value of the counter should be set | |||
*/ | |||
public boolean shouldSetValue = false; | |||
/** | |||
* flag telling whether a property should be set | |||
*/ | |||
public boolean shouldSetProperty = false; | |||
/** | |||
* new value for the counter | |||
*/ | |||
public int value = 0; | |||
/** | |||
* The name of the counter; required | |||
* @param counter name of the counter | |||
*/ | |||
public void setName(String counter) { | |||
this.counter = counter; | |||
@@ -101,6 +117,7 @@ public class P4Counter extends P4Base { | |||
/** | |||
* The new value for the counter; optional. | |||
* @param value new value for the counter | |||
*/ | |||
public void setValue(int value) { | |||
this.value = value; | |||
@@ -109,6 +126,8 @@ public class P4Counter extends P4Base { | |||
/** | |||
* A property to be set with the value of the counter | |||
* @param property the name of a property to set with the value | |||
* of the counter | |||
*/ | |||
public void setProperty(String property) { | |||
this.property = property; | |||
@@ -117,6 +136,7 @@ public class P4Counter extends P4Base { | |||
/** | |||
* again, properties are mutable in this tsk | |||
* @throws BuildException if the required parameters are not supplied. | |||
*/ | |||
public void execute() throws BuildException { | |||
@@ -125,7 +145,8 @@ public class P4Counter extends P4Base { | |||
} | |||
if (shouldSetValue && shouldSetProperty) { | |||
throw new BuildException("Cannot both set the value of the property and retrieve the value of the property."); | |||
throw new BuildException("Cannot both set the value of the property and retrieve the " | |||
+ "value of the property."); | |||
} | |||
String command = "counter " + P4CmdOpts + " " + counter; | |||
@@ -150,7 +171,8 @@ public class P4Counter extends P4Base { | |||
value = Integer.parseInt(line); | |||
myProj.setProperty(property, "" + value); | |||
} catch (NumberFormatException nfe) { | |||
throw new BuildException("Perforce error. Could not retrieve counter value."); | |||
throw new BuildException("Perforce error. " | |||
+ "Could not retrieve counter value."); | |||
} | |||
} | |||
}; | |||
@@ -65,22 +65,31 @@ import org.apache.tools.ant.BuildException; | |||
* @todo What to do if file is already open in one of our changelists perhaps | |||
* (See also {@link P4Edit P4Edit})?<br> | |||
* | |||
* @author <A HREF="mailto:mike@tmorph.com">Mike Roberts</A>, <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
* @author <A HREF="mailto:mike@tmorph.com">Mike Roberts</A> | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
* | |||
* @ant.task category="scm" | |||
*/ | |||
public class P4Delete extends P4Base { | |||
/** | |||
* number of the change list to work on | |||
*/ | |||
public String change = null; | |||
/** | |||
* An existing changelist number for the deletion; optional | |||
* but strongly recommended. | |||
* @param change the number of a change list | |||
*/ | |||
public void setChange(String change) { | |||
this.change = change; | |||
} | |||
/** | |||
* executes the p4 delete task | |||
* @throws BuildException if there is no view specified | |||
*/ | |||
public void execute() throws BuildException { | |||
if (change != null) { | |||
P4CmdOpts = "-c " + change; | |||
@@ -78,16 +78,24 @@ import org.apache.tools.ant.BuildException; | |||
public class P4Edit extends P4Base { | |||
/** | |||
* number of the change list to work on | |||
*/ | |||
public String change = null; | |||
/** | |||
* An existing changelist number to assign files to; optional | |||
* but strongly recommended. | |||
* @param change the change list number | |||
*/ | |||
public void setChange(String change) { | |||
this.change = change; | |||
} | |||
/** | |||
* Run the p4 edit command | |||
* @throws BuildException if there is no view specified | |||
*/ | |||
public void execute() throws BuildException { | |||
if (change != null) { | |||
P4CmdOpts = "-c " + change; | |||
@@ -74,7 +74,8 @@ import org.apache.tools.ant.types.FileSet; | |||
* | |||
* <br><b>Example Usage:</b><br> | |||
* <pre> | |||
* <project name="p4fstat" default="p4fstat" basedir="C:\dev\gnu"> | |||
* <project name="p4fstat" default="p4fstat" | |||
* basedir="C:\dev\gnu"> | |||
* <target name="p4fstat" > | |||
* <p4fstat showfilter="all"> | |||
* <fileset dir="depot" includes="**\/*"/> | |||
@@ -94,7 +95,8 @@ public class P4Fstat extends P4Base { | |||
private int changelist; | |||
private String addCmd = ""; | |||
private Vector filesets = new Vector(); | |||
private int cmdLength = 300; | |||
private static final int DEFAULT_CMD_LENGTH = 300; | |||
private int cmdLength = DEFAULT_CMD_LENGTH; | |||
private static final int SHOW_ALL = 0; | |||
private static final int SHOW_EXISTING = 1; | |||
private static final int SHOW_NON_EXISTING = 2; | |||
@@ -110,7 +112,16 @@ public class P4Fstat extends P4Base { | |||
private static final String NONEXISTING_HEADER | |||
= "Following files do not exist in perforce"; | |||
/** | |||
* sets the filter that one wants applied | |||
* <table> | |||
* <tr><th>Option</th><th>Meaning</th></tr> | |||
* <tr><td>all</td><td>all files under Perforce control or not</td></tr> | |||
* <tr><td>existing</td><td>only files under Perforce control</td></tr> | |||
* <tr><td>non-existing</td><td>only files not under Perforce control or not</td></tr> | |||
* </table> | |||
* @param filter should be one of all|existing|non-existing | |||
*/ | |||
public void setShowFilter(String filter) { | |||
if (filter.equalsIgnoreCase("all")) { | |||
show = SHOW_ALL; | |||
@@ -124,7 +135,11 @@ public class P4Fstat extends P4Base { | |||
} | |||
} | |||
/** | |||
* sets optionally a change list number | |||
* @param changelist change list that one wants information about | |||
* @throws BuildException if the change list number is negative | |||
*/ | |||
public void setChangelist(int changelist) throws BuildException { | |||
if (changelist <= 0) { | |||
throw new BuildException("P4FStat: Changelist# should be a " | |||
@@ -134,10 +149,18 @@ public class P4Fstat extends P4Base { | |||
this.changelist = changelist; | |||
} | |||
/** | |||
* adds a fileset to be examined by p4fstat | |||
* @param set the fileset to add | |||
*/ | |||
public void addFileset(FileSet set) { | |||
filesets.addElement(set); | |||
} | |||
/** | |||
* executes the p4fstat task | |||
* @throws BuildException if no files are specified | |||
*/ | |||
public void execute() throws BuildException { | |||
handler = new FStatP4OutputHandler(this); | |||
@@ -172,7 +195,7 @@ public class P4Fstat extends P4Base { | |||
execP4Fstat(filelist); | |||
} | |||
} else { | |||
log("No files specified to add!", Project.MSG_WARN); | |||
log("No files specified to query status on!", Project.MSG_WARN); | |||
} | |||
} | |||
@@ -186,7 +209,10 @@ public class P4Fstat extends P4Base { | |||
} | |||
/** | |||
* return the number of files seen | |||
* @return the number of files seen | |||
*/ | |||
public int getLengthOfTask() { | |||
return fileNum; | |||
} | |||
@@ -64,15 +64,17 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; | |||
*/ | |||
public interface P4Handler extends ExecuteStreamHandler { | |||
/** | |||
* processing of one line of stdout or of stderr | |||
* @param line | |||
*/ | |||
public void process(String line) throws BuildException; | |||
/** | |||
* processing of one line of stdout or of stderr | |||
* @param line a line of stdout or stderr that the implementation will process | |||
* @throws BuildException at the discretion of the implementation. | |||
*/ | |||
void process(String line) throws BuildException; | |||
/** | |||
* set any data to be written to P4's stdin | |||
* @param line the text to write to P4's stdin | |||
*/ | |||
public void setOutput(String line) throws BuildException; | |||
/** | |||
* set any data to be written to P4's stdin | |||
* @param line the text to write to P4's stdin | |||
* @throws BuildException if the line cannot be processed. | |||
*/ | |||
void setOutput(String line) throws BuildException; | |||
} |
@@ -62,8 +62,9 @@ import java.io.OutputStream; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.taskdefs.PumpStreamHandler; | |||
/** | |||
* base class to manage streams around the execution of the Perforce | |||
* command line client | |||
* base class to manage streams around the execution of the Perforce | |||
* command line client | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
*/ | |||
public abstract class P4HandlerAdapter implements P4Handler { | |||
@@ -79,15 +80,21 @@ public abstract class P4HandlerAdapter implements P4Handler { | |||
/** | |||
* subclasses of P4HandlerAdapter must implement this routine | |||
* processing of one line of stdout or of stderr | |||
* @param line | |||
* @param line line of stdout or stderr to process | |||
*/ | |||
public abstract void process(String line); | |||
/** | |||
* this routine gets called by the execute routine of the Execute class | |||
* it connects the PumpStreamHandler to the input/output/error streams of the process. | |||
* @throws BuildException | |||
* @see org.apache.tools.ant.taskdefs.Execute#execute | |||
*/ | |||
public void start() throws BuildException { | |||
if (p4input != null && p4input.length() > 0) { | |||
myHandler = new PumpStreamHandler(new P4OutputStream(this),new P4OutputStream(this), new ByteArrayInputStream(p4input.getBytes())); | |||
} | |||
else { | |||
myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this), | |||
new ByteArrayInputStream(p4input.getBytes())); | |||
} else { | |||
myHandler = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this)); | |||
} | |||
myHandler.setProcessInputStream(os); | |||
@@ -96,22 +103,44 @@ public abstract class P4HandlerAdapter implements P4Handler { | |||
myHandler.start(); | |||
} | |||
/** | |||
* stops the processing of streams | |||
* called from P4Base#execP4Command(String command, P4Handler handler) | |||
* @see P4Base#execP4Command(String, P4Handler) | |||
*/ | |||
public void stop() { | |||
myHandler.stop(); | |||
} | |||
OutputStream os; //OUtput | |||
InputStream is; //Input | |||
OutputStream os; //Input | |||
InputStream is; //Output | |||
InputStream es; //Error | |||
/** | |||
* connects the handler to the input stream into Perforce | |||
* used indirectly by tasks requiring to send specific standard input | |||
* such as p4label, p4change | |||
* @param os the stream bringing input to the p4 executable | |||
* @throws IOException under unknown circumstances | |||
*/ | |||
public void setProcessInputStream(OutputStream os) throws IOException { | |||
this.os = os; | |||
} | |||
/** | |||
* connects the handler to the stderr of the Perforce process | |||
* @param is stderr coming from Perforce | |||
* @throws IOException under unknown circumstances | |||
*/ | |||
public void setProcessErrorStream(InputStream is) throws IOException { | |||
this.es = is; | |||
} | |||
/** | |||
* connects the handler to the stdout of the Perforce process | |||
* @param is stdout coming from Perforce | |||
* @throws IOException under unknown circumstances | |||
*/ | |||
public void setProcessOutputStream(InputStream is) throws IOException { | |||
this.is = is; | |||
} | |||
@@ -67,7 +67,8 @@ import org.apache.tools.ant.BuildException; | |||
* although P4Integrate can open files to the default change, | |||
* P4Submit cannot yet submit to it. | |||
* Example Usage:<br> | |||
* <p4integrate change="${p4.change}" fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" /> | |||
* <p4integrate change="${p4.change}" | |||
* fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" /> | |||
* | |||
* @author <A HREF="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</A> | |||
* | |||
@@ -279,15 +280,18 @@ public class P4Integrate extends P4Base { | |||
/** | |||
* sets flag indicating if one wants to propagate the source file type | |||
* | |||
* @param propagatesourcefiletype set it to true if you want to change the type of existing target files according to type of source file. | |||
* @param propagatesourcefiletype | |||
* set it to true if you want to change the type of existing target files | |||
* according to type of source file. | |||
*/ | |||
public void setPropagatesourcefiletype(boolean propagatesourcefiletype) { | |||
this.propagatesourcefiletype = propagatesourcefiletype; | |||
} | |||
/** | |||
* returns flag indicating if one wants to suppress the copying on the local hard disk of new target files | |||
* indicates intention to suppress the copying on the local hard disk of new target files. | |||
* | |||
* @return flag indicating if one wants to suppress the copying on the local hard disk of new target files | |||
* @return indicates intention to suppress the copying | |||
* on the local hard disk of new target files. | |||
*/ | |||
public boolean isNocopynewtargetfiles() { | |||
return nocopynewtargetfiles; | |||
@@ -296,7 +300,8 @@ public class P4Integrate extends P4Base { | |||
/** | |||
* sets nocopynewtargetfiles flag | |||
* | |||
* @param nocopynewtargetfiles set it to true to gain speed in integration by not copying on the local Perforce client new target files | |||
* @param nocopynewtargetfiles set it to true to gain speed in integration by not copying on | |||
* the local Perforce client new target files | |||
*/ | |||
public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) { | |||
this.nocopynewtargetfiles = nocopynewtargetfiles; | |||
@@ -304,6 +309,7 @@ public class P4Integrate extends P4Base { | |||
/** | |||
* execute the p4 integrate | |||
* @throws BuildException if there are missing parameters | |||
*/ | |||
public void execute() throws BuildException { | |||
if (change != null) { | |||
@@ -315,39 +321,34 @@ public class P4Integrate extends P4Base { | |||
if (this.restoredeletedrevisions) { | |||
P4CmdOpts = P4CmdOpts + " -d"; | |||
} | |||
if ( this.leavetargetrevision) { | |||
if (this.leavetargetrevision) { | |||
P4CmdOpts = P4CmdOpts + " -h"; | |||
} | |||
if ( this.enablebaselessmerges ) { | |||
if (this.enablebaselessmerges) { | |||
P4CmdOpts = P4CmdOpts + " -i"; | |||
} | |||
if (this.simulationmode ) { | |||
if (this.simulationmode) { | |||
P4CmdOpts = P4CmdOpts + " -n"; | |||
} | |||
if ( this.reversebranchmappings ) { | |||
if (this.reversebranchmappings) { | |||
P4CmdOpts = P4CmdOpts + " -r"; | |||
} | |||
if ( this.propagatesourcefiletype ) { | |||
if (this.propagatesourcefiletype) { | |||
P4CmdOpts = P4CmdOpts + " -t"; | |||
} | |||
if ( this.nocopynewtargetfiles ) { | |||
if (this.nocopynewtargetfiles) { | |||
P4CmdOpts = P4CmdOpts + "-v"; | |||
} | |||
String command; | |||
if (branch == null && fromfile != null && tofile != null) { | |||
command = P4CmdOpts + " " + fromfile + " " + tofile; | |||
} | |||
else if ( branch != null && fromfile == null && tofile != null ) | |||
{ | |||
} else if (branch != null && fromfile == null && tofile != null) { | |||
command = P4CmdOpts + " -b " + branch + " " + tofile; | |||
} | |||
else if ( branch != null && fromfile != null ) | |||
{ | |||
command = P4CmdOpts + " -b " + branch + " -s "+ fromfile + " " + tofile; | |||
} | |||
else { | |||
throw new BuildException("you need to specify fromfile and tofile, or branch and tofile, or branch and fromfile, or branch and fromfile and tofile "); | |||
} else if (branch != null && fromfile != null) { | |||
command = P4CmdOpts + " -b " + branch + " -s " + fromfile + " " + tofile; | |||
} else { | |||
throw new BuildException("you need to specify fromfile and tofile, " | |||
+ "or branch and tofile, or branch and fromfile, or branch and fromfile and tofile "); | |||
} | |||
execP4Command("-s integrate " + command, new SimpleP4OutputHandler(this)); | |||
} | |||
@@ -88,6 +88,7 @@ public class P4Label extends P4Base { | |||
/** | |||
* The name of the label; optional, default "AntLabel" | |||
* @param name the name of the label | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
@@ -95,6 +96,7 @@ public class P4Label extends P4Base { | |||
/** | |||
*Label Description; optional | |||
* @param desc description of the label | |||
*/ | |||
public void setDesc(String desc) { | |||
this.desc = desc; | |||
@@ -102,13 +104,15 @@ public class P4Label extends P4Base { | |||
/** | |||
* when set to "locked", Perforce will lock the label once created; optional. | |||
* @param lock only admissible value "locked" | |||
*/ | |||
public void setLock(String lock) { | |||
this.lock = lock; | |||
} | |||
/** | |||
* do the work | |||
* do the work | |||
* @throws BuildException if failonerror has been set to true and Perforce fails | |||
*/ | |||
public void execute() throws BuildException { | |||
log("P4Label exec:", Project.MSG_INFO); | |||
@@ -142,10 +146,10 @@ public class P4Label extends P4Base { | |||
//We have to create a unlocked label first | |||
String newLabel = | |||
"Label: " + name + | |||
"\nDescription: " + desc + | |||
"\nOptions: unlocked" + | |||
"\nView: \n\t" + P4View; | |||
"Label: " + name | |||
+ "\nDescription: " + desc | |||
+ "\nOptions: unlocked" | |||
+ "\nView: \n\t" + P4View; | |||
P4Handler handler = new P4HandlerAdapter() { | |||
public void process(String line) { | |||
@@ -70,7 +70,8 @@ import org.apache.tools.ant.util.StringUtils; | |||
* | |||
* Example Usage: | |||
* <pre> | |||
* <p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}" view="//depot/...#head;//depot2/file1#25" /> | |||
* <p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}" | |||
* view="//depot/...#head;//depot2/file1#25" /> | |||
* </pre> | |||
* | |||
* @author <A HREF="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</A> | |||
@@ -84,7 +85,8 @@ public class P4Labelsync extends P4Base { | |||
private boolean delete; /* -n */ | |||
private boolean simulationmode; /* -n */ | |||
/** | |||
* -a flag of p4 labelsync - preserve files which exist in the label, but not in the current view | |||
* -a flag of p4 labelsync - preserve files which exist in the label, | |||
* but not in the current view | |||
* @return add attribute | |||
* if set to true the task will not remove any files from the label | |||
* only add files which were not there previously or update these where the revision has changed | |||
@@ -94,7 +96,8 @@ public class P4Labelsync extends P4Base { | |||
return add; | |||
} | |||
/** | |||
* -a flag of p4 labelsync - preserve files which exist in the label, but not in the current view | |||
* -a flag of p4 labelsync - preserve files which exist in the label, | |||
* but not in the current view | |||
* @param add if set to true the task will not remove any files from the label | |||
* only add files which were not there previously or update these where the revision has changed | |||
* the add attribute is the -a flag of p4 labelsync | |||
@@ -103,7 +106,8 @@ public class P4Labelsync extends P4Base { | |||
this.add = add; | |||
} | |||
/** | |||
* -d flag of p4 labelsync; indicates an intention of deleting from the label the files specified in the view | |||
* -d flag of p4 labelsync; indicates an intention of deleting from the label | |||
* the files specified in the view | |||
* @return delete attribute | |||
*/ | |||
public boolean isDelete() { | |||
@@ -111,8 +115,10 @@ public class P4Labelsync extends P4Base { | |||
} | |||
/** | |||
* -d flag of p4 labelsync; indicates an intention of deleting from the label the files specified in the view | |||
* @param delete | |||
* -d flag of p4 labelsync; indicates an intention of deleting from the label | |||
* the files specified in the view | |||
* @param delete indicates intention of deleting from the label | |||
* the files specified in the view | |||
*/ | |||
public void setDelete(boolean delete) { | |||
this.delete = delete; | |||
@@ -121,6 +127,7 @@ public class P4Labelsync extends P4Base { | |||
/** | |||
* The name of the label; optional, default "AntLabel" | |||
* @param name of the label | |||
*/ | |||
public void setName(String name) { | |||
this.name = name; | |||
@@ -134,7 +141,7 @@ public class P4Labelsync extends P4Base { | |||
} | |||
/** | |||
* -n flag of p4 labelsync - display changes without actually doing them | |||
* @param simulationmode | |||
* @param simulationmode display changes without actually doing them | |||
*/ | |||
public void setSimulationmode(boolean simulationmode) { | |||
this.simulationmode = simulationmode; | |||
@@ -143,6 +150,7 @@ public class P4Labelsync extends P4Base { | |||
/** | |||
* do the work | |||
* @throws BuildException if the label name is not supplied | |||
*/ | |||
public void execute() throws BuildException { | |||
log("P4Labelsync exec:", Project.MSG_INFO); | |||
@@ -152,24 +160,25 @@ public class P4Labelsync extends P4Base { | |||
P4View = StringUtils.replace(P4View, ";", "\n\t"); | |||
} | |||
if (P4View == null) { | |||
P4View=""; | |||
P4View = ""; | |||
} | |||
if (name == null || name.length() < 1) { | |||
throw new BuildException("name attribute is compulsory for labelsync"); | |||
} | |||
if ( this.isSimulationmode() ) { | |||
if (this.isSimulationmode()) { | |||
P4CmdOpts = P4CmdOpts + " -n"; | |||
} | |||
if ( this.isDelete() ) { | |||
if (this.isDelete()) { | |||
P4CmdOpts = P4CmdOpts + " -d"; | |||
} | |||
if ( this.isAdd() ) { | |||
if (this.isAdd()) { | |||
P4CmdOpts = P4CmdOpts + " -a"; | |||
} | |||
execP4Command("-s labelsync -l "+name +" "+ P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); | |||
execP4Command("-s labelsync -l " + name + " " + P4CmdOpts + " " + P4View, | |||
new SimpleP4OutputHandler(this)); | |||
} | |||
@@ -1,7 +1,7 @@ | |||
/* | |||
* The Apache Software License, Version 1.1 | |||
* | |||
* Copyright (c) 2000 The Apache Software Foundation. All rights | |||
* Copyright (c) 2000-2003 The Apache Software Foundation. All rights | |||
* reserved. | |||
* | |||
* Redistribution and use in source and binary forms, with or without | |||
@@ -62,6 +62,10 @@ import org.apache.tools.ant.BuildException; | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
*/ | |||
public interface P4OutputHandler { | |||
public void process(String line) throws BuildException; | |||
/** | |||
* implementations will be able to process lines of output from Perforce | |||
* @param line a line of stdout or stderr coming from Perforce | |||
* @throws BuildException implementations are allowed to throw BuildException | |||
*/ | |||
void process(String line) throws BuildException; | |||
} |
@@ -70,7 +70,7 @@ public class P4OutputStream extends OutputStream { | |||
/** | |||
* creates a new P4OutputStream for a P4Handler | |||
* @param handler | |||
* @param handler the handler which will process the streams | |||
*/ | |||
public P4OutputStream(P4Handler handler) { | |||
this.handler = handler; | |||
@@ -81,6 +81,9 @@ public class P4OutputStream extends OutputStream { | |||
* separator is detected. | |||
* | |||
* @param cc data to log (byte). | |||
* @throws IOException IOException if an I/O error occurs. In particular, | |||
* an <code>IOException</code> may be thrown if the | |||
* output stream has been closed. | |||
*/ | |||
public void write(int cc) throws IOException { | |||
final byte c = (byte) cc; | |||
@@ -105,6 +108,7 @@ public class P4OutputStream extends OutputStream { | |||
/** | |||
* Writes all remaining | |||
* @throws IOException if an I/O error occurs. | |||
*/ | |||
public void close() throws IOException { | |||
if (buffer.size() > 0) { | |||
@@ -74,6 +74,8 @@ public class P4Reopen extends P4Base { | |||
/** | |||
* The changelist to move files to; required. | |||
* @param toChange new change list number | |||
* @throws BuildException if the change parameter is null or empty | |||
*/ | |||
public void setToChange(String toChange) throws BuildException { | |||
if (toChange == null && !toChange.equals("")) { | |||
@@ -83,6 +85,10 @@ public class P4Reopen extends P4Base { | |||
this.toChange = toChange; | |||
} | |||
/** | |||
* do the work | |||
* @throws BuildException if P4View is null | |||
*/ | |||
public void execute() throws BuildException { | |||
if (P4View == null) { | |||
throw new BuildException("No view specified to reopen"); | |||
@@ -63,6 +63,7 @@ import org.apache.tools.ant.BuildException; | |||
/** | |||
* @ant.task category="scm" | |||
* @author <a href="mailto:antoine@antbuild.com">Antoine Levy-Lambert</a> | |||
*/ | |||
public class P4Resolve extends P4Base { | |||
private String resolvemode = null; | |||
@@ -77,14 +78,17 @@ public class P4Resolve extends P4Base { | |||
private static final String SAFE = "safe"; | |||
private static final String THEIRS = "theirs"; | |||
private static final String YOURS = "yours"; | |||
private static final String[] resolvemodes = { | |||
private static final String[] RESOLVE_MODES = { | |||
AUTOMATIC, | |||
FORCE, | |||
SAFE, | |||
THEIRS, | |||
YOURS | |||
}; | |||
/** | |||
* returns the resolve mode | |||
* @return returns the resolve mode | |||
*/ | |||
public String getResolvemode() { | |||
return resolvemode; | |||
} | |||
@@ -97,90 +101,122 @@ public class P4Resolve extends P4Base { | |||
* <li> theirs -at </li> | |||
* <li> yours -ay </li> | |||
* </ul> | |||
* @param resolvemode one of automatic, force, safe, theirs, yours | |||
*/ | |||
public void setResolvemode(String resolvemode) { | |||
boolean found=false; | |||
for (int counter=0; counter < resolvemodes.length; counter++) | |||
{ | |||
if (resolvemode.equals(resolvemodes[counter])) { | |||
found=true; | |||
boolean found = false; | |||
for (int counter = 0; counter < RESOLVE_MODES.length; counter++) { | |||
if (resolvemode.equals(RESOLVE_MODES[counter])) { | |||
found = true; | |||
break; | |||
} | |||
} | |||
if (found==false) { | |||
if (found == false) { | |||
throw new BuildException("Unacceptable value for resolve mode"); | |||
} | |||
this.resolvemode = resolvemode; | |||
} | |||
/** | |||
* allows previously resolved files to be resolved again | |||
* @return flag indicating whether one wants to | |||
* allow previously resolved files to be resolved again | |||
*/ | |||
public boolean isRedoall() { | |||
return redoall; | |||
} | |||
/** | |||
* set the redoall flag | |||
* @param redoall flag indicating whether one want to | |||
* allow previously resolved files to be resolved again | |||
*/ | |||
public void setRedoall(boolean redoall) { | |||
this.redoall = redoall; | |||
} | |||
/** | |||
* read the simulation mode flag | |||
* @return flag indicating whether one wants just to simulate | |||
* the p4 resolve operation whithout actually doing it | |||
*/ | |||
public boolean isSimulationmode() { | |||
return simulationmode; | |||
} | |||
/** | |||
* sets a flag | |||
* @param simulationmode set to true, lists the integrations which would be performed, | |||
* without actually doing them. | |||
*/ | |||
public void setSimulationmode(boolean simulationmode) { | |||
this.simulationmode = simulationmode; | |||
} | |||
/** | |||
* If set to true, attempts a textual merge, even for binary files | |||
* @return flag value | |||
*/ | |||
public boolean isForcetextmode() { | |||
return forcetextmode; | |||
} | |||
/** | |||
* If set to true, attempts a textual merge, even for binary files | |||
* @param forcetextmode set the flag value | |||
*/ | |||
public void setForcetextmode(boolean forcetextmode) { | |||
this.forcetextmode = forcetextmode; | |||
} | |||
/** | |||
* If set to true, puts in markers for all changes, conflicting or not | |||
* @return flag markersforall value | |||
*/ | |||
public boolean isMarkersforall() { | |||
return markersforall; | |||
} | |||
/** | |||
* If set to true, puts in markers for all changes, conflicting or not | |||
* @param markersforall flag true or false | |||
*/ | |||
public void setMarkersforall(boolean markersforall) { | |||
this.markersforall = markersforall; | |||
} | |||
/** | |||
* execute the p4 resolve | |||
* @throws BuildException if there is a wrong resolve mode specified | |||
* or no view specified | |||
*/ | |||
public void execute() throws BuildException { | |||
if (this.resolvemode.equals(AUTOMATIC)) { | |||
P4CmdOpts = P4CmdOpts + " -am"; | |||
} | |||
else if (this.resolvemode.equals(FORCE)) { | |||
} else if (this.resolvemode.equals(FORCE)) { | |||
P4CmdOpts = P4CmdOpts + " -af"; | |||
} | |||
else if (this.resolvemode.equals(SAFE)) { | |||
} else if (this.resolvemode.equals(SAFE)) { | |||
P4CmdOpts = P4CmdOpts + " -as"; | |||
} | |||
else if (this.resolvemode.equals(THEIRS)) { | |||
} else if (this.resolvemode.equals(THEIRS)) { | |||
P4CmdOpts = P4CmdOpts + " -at"; | |||
} | |||
else if (this.resolvemode.equals(YOURS)) { | |||
} else if (this.resolvemode.equals(YOURS)) { | |||
P4CmdOpts = P4CmdOpts + " -ay"; | |||
} | |||
else | |||
{ | |||
} else { | |||
throw new BuildException("unsupported or absent resolve mode"); | |||
} | |||
if (P4View==null) { | |||
if (P4View == null) { | |||
throw new BuildException("please specify a view"); | |||
} | |||
if ( this.isRedoall() ) { | |||
if (this.isRedoall()) { | |||
P4CmdOpts = P4CmdOpts + " -f"; | |||
} | |||
if ( this.isSimulationmode() ) { | |||
if (this.isSimulationmode()) { | |||
P4CmdOpts = P4CmdOpts + " -n"; | |||
} | |||
if ( this.isForcetextmode() ) { | |||
if (this.isForcetextmode()) { | |||
P4CmdOpts = P4CmdOpts + " -t"; | |||
} | |||
if ( this.isMarkersforall() ) { | |||
if (this.isMarkersforall()) { | |||
P4CmdOpts = P4CmdOpts + " -v"; | |||
} | |||
execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); | |||
@@ -75,6 +75,8 @@ public class P4Revert extends P4Base { | |||
/** | |||
* The changelist to revert; optional. | |||
* @param revertChange : the change list to revert | |||
* @throws BuildException if the change list is null or empty string | |||
*/ | |||
public void setChange(String revertChange) throws BuildException { | |||
if (revertChange == null && !revertChange.equals("")) { | |||
@@ -87,11 +89,17 @@ public class P4Revert extends P4Base { | |||
/** | |||
* flag to revert only unchanged files (p4 revert -a); optional, default false. | |||
* @param onlyUnchanged if set to true revert only unchanged files | |||
*/ | |||
public void setRevertOnlyUnchanged(boolean onlyUnchanged) { | |||
this.onlyUnchanged = onlyUnchanged; | |||
} | |||
/** | |||
* do the work | |||
* @throws BuildException if an error occurs during the execution of the Perforce command | |||
* and failonError is set to true | |||
*/ | |||
public void execute() throws BuildException { | |||
/* Here we can either revert any unchanged files in a changelist | |||
@@ -79,15 +79,23 @@ import java.util.Vector; | |||
public class P4Submit extends P4Base { | |||
//ToDo: If dealing with default cl need to parse out <enter description here> | |||
/** | |||
* change list number | |||
*/ | |||
public String change; | |||
/** | |||
* set the change list number to submit | |||
* @param change The changelist number to submit; required. | |||
*/ | |||
public void setChange(String change) { | |||
this.change = change; | |||
} | |||
/** | |||
* do the work | |||
* @throws BuildException if no change list specified | |||
*/ | |||
public void execute() throws BuildException { | |||
if (change != null) { | |||
execP4Command("submit -c " + change, (P4HandlerAdapter) new P4SubmitAdapter()); | |||
@@ -98,10 +106,17 @@ public class P4Submit extends P4Base { | |||
} | |||
} | |||
/** | |||
* internal class used to process the output of p4 submit | |||
*/ | |||
public class P4SubmitAdapter extends P4HandlerAdapter { | |||
/** | |||
* process a line of stdout/stderr coming from Perforce | |||
* @param line line of stdout or stderr coming from Perforce | |||
*/ | |||
public void process(String line) { | |||
log(line, Project.MSG_VERBOSE); | |||
getProject().setProperty("p4.needsresolve","0"); | |||
getProject().setProperty("p4.needsresolve", "0"); | |||
// this type of output might happen | |||
// Change 18 renamed change 20 and submitted. | |||
if (util.match("/renamed/", line)) { | |||
@@ -111,12 +126,13 @@ public class P4Submit extends P4Base { | |||
boolean found = false; | |||
for (int counter = 0; counter < myarray.size(); counter++) { | |||
if (found == true) { | |||
int changenumber = Integer.parseInt((String) myarray.elementAt(counter + 1)); | |||
String chnum = (String) myarray.elementAt(counter + 1); | |||
int changenumber = Integer.parseInt(chnum); | |||
log("Perforce change renamed " + changenumber, Project.MSG_INFO); | |||
getProject().setProperty("p4.change", "" + changenumber); | |||
found = false; | |||
} | |||
if (((String) (myarray.elementAt(counter))).equals("renamed")) { | |||
if (((myarray.elementAt(counter))).equals("renamed")) { | |||
found = true; | |||
} | |||
} | |||
@@ -128,8 +144,8 @@ public class P4Submit extends P4Base { | |||
throw new BuildException(msg, e, getLocation()); | |||
} | |||
} | |||
if (util.match("/p4 submit -c/",line)) { | |||
getProject().setProperty("p4.needsresolve","1"); | |||
if (util.match("/p4 submit -c/", line)) { | |||
getProject().setProperty("p4.needsresolve", "1"); | |||
} | |||
} | |||
@@ -70,9 +70,13 @@ import org.apache.tools.ant.Project; | |||
* <b>Example Usage:</b> | |||
* <table border="1"> | |||
* <th>Function</th><th>Command</th> | |||
* <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings specified</td><td><P4Sync <br>P4view="//projects/foo/main/source/..." <br>P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient" /></td></tr> | |||
* <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings defined in environment</td><td><P4Sync P4view="//projects/foo/main/source/..." /></td></tr> | |||
* <tr><td>Force a re-sync to head, refreshing all files</td><td><P4Sync force="yes" P4view="//projects/foo/main/source/..." /></td></tr> | |||
* <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings specified</td> | |||
* <td><P4Sync <br>P4view="//projects/foo/main/source/..." <br> | |||
* P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient" /></td></tr> | |||
* <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings defined in environment</td> | |||
* <td><P4Sync P4view="//projects/foo/main/source/..." /></td></tr> | |||
* <tr><td>Force a re-sync to head, refreshing all files</td> | |||
* <td><P4Sync force="yes" P4view="//projects/foo/main/source/..." /></td></tr> | |||
* <tr><td>Sync to a label</td><td><P4Sync label="myPerforceLabel" /></td></tr> | |||
* </table> | |||
* | |||
@@ -89,6 +93,8 @@ public class P4Sync extends P4Base { | |||
/** | |||
* Label to sync client to; optional. | |||
* @param label name of a label against which one want to sync | |||
* @throws BuildException if label is null or empty string | |||
*/ | |||
public void setLabel(String label) throws BuildException { | |||
if (label == null && !label.equals("")) { | |||
@@ -102,6 +108,8 @@ public class P4Sync extends P4Base { | |||
/** | |||
* force a refresh of files, if this attribute is set; false by default. | |||
* @param force sync all files, whether they are supposed to be already uptodate or not. | |||
* @throws BuildException if a label is set and force is null | |||
*/ | |||
public void setForce(String force) throws BuildException { | |||
if (force == null && !label.equals("")) { | |||
@@ -110,6 +118,11 @@ public class P4Sync extends P4Base { | |||
P4CmdOpts = "-f"; | |||
} | |||
/** | |||
* do the work | |||
* @throws BuildException if an error occurs during the execution of the Perforce command | |||
* and failOnError is set to true | |||
*/ | |||
public void execute() throws BuildException { | |||
@@ -62,14 +62,28 @@ package org.apache.tools.ant.taskdefs.optional.perforce; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
/** | |||
* simple implementation of P4HandlerAdapter used by tasks which are not | |||
* actually processing the output from Perforce | |||
* @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
*/ | |||
public class SimpleP4OutputHandler extends P4HandlerAdapter { | |||
P4Base parent; | |||
/** | |||
* simple constructor | |||
* @param parent a P4Base instance | |||
*/ | |||
public SimpleP4OutputHandler(P4Base parent) { | |||
this.parent = parent; | |||
} | |||
/** | |||
* process one line of stderr/stdout | |||
* @param line line of output | |||
* @throws BuildException if errror output is received | |||
*/ | |||
public void process(String line) throws BuildException { | |||
if (parent.util.match("/^exit/", line)) { | |||
return; | |||
@@ -88,7 +102,8 @@ public class SimpleP4OutputHandler extends P4HandlerAdapter { | |||
//looking like this one : | |||
//error: //depot/file2 - label in sync. | |||
if (parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line) && !parent.util.match("/label in sync/", line)) { | |||
if (parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line) | |||
&& !parent.util.match("/label in sync/", line)) { | |||
throw new BuildException(line); | |||
} | |||