diff --git a/docs/index.html b/docs/index.html
index 6bff27131..f08669ce9 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -5377,6 +5377,7 @@ current directory as docs/ChangeLog.txt
. For example, the archive m
Native2Ascii
NetRexxC
PropertyFile
+ Perforce Tasks
RenameExtensions
Script
Sound
diff --git a/docs/perforce.html b/docs/perforce.html
new file mode 100644
index 000000000..11b68fa6a
--- /dev/null
+++ b/docs/perforce.html
@@ -0,0 +1,352 @@
+
+
+Perforce Tasks for ANT
+
+
+Perforce Tasks User Manual
+by
+
+Version 1.1 - 2001/01/09
+
+Contents
+
+
+
+These tasks provide an interface to the Perforce SCM.
+The org.apache.tools.ant.taskdefs.optional.perforce
package consists of a simple framework to support
+p4 functionality as well as some Ant tasks encapsulating frequently used (by me :-) p4 commands.
+However, the addition of new p4 commands is a pretty simple task (see the source).
+Although it is possible to use these commands on the desktop,
+they were primarily intended to be used by automated build systems.
+
+Note: These tasks require the oro 2.0 regular
+expression package. Simply download this package and copy the jakarta-oro-2.0.jar file into Ant's lib directory.
+You will also need the perforce client executable (p4 or p4.exe but not p4win.exe) in your path.
+
+
+
+
+
+
+
+
+ P4Sync |
+ Synchronise a workspce to a depot |
+
+
+ P4Change |
+ Request a new changelist from the perforce server |
+
+ P4Edit |
+ Open files for edit (checkout) |
+
+ P4Submit |
+ Submit a changelist to the perforce server (checkin) |
+
+ P4Have |
+ List current files in client view, useful for reporting |
+
+ P4Label |
+ Create a label reflecting files in the current workspace |
+
+
+
+
+General P4 Properties
+Each p4 task requires a number of settings, either through build-wide properties, individual attributes
+or environment variables. These are
+
+
+
+ Property |
+ Attribute |
+ Env Var |
+ Description |
+ Default |
+
+
+ p4.port |
+ port |
+ P4PORT |
+ The p4d server and port to connect to |
+ perforce:1666 |
+
+
+ p4.client |
+ client |
+ P4CLIENT |
+ The p4 client spec to use |
+ The logged in username |
+
+
+ p4.user |
+ user |
+ P4USER |
+ The p4 username |
+ The logged in username |
+
+
+ -- |
+ view |
+ -- |
+ The client, branch or label view to operate upon. See the p4 user guide for more info. |
+ //... |
+
+
+
+
+Your local installation of perforce may require other settings (e.g. P4PASSWD, P4CONFIG). At the moment, these can only be set outside of Ant, as environment variables.
+
+
+Examples
+Setting in the environment:-
+
+(Unix csh)
+
setenv P4PORT myperforcebox:1666
+(Unix sh et al)
+P4USER=myp4userid; export P4USER
+Using build properties:-
+<property name="p4.client" value="nightlybuild"/>
+Using task attributes:-
+
+<p4Whatever
+ port="myserver:1666"
+ client="smoketest"
+ user="smoketestdude"
+ .
+ .
+ .
+/>
+
+
+
+For more information regarding the underlying 'p4' commands you are referred to the Perforce Command Reference
+available from the Perforce website.
+
+
+Taskdefs
+Standard taskdefs (for you to copy'n'paste)
+
+ <taskdef name="p4sync" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Sync" />
+ <taskdef name="p4change" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Change" />
+ <taskdef name="p4edit" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Edit" />
+ <taskdef name="p4submit" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Submit" />
+ <taskdef name="p4have" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Have" />
+ <taskdef name="p4label" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Label" />
+
+
+
+Task Descriptions
+
+Description:
+Synchronise the current workspace with the depot.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ force |
+ force a refresh of files |
+ no |
+
+
+ label |
+ sync client to label |
+ no |
+
+
+
+Examples
+<p4sync label="nightlybuild-0.0123" force="yes" />
+<p4sync view="//depot/projects/projectfoo/main/src/..." />
+
+
+
+
+
+
+Description:
+Request a new changelist from the perforce server.
+This task sets the ${p4.change} property which can then be passed to P4Submit or P4Edit.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ None |
+ -- |
+ -- |
+
+
+
+Examples
+<p4change />
+
+
+
+
+
+
+
+Description:
+Open file(s) for edit. P4Change should be used to obtain a new changelist for P4Edit as,
+although P4Edit can open files to the default change, P4Submit cannot yet submit it.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ view |
+ The filespec to request to edit |
+ Yes |
+
+
+ change |
+ An existing changelist number to assign files to. |
+ No, but see above. |
+
+
+
+
+Examples
+
+<p4edit
+ view="//depot/projects/projectfoo/main/src/Blah.java..."
+ change="${p4.change}" />
+
+
+
+
+
+
+
+Description:
+Submit a changelist, usually obtained from P4Change.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ change |
+ The changelist number to submit |
+ Yes |
+
+
+
+Examples
+<p4submit change="${p4.change}" />
+
+
+
+
+
+
+
+Description:
+List handy file info reflecting the current client contents.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ None |
+ -- |
+ -- |
+
+
+
+Examples
+<p4have />
+
+
+
+
+
+
+
+Description:
+Create a new label and set contents to reflect current client file revisions.
+
+Parameters
+
+
+ Attribute |
+ Description |
+ Required |
+
+
+ name |
+ The name of the label |
+ Yes |
+
+
+ view |
+ client view to use for label |
+ No |
+
+
+ desc |
+ Label Description |
+ No |
+
+
+
+
+
+Examples
+
+<p4label
+ name="NightlyBuild:${DSTAMP}:${TSTAMP}"
+ desc="Auto Nightly Build"
+/>
+
+
+
+
+
+
+
+ Sept 2000 |
+ -- |
+ Internal Release within Rubus |
+ |
+
+
+ Nov 2000 |
+ V1.0 |
+ Initial Release donated to ASF :-) |
+ |
+
+ Jan 2001 |
+ V1.1 |
+ fixed cross platform (NT/Unix) bug refactored p4 output handling code refactored exec'ing code |
+
+
+
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
index d0b1e0d07..4c8cf9f7d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Base.java
@@ -50,15 +50,21 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
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.tools.ant.taskdefs.*;
+import org.apache.tools.ant.types.*;
import org.apache.oro.text.perl.*;
+
/** Base class for Perforce (P4) ANT tasks. See individual task for example usage.
*
* @see P4Sync
@@ -84,15 +90,15 @@ public abstract class P4Base extends org.apache.tools.ant.Task {
protected String P4Client = "";
/** Perforce User (eg fbloggs) */
protected String P4User = "";
- /** Perforce view for commands (eg //projects/foobar/main/source/... ) */
+ /** 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 */
+ * Forms half of low level API */
protected String P4Opts = "";
/** Perforce command opts.
- * Forms half of low level API */
+ * Forms half of low level API */
protected String P4CmdOpts = "";
//Setters called by Ant
@@ -106,73 +112,59 @@ public abstract class P4Base extends org.apache.tools.ant.Task {
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");
- myOS = myOS.toLowerCase();
-
- if( myOS.indexOf("os/2") >= 0 ) {
- shell = "cmd /c ";
- } else if( myOS.startsWith("windows")
- && (myOS.indexOf("2000") >= 0 || myOS.indexOf("nt") >= 0 ) ) {
- shell = "cmd /c ";
- } else {
- // What about Mac OS? No perforce support there?
- 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;
+ //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);
+ if((tmpprop = project.getProperty("p4.user")) != null) setUser(tmpprop);
}
protected void execP4Command(String command) throws BuildException {
- execP4Command(command, null, null);
+ execP4Command(command, 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
+ @param command The command to run
+ @param p4input Input to be fed to command on stdin
+ @param handler A P4Handler to process any input and output
*/
- protected void execP4Command(String command, String p4input, P4OutputHandler handler) throws BuildException {
+ protected void execP4Command(String command, P4Handler 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);
+ Commandline commandline = new Commandline();
+ commandline.setExecutable("p4");
- 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())));
+ //Check API for these - it's how CVS does it...
+ commandline.createArgument().setValue(P4Port);
+ commandline.createArgument().setValue(P4User);
+ commandline.createArgument().setValue(P4Client);
+ commandline.createArgument().setLine(command);
+ log("Execing "+commandline.getCommandline(), Project.MSG_VERBOSE);
- //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);
+ if(handler == null ) handler = new SimpleP4OutputHandler(this);
+
+ Execute exe = new Execute(handler, null);
+
+ exe.setAntRun(project);
+
+ exe.setCommandline(commandline.getCommandline());
+
+ try{
+ exe.execute();
+ }catch(IOException e) {
+ throw new BuildException(e);
+ } finally {
+ try{
+ handler.stop();
+ }catch(Exception e) {}
}
-
- proc.waitFor();
- input.close();
- }catch(Exception e) {
- throw new BuildException("Problem exec'ing P4 command: "+e.getMessage());
- }
+
+
+
+ }catch(Exception e) {
+ throw new BuildException("Problem exec'ing P4 command: "+e.getMessage());
+ }
}
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
index 35cfdde3c..f946b72f7 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Change.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
@@ -71,58 +75,63 @@ import org.apache.tools.ant.*;
*/
public class P4Change extends P4Base {
- protected String emptyChangeList = null;
+ 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)) {
+
+ P4Handler handler = new P4HandlerAdapter() {
+ 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");
- }
-
- }});
+ //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");
+ }
+
+ }};
+
+ handler.setOutput(emptyChangeList);
+
+ execP4Command("change -i", handler);
}
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("//",line)) {
-
- line = util.substitute("s//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();
+ execP4Command("change -o", new P4HandlerAdapter() {
+ 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("//",line)) {
+
+ line = util.substitute("s//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();
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
index f3c9447f6..4cb6439c7 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Edit.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
@@ -65,17 +69,17 @@ import org.apache.tools.ant.*;
* ToDo: Should call reopen if file is already open in one of our changelists perhaps?
*/
-public class P4Edit extends P4Base {
+ public class P4Edit extends P4Base {
- public String change = null;
+ 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));
- }
+ 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));
+ }
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java
new file mode 100644
index 000000000..bef5f9843
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Handler.java
@@ -0,0 +1,69 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999, 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
+ * .
+ */
+
+package org.apache.tools.ant.taskdefs.optional.perforce;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+
+/** Interface for p4 job output stream handler. Classes implementing this interface
+ * can be called back by P4Base.execP4Command();
+ *
+ * @author Les Hughes
+ */
+public interface P4Handler extends ExecuteStreamHandler {
+
+ public void process(String line) throws BuildException;
+ public void setOutput(String line) throws BuildException;
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java
new file mode 100644
index 000000000..a17009871
--- /dev/null
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4HandlerAdapter.java
@@ -0,0 +1,119 @@
+/*
+ * The Apache Software License, Version 1.1
+ *
+ * Copyright (c) 1999, 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
+ * .
+ */
+
+package org.apache.tools.ant.taskdefs.optional.perforce;
+
+import java.io.*;
+import org.apache.tools.ant.*;
+
+public abstract class P4HandlerAdapter implements P4Handler {
+
+ public abstract void process(String line);
+
+
+ String p4input = "";
+
+ //set any data to be written to P4's stdin - messy, needs work
+ public void setOutput(String p4Input) {
+ this.p4input = p4Input;
+ }
+
+
+ public void start() throws BuildException {
+
+ try{
+ //First write any output to P4
+ if(p4input != null && p4input.length() >0 && os != null) {
+ os.write(p4input.getBytes());
+ os.flush();
+ os.close();
+ }
+
+ //Now read any input and process
+
+ BufferedReader input = new BufferedReader(
+ new InputStreamReader(
+ new SequenceInputStream(is,es)));
+
+ String line;
+ while((line = input.readLine()) != null) {
+ process(line);
+ }
+
+ input.close();
+
+
+ }catch(Exception e) {
+ throw new BuildException(e);
+ }
+ }
+
+ OutputStream os; //OUtput
+ InputStream is; //Input
+ InputStream es; //Error
+
+ public void setProcessInputStream(OutputStream os) throws IOException {
+ this.os = os;
+ }
+
+ public void setProcessErrorStream(InputStream is) throws IOException {
+ this.es = is;
+ }
+
+ public void setProcessOutputStream(InputStream is) throws IOException {
+ this.is = is;
+ }
+
+ public void stop(){}
+}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
index b6550a179..b771f01f6 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Have.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
index e6e443757..e97229b20 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Label.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
@@ -112,17 +116,21 @@ public class P4Label extends P4Base {
"Options: unlocked\n"+
"View: "+P4View+"\n";
- execP4Command("label -i", newLabel, new P4OutputHandler() {
- public void process(String line) {
- log(line, Project.MSG_VERBOSE);
- }
- });
+ P4Handler handler = new P4HandlerAdapter() {
+ public void process(String line) {
+ log(line, Project.MSG_VERBOSE);
+ }
+ };
+
+ handler.setOutput(newLabel);
+
+ execP4Command("label -i", handler);
- execP4Command("labelsync -l "+name, null, new P4OutputHandler() {
- public void process(String line) {
- log(line, Project.MSG_VERBOSE);
- }
- });
+ execP4Command("labelsync -l "+name, new P4HandlerAdapter() {
+ public void process(String line) {
+ log(line, Project.MSG_VERBOSE);
+ }
+ });
log("Created Label "+name+" ("+desc+")", Project.MSG_INFO);
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
index 934c5e2e0..09444b76f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Submit.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
@@ -75,20 +79,20 @@ public class P4Submit extends P4Base {
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....");
- }
- }
-
+ execP4Command("submit -c "+change, new P4HandlerAdapter(){
+ 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....");
+ }
+ }
+
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
index 542e911af..4a1563c6f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Sync.java
@@ -50,6 +50,10 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
@@ -80,7 +84,7 @@ public class P4Sync extends P4Base {
public void setLabel(String label) throws BuildException {
if(label == null && !label.equals(""))
- throw new BuildException("P4Sync: Labels cannot be Null or Empty");
+ throw new BuildException("P4Sync: Labels cannot be Null or Empty");
this.label = label;
@@ -89,20 +93,20 @@ public class P4Sync extends P4Base {
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";
- }
+ 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;
+ syncCmd = P4View;
}
if(label != null && !label.equals("")) {
- syncCmd = syncCmd + "@" + label;
+ syncCmd = syncCmd + "@" + label;
}
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java
index 445e46ab9..c4b57a399 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/SimpleP4OutputHandler.java
@@ -50,38 +50,42 @@
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* .
+ *
+ * Portions of this software are based upon public domain software
+ * originally written at the National Center for Supercomputing Applications,
+ * University of Illinois, Urbana-Champaign.
*/
package org.apache.tools.ant.taskdefs.optional.perforce;
import org.apache.tools.ant.*;
-public class SimpleP4OutputHandler implements P4OutputHandler {
+public class SimpleP4OutputHandler extends P4HandlerAdapter {
- P4Base parent;
- public SimpleP4OutputHandler(P4Base parent) {
- this.parent = parent;
- }
-
- public void process(String line) throws BuildException {
- if(parent.util.match("/^exit/",line)) return;
+ 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....
+ //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);
-
- }
+ 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);
-
- }
+ parent.log(parent.util.substitute("s/^.*: //",line), Project.MSG_INFO);
+
+ }
}