From a1a910e2dfaba629e90b83f722b77c3a9a0c72b6 Mon Sep 17 00:00:00 2001 From: Conor MacNeill Date: Tue, 4 Feb 2003 12:23:52 +0000 Subject: [PATCH] New perforce functionality PR: 15707 Submitted by: Antoine Levy-Lambert git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273968 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/perforce.html | 232 +++++++++++- .../tools/ant/taskdefs/defaults.properties | 2 + .../optional/perforce/P4Integrate.java | 353 ++++++++++++++++++ .../taskdefs/optional/perforce/P4Resolve.java | 185 +++++++++ .../taskdefs/optional/perforce/P4Submit.java | 47 ++- .../ant/taskdefs/optional/perforce/build1.xml | 33 ++ .../ant/taskdefs/optional/perforce/build2.xml | 53 +++ .../optional/perforce/p4integrate.xml | 15 + 8 files changed, 911 insertions(+), 9 deletions(-) create mode 100644 src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Integrate.java create mode 100644 src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Resolve.java create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build1.xml create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build2.xml create mode 100644 src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/p4integrate.xml diff --git a/docs/manual/OptionalTasks/perforce.html b/docs/manual/OptionalTasks/perforce.html index 328089f9b..5f90b8c6d 100644 --- a/docs/manual/OptionalTasks/perforce.html +++ b/docs/manual/OptionalTasks/perforce.html @@ -79,7 +79,18 @@ You will also need the Perforce client executable (p4 or p4.exe but not p4win.ex P4Add Add files - + + P4Delete + Delete files + + + P4Integrate + Integrate files + + + P4Resolve + Resolve files + P4Fstat Show differences between local repository and p4 repository @@ -204,6 +215,9 @@ available from the Perforce web <taskdef name="p4reopen" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Reopen"/> <taskdef name="p4revert" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Revert"/> <taskdef name="p4add" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Add"/> + <taskdef name="p4delete" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Delete"/> + <taskdef name="p4integrate" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Integrate"/> + <taskdef name="p4resolve" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Resolve"/>
@@ -245,7 +259,8 @@ available from the
Perforce web

Description:

Request a new changelist from the Perforce server. This task sets the ${p4.change} property which can then be passed to P4Submit, -P4Edit, or P4Add. +P4Edit, or P4Add, or P4Delete, +then to P4Submit.

Parameters

@@ -309,6 +324,11 @@ although P4Edit can open files to the default change, P4Submit cannot yet submi

P4Submit

Description:

Submit a changelist, usually obtained from P4Change. +

P4Submit will also change the value of the property p4.change if the change list is renamed by the Perforce server. +

P4Submit will set a property p4.needsresolve to 1 if the change could not be submitted due to files needing resolving. +

Files will need resolve if at the time of checking in, the revision that was checked out to do the current edit +is not the latest any more. +

If no files need resolve, the p4.needsresolve will be set to 0.

Parameters

@@ -618,6 +638,214 @@ will list all the files under C:\dev\gnu\depot, sorted by under Perforce or not +

P4Delete

+

Description:

+

Open file(s) for delete. P4Change should be used to obtain a new changelist for P4Delete as, +although P4Delete can open files to the default change, P4Submit cannot yet submit it. +

+

Parameters

+
+ + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
viewThe filespec to request to deleteYes
changeAn existing changelist number to assign files to.No, but see above.
+ +

Examples

+
+<p4delete
+    view="//depot/projects/projectfoo/main/src/Blah.java..."
+    change="${p4.change}"/>
+
+
+

P4Integrate

+

Description:

+

Open file(s) for integrate. P4Change should be used to obtain a new changelist for P4Integrate as, +although P4Integrate can open files to the default change, P4Submit cannot yet submit it. +

+

Parameters

+

If this task is used without using a branch definition, both fromfile and tofile must be supplied. +If a branch definition is supplied, at least one of fromfile or tofile should be supplied. +Both fromfile and tofile can be supplied together with a branch definition.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequiredPerforce command line flag
fromfileOriginal file or viewrequired if a branch is not specified
tofileTarget file or view.required if a branch is not specified
branchName of branch specificationNo-b
changeAn existing changelist number to assign files to.No, but see above.-c
forceintegrateForces integration regardless of previous integration history (*)No-f
restoredeletedrevisionsEnables integration around deleted revisions (*)No-d
leavetargetrevisionPrevents target files from being synced to head revision before integration (*)No-h
enablebaselessmergesForces integration to existing target files which have no integration history relative to the source files (*)No-i
simulationmodeDisplays which integrations are necessary but do not actually schedule them (*)No-n
reversebranchmappingsReverses mappings in the branch view, with source and target files exchanging place (*)No-r
propagatesourcefiletypeMakes source file type propagate to existing target files (*)No-t
nocopytargetfilesPrevents the physical delivery on disk of new target files (*)No-v
+
+(*) The following applies for a number of flags. The default is false. To set the flag, use "true" + +

Examples

+
+<p4integrate
+    fromfile="//depot/projects/projectfoo/main/src/Blah.java..."
+    tofile="//depot/projects/projectfoo/release/src/Blah.java..."
+    change="${p4.change}"/>
+
+
+

P4Resolve

+

Description:

+

Resolves files. You want to do this if : +

+P4Resolve does not use a change list number (it takes it from the files it is working on). +

+

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequiredPerforce command line flag
viewThe filespec to request to deleteYes
resolvemodeShould have one of these values : +
    +
  • "automatic"
  • +
  • "force"
  • +
  • "safe"
  • +
  • "theirs"
  • +
  • "yours"
  • +
Yescorresponds to one of -am -af -as -at -ay
redoallallows previously resolved files to be resolved again (*)No-f
simulationmodeLists the integrations which would be performed, without actually doing them. (*)No-n
forcetextmodeAttempts a textual merge, even for binary files (*)No-t
markersforallPuts in markers for all changes, conflicting or not (*)No-v
+
+(*) The following applies for a number of flags. The default is false. To set the flag, use "true" + +

Examples

+
+<p4resolve
+    view="//depot/projects/projectfoo/main/src/Blah.java..."
+    change="${p4.change}"
+    resolvemode="automatic"/>
+
+

Change History

diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index 54ea31fbe..01e34c7ae 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -128,6 +128,8 @@ p4label=org.apache.tools.ant.taskdefs.optional.perforce.P4Label p4have=org.apache.tools.ant.taskdefs.optional.perforce.P4Have p4sync=org.apache.tools.ant.taskdefs.optional.perforce.P4Sync p4edit=org.apache.tools.ant.taskdefs.optional.perforce.P4Edit +p4integrate=org.apache.tools.ant.taskdefs.optional.perforce.P4Integrate +p4resolve=org.apache.tools.ant.taskdefs.optional.perforce.P4Resolve p4submit=org.apache.tools.ant.taskdefs.optional.perforce.P4Submit p4counter=org.apache.tools.ant.taskdefs.optional.perforce.P4Counter p4revert=org.apache.tools.ant.taskdefs.optional.perforce.P4Revert diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Integrate.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Integrate.java new file mode 100644 index 000000000..6cf9ab341 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Integrate.java @@ -0,0 +1,353 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2002 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 + * . + */ +/* + * 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.BuildException; + +/** + * Integrate file(s). + * P4Change should be used to obtain a new changelist for P4Integrate, + * although P4Integrate can open files to the default change, + * P4Submit cannot yet submit to it. + * Example Usage:
+ * <p4integrate change="${p4.change}" fromfile="//depot/project/dev/foo.txt" tofile="//depot/project/main/foo.txt" /> + * + * @author Antoine Levy-Lambert + * + */ + +public class P4Integrate extends P4Base { + + private String change = null; + private String fromfile = null; + private String tofile = null; + private String branch = null; + private boolean restoredeletedrevisions = false; + private boolean forceintegrate = false; + private boolean leavetargetrevision = false; + private boolean enablebaselessmerges = false; + private boolean simulationmode = false; + private boolean reversebranchmappings = false; + private boolean propagatesourcefiletype = false; + private boolean nocopynewtargetfiles = false; + + /** + * get the changelist number + * + * @returns the changelist number set for this task + */ + public String getChange() { + return change; + } + + /** + * set the changelist number for the operation + * + * @param change An existing changelist number to assign files to; optional + * but strongly recommended. + */ + public void setChange(String change) { + this.change = change; + } + + /** + * get the from file specification + * + * @returns the from file specification + */ + public String getFromfile() { + return fromfile; + } + + /** + * sets the from file specification + * + * @param fromf the from file specification + */ + public void setFromfile(String fromf) { + this.fromfile = fromf; + } + + /** + * get the to file specification + * + * @returns the to file specification + */ + public String getTofile() { + return tofile; + } + + /** + * sets the to file specification + * + * @param tof the to file specification + */ + public void setTofile(String tof) { + this.tofile = tof; + } + + /** + * get the branch + * + * @returns the name of the branch + */ + public String getBranch() { + return branch; + } + + /** + * sets the branch + * + * @param br the name of the branch to use + */ + public void setBranch(String br) { + this.branch = br; + } + + /** + * gets the restoredeletedrevisions flag + * + * @returns restore deleted revisions + */ + public boolean isRestoreDeletedRevisions() { + return restoredeletedrevisions; + } + + /** + * sets the restoredeletedrevisions flag + * + * @param setrest value chosen for restoredeletedrevisions + */ + public void setRestoreDeletedRevisions(boolean setrest) { + this.restoredeletedrevisions = setrest; + } + + /** + * gets the forceintegrate flag + * + * @returns restore deleted revisions + */ + public boolean isForceIntegrate() { + return forceintegrate; + } + + /** + * sets the forceintegrate flag + * + * @param setrest value chosen for forceintegrate + */ + public void setForceIntegrate(boolean setrest) { + this.forceintegrate = setrest; + } + + /** + * gets the leavetargetrevision flag + * + * @returns flag indicating if the target revision should be preserved + */ + public boolean isLeaveTargetRevision() { + return leavetargetrevision; + } + + /** + * sets the leavetargetrevision flag + * + * @param setrest value chosen for leavetargetrevision + */ + public void setLeaveTargetRevision(boolean setrest) { + this.leavetargetrevision = setrest; + } + + /** + * gets the enablebaselessmerges flag + * + * @returns boolean indicating if baseless merges are desired + */ + public boolean isEnableBaselessMerges() { + return enablebaselessmerges; + } + + /** + * sets the enablebaselessmerges flag + * + * @param setrest value chosen for enablebaselessmerges + */ + public void setEnableBaselessMerges(boolean setrest) { + this.enablebaselessmerges = setrest; + } + + /** + * gets the simulationmode flag + * + * @returns simulation mode flag + */ + public boolean isSimulationMode() { + return simulationmode; + } + + /** + * sets the simulationmode flag + * + * @param setrest value chosen for simulationmode + */ + public void setSimulationMode(boolean setrest) { + this.simulationmode = setrest; + } + /** + * returns the flag indicating if reverse branch mappings are sought + * + * @returns reversebranchmappings flag + */ + public boolean isReversebranchmappings() { + return reversebranchmappings; + } + + /** + * sets the reversebranchmappings flag + * + * @param reversebranchmappings flag indicating if reverse branch mappings are sought + */ + public void setReversebranchmappings(boolean reversebranchmappings) { + this.reversebranchmappings = reversebranchmappings; + } + /** + * returns flag indicating if propagation of source file type is sought + * + * @returns flag set to true if you want to propagate source file type for existing target files + */ + public boolean isPropagatesourcefiletype() { + return propagatesourcefiletype; + } + /** + * 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. + */ + public void setPropagatesourcefiletype(boolean propagatesourcefiletype) { + this.propagatesourcefiletype = propagatesourcefiletype; + } + /** + * returns flag indicating if one wants to suppress the copying on the local hard disk of new target files + * + * @returns flag indicating if one wants to suppress the copying on the local hard disk of new target files + */ + public boolean isNocopynewtargetfiles() { + return nocopynewtargetfiles; + } + + /** + * 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 + */ + public void setNocopynewtargetfiles(boolean nocopynewtargetfiles) { + this.nocopynewtargetfiles = nocopynewtargetfiles; + } + + /** + * execute the p4 integrate + */ + public void execute() throws BuildException { + if (change != null) { + P4CmdOpts = "-c " + change; + } + if (this.forceintegrate) { + P4CmdOpts = P4CmdOpts + " -f"; + } + if (this.restoredeletedrevisions) { + P4CmdOpts = P4CmdOpts + " -d"; + } + if ( this.leavetargetrevision) { + P4CmdOpts = P4CmdOpts + " -h"; + } + if ( this.enablebaselessmerges ) { + P4CmdOpts = P4CmdOpts + " -i"; + } + if (this.simulationmode ) { + P4CmdOpts = P4CmdOpts + " -n"; + } + if ( this.reversebranchmappings ) { + P4CmdOpts = P4CmdOpts + " -r"; + } + if ( this.propagatesourcefiletype ) { + P4CmdOpts = P4CmdOpts + " -t"; + } + if ( this.nocopynewtargetfiles ) { + P4CmdOpts = P4CmdOpts + "-v"; + } + String command; + if (branch == null && fromfile != null && tofile != null) { + command = P4CmdOpts + " " + fromfile + " " + tofile; + + } + else if ( branch != null && fromfile == null && tofile != null ) + { + 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 "); + } + execP4Command("-s integrate " + command, new SimpleP4OutputHandler(this)); + } +} diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Resolve.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Resolve.java new file mode 100644 index 000000000..caf4dd1da --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Resolve.java @@ -0,0 +1,185 @@ +/* +* The Apache Software License, Version 1.1 +* +* Copyright (c) 2000-2002 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 +* . +*/ +/* +* 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.BuildException; + +public class P4Resolve extends P4Base{ + private String resolvemode = null; + + + private boolean redoall; /* -f */ + private boolean simulationmode; /* -n */ + private boolean forcetextmode; /* -t */ + private boolean markersforall; /* -v */ + private static final String AUTOMATIC = "automatic"; + private static final String FORCE = "force"; + private static final String SAFE = "safe"; + private static final String THEIRS = "theirs"; + private static final String YOURS = "yours"; + private static final String[] resolvemodes = { + AUTOMATIC, + FORCE, + SAFE, + THEIRS, + YOURS + }; + + public String getResolvemode() { + return resolvemode; + } + /** + * values for resolvemode + *
    + *
  • automatic -am
  • + *
  • force -af
  • + *
  • safe -as
  • + *
  • theirs -at
  • + *
  • yours -ay
  • + *
+ */ + public void setResolvemode(String resolvemode) { + boolean found=false; + for (int counter=0; counter < resolvemodes.length; counter++) + { + if (resolvemode.equals(resolvemodes[counter])) { + found=true; + break; + } + } + if (found==false) { + throw new BuildException("Unacceptable value for resolve mode"); + } + this.resolvemode = resolvemode; + } + + public boolean isRedoall() { + return redoall; + } + + public void setRedoall(boolean redoall) { + this.redoall = redoall; + } + + public boolean isSimulationmode() { + return simulationmode; + } + + public void setSimulationmode(boolean simulationmode) { + this.simulationmode = simulationmode; + } + + public boolean isForcetextmode() { + return forcetextmode; + } + + public void setForcetextmode(boolean forcetextmode) { + this.forcetextmode = forcetextmode; + } + + public boolean isMarkersforall() { + return markersforall; + } + + public void setMarkersforall(boolean markersforall) { + this.markersforall = markersforall; + } + + /** + * execute the p4 resolve + */ + public void execute() throws BuildException { + if (this.resolvemode.equals(AUTOMATIC)) { + P4CmdOpts = P4CmdOpts + " -am"; + } + else if (this.resolvemode.equals(FORCE)) { + P4CmdOpts = P4CmdOpts + " -af"; + } + else if (this.resolvemode.equals(SAFE)) { + P4CmdOpts = P4CmdOpts + " -as"; + } + else if (this.resolvemode.equals(THEIRS)) { + P4CmdOpts = P4CmdOpts + " -at"; + } + else if (this.resolvemode.equals(YOURS)) { + P4CmdOpts = P4CmdOpts + " -ay"; + } + else + { + throw new BuildException("unsupported or absent resolve mode"); + } + if (P4View==null) { + throw new BuildException("please specify a view"); + } + if ( this.isRedoall() ) { + P4CmdOpts = P4CmdOpts + " -f"; + } + if ( this.isSimulationmode() ) { + P4CmdOpts = P4CmdOpts + " -n"; + } + if ( this.isForcetextmode() ) { + P4CmdOpts = P4CmdOpts + " -t"; + } + if ( this.isMarkersforall() ) { + P4CmdOpts = P4CmdOpts + " -v"; + } + execP4Command("-s resolve " + P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); + } +} 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 541b44175..e02ac9ddb 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 @@ -61,6 +61,7 @@ package org.apache.tools.ant.taskdefs.optional.perforce; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; +import java.util.Vector; /** Submits a numbered changelist to Perforce. * @@ -80,7 +81,7 @@ public class P4Submit extends P4Base { public String change; /** - * The changelist number to submit; required. + * @param change The changelist number to submit; required. */ public void setChange(String change) { this.change = change; @@ -88,12 +89,7 @@ public class P4Submit extends P4Base { public void execute() throws BuildException { if (change != null) { - execP4Command("submit -c " + change, - new P4HandlerAdapter() { - public void process(String line) { - log(line, Project.MSG_VERBOSE); - } - }); + execP4Command("submit -c " + change, (P4HandlerAdapter) new P4SubmitAdapter()); } else { //here we'd parse the output from change -o into submit -i //in order to support default change. @@ -101,4 +97,41 @@ public class P4Submit extends P4Base { } } + public class P4SubmitAdapter extends P4HandlerAdapter { + public void process(String line) { + log(line, Project.MSG_VERBOSE); + getProject().setProperty("p4.needsresolve","0"); + // this type of output might happen + // Change 18 renamed change 20 and submitted. + if (util.match("/renamed/", line)) { + try { + Vector myarray = new Vector(); + util.split(myarray, line); + boolean found = false; + for (int counter = 0; counter < myarray.size(); counter++) { + if (found == true) { + int changenumber = Integer.parseInt((String) myarray.elementAt(counter + 1)); + log("Perforce change renamed " + changenumber, Project.MSG_INFO); + getProject().setProperty("p4.change", "" + changenumber); + found = false; + } + if (((String) (myarray.elementAt(counter))).equals("renamed")) { + found = true; + } + } + } + // NumberFormatException or ArrayOutOfBondsException could happen here + catch (Exception e) { + String msg = "Failed to parse " + line + "\n" + + " due to " + e.getMessage(); + throw new BuildException(msg, e, getLocation()); + } + } + if (util.match("/p4 submit -c/",line)) { + getProject().setProperty("p4.needsresolve","1"); + } + + } + } + } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build1.xml b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build1.xml new file mode 100644 index 000000000..b313b87cd --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build1.xml @@ -0,0 +1,33 @@ + + + + + + + + +doing a first change ${change1} + + + + +doing a second change ${change2} + + + + +before submitting of hello change ${change2} p4.change is now ${p4.change} + + + +after submitting of hello p4.change is now ${p4.change} + + +before submitting of foobar change ${change1} + + + +after submitting of foobar p4.change is now ${p4.change} + + + diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build2.xml b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build2.xml new file mode 100644 index 000000000..6d4e1dcfc --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/build2.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +doing a change ${change} on client ${p4.client} + + + +hello ${p4.client} ${change} + + + + + +p4.needsresolve ${p4.needsresolve} after submit + + + \ No newline at end of file diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/p4integrate.xml b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/p4integrate.xml new file mode 100644 index 000000000..31001ddf8 --- /dev/null +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/perforce/p4integrate.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + +