From 750031ae84bae440e6a4061f9525794c32d14f79 Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Sat, 24 May 2003 15:28:38 +0000 Subject: [PATCH] New p4labelsync task - update in documentation of Perforce tasks PR: 18431 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274612 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/perforce.html | 119 ++++++++++-- .../tools/ant/taskdefs/defaults.properties | 1 + .../optional/perforce/P4Labelsync.java | 179 ++++++++++++++++++ .../perforce/SimpleP4OutputHandler.java | 5 +- 4 files changed, 286 insertions(+), 18 deletions(-) create mode 100644 src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Labelsync.java diff --git a/docs/manual/OptionalTasks/perforce.html b/docs/manual/OptionalTasks/perforce.html index 5f90b8c6d..97c72e297 100644 --- a/docs/manual/OptionalTasks/perforce.html +++ b/docs/manual/OptionalTasks/perforce.html @@ -9,6 +9,7 @@
  • Les Hughes (leslie.hughes@rubus.com)
  • Kirk Wylie (kirk@radik.com)
  • Matt Bishop (matt@thebishops.org)
  • +
  • Antoine Levy-Lambert (levylambert@tiscali-dsl.de)
  • Version $Revision$ - $Date$


    @@ -61,6 +62,10 @@ You will also need the Perforce client executable (p4 or p4.exe but not p4win.ex P4Label Create a label reflecting files in the current workspace + + P4Labelsync + Syncs an existing label + P4Counter Obtain or set the value of a counter @@ -202,23 +207,6 @@ For more information regarding the underlying 'p4' commands you are referred to available from the Perforce website.

    -

    Taskdefs

    -

    Standard taskdefs (for you to copy'n'paste) -- normally this is done automatically if you install this optional task.

    -
    -    <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"/>
    -    <taskdef name="p4counter" classname="org.apache.tools.ant.taskdefs.optional.perforce.P4Counter"/>
    -    <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"/>
    -

    Task Descriptions

    @@ -423,6 +411,96 @@ is not the latest any more.
    +

    P4Labelsync

    +

    Description:

    +

    Syncs an existing label against the current workspace or against specified revisions. +

    +

    Parameters

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    AttributeDescriptionRequiredPerforce command line flag
    nameThe name of the labelYes-l labelname
    view + list of files or revision specs separated by : or ;
    + in the absence of this attribute, the labelsync will be done against the current Perforce client or the value of the p4client attribute or the value of the p4.client property or the value of the environment variable P4CLIENT
    Nofile[revRange] ...
    simulationmodeDisplays which effect the operation would have on the label but do not actually do itNo-n
    addIf set to true, preserve files which exist in the label, but not in the current viewNo-a
    deleteIf set to true, remove from the label the files mentioned in the view attributeNo-d
    +

    Examples

    +
    +<
    +p4labelsync
    +name="current_release"
    +view="//depot/...#head;//depot2/file1#25"
    +add="true"
    +/>
    +
    +This example will add into the label called current_release the current head revision of all the files located under //depot +and the revision 25 of the file //depot2/file1. +
    +<
    +p4labelsync
    +name="current_release"
    +p4client="myclient"
    +/>
    +
    +This example will update the label called current_release so that it reflects the Perforce client myclient.
    +Files present in the label before the sync and not present currently in the client will be removed from the label, because the add attribute is not set. +
    +<
    +p4labelsync
    +name="current_release"
    +/>
    +
    +This example will update the label called current_release so that it reflects the current default client for the ant Perforce tasks.
    +The default client is by order of priority : + +Files present in the label before the sync and not present currently in the client will be removed from the label, because the add attribute is not set. +
    + +

    P4Counter

    Description:

    @@ -873,6 +951,13 @@ P4Resolve does not use a change list number (it takes it from the files it is wo additional global options to be set.
    Added p4fstat task + + May 2003 + V1.3 + Added p4labelsync, p4resolve, p4integrate.
    + Changed p4submit (detection of changes of change numbers, + and of failed submits due to resolution needed) +


    Copyright © 2001-2003 Apache Software Foundation. All rights diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index 9237f6a48..a9d792320 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -128,6 +128,7 @@ pvcs=org.apache.tools.ant.taskdefs.optional.pvcs.Pvcs p4change=org.apache.tools.ant.taskdefs.optional.perforce.P4Change p4delete=org.apache.tools.ant.taskdefs.optional.perforce.P4Delete p4label=org.apache.tools.ant.taskdefs.optional.perforce.P4Label +p4labelsync=org.apache.tools.ant.taskdefs.optional.perforce.P4Labelsync 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 diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Labelsync.java b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Labelsync.java new file mode 100644 index 000000000..684eefba2 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/perforce/P4Labelsync.java @@ -0,0 +1,179 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2000-2003 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 "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 java.text.SimpleDateFormat; +import java.util.Date; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.StringUtils; + +/** + * Syncs an existing Perforce label against the Perforce client + * or against a set of files/revisions + * + * + * Example Usage: + *

    + *   <p4labelsync name="MyLabel-${TSTAMP}-${DSTAMP}" view="//depot/...#head;//depot2/file1#25" />
    + * 
    + * + * @author Antoine Levy-Lambert + * + * @ant.task category="scm" + */ +public class P4Labelsync extends P4Base { + + protected String name; + private boolean add; /* -a */ + private boolean delete; /* -n */ + private boolean simulationmode; /* -n */ + /** + * -a flag of p4 labelsync - preserve files which exist in the label, but not in the current view + * @return add attribute + * if set to true the task will not remove any files from the label + * only add files which were not there previously or update these where the revision has changed + * the add attribute is the -a flag of p4 labelsync + */ + public boolean isAdd() { + return add; + } + /** + * -a flag of p4 labelsync - preserve files which exist in the label, but not in the current view + * @param add if set to true the task will not remove any files from the label + * only add files which were not there previously or update these where the revision has changed + * the add attribute is the -a flag of p4 labelsync + */ + public void setAdd(boolean add) { + this.add = add; + } + /** + * -d flag of p4 labelsync; indicates an intention of deleting from the label the files specified in the view + * @return delete attribute + */ + public boolean isDelete() { + return delete; + } + + /** + * -d flag of p4 labelsync; indicates an intention of deleting from the label the files specified in the view + * @param delete + */ + public void setDelete(boolean delete) { + this.delete = delete; + } + + + /** + * The name of the label; optional, default "AntLabel" + */ + public void setName(String name) { + this.name = name; + } + /** + * -n flag of p4 labelsync - display changes without actually doing them + * @return -n flag of p4 labelsync + */ + public boolean isSimulationmode() { + return simulationmode; + } + /** + * -n flag of p4 labelsync - display changes without actually doing them + * @param simulationmode + */ + public void setSimulationmode(boolean simulationmode) { + this.simulationmode = simulationmode; + } + + + /** + * do the work + */ + public void execute() throws BuildException { + log("P4Labelsync exec:", Project.MSG_INFO); + + if (P4View != null && P4View.length() >= 1) { + P4View = StringUtils.replace(P4View, ":", "\n\t"); + P4View = StringUtils.replace(P4View, ";", "\n\t"); + } + if (P4View == null) { + P4View=""; + } + + if (name == null || name.length() < 1) { + throw new BuildException("name attribute is compulsory for labelsync"); + } + + if ( this.isSimulationmode() ) { + P4CmdOpts = P4CmdOpts + " -n"; + } + if ( this.isDelete() ) { + P4CmdOpts = P4CmdOpts + " -d"; + } + if ( this.isAdd() ) { + P4CmdOpts = P4CmdOpts + " -a"; + } + + execP4Command("-s labelsync -l "+name +" "+ P4CmdOpts + " " + P4View, new SimpleP4OutputHandler(this)); + + + } +} + 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 323158f24..8a51c6815 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 @@ -84,8 +84,11 @@ public class SimpleP4OutputHandler extends P4HandlerAdapter { //Others mark errors as info, for example edit a file //which is already open for edit..... //Just look for error: - catches most things.... + //when running labelsync, if view elements are in sync, Perforce produces a line of output + //looking like this one : + //error: //depot/file2 - label in sync. - if (parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line)) { + if (parent.util.match("/error:/", line) && !parent.util.match("/up-to-date/", line) && !parent.util.match("/label in sync/", line)) { throw new BuildException(line); }