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; | import java.util.ArrayList; | ||||
| /** | |||||
| /** | |||||
| * FStatP4OutputHandler - spezialied Perforce output handler | * 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 | * managed by Perforce in the output | ||||
| * | * | ||||
| * @author <A HREF="mailto:miha@softhome.net">Miha</A> | * @author <A HREF="mailto:miha@softhome.net">Miha</A> | ||||
| @@ -83,7 +83,7 @@ class FStatP4OutputHandler extends P4HandlerAdapter { | |||||
| String f = util.group(1); | String f = util.group(1); | ||||
| nonExisting.add(f); | nonExisting.add(f); | ||||
| } | } | ||||
| parent.log(parent.util.substitute("s/^.*: //", line), | |||||
| parent.log(parent.util.substitute("s/^.*: //", line), | |||||
| Project.MSG_VERBOSE); | Project.MSG_VERBOSE); | ||||
| } | } | ||||
| @@ -72,9 +72,16 @@ import org.apache.tools.ant.types.FileSet; | |||||
| * <b>Example Usage:</b> | * <b>Example Usage:</b> | ||||
| * <table border="1"> | * <table border="1"> | ||||
| * <th>Function</th><th>Command</th> | * <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> | * </table> | ||||
| * | * | ||||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | * @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" | * @ant.task category="scm" | ||||
| */ | */ | ||||
| public class P4Add extends P4Base { | public class P4Add extends P4Base { | ||||
| private static final int DEFAULT_CMD_LENGTH = 450; | |||||
| private int changelist; | private int changelist; | ||||
| private String addCmd = ""; | private String addCmd = ""; | ||||
| private Vector filesets = new Vector(); | private Vector filesets = new Vector(); | ||||
| private int cmdLength = 450; | |||||
| private int cmdLength = DEFAULT_CMD_LENGTH; | |||||
| /** | /** | ||||
| * positive integer specifying the maximum length | * positive integer specifying the maximum length | ||||
| * of the commandline when calling Perforce to add the files. | * of the commandline when calling Perforce to add the files. | ||||
| * Defaults to 450, higher values mean faster execution, | * Defaults to 450, higher values mean faster execution, | ||||
| * but also possible failures. | * 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 { | 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 | * If specified the open files are associated with the | ||||
| * specified pending changelist number; otherwise the open files are | * specified pending changelist number; otherwise the open files are | ||||
| * associated with the default changelist. | * 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 { | public void setChangelist(int changelist) throws BuildException { | ||||
| if (changelist <= 0) { | if (changelist <= 0) { | ||||
| @@ -118,11 +131,18 @@ public class P4Add extends P4Base { | |||||
| /** | /** | ||||
| * files to add | * files to add | ||||
| * | |||||
| * @param set the FileSet that one wants to add to Perforce Source Control | |||||
| */ | */ | ||||
| public void addFileset(FileSet set) { | public void addFileset(FileSet set) { | ||||
| filesets.addElement(set); | filesets.addElement(set); | ||||
| } | } | ||||
| /** | |||||
| * run the task. | |||||
| * | |||||
| * @throws BuildException if the execution of the Perforce command fails. | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (P4View != null) { | if (P4View != null) { | ||||
| @@ -75,7 +75,7 @@ import org.apache.tools.ant.types.Commandline; | |||||
| * @see P4Edit | * @see P4Edit | ||||
| * @see P4Submit | * @see P4Submit | ||||
| * @see P4Label | * @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> | * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | ||||
| */ | */ | ||||
| public abstract class P4Base extends org.apache.tools.ant.Task { | 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; | * The p4d server and port to connect to; | ||||
| * optional, default "perforce:1666" | * optional, default "perforce:1666" | ||||
| * | |||||
| * @param P4Port the port one wants to set such as localhost:1666 | |||||
| */ | */ | ||||
| public void setPort(String P4Port) { | public void setPort(String P4Port) { | ||||
| this.P4Port = "-p" + 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; | * The p4 client spec to use; | ||||
| * optional, defaults to the current user | * optional, defaults to the current user | ||||
| * | |||||
| * @param P4Client the name of the Perforce client spec | |||||
| */ | */ | ||||
| public void setClient(String P4Client) { | public void setClient(String P4Client) { | ||||
| this.P4Client = "-c" + P4Client; | this.P4Client = "-c" + P4Client; | ||||
| @@ -128,22 +132,34 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||||
| /** | /** | ||||
| * The p4 username; | * The p4 username; | ||||
| * optional, defaults to the current user | * optional, defaults to the current user | ||||
| * | |||||
| * @param P4User the user name | |||||
| */ | */ | ||||
| public void setUser(String P4User) { | public void setUser(String P4User) { | ||||
| this.P4User = "-u" + P4User; | this.P4User = "-u" + P4User; | ||||
| } | } | ||||
| /** | /** | ||||
| * Set global P4 options; Used on all | * Set global P4 options; Used on all | ||||
| * of the Perforce tasks. | * of the Perforce tasks. | ||||
| */ | |||||
| * | |||||
| * @param P4Opts global options, to use a specific P4Config file for instance | |||||
| */ | |||||
| public void setGlobalopts(String P4Opts) { | public void setGlobalopts(String P4Opts) { | ||||
| this.P4Opts = P4Opts; | this.P4Opts = P4Opts; | ||||
| } | } | ||||
| /** | /** | ||||
| * The client, branch or label view to operate upon; | * 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) { | public void setView(String P4View) { | ||||
| this.P4View = 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 | * Set extra command options; only used on some | ||||
| * of the Perforce tasks. | * of the Perforce tasks. | ||||
| * | |||||
| * @param P4CmdOpts command line options going after the particular | |||||
| * Perforce command | |||||
| */ | */ | ||||
| public void setCmdopts(String P4CmdOpts) { | public void setCmdopts(String P4CmdOpts) { | ||||
| this.P4CmdOpts = 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) | * whether to stop the build (true, default) | ||||
| * or keep going if an error is returned from the p4 command | * 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) { | public void setFailonerror(boolean fail) { | ||||
| failOnError = 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() { | public void init() { | ||||
| util = new Perl5Util(); | util = new Perl5Util(); | ||||
| @@ -182,14 +214,23 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||||
| setUser(tmpprop); | 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 { | protected void execP4Command(String command) throws BuildException { | ||||
| execP4Command(command, null); | 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 { | protected void execP4Command(String command, P4Handler handler) throws BuildException { | ||||
| try { | try { | ||||
| @@ -232,6 +273,7 @@ public abstract class P4Base extends org.apache.tools.ant.Task { | |||||
| try { | try { | ||||
| handler.stop(); | handler.stop(); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| log(e.toString(), Project.MSG_ERR); | |||||
| } | } | ||||
| } | } | ||||
| @@ -81,7 +81,9 @@ public class P4Change extends P4Base { | |||||
| protected String description = "AutoSubmit By Ant"; | 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 { | public void execute() throws BuildException { | ||||
| @@ -113,7 +115,12 @@ public class P4Change extends P4Base { | |||||
| execP4Command("change -i", handler); | 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 { | public String getEmptyChangeList() throws BuildException { | ||||
| final StringBuffer stringbuf = new StringBuffer(); | final StringBuffer stringbuf = new StringBuffer(); | ||||
| @@ -121,28 +128,23 @@ public class P4Change extends P4Base { | |||||
| public void process(String line) { | public void process(String line) { | ||||
| if (!util.match("/^#/", line)) { | if (!util.match("/^#/", line)) { | ||||
| if (util.match("/error/", line)) { | if (util.match("/error/", line)) { | ||||
| log("Client Error", Project.MSG_VERBOSE); | 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)) { | } else if (util.match("/<enter description here>/", line)) { | ||||
| // we need to escape the description in case there are / | // we need to escape the description in case there are / | ||||
| description = backslash(description); | 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)) { | } else if (util.match("/\\/\\//", line)) { | ||||
| //Match "//" for begining of depot filespec | //Match "//" for begining of depot filespec | ||||
| return; | return; | ||||
| } | } | ||||
| stringbuf.append(line); | stringbuf.append(line); | ||||
| stringbuf.append("\n"); | stringbuf.append("\n"); | ||||
| } | } | ||||
| } | } | ||||
| }); | }); | ||||
| return stringbuf.toString(); | return stringbuf.toString(); | ||||
| } | } | ||||
| @@ -152,7 +154,8 @@ public class P4Change extends P4Base { | |||||
| * always backslashes in a string unless they escape the delimiter. | * always backslashes in a string unless they escape the delimiter. | ||||
| * @param value the string to backslash for slashes | * @param value the string to backslash for slashes | ||||
| * @return the backslashed string | * @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) { | public static final String backslash(String value) { | ||||
| final StringBuffer buf = new StringBuffer(value.length()); | final StringBuffer buf = new StringBuffer(value.length()); | ||||
| @@ -170,6 +173,7 @@ public class P4Change extends P4Base { | |||||
| /** | /** | ||||
| * Description for ChangeList;optional. | * Description for ChangeList;optional. | ||||
| * If none is specified, it will default to "AutoSubmit By Ant" | * If none is specified, it will default to "AutoSubmit By Ant" | ||||
| * @param desc description for the change list | |||||
| */ | */ | ||||
| public void setDescription(String desc) { | public void setDescription(String desc) { | ||||
| this.description = desc; | this.description = desc; | ||||
| @@ -86,14 +86,30 @@ import org.apache.tools.ant.Project; | |||||
| */ | */ | ||||
| public class P4Counter extends P4Base { | public class P4Counter extends P4Base { | ||||
| /** | |||||
| * name of the counter | |||||
| */ | |||||
| public String counter = null; | public String counter = null; | ||||
| /** | |||||
| * name of an optional property | |||||
| */ | |||||
| public String property = null; | public String property = null; | ||||
| /** | |||||
| * flag telling whether the value of the counter should be set | |||||
| */ | |||||
| public boolean shouldSetValue = false; | public boolean shouldSetValue = false; | ||||
| /** | |||||
| * flag telling whether a property should be set | |||||
| */ | |||||
| public boolean shouldSetProperty = false; | public boolean shouldSetProperty = false; | ||||
| /** | |||||
| * new value for the counter | |||||
| */ | |||||
| public int value = 0; | public int value = 0; | ||||
| /** | /** | ||||
| * The name of the counter; required | * The name of the counter; required | ||||
| * @param counter name of the counter | |||||
| */ | */ | ||||
| public void setName(String counter) { | public void setName(String counter) { | ||||
| this.counter = counter; | this.counter = counter; | ||||
| @@ -101,6 +117,7 @@ public class P4Counter extends P4Base { | |||||
| /** | /** | ||||
| * The new value for the counter; optional. | * The new value for the counter; optional. | ||||
| * @param value new value for the counter | |||||
| */ | */ | ||||
| public void setValue(int value) { | public void setValue(int value) { | ||||
| this.value = value; | this.value = value; | ||||
| @@ -109,6 +126,8 @@ public class P4Counter extends P4Base { | |||||
| /** | /** | ||||
| * A property to be set with the value of the counter | * 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) { | public void setProperty(String property) { | ||||
| this.property = property; | this.property = property; | ||||
| @@ -117,6 +136,7 @@ public class P4Counter extends P4Base { | |||||
| /** | /** | ||||
| * again, properties are mutable in this tsk | * again, properties are mutable in this tsk | ||||
| * @throws BuildException if the required parameters are not supplied. | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| @@ -125,7 +145,8 @@ public class P4Counter extends P4Base { | |||||
| } | } | ||||
| if (shouldSetValue && shouldSetProperty) { | 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; | String command = "counter " + P4CmdOpts + " " + counter; | ||||
| @@ -150,7 +171,8 @@ public class P4Counter extends P4Base { | |||||
| value = Integer.parseInt(line); | value = Integer.parseInt(line); | ||||
| myProj.setProperty(property, "" + value); | myProj.setProperty(property, "" + value); | ||||
| } catch (NumberFormatException nfe) { | } 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 | * @todo What to do if file is already open in one of our changelists perhaps | ||||
| * (See also {@link P4Edit P4Edit})?<br> | * (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" | * @ant.task category="scm" | ||||
| */ | */ | ||||
| public class P4Delete extends P4Base { | public class P4Delete extends P4Base { | ||||
| /** | |||||
| * number of the change list to work on | |||||
| */ | |||||
| public String change = null; | public String change = null; | ||||
| /** | /** | ||||
| * An existing changelist number for the deletion; optional | * An existing changelist number for the deletion; optional | ||||
| * but strongly recommended. | * but strongly recommended. | ||||
| * @param change the number of a change list | |||||
| */ | */ | ||||
| public void setChange(String change) { | public void setChange(String change) { | ||||
| this.change = change; | this.change = change; | ||||
| } | } | ||||
| /** | |||||
| * executes the p4 delete task | |||||
| * @throws BuildException if there is no view specified | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (change != null) { | if (change != null) { | ||||
| P4CmdOpts = "-c " + change; | P4CmdOpts = "-c " + change; | ||||
| @@ -78,16 +78,24 @@ import org.apache.tools.ant.BuildException; | |||||
| public class P4Edit extends P4Base { | public class P4Edit extends P4Base { | ||||
| /** | |||||
| * number of the change list to work on | |||||
| */ | |||||
| public String change = null; | public String change = null; | ||||
| /** | /** | ||||
| * An existing changelist number to assign files to; optional | * An existing changelist number to assign files to; optional | ||||
| * but strongly recommended. | * but strongly recommended. | ||||
| * @param change the change list number | |||||
| */ | */ | ||||
| public void setChange(String change) { | public void setChange(String change) { | ||||
| this.change = change; | this.change = change; | ||||
| } | } | ||||
| /** | |||||
| * Run the p4 edit command | |||||
| * @throws BuildException if there is no view specified | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (change != null) { | if (change != null) { | ||||
| P4CmdOpts = "-c " + change; | P4CmdOpts = "-c " + change; | ||||
| @@ -74,7 +74,8 @@ import org.apache.tools.ant.types.FileSet; | |||||
| * | * | ||||
| * <br><b>Example Usage:</b><br> | * <br><b>Example Usage:</b><br> | ||||
| * <pre> | * <pre> | ||||
| * <project name="p4fstat" default="p4fstat" basedir="C:\dev\gnu"> | |||||
| * <project name="p4fstat" default="p4fstat" | |||||
| * basedir="C:\dev\gnu"> | |||||
| * <target name="p4fstat" > | * <target name="p4fstat" > | ||||
| * <p4fstat showfilter="all"> | * <p4fstat showfilter="all"> | ||||
| * <fileset dir="depot" includes="**\/*"/> | * <fileset dir="depot" includes="**\/*"/> | ||||
| @@ -94,7 +95,8 @@ public class P4Fstat extends P4Base { | |||||
| private int changelist; | private int changelist; | ||||
| private String addCmd = ""; | private String addCmd = ""; | ||||
| private Vector filesets = new Vector(); | 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_ALL = 0; | ||||
| private static final int SHOW_EXISTING = 1; | private static final int SHOW_EXISTING = 1; | ||||
| private static final int SHOW_NON_EXISTING = 2; | private static final int SHOW_NON_EXISTING = 2; | ||||
| @@ -110,7 +112,16 @@ public class P4Fstat extends P4Base { | |||||
| private static final String NONEXISTING_HEADER | private static final String NONEXISTING_HEADER | ||||
| = "Following files do not exist in perforce"; | = "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) { | public void setShowFilter(String filter) { | ||||
| if (filter.equalsIgnoreCase("all")) { | if (filter.equalsIgnoreCase("all")) { | ||||
| show = SHOW_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 { | public void setChangelist(int changelist) throws BuildException { | ||||
| if (changelist <= 0) { | if (changelist <= 0) { | ||||
| throw new BuildException("P4FStat: Changelist# should be a " | throw new BuildException("P4FStat: Changelist# should be a " | ||||
| @@ -134,10 +149,18 @@ public class P4Fstat extends P4Base { | |||||
| this.changelist = changelist; | this.changelist = changelist; | ||||
| } | } | ||||
| /** | |||||
| * adds a fileset to be examined by p4fstat | |||||
| * @param set the fileset to add | |||||
| */ | |||||
| public void addFileset(FileSet set) { | public void addFileset(FileSet set) { | ||||
| filesets.addElement(set); | filesets.addElement(set); | ||||
| } | } | ||||
| /** | |||||
| * executes the p4fstat task | |||||
| * @throws BuildException if no files are specified | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| handler = new FStatP4OutputHandler(this); | handler = new FStatP4OutputHandler(this); | ||||
| @@ -172,7 +195,7 @@ public class P4Fstat extends P4Base { | |||||
| execP4Fstat(filelist); | execP4Fstat(filelist); | ||||
| } | } | ||||
| } else { | } 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() { | public int getLengthOfTask() { | ||||
| return fileNum; | return fileNum; | ||||
| } | } | ||||
| @@ -64,15 +64,17 @@ import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; | |||||
| */ | */ | ||||
| public interface P4Handler extends 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.BuildException; | ||||
| import org.apache.tools.ant.taskdefs.PumpStreamHandler; | 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 { | public abstract class P4HandlerAdapter implements P4Handler { | ||||
| @@ -79,15 +80,21 @@ public abstract class P4HandlerAdapter implements P4Handler { | |||||
| /** | /** | ||||
| * subclasses of P4HandlerAdapter must implement this routine | * subclasses of P4HandlerAdapter must implement this routine | ||||
| * processing of one line of stdout or of stderr | * 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); | 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 { | public void start() throws BuildException { | ||||
| if (p4input != null && p4input.length() > 0) { | 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 = new PumpStreamHandler(new P4OutputStream(this), new P4OutputStream(this)); | ||||
| } | } | ||||
| myHandler.setProcessInputStream(os); | myHandler.setProcessInputStream(os); | ||||
| @@ -96,22 +103,44 @@ public abstract class P4HandlerAdapter implements P4Handler { | |||||
| myHandler.start(); | myHandler.start(); | ||||
| } | } | ||||
| /** | |||||
| * stops the processing of streams | |||||
| * called from P4Base#execP4Command(String command, P4Handler handler) | |||||
| * @see P4Base#execP4Command(String, P4Handler) | |||||
| */ | |||||
| public void stop() { | public void stop() { | ||||
| myHandler.stop(); | myHandler.stop(); | ||||
| } | } | ||||
| OutputStream os; //OUtput | |||||
| InputStream is; //Input | |||||
| OutputStream os; //Input | |||||
| InputStream is; //Output | |||||
| InputStream es; //Error | 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 { | public void setProcessInputStream(OutputStream os) throws IOException { | ||||
| this.os = os; | 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 { | public void setProcessErrorStream(InputStream is) throws IOException { | ||||
| this.es = is; | 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 { | public void setProcessOutputStream(InputStream is) throws IOException { | ||||
| this.is = is; | this.is = is; | ||||
| } | } | ||||
| @@ -67,7 +67,8 @@ import org.apache.tools.ant.BuildException; | |||||
| * although P4Integrate can open files to the default change, | * although P4Integrate can open files to the default change, | ||||
| * P4Submit cannot yet submit to it. | * P4Submit cannot yet submit to it. | ||||
| * Example Usage:<br> | * 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> | * @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 | * 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) { | public void setPropagatesourcefiletype(boolean propagatesourcefiletype) { | ||||
| this.propagatesourcefiletype = 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() { | public boolean isNocopynewtargetfiles() { | ||||
| return nocopynewtargetfiles; | return nocopynewtargetfiles; | ||||
| @@ -296,7 +300,8 @@ public class P4Integrate extends P4Base { | |||||
| /** | /** | ||||
| * sets nocopynewtargetfiles flag | * 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) { | public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) { | ||||
| this.nocopynewtargetfiles = nocopynewtargetfiles; | this.nocopynewtargetfiles = nocopynewtargetfiles; | ||||
| @@ -304,6 +309,7 @@ public class P4Integrate extends P4Base { | |||||
| /** | /** | ||||
| * execute the p4 integrate | * execute the p4 integrate | ||||
| * @throws BuildException if there are missing parameters | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (change != null) { | if (change != null) { | ||||
| @@ -315,39 +321,34 @@ public class P4Integrate extends P4Base { | |||||
| if (this.restoredeletedrevisions) { | if (this.restoredeletedrevisions) { | ||||
| P4CmdOpts = P4CmdOpts + " -d"; | P4CmdOpts = P4CmdOpts + " -d"; | ||||
| } | } | ||||
| if ( this.leavetargetrevision) { | |||||
| if (this.leavetargetrevision) { | |||||
| P4CmdOpts = P4CmdOpts + " -h"; | P4CmdOpts = P4CmdOpts + " -h"; | ||||
| } | } | ||||
| if ( this.enablebaselessmerges ) { | |||||
| if (this.enablebaselessmerges) { | |||||
| P4CmdOpts = P4CmdOpts + " -i"; | P4CmdOpts = P4CmdOpts + " -i"; | ||||
| } | } | ||||
| if (this.simulationmode ) { | |||||
| if (this.simulationmode) { | |||||
| P4CmdOpts = P4CmdOpts + " -n"; | P4CmdOpts = P4CmdOpts + " -n"; | ||||
| } | } | ||||
| if ( this.reversebranchmappings ) { | |||||
| if (this.reversebranchmappings) { | |||||
| P4CmdOpts = P4CmdOpts + " -r"; | P4CmdOpts = P4CmdOpts + " -r"; | ||||
| } | } | ||||
| if ( this.propagatesourcefiletype ) { | |||||
| if (this.propagatesourcefiletype) { | |||||
| P4CmdOpts = P4CmdOpts + " -t"; | P4CmdOpts = P4CmdOpts + " -t"; | ||||
| } | } | ||||
| if ( this.nocopynewtargetfiles ) { | |||||
| if (this.nocopynewtargetfiles) { | |||||
| P4CmdOpts = P4CmdOpts + "-v"; | P4CmdOpts = P4CmdOpts + "-v"; | ||||
| } | } | ||||
| String command; | String command; | ||||
| if (branch == null && fromfile != null && tofile != null) { | if (branch == null && fromfile != null && tofile != null) { | ||||
| command = P4CmdOpts + " " + fromfile + " " + tofile; | 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; | 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)); | execP4Command("-s integrate " + command, new SimpleP4OutputHandler(this)); | ||||
| } | } | ||||
| @@ -88,6 +88,7 @@ public class P4Label extends P4Base { | |||||
| /** | /** | ||||
| * The name of the label; optional, default "AntLabel" | * The name of the label; optional, default "AntLabel" | ||||
| * @param name the name of the label | |||||
| */ | */ | ||||
| public void setName(String name) { | public void setName(String name) { | ||||
| this.name = name; | this.name = name; | ||||
| @@ -95,6 +96,7 @@ public class P4Label extends P4Base { | |||||
| /** | /** | ||||
| *Label Description; optional | *Label Description; optional | ||||
| * @param desc description of the label | |||||
| */ | */ | ||||
| public void setDesc(String desc) { | public void setDesc(String desc) { | ||||
| this.desc = 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. | * when set to "locked", Perforce will lock the label once created; optional. | ||||
| * @param lock only admissible value "locked" | |||||
| */ | */ | ||||
| public void setLock(String lock) { | public void setLock(String lock) { | ||||
| this.lock = 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 { | public void execute() throws BuildException { | ||||
| log("P4Label exec:", Project.MSG_INFO); | log("P4Label exec:", Project.MSG_INFO); | ||||
| @@ -142,10 +146,10 @@ public class P4Label extends P4Base { | |||||
| //We have to create a unlocked label first | //We have to create a unlocked label first | ||||
| String newLabel = | 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() { | P4Handler handler = new P4HandlerAdapter() { | ||||
| public void process(String line) { | public void process(String line) { | ||||
| @@ -70,7 +70,8 @@ import org.apache.tools.ant.util.StringUtils; | |||||
| * | * | ||||
| * Example Usage: | * Example Usage: | ||||
| * <pre> | * <pre> | ||||
| * <p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}" view="//depot/...#head;//depot2/file1#25" /> | |||||
| * <p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}" | |||||
| * view="//depot/...#head;//depot2/file1#25" /> | |||||
| * </pre> | * </pre> | ||||
| * | * | ||||
| * @author <A HREF="mailto:levylambert@tiscali-dsl.de">Antoine Levy-Lambert</A> | * @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 delete; /* -n */ | ||||
| private boolean simulationmode; /* -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 | * @return add attribute | ||||
| * if set to true the task will not remove any files from the label | * 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 | * 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; | 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 | * @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 | * 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 | * the add attribute is the -a flag of p4 labelsync | ||||
| @@ -103,7 +106,8 @@ public class P4Labelsync extends P4Base { | |||||
| this.add = add; | 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 | * @return delete attribute | ||||
| */ | */ | ||||
| public boolean isDelete() { | 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) { | public void setDelete(boolean delete) { | ||||
| this.delete = delete; | this.delete = delete; | ||||
| @@ -121,6 +127,7 @@ public class P4Labelsync extends P4Base { | |||||
| /** | /** | ||||
| * The name of the label; optional, default "AntLabel" | * The name of the label; optional, default "AntLabel" | ||||
| * @param name of the label | |||||
| */ | */ | ||||
| public void setName(String name) { | public void setName(String name) { | ||||
| this.name = name; | this.name = name; | ||||
| @@ -134,7 +141,7 @@ public class P4Labelsync extends P4Base { | |||||
| } | } | ||||
| /** | /** | ||||
| * -n flag of p4 labelsync - display changes without actually doing them | * -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) { | public void setSimulationmode(boolean simulationmode) { | ||||
| this.simulationmode = simulationmode; | this.simulationmode = simulationmode; | ||||
| @@ -143,6 +150,7 @@ public class P4Labelsync extends P4Base { | |||||
| /** | /** | ||||
| * do the work | * do the work | ||||
| * @throws BuildException if the label name is not supplied | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| log("P4Labelsync exec:", Project.MSG_INFO); | log("P4Labelsync exec:", Project.MSG_INFO); | ||||
| @@ -152,24 +160,25 @@ public class P4Labelsync extends P4Base { | |||||
| P4View = StringUtils.replace(P4View, ";", "\n\t"); | P4View = StringUtils.replace(P4View, ";", "\n\t"); | ||||
| } | } | ||||
| if (P4View == null) { | if (P4View == null) { | ||||
| P4View=""; | |||||
| P4View = ""; | |||||
| } | } | ||||
| if (name == null || name.length() < 1) { | if (name == null || name.length() < 1) { | ||||
| throw new BuildException("name attribute is compulsory for labelsync"); | throw new BuildException("name attribute is compulsory for labelsync"); | ||||
| } | } | ||||
| if ( this.isSimulationmode() ) { | |||||
| if (this.isSimulationmode()) { | |||||
| P4CmdOpts = P4CmdOpts + " -n"; | P4CmdOpts = P4CmdOpts + " -n"; | ||||
| } | } | ||||
| if ( this.isDelete() ) { | |||||
| if (this.isDelete()) { | |||||
| P4CmdOpts = P4CmdOpts + " -d"; | P4CmdOpts = P4CmdOpts + " -d"; | ||||
| } | } | ||||
| if ( this.isAdd() ) { | |||||
| if (this.isAdd()) { | |||||
| P4CmdOpts = P4CmdOpts + " -a"; | 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 | * 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. | * reserved. | ||||
| * | * | ||||
| * Redistribution and use in source and binary forms, with or without | * 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> | * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | ||||
| */ | */ | ||||
| public interface P4OutputHandler { | 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 | * creates a new P4OutputStream for a P4Handler | ||||
| * @param handler | |||||
| * @param handler the handler which will process the streams | |||||
| */ | */ | ||||
| public P4OutputStream(P4Handler handler) { | public P4OutputStream(P4Handler handler) { | ||||
| this.handler = handler; | this.handler = handler; | ||||
| @@ -81,6 +81,9 @@ public class P4OutputStream extends OutputStream { | |||||
| * separator is detected. | * separator is detected. | ||||
| * | * | ||||
| * @param cc data to log (byte). | * @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 { | public void write(int cc) throws IOException { | ||||
| final byte c = (byte) cc; | final byte c = (byte) cc; | ||||
| @@ -105,6 +108,7 @@ public class P4OutputStream extends OutputStream { | |||||
| /** | /** | ||||
| * Writes all remaining | * Writes all remaining | ||||
| * @throws IOException if an I/O error occurs. | |||||
| */ | */ | ||||
| public void close() throws IOException { | public void close() throws IOException { | ||||
| if (buffer.size() > 0) { | if (buffer.size() > 0) { | ||||
| @@ -74,6 +74,8 @@ public class P4Reopen extends P4Base { | |||||
| /** | /** | ||||
| * The changelist to move files to; required. | * 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 { | public void setToChange(String toChange) throws BuildException { | ||||
| if (toChange == null && !toChange.equals("")) { | if (toChange == null && !toChange.equals("")) { | ||||
| @@ -83,6 +85,10 @@ public class P4Reopen extends P4Base { | |||||
| this.toChange = toChange; | this.toChange = toChange; | ||||
| } | } | ||||
| /** | |||||
| * do the work | |||||
| * @throws BuildException if P4View is null | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (P4View == null) { | if (P4View == null) { | ||||
| throw new BuildException("No view specified to reopen"); | throw new BuildException("No view specified to reopen"); | ||||
| @@ -63,6 +63,7 @@ import org.apache.tools.ant.BuildException; | |||||
| /** | /** | ||||
| * @ant.task category="scm" | * @ant.task category="scm" | ||||
| * @author <a href="mailto:antoine@antbuild.com">Antoine Levy-Lambert</a> | |||||
| */ | */ | ||||
| public class P4Resolve extends P4Base { | public class P4Resolve extends P4Base { | ||||
| private String resolvemode = null; | private String resolvemode = null; | ||||
| @@ -77,14 +78,17 @@ public class P4Resolve extends P4Base { | |||||
| private static final String SAFE = "safe"; | private static final String SAFE = "safe"; | ||||
| private static final String THEIRS = "theirs"; | private static final String THEIRS = "theirs"; | ||||
| private static final String YOURS = "yours"; | private static final String YOURS = "yours"; | ||||
| private static final String[] resolvemodes = { | |||||
| private static final String[] RESOLVE_MODES = { | |||||
| AUTOMATIC, | AUTOMATIC, | ||||
| FORCE, | FORCE, | ||||
| SAFE, | SAFE, | ||||
| THEIRS, | THEIRS, | ||||
| YOURS | YOURS | ||||
| }; | }; | ||||
| /** | |||||
| * returns the resolve mode | |||||
| * @return returns the resolve mode | |||||
| */ | |||||
| public String getResolvemode() { | public String getResolvemode() { | ||||
| return resolvemode; | return resolvemode; | ||||
| } | } | ||||
| @@ -97,90 +101,122 @@ public class P4Resolve extends P4Base { | |||||
| * <li> theirs -at </li> | * <li> theirs -at </li> | ||||
| * <li> yours -ay </li> | * <li> yours -ay </li> | ||||
| * </ul> | * </ul> | ||||
| * @param resolvemode one of automatic, force, safe, theirs, yours | |||||
| */ | */ | ||||
| public void setResolvemode(String resolvemode) { | 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; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (found==false) { | |||||
| if (found == false) { | |||||
| throw new BuildException("Unacceptable value for resolve mode"); | throw new BuildException("Unacceptable value for resolve mode"); | ||||
| } | } | ||||
| this.resolvemode = resolvemode; | 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() { | public boolean isRedoall() { | ||||
| return redoall; | 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) { | public void setRedoall(boolean redoall) { | ||||
| this.redoall = 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() { | public boolean isSimulationmode() { | ||||
| return simulationmode; | 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) { | public void setSimulationmode(boolean simulationmode) { | ||||
| this.simulationmode = simulationmode; | this.simulationmode = simulationmode; | ||||
| } | } | ||||
| /** | |||||
| * If set to true, attempts a textual merge, even for binary files | |||||
| * @return flag value | |||||
| */ | |||||
| public boolean isForcetextmode() { | public boolean isForcetextmode() { | ||||
| return forcetextmode; | 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) { | public void setForcetextmode(boolean forcetextmode) { | ||||
| this.forcetextmode = forcetextmode; | this.forcetextmode = forcetextmode; | ||||
| } | } | ||||
| /** | |||||
| * If set to true, puts in markers for all changes, conflicting or not | |||||
| * @return flag markersforall value | |||||
| */ | |||||
| public boolean isMarkersforall() { | public boolean isMarkersforall() { | ||||
| return markersforall; | 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) { | public void setMarkersforall(boolean markersforall) { | ||||
| this.markersforall = markersforall; | this.markersforall = markersforall; | ||||
| } | } | ||||
| /** | /** | ||||
| * execute the p4 resolve | * execute the p4 resolve | ||||
| * @throws BuildException if there is a wrong resolve mode specified | |||||
| * or no view specified | |||||
| */ | */ | ||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (this.resolvemode.equals(AUTOMATIC)) { | if (this.resolvemode.equals(AUTOMATIC)) { | ||||
| P4CmdOpts = P4CmdOpts + " -am"; | P4CmdOpts = P4CmdOpts + " -am"; | ||||
| } | |||||
| else if (this.resolvemode.equals(FORCE)) { | |||||
| } else if (this.resolvemode.equals(FORCE)) { | |||||
| P4CmdOpts = P4CmdOpts + " -af"; | P4CmdOpts = P4CmdOpts + " -af"; | ||||
| } | |||||
| else if (this.resolvemode.equals(SAFE)) { | |||||
| } else if (this.resolvemode.equals(SAFE)) { | |||||
| P4CmdOpts = P4CmdOpts + " -as"; | P4CmdOpts = P4CmdOpts + " -as"; | ||||
| } | |||||
| else if (this.resolvemode.equals(THEIRS)) { | |||||
| } else if (this.resolvemode.equals(THEIRS)) { | |||||
| P4CmdOpts = P4CmdOpts + " -at"; | P4CmdOpts = P4CmdOpts + " -at"; | ||||
| } | |||||
| else if (this.resolvemode.equals(YOURS)) { | |||||
| } else if (this.resolvemode.equals(YOURS)) { | |||||
| P4CmdOpts = P4CmdOpts + " -ay"; | P4CmdOpts = P4CmdOpts + " -ay"; | ||||
| } | |||||
| else | |||||
| { | |||||
| } else { | |||||
| throw new BuildException("unsupported or absent resolve mode"); | throw new BuildException("unsupported or absent resolve mode"); | ||||
| } | } | ||||
| if (P4View==null) { | |||||
| if (P4View == null) { | |||||
| throw new BuildException("please specify a view"); | throw new BuildException("please specify a view"); | ||||
| } | } | ||||
| if ( this.isRedoall() ) { | |||||
| if (this.isRedoall()) { | |||||
| P4CmdOpts = P4CmdOpts + " -f"; | P4CmdOpts = P4CmdOpts + " -f"; | ||||
| } | } | ||||
| if ( this.isSimulationmode() ) { | |||||
| if (this.isSimulationmode()) { | |||||
| P4CmdOpts = P4CmdOpts + " -n"; | P4CmdOpts = P4CmdOpts + " -n"; | ||||
| } | } | ||||
| if ( this.isForcetextmode() ) { | |||||
| if (this.isForcetextmode()) { | |||||
| P4CmdOpts = P4CmdOpts + " -t"; | P4CmdOpts = P4CmdOpts + " -t"; | ||||
| } | } | ||||
| if ( this.isMarkersforall() ) { | |||||
| if (this.isMarkersforall()) { | |||||
| P4CmdOpts = P4CmdOpts + " -v"; | P4CmdOpts = P4CmdOpts + " -v"; | ||||
| } | } | ||||
| execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); | execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); | ||||
| @@ -75,6 +75,8 @@ public class P4Revert extends P4Base { | |||||
| /** | /** | ||||
| * The changelist to revert; optional. | * 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 { | public void setChange(String revertChange) throws BuildException { | ||||
| if (revertChange == null && !revertChange.equals("")) { | 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. | * 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) { | public void setRevertOnlyUnchanged(boolean onlyUnchanged) { | ||||
| this.onlyUnchanged = 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 { | public void execute() throws BuildException { | ||||
| /* Here we can either revert any unchanged files in a changelist | /* Here we can either revert any unchanged files in a changelist | ||||
| @@ -79,15 +79,23 @@ import java.util.Vector; | |||||
| public class P4Submit extends P4Base { | public class P4Submit extends P4Base { | ||||
| //ToDo: If dealing with default cl need to parse out <enter description here> | //ToDo: If dealing with default cl need to parse out <enter description here> | ||||
| /** | |||||
| * change list number | |||||
| */ | |||||
| public String change; | public String change; | ||||
| /** | /** | ||||
| * set the change list number to submit | |||||
| * @param change The changelist number to submit; required. | * @param change The changelist number to submit; required. | ||||
| */ | */ | ||||
| public void setChange(String change) { | public void setChange(String change) { | ||||
| this.change = change; | this.change = change; | ||||
| } | } | ||||
| /** | |||||
| * do the work | |||||
| * @throws BuildException if no change list specified | |||||
| */ | |||||
| public void execute() throws BuildException { | public void execute() throws BuildException { | ||||
| if (change != null) { | if (change != null) { | ||||
| execP4Command("submit -c " + change, (P4HandlerAdapter) new P4SubmitAdapter()); | 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 { | 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) { | public void process(String line) { | ||||
| log(line, Project.MSG_VERBOSE); | log(line, Project.MSG_VERBOSE); | ||||
| getProject().setProperty("p4.needsresolve","0"); | |||||
| getProject().setProperty("p4.needsresolve", "0"); | |||||
| // this type of output might happen | // this type of output might happen | ||||
| // Change 18 renamed change 20 and submitted. | // Change 18 renamed change 20 and submitted. | ||||
| if (util.match("/renamed/", line)) { | if (util.match("/renamed/", line)) { | ||||
| @@ -111,12 +126,13 @@ public class P4Submit extends P4Base { | |||||
| boolean found = false; | boolean found = false; | ||||
| for (int counter = 0; counter < myarray.size(); counter++) { | for (int counter = 0; counter < myarray.size(); counter++) { | ||||
| if (found == true) { | 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); | log("Perforce change renamed " + changenumber, Project.MSG_INFO); | ||||
| getProject().setProperty("p4.change", "" + changenumber); | getProject().setProperty("p4.change", "" + changenumber); | ||||
| found = false; | found = false; | ||||
| } | } | ||||
| if (((String) (myarray.elementAt(counter))).equals("renamed")) { | |||||
| if (((myarray.elementAt(counter))).equals("renamed")) { | |||||
| found = true; | found = true; | ||||
| } | } | ||||
| } | } | ||||
| @@ -128,8 +144,8 @@ public class P4Submit extends P4Base { | |||||
| throw new BuildException(msg, e, getLocation()); | 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> | * <b>Example Usage:</b> | ||||
| * <table border="1"> | * <table border="1"> | ||||
| * <th>Function</th><th>Command</th> | * <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> | * <tr><td>Sync to a label</td><td><P4Sync label="myPerforceLabel" /></td></tr> | ||||
| * </table> | * </table> | ||||
| * | * | ||||
| @@ -89,6 +93,8 @@ public class P4Sync extends P4Base { | |||||
| /** | /** | ||||
| * Label to sync client to; optional. | * 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 { | public void setLabel(String label) throws BuildException { | ||||
| if (label == null && !label.equals("")) { | 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. | * 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 { | public void setForce(String force) throws BuildException { | ||||
| if (force == null && !label.equals("")) { | if (force == null && !label.equals("")) { | ||||
| @@ -110,6 +118,11 @@ public class P4Sync extends P4Base { | |||||
| P4CmdOpts = "-f"; | 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 { | 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.BuildException; | ||||
| import org.apache.tools.ant.Project; | 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 { | public class SimpleP4OutputHandler extends P4HandlerAdapter { | ||||
| P4Base parent; | P4Base parent; | ||||
| /** | |||||
| * simple constructor | |||||
| * @param parent a P4Base instance | |||||
| */ | |||||
| public SimpleP4OutputHandler(P4Base parent) { | public SimpleP4OutputHandler(P4Base parent) { | ||||
| this.parent = 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 { | public void process(String line) throws BuildException { | ||||
| if (parent.util.match("/^exit/", line)) { | if (parent.util.match("/^exit/", line)) { | ||||
| return; | return; | ||||
| @@ -88,7 +102,8 @@ public class SimpleP4OutputHandler extends P4HandlerAdapter { | |||||
| //looking like this one : | //looking like this one : | ||||
| //error: //depot/file2 - label in sync. | //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); | throw new BuildException(line); | ||||
| } | } | ||||