1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | /*
|
---|
18 | * Portions of this software are based upon public domain software
|
---|
19 | * originally written at the National Center for Supercomputing Applications,
|
---|
20 | * University of Illinois, Urbana-Champaign.
|
---|
21 | */
|
---|
22 |
|
---|
23 | package org.apache.tools.ant.taskdefs.optional.perforce;
|
---|
24 |
|
---|
25 | import org.apache.tools.ant.BuildException;
|
---|
26 | import org.apache.tools.ant.Project;
|
---|
27 |
|
---|
28 | /** Synchronize client space to a Perforce depot view.
|
---|
29 | *
|
---|
30 | * The API allows additional functionality of the "p4 sync" command
|
---|
31 | * (such as "p4 sync -f //...#have" or other exotic invocations).</P>
|
---|
32 | *
|
---|
33 | * <b>Example Usage:</b>
|
---|
34 | * <table border="1">
|
---|
35 | * <th>Function</th><th>Command</th>
|
---|
36 | * <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings specified</td>
|
---|
37 | * <td><P4Sync <br>P4view="//projects/foo/main/source/..." <br>
|
---|
38 | * P4User="fbloggs" <br>P4Port="km01:1666" <br>P4Client="fbloggsclient" /></td></tr>
|
---|
39 | * <tr><td>Sync to head using P4USER, P4PORT and P4CLIENT settings defined in environment</td>
|
---|
40 | * <td><P4Sync P4view="//projects/foo/main/source/..." /></td></tr>
|
---|
41 | * <tr><td>Force a re-sync to head, refreshing all files</td>
|
---|
42 | * <td><P4Sync force="yes" P4view="//projects/foo/main/source/..." /></td></tr>
|
---|
43 | * <tr><td>Sync to a label</td><td><P4Sync label="myPerforceLabel" /></td></tr>
|
---|
44 | * </table>
|
---|
45 | *
|
---|
46 | * @todo Add decent label error handling for non-exsitant labels
|
---|
47 | *
|
---|
48 | *
|
---|
49 | * @ant.task category="scm"
|
---|
50 | */
|
---|
51 | public class P4Sync extends P4Base {
|
---|
52 |
|
---|
53 | String label;
|
---|
54 | private String syncCmd = "";
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Label to sync client to; optional.
|
---|
58 | * @param label name of a label against which one want to sync
|
---|
59 | * @throws BuildException if label is null or empty string
|
---|
60 | */
|
---|
61 | public void setLabel(String label) throws BuildException {
|
---|
62 | if (label == null && !label.equals("")) {
|
---|
63 | throw new BuildException("P4Sync: Labels cannot be Null or Empty");
|
---|
64 | }
|
---|
65 |
|
---|
66 | this.label = label;
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * force a refresh of files, if this attribute is set; false by default.
|
---|
73 | * @param force sync all files, whether they are supposed to be already uptodate or not.
|
---|
74 | * @throws BuildException if a label is set and force is null
|
---|
75 | */
|
---|
76 | public void setForce(String force) throws BuildException {
|
---|
77 | if (force == null && !label.equals("")) {
|
---|
78 | throw new BuildException("P4Sync: If you want to force, set force to non-null string!");
|
---|
79 | }
|
---|
80 | P4CmdOpts = "-f";
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * do the work
|
---|
85 | * @throws BuildException if an error occurs during the execution of the Perforce command
|
---|
86 | * and failOnError is set to true
|
---|
87 | */
|
---|
88 | public void execute() throws BuildException {
|
---|
89 |
|
---|
90 |
|
---|
91 | if (P4View != null) {
|
---|
92 | syncCmd = P4View;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | if (label != null && !label.equals("")) {
|
---|
97 | syncCmd = syncCmd + "@" + label;
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | log("Execing sync " + P4CmdOpts + " " + syncCmd, Project.MSG_VERBOSE);
|
---|
102 |
|
---|
103 | execP4Command("-s sync " + P4CmdOpts + " " + syncCmd, new SimpleP4OutputHandler(this));
|
---|
104 | }
|
---|
105 | }
|
---|