git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268260 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -0,0 +1,173 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import java.io.*; | |||
| import org.apache.tools.ant.*; | |||
| //import org.apache.tools.ant.util.regexp.*; | |||
| import org.apache.oro.text.perl.*; | |||
| /** Base class for Perforce (P4) ANT tasks. See individual task for example usage. | |||
| * | |||
| * @see P4Sync | |||
| * @see P4Have | |||
| * @see P4Change | |||
| * @see P4Edit | |||
| * @see P4Submit | |||
| * @see P4Label | |||
| * @see org.apache.tools.ant.taskdefs.Exec | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| */ | |||
| public abstract class P4Base extends org.apache.tools.ant.Task { | |||
| /**Perl5 regexp in Java - cool eh? */ | |||
| protected Perl5Util util = null; | |||
| /** The OS shell to use (cmd.exe or /bin/sh) */ | |||
| protected String shell; | |||
| //P4 runtime directives | |||
| /** Perforce Server Port (eg KM01:1666) */ | |||
| protected String P4Port = ""; | |||
| /** Perforce Client (eg myclientspec) */ | |||
| protected String P4Client = ""; | |||
| /** Perforce User (eg fbloggs) */ | |||
| protected String P4User = ""; | |||
| /** Perforce view for commands (eg //projects/foobar/main/source/... ) */ | |||
| protected String P4View = ""; | |||
| //P4 g-opts and cmd opts (rtfm) | |||
| /** Perforce 'global' opts. | |||
| * Forms half of low level API */ | |||
| protected String P4Opts = ""; | |||
| /** Perforce command opts. | |||
| * Forms half of low level API */ | |||
| protected String P4CmdOpts = ""; | |||
| //Setters called by Ant | |||
| public void setPort(String P4Port) { this.P4Port = "-p"+P4Port; } | |||
| public void setClient(String P4Client) { this.P4Client = "-c"+P4Client; } | |||
| public void setUser(String P4User) { this.P4User = "-u"+P4User; } | |||
| public void setView(String P4View) { this.P4View = P4View; } | |||
| public void setCmdopts(String P4CmdOpts) { this.P4CmdOpts = P4CmdOpts; } | |||
| public void init() { | |||
| util = new Perl5Util(); | |||
| // Not as comprehensive as Exec but Exec | |||
| // doesn't allow stdin and stdout/stderr processing | |||
| String myOS = System.getProperty("os.name"); | |||
| if(myOS == null) throw new BuildException("Unable to determine OS"); | |||
| if(myOS.toLowerCase().indexOf("nt") >= 0) { | |||
| shell = "cmd /c "; | |||
| } else { | |||
| shell = "/bin/sh "; //This needs testing on Unix!!!! | |||
| } | |||
| //Get default P4 settings from environment - Mark would have done something cool with | |||
| //introspection here.....:-) | |||
| String tmpprop; | |||
| if((tmpprop = project.getProperty("p4.port")) != null) setPort(tmpprop); | |||
| if((tmpprop = project.getProperty("p4.client")) != null) setClient(tmpprop); | |||
| if((tmpprop = project.getProperty("p4.user")) != null) setUser(tmpprop); | |||
| } | |||
| protected void execP4Command(String command) throws BuildException { | |||
| execP4Command(command, null, null); | |||
| } | |||
| protected void execP4Command(String command, P4OutputHandler handler) throws BuildException { | |||
| execP4Command(command, null, handler); | |||
| } | |||
| /** Execute P4 command assembled by subclasses. | |||
| @param command The command to run | |||
| @param p4input Input to be fed to command on stdin | |||
| @param handler A P4OutputHandler to process any output | |||
| */ | |||
| protected void execP4Command(String command, String p4input, P4OutputHandler handler) throws BuildException { | |||
| try{ | |||
| P4Opts = P4Port+" "+P4User+" "+P4Client; | |||
| log("Execing "+shell+"p4 "+P4Opts+" "+command, Project.MSG_VERBOSE); | |||
| Process proc = Runtime.getRuntime().exec(shell+"p4 "+P4Opts+" "+command); | |||
| if(p4input != null && p4input.length() >0) { | |||
| OutputStream out = proc.getOutputStream(); | |||
| out.write(p4input.getBytes()); | |||
| out.flush(); | |||
| out.close(); | |||
| } | |||
| //Q: Do we need to read p4 output if we're not interested? | |||
| BufferedReader input = new BufferedReader( | |||
| new InputStreamReader( | |||
| new SequenceInputStream(proc.getInputStream(),proc.getErrorStream()))); | |||
| //we check for a match on the input to save time on the substitution. | |||
| String line; | |||
| while((line = input.readLine()) != null) { | |||
| if(handler != null) handler.process(line); | |||
| } | |||
| proc.waitFor(); | |||
| input.close(); | |||
| }catch(Exception e) { | |||
| throw new BuildException("Problem exec'ing P4 command: "+e.getMessage()); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,129 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import java.io.*; | |||
| import org.apache.tools.ant.*; | |||
| /** P4Change - grab a new changelist from Perforce. | |||
| * | |||
| * P4Change creates a new changelist in perforce. P4Change sets the property | |||
| * ${p4.change} with the new changelist number. This should then be passed into | |||
| * p4edit and p4submit. | |||
| * | |||
| * @see P4Edit | |||
| * @see P4Submit | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| * | |||
| */ | |||
| public class P4Change extends P4Base { | |||
| protected String emptyChangeList = null; | |||
| public void execute() throws BuildException { | |||
| if(emptyChangeList == null) emptyChangeList = getEmptyChangeList(); | |||
| final Project myProj = project; | |||
| execP4Command("change -i", emptyChangeList, new P4OutputHandler() { | |||
| public void process(String line) { | |||
| if (util.match("/Change/", line)) { | |||
| //Remove any non-numerical chars - should leave the change number | |||
| line = util.substitute("s/[^0-9]//g", line); | |||
| int changenumber = Integer.parseInt(line); | |||
| log("Change Number is "+changenumber, Project.MSG_INFO); | |||
| myProj.setProperty("p4.change", ""+changenumber); | |||
| } else if(util.match("/error/", line)) { | |||
| throw new BuildException("Perforce Error, check client settings and/or server"); | |||
| } | |||
| }}); | |||
| } | |||
| public String getEmptyChangeList() throws BuildException { | |||
| final StringBuffer stringbuf = new StringBuffer(); | |||
| execP4Command("change -o", new P4OutputHandler() { | |||
| 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"); | |||
| } else if(util.match("/<enter description here>/",line)) { | |||
| line = util.substitute("s/<enter description here>/AutoSubmit By Ant/", line); | |||
| } else if(util.match("/\\/\\//", line)) { | |||
| //Match "//" for begining of depot filespec | |||
| return; | |||
| } | |||
| stringbuf.append(line); | |||
| stringbuf.append("\n"); | |||
| } | |||
| }}); | |||
| return stringbuf.toString(); | |||
| } | |||
| } //EoF | |||
| @@ -0,0 +1,81 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| /** P4Edit - checkout file(s) for edit. | |||
| * | |||
| * Example Usage:<br> | |||
| * <p4edit change="${p4.change}" view="//depot/project/foo.txt" /> | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| * | |||
| * ToDo: Should call reopen if file is already open in one of our changelists perhaps? | |||
| */ | |||
| public class P4Edit extends P4Base { | |||
| public String change = null; | |||
| public void setChange(String change) { | |||
| this.change = change; | |||
| } | |||
| public void execute() throws BuildException { | |||
| if(change != null ) P4CmdOpts = "-c "+change; | |||
| if(P4View == null) throw new BuildException("No view specified to edit"); | |||
| execP4Command("-s edit "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,71 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| /** P4Have - lists files currently on client. | |||
| * | |||
| * P4Have simply dumps the current file version info into | |||
| * the Ant log (or stdout). | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| */ | |||
| public class P4Have extends P4Base { | |||
| public void execute() throws BuildException { | |||
| execP4Command("have "+P4CmdOpts+" "+P4View, new SimpleP4OutputHandler(this)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,132 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| import java.util.Date; | |||
| import java.text.SimpleDateFormat; | |||
| /** P4Label - create a Perforce Label. | |||
| * | |||
| * P4Label inserts a label into perforce reflecting the | |||
| * current client contents. | |||
| * | |||
| * Label name defaults to AntLabel if none set. | |||
| * | |||
| * Example Usage: <P4Label name="MyLabel-${TSTAMP}-${DSTAMP}" desc="Auto Build Label" /> | |||
| * | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| */ | |||
| public class P4Label extends P4Base { | |||
| protected String name; | |||
| protected String desc; | |||
| public void setName(String name) { | |||
| this.name = name; | |||
| } | |||
| public void setDesc(String desc) { | |||
| this.desc = desc; | |||
| } | |||
| public void execute() throws BuildException { | |||
| log("P4Label exec:",Project.MSG_INFO); | |||
| if(P4View == null || P4View.length() < 1) { | |||
| log("View not set, assuming //depot/...", Project.MSG_WARN); | |||
| P4View = "//depot/..."; | |||
| } | |||
| if(desc == null || desc.length() < 1) { | |||
| log("Label Description not set, assuming 'AntLabel'", Project.MSG_WARN); | |||
| desc = "AntLabel"; | |||
| } | |||
| if(name == null || name.length() < 1) { | |||
| SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd-hh:mm"); | |||
| Date now = new Date(); | |||
| name = "AntLabel-"+formatter.format(now); | |||
| log("name not set, assuming '"+name+"'", Project.MSG_WARN); | |||
| } | |||
| String newLabel = | |||
| "Label: "+name+"\n"+ | |||
| "Description: "+desc+"\n"+ | |||
| "Options: unlocked\n"+ | |||
| "View: "+P4View+"\n"; | |||
| execP4Command("label -i", newLabel, new P4OutputHandler() { | |||
| public void process(String line) { | |||
| log(line, Project.MSG_VERBOSE); | |||
| } | |||
| }); | |||
| execP4Command("labelsync -l "+name, null, new P4OutputHandler() { | |||
| public void process(String line) { | |||
| log(line, Project.MSG_VERBOSE); | |||
| } | |||
| }); | |||
| log("Created Label "+name+" ("+desc+")", Project.MSG_INFO); | |||
| } | |||
| } | |||
| @@ -0,0 +1,67 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.BuildException; | |||
| /** Interface for p4 job output stream handler. Classes implementing this interface | |||
| * can be called back by P4Base.execP4Command(); | |||
| * | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| */ | |||
| public interface P4OutputHandler { | |||
| public void process(String line) throws BuildException; | |||
| } | |||
| @@ -0,0 +1,94 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| /** P4Submit - submit a numbered changelist to Perforce. | |||
| * | |||
| * <B>Note:</B> P4Submit cannot (yet) submit the default changelist. | |||
| * This shouldn't be a problem with the ANT API as the usual flow is | |||
| * P4Change to create a new numbered change followed by P4Edit then P4Submit. | |||
| * | |||
| * Example Usage:-<br> | |||
| * <p4submit change="${p4.change}" /> | |||
| * | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| * | |||
| */ | |||
| public class P4Submit extends P4Base { | |||
| //ToDo: If dealing with default cl need to parse out <enter description here> | |||
| public String change; | |||
| public void setChange(String change) { | |||
| this.change = change; | |||
| } | |||
| public void execute() throws BuildException { | |||
| if(change != null) { | |||
| execP4Command("submit -c "+change, new P4OutputHandler(){ | |||
| public void process(String line) { | |||
| log(line, Project.MSG_VERBOSE); | |||
| } | |||
| }); | |||
| } else { | |||
| //here we'd parse the output from change -o into submit -i | |||
| //in order to support default change. | |||
| throw new BuildException("No change specified (no support for default change yet...."); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,113 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| /** P4Sync - synchronise client space to a perforce depot view. | |||
| * The API allows additional functionality of the "p4 sync" command | |||
| * (such as "p4 sync -f //...#have" or other exotic invocations).</P> | |||
| * | |||
| * <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 a label</td><td><P4Sync label="myPerforceLabel" /></td></tr> | |||
| * </table> | |||
| * | |||
| * ToDo: Add decent label error handling for non-exsitant labels | |||
| * | |||
| * @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| */ | |||
| public class P4Sync extends P4Base { | |||
| String label; | |||
| private String syncCmd = ""; | |||
| public void setLabel(String label) throws BuildException { | |||
| if(label == null && !label.equals("")) | |||
| throw new BuildException("P4Sync: Labels cannot be Null or Empty"); | |||
| this.label = label; | |||
| } | |||
| public void setForce(String force) throws BuildException { | |||
| if(force == null && !label.equals("")) | |||
| throw new BuildException("P4Sync: If you want to force, set force to non-null string!"); | |||
| P4CmdOpts = "-f"; | |||
| } | |||
| public void execute() throws BuildException { | |||
| if (P4View != null) { | |||
| syncCmd = P4View; | |||
| } | |||
| if(label != null && !label.equals("")) { | |||
| syncCmd = syncCmd + "@" + label; | |||
| } | |||
| log("Execing sync "+P4CmdOpts+" "+syncCmd, Project.MSG_VERBOSE); | |||
| execP4Command("-s sync "+P4CmdOpts+" "+syncCmd, new SimpleP4OutputHandler(this)); | |||
| } | |||
| } | |||
| @@ -0,0 +1,87 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2000 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.taskdefs.optional.perforce; | |||
| import org.apache.tools.ant.*; | |||
| public class SimpleP4OutputHandler implements P4OutputHandler { | |||
| P4Base parent; | |||
| public SimpleP4OutputHandler(P4Base parent) { | |||
| this.parent = parent; | |||
| } | |||
| public void process(String line) throws BuildException { | |||
| if(parent.util.match("/^exit/",line)) return; | |||
| //Throw exception on errors (except up-to-date) | |||
| //p4 -s is unpredicatable. For example a server down | |||
| //does not return error: markup | |||
| // | |||
| //Some forms producing commands (p4 -s change -o) do tag the output | |||
| //others don't..... | |||
| //Others mark errors as info, for example edit a file | |||
| //which is already open for edit..... | |||
| //Just look for error: - catches most things.... | |||
| if(parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) { | |||
| throw new BuildException(line); | |||
| } | |||
| parent.log(parent.util.substitute("s/^.*: //",line), Project.MSG_INFO); | |||
| } | |||
| } | |||
| @@ -0,0 +1,25 @@ | |||
| <body> | |||
| ANT Tasks for Perforce integration. | |||
| These tasks provide basic P4 capabilities to automated ANT-based build systems. <b>Note:</b> | |||
| the tasks in this package are linked against the Jakarta ORO 2.0 library which | |||
| brings the power of Perl 5 regular expressions to Java. | |||
| These tasks also require you to have the p4 (or p4.exe) client in your path. | |||
| @see <A HREF="http://jakarta.apache.org/">Jakarta Project</A> | |||
| @see <A HREF="http://www.perforce.com/">Perforce</A> | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Sync | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Label | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Have | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Change | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Edit | |||
| @see org.apache.tools.ant.taskdefs.optional.perforce.P4Submit | |||
| @author <A HREF="mailto:leslie.hughes@rubus.com">Les Hughes</A> | |||
| </body> | |||