KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > cvsclient > command > tag > RtagCommand


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.lib.cvsclient.command.tag;
20
21 import java.io.*;
22
23 import org.netbeans.lib.cvsclient.*;
24 import org.netbeans.lib.cvsclient.command.*;
25 import org.netbeans.lib.cvsclient.connection.*;
26 import org.netbeans.lib.cvsclient.event.*;
27 import org.netbeans.lib.cvsclient.request.*;
28
29 /**
30  * The rtag command adds or deletes a tag to the specified files/directories in
31  * the repository.
32  *
33  * @author Martin Entlicher
34  */

35 public class RtagCommand extends RepositoryCommand {
36     /**
37      * The event manager to use.
38      */

39     private EventManager eventManager;
40
41     private boolean clearFromRemoved;
42
43     private boolean deleteTag;
44
45     private boolean makeBranchTag;
46
47     private boolean overrideExistingTag;
48     
49     private boolean matchHeadIfRevisionNotFound;
50     
51     private boolean noExecTagProgram;
52
53     private String JavaDoc tag;
54
55     private String JavaDoc tagByDate;
56
57     private String JavaDoc tagByRevision;
58
59     /**
60      * Construct a new tag command.
61      */

62     public RtagCommand() {
63     }
64
65     /**
66      * Creates the TagBuilder.
67      * @param eventManager the event manager used to received cvs events
68      */

69     public Builder createBuilder(EventManager eventManager) {
70         return new TagBuilder(eventManager, getLocalDirectory());
71     }
72
73     /**
74      * Returns true if the tag from removed files is cleared.
75      */

76     public boolean isClearFromRemoved() {
77         return clearFromRemoved;
78     }
79
80     /**
81      * Clear tag from removed files
82      */

83     public void setClearFromRemoved(boolean clearFromRemoved) {
84         this.clearFromRemoved = clearFromRemoved;
85     }
86
87     /**
88      * Returns true if the tag should be deleted (otherwise added).
89      */

90     public boolean isDeleteTag() {
91         return deleteTag;
92     }
93
94     /**
95      * Sets whether the tag should be deleted (true) or added (false).
96      */

97     public void setDeleteTag(boolean deleteTag) {
98         this.deleteTag = deleteTag;
99     }
100
101     /**
102      * Returns true if the tag should be a branch tag.
103      */

104     public boolean isMakeBranchTag() {
105         return makeBranchTag;
106     }
107
108     /**
109      * Sets whether the tag should be a branch tag.
110      */

111     public void setMakeBranchTag(boolean makeBranchTag) {
112         this.makeBranchTag = makeBranchTag;
113     }
114
115     /**
116      * Returns true to indicate that existing tag will be overridden.
117      */

118     public boolean isOverrideExistingTag() {
119         return overrideExistingTag;
120     }
121
122     /**
123      * Sets whether existing tags should be overridden.
124      */

125     public void setOverrideExistingTag(boolean overrideExistingTag) {
126         this.overrideExistingTag = overrideExistingTag;
127     }
128     
129     public boolean isMatchHeadIfRevisionNotFound() {
130         return matchHeadIfRevisionNotFound;
131     }
132     
133     public void setMatchHeadIfRevisionNotFound(boolean matchHeadIfRevisionNotFound) {
134         this.matchHeadIfRevisionNotFound = matchHeadIfRevisionNotFound;
135     }
136     
137     public boolean isNoExecTagProgram() {
138         return noExecTagProgram;
139     }
140
141     public void setNoExecTagProgram(boolean noExecTagProgram) {
142         this.noExecTagProgram = noExecTagProgram;
143     }
144     
145     /**
146      * Returns the tag that should be added or deleted.
147      */

148     public String JavaDoc getTag() {
149         return tag;
150     }
151
152     /**
153      * Sets the tag that should be added or deleted.
154      */

155     public void setTag(String JavaDoc tag) {
156         this.tag = tag;
157     }
158
159     /**
160      * Returns the latest date of a revision to be tagged.
161      * @return date value. the latest Revision not later ten date is tagged.
162      */

163     public String JavaDoc getTagByDate() {
164         return tagByDate;
165     }
166
167     /**
168      * Sets the latest date of a revision to be tagged.
169      * @param tagDate New value of property tagDate.
170      */

171     public void setTagByDate(String JavaDoc tagDate) {
172         tagByDate = tagDate;
173     }
174
175     /**
176      * Sets the latest date of a revision to be tagged. Can be both a number and a tag.
177      * @return Value of property tagRevision.
178      */

179     public String JavaDoc getTagByRevision() {
180         return tagByRevision;
181     }
182
183     /**
184      * Sets the latest date of a revision to be tagged. Can be both a number and a tag.
185      * @param tagRevision New value of property tagRevision.
186      */

187     public void setTagByRevision(String JavaDoc tagRevision) {
188         tagByRevision = tagRevision;
189     }
190
191     /**
192      * Execute the command.
193      *
194      * @param client the client services object that provides any necessary
195      * services to this command, including the ability to actually
196      * process all the requests.
197      */

198     protected void postExpansionExecute(ClientServices client, EventManager eventManager)
199             throws CommandException, AuthenticationException {
200         client.ensureConnection();
201
202         this.eventManager = eventManager;
203
204         try {
205             if (clearFromRemoved) {
206                 requests.add(new ArgumentRequest("-a")); //NOI18N
207
}
208
209             if (overrideExistingTag) {
210                 requests.add(new ArgumentRequest("-F")); //NOI18N
211
}
212             
213             if (matchHeadIfRevisionNotFound) {
214                 requests.add(new ArgumentRequest("-f")); // NOI18N
215
}
216
217             if (makeBranchTag) {
218                 requests.add(new ArgumentRequest("-b")); //NOI18N
219
}
220
221             if (deleteTag) {
222                 requests.add(new ArgumentRequest("-d")); //NOI18N
223
}
224             
225             if (noExecTagProgram) {
226                 requests.add(new ArgumentRequest("-n ")); // NOI18N
227
}
228             
229             if (tagByDate != null && tagByDate.length() > 0) {
230                 requests.add(new ArgumentRequest("-D")); //NOI18N
231
requests.add(new ArgumentRequest(getTagByDate()));
232             }
233             if (tagByRevision != null && tagByRevision.length() > 0) {
234                 requests.add(new ArgumentRequest("-r")); //NOI18N
235
requests.add(new ArgumentRequest(getTagByRevision()));
236             }
237
238             requests.add(new ArgumentRequest(getTag()));
239             
240             //addRequestForWorkingDirectory(client);
241
addArgumentRequests();
242             addRequest(CommandRequest.RTAG);
243
244             client.processRequests(requests);
245         }
246         catch (CommandException ex) {
247             throw ex;
248         }
249         catch (EOFException ex) {
250             throw new CommandException(ex, CommandException.getLocalMessage("CommandException.EndOfFile", null)); //NOI18N
251
}
252         catch (Exception JavaDoc ex) {
253             throw new CommandException(ex, ex.getLocalizedMessage());
254         }
255         finally {
256             requests.clear();
257         }
258     }
259
260     /**
261      * Called when server responses with "ok" or "error", (when the command
262      * finishes).
263      */

264     public void commandTerminated(TerminationEvent e) {
265         if (builder != null) {
266             builder.outputDone();
267         }
268     }
269
270     /**
271      * This method returns how the tag command would looklike when typed on the
272      * command line.
273      */

274     public String JavaDoc getCVSCommand() {
275         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc("rtag "); //NOI18N
276
toReturn.append(getCVSArguments());
277         if (getTag() != null) {
278             toReturn.append(getTag());
279             toReturn.append(" "); //NOI18N
280
}
281         appendModuleArguments(toReturn);
282         return toReturn.toString();
283     }
284
285     /**
286      * Takes the arguments and sets the command.
287      * To be mainly used for automatic settings (like parsing the .cvsrc file)
288      * @return true if the option (switch) was recognized and set
289      */

290     public boolean setCVSCommand(char opt, String JavaDoc optArg) {
291         if (opt == 'R') {
292             setRecursive(true);
293         }
294         else if (opt == 'l') {
295             setRecursive(false);
296         }
297         else if (opt == 'a') {
298             setClearFromRemoved(true);
299         }
300         else if (opt == 'd') {
301             setDeleteTag(true);
302         }
303         else if (opt == 'F') {
304             setOverrideExistingTag(true);
305         }
306         else if (opt == 'f') {
307             setMatchHeadIfRevisionNotFound(true);
308         }
309         else if (opt == 'b') {
310             setMakeBranchTag(true);
311         }
312         else if (opt == 'n') {
313             setNoExecTagProgram(true);
314         }
315         else if (opt == 'D') {
316             setTagByDate(optArg.trim());
317         }
318         else if (opt == 'r') {
319             setTagByRevision(optArg.trim());
320         }
321         else {
322             return false;
323         }
324         return true;
325     }
326
327     /**
328      * String returned by this method defines which options are available for
329      * this command.
330      */

331     public String JavaDoc getOptString() {
332         return "RlaFfbdnD:r:"; //NOI18N
333
}
334
335     /**
336      * Resets all switches in the command.
337      * After calling this method, the command should have no switches defined
338      * and should behave defaultly.
339      */

340     public void resetCVSCommand() {
341         setRecursive(true);
342         setClearFromRemoved(false);
343         setDeleteTag(false);
344         setMakeBranchTag(false);
345         setOverrideExistingTag(false);
346         setMatchHeadIfRevisionNotFound(false);
347         setNoExecTagProgram(false);
348     }
349
350     /**
351      * Returns the arguments of the command in the command-line style.
352      * Similar to getCVSCommand() however without the files and command's name
353      */

354     public String JavaDoc getCVSArguments() {
355         StringBuffer JavaDoc toReturn = new StringBuffer JavaDoc();
356         if (!isRecursive()) {
357             toReturn.append("-l "); //NOI18N
358
}
359         if (isClearFromRemoved()) {
360             toReturn.append("-a "); //NOI18N
361
}
362         if (isOverrideExistingTag()) {
363             toReturn.append("-F "); //NOI18N
364
}
365         if (isMatchHeadIfRevisionNotFound()) {
366             toReturn.append("-f ");
367         }
368         if (isMakeBranchTag()) {
369             toReturn.append("-b "); //NOI18N
370
}
371         if (isDeleteTag()) {
372             toReturn.append("-d "); //NOI18N
373
}
374         if (isNoExecTagProgram()) {
375             toReturn.append("-n "); // NOI18N
376
}
377         if (getTagByRevision() != null && getTagByRevision().length() > 0) {
378             toReturn.append("-r "); //NOI18N
379
toReturn.append(getTagByRevision());
380             toReturn.append(" "); //NOI18N
381
}
382         if (getTagByDate() != null && getTagByDate().length() > 0) {
383             toReturn.append("-D "); //NOI18N
384
toReturn.append(getTagByDate());
385             toReturn.append(" "); //NOI18N
386
}
387         return toReturn.toString();
388     }
389 }
390
Popular Tags