package org.apache.tools.ant.taskdefs.optional.perforce; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.Exec; import org.apache.tools.ant.Task; import java.lang.StringBuffer; // // Implements the ability to write: // <p4sync dir="src" force="no" date="2000/04/01" time="14:15:29" // label="labelname" revision="#have" /> // Where: // 1. "dir" is mandatory, the rest are optional; // 2. If you specify time, you have to specify date. // 2a. If you specify date but not time, midnight is implied. // 3. You cannot specify more than one of (date, label, revision). // 4. Any "sync" error is considered a fatal error, and a BuildException // is returned. // public class p4sync extends Exec { private String p4user, p4port; private String directory; private String force; private String date, time; private String label, revision; // The method executing the task public void execute() throws BuildException { StringBuffer cmdline = new StringBuffer(); String RevisionString = ""; int nRevisions = 0; cmdline.append("p4"); if (p4user != null) { cmdline.append( " " + "-u"); cmdline.append( " " + p4user); } if (p4port != null) { cmdline.append( " " + "-p"); cmdline.append( " " + p4port); } cmdline.append( " " + "sync"); if (force != null) { if (force.equalsIgnoreCase("yes")) { cmdline.append( " " + "-f"); } } if (directory == null) { throw new BuildException("dir= not specified for 'p4sync'"); } if (label != null) { String prefix = ""; if ( ! label.startsWith("@")) { prefix = "@"; } RevisionString = prefix + label; nRevisions = nRevisions + 1; } if (date != null) { String prefix = ""; if ( ! date.startsWith("@")) { prefix = "@"; } RevisionString = prefix + date; nRevisions = nRevisions + 1; } if (revision != null) { if (revision.startsWith("#")) { RevisionString = revision; } else { RevisionString = "#" + revision; } nRevisions = nRevisions + 1; } if (nRevisions > 1) { throw new BuildException("date/revision/label are mutually exclusive - specify only one."); } cmdline.append( " " + directory + RevisionString); System.out.println("***"); System.out.println(cmdline.toString()); run(cmdline.toString()); System.out.println("***"); } // The setter for the "message" attribute public void setDir(String directory) { this.directory = directory; } public void setForce(String force) { this.force = force; } public void setDate(String date) { this.date = date; } public void setTime(String time) { this.time = time; } public void setLabel(String label) { this.label = label; } public void setRevision(String revision) { this.revision = revision; } public void setP4user(String p4user) { this.p4user = p4user; } public void setUser(String p4user) { this.p4user = p4user; } public void setPort(String p4user) { this.p4user = p4user; } public void setP4port(String p4port) { this.p4port = p4port; } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 443 | Jeff Bowles |
including Joe.Walker@barclaycard.co.uk's edits: 1. Adding Apache copyright (needed for inclusion with 'ant') 2. Now parses 'p4 -s' output. (Thanks, Joe!) |
||
#1 | 413 | Jeff Bowles | Alpha-level work on "ant" plug-in for Perforce. |