KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > perforce > P4Sync


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 /*
19  * Portions of this software are based upon public domain software
20  * originally written at the National Center for Supercomputing Applications,
21  * University of Illinois, Urbana-Champaign.
22  */

23
24 package org.apache.tools.ant.taskdefs.optional.perforce;
25
26 import org.apache.tools.ant.BuildException;
27 import org.apache.tools.ant.Project;
28
29 /** Synchronize client space to a Perforce depot view.
30  *
31  * The API allows additional functionality of the "p4 sync" command
32  * (such as "p4 sync -f //...#have" or other exotic invocations).</P>
33  *
34  * <b>Example Usage:</b>
35  * <table border="1">
36  * <th>Function</th><th>Command</th>
37  * <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings specified</td>
38  * <td>&lt;P4Sync <br>P4view="//projects/foo/main/source/..." <br>
39  * P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient" /&gt;</td></tr>
40  * <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings defined in environment</td>
41  * <td>&lt;P4Sync P4view="//projects/foo/main/source/..." /&gt;</td></tr>
42  * <tr><td>Force a re-sync to head, refreshing all files</td>
43  * <td>&lt;P4Sync force="yes" P4view="//projects/foo/main/source/..." /&gt;</td></tr>
44  * <tr><td>Sync to a label</td><td>&lt;P4Sync label="myPerforceLabel" /&gt;</td></tr>
45  * </table>
46  *
47  * @todo Add decent label error handling for non-exsitant labels
48  *
49  * @ant.task category="scm"
50  */

51 public class P4Sync extends P4Base {
52
53     // CheckStyle:VisibilityModifier OFF - bc
54
String JavaDoc label;
55     private String JavaDoc syncCmd = "";
56     // CheckStyle:VisibilityModifier ON
57

58     /**
59      * Label to sync client to; optional.
60      * @param label name of a label against which one want to sync
61      * @throws BuildException if label is null or empty string
62      */

63     public void setLabel(String JavaDoc label) throws BuildException {
64         if (label == null || label.equals("")) {
65             throw new BuildException("P4Sync: Labels cannot be Null or Empty");
66         }
67
68         this.label = label;
69
70     }
71
72
73     /**
74      * force a refresh of files, if this attribute is set; false by default.
75      * @param force sync all files, whether they are supposed to be already uptodate or not.
76      * @throws BuildException if a label is set and force is null
77      */

78     public void setForce(String JavaDoc force) throws BuildException {
79         if (force == null && !label.equals("")) {
80             throw new BuildException("P4Sync: If you want to force, set force to non-null string!");
81         }
82         P4CmdOpts = "-f";
83     }
84
85     /**
86      * do the work
87      * @throws BuildException if an error occurs during the execution of the Perforce command
88      * and failOnError is set to true
89      */

90     public void execute() throws BuildException {
91
92
93         if (P4View != null) {
94             syncCmd = P4View;
95         }
96
97
98         if (label != null && !label.equals("")) {
99             syncCmd = syncCmd + "@" + label;
100         }
101
102
103         log("Execing sync " + P4CmdOpts + " " + syncCmd, Project.MSG_VERBOSE);
104
105         execP4Command("-s sync " + P4CmdOpts + " " + syncCmd, new SimpleP4OutputHandler(this));
106     }
107 }
108
Popular Tags