1
/*****************************************************************************
2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is the CVS Client Library.
27
* The Initial Developer of the Original Software is Thomas Singer.
28
* Portions created by Robert Greig are Copyright (C) 2001.
29
* All Rights Reserved.
31
* If you wish your version of this file to be governed by only the CDDL
32
* or only the GPL Version 2, indicate your decision by adding
33
* "[Contributor] elects to include this software in this distribution
34
* under the [CDDL or GPL Version 2] license." If you do not indicate a
35
* single choice of license, a recipient has the option to distribute
36
* your version of this file under either the CDDL, the GPL Version 2 or
37
* to extend the choice of license to its licensees as provided above.
38
* However, if you add GPL Version 2 code and therefore, elected the GPL
39
* Version 2 license, then the option applies only if the new code is
40
* made subject to such option by the copyright holder.
42
* Contributor(s): Thomas Singer.
43
*****************************************************************************/
44
package org.netbeans.lib.cvsclient.command.tag;
48
import org.netbeans.lib.cvsclient.*;
49
import org.netbeans.lib.cvsclient.command.*;
50
import org.netbeans.lib.cvsclient.connection.*;
51
import org.netbeans.lib.cvsclient.event.*;
52
import org.netbeans.lib.cvsclient.request.*;
55
* The tag command adds or deleted a tag to the specified files/directories.
57
* @author Thomas Singer
59
public class TagCommand extends BasicCommand {
61
* The event manager to use.
63
private EventManager eventManager;
65
private boolean checkThatUnmodified;
67
private boolean deleteTag;
69
private boolean makeBranchTag;
71
private boolean overrideExistingTag;
73
private boolean matchHeadIfRevisionNotFound;
77
private String tagByDate;
79
private String tagByRevision;
82
* Construct a new tag command.
88
* Creates the TagBuilder.
89
* @param eventManager the event manager used to received cvs events
91
public Builder createBuilder(EventManager eventManager) {
92
return new TagBuilder(eventManager, getLocalDirectory());
96
* Returns true if checking for unmodified files is enabled.
99
public boolean doesCheckThatUnmodified() {
100
return checkThatUnmodified;
104
* Returns true if checking for unmodified files is enabled.
106
public boolean isCheckThatUnmodified() {
107
return checkThatUnmodified;
111
* Enabled the check for unmodified files.
113
public void setCheckThatUnmodified(boolean checkThatUnmodified) {
114
this.checkThatUnmodified = checkThatUnmodified;
118
* Returnes true if the tag should be deleted (otherwise added).
121
public boolean doesDeleteTag() {
126
* Returnes true if the tag should be deleted (otherwise added).
128
public boolean isDeleteTag() {
133
* Sets whether the tag should be deleted (true) or added (false).
135
public void setDeleteTag(boolean deleteTag) {
136
this.deleteTag = deleteTag;
140
* Returns true if the tag should be a branch tag.
143
public boolean doesMakeBranchTag() {
144
return makeBranchTag;
148
* Returns true if the tag should be a branch tag.
150
public boolean isMakeBranchTag() {
151
return makeBranchTag;
155
* Sets whether the tag should be a branch tag.
157
public void setMakeBranchTag(boolean makeBranchTag) {
158
this.makeBranchTag = makeBranchTag;
162
* Returns true to indicate that existing tag will be overridden.
165
public boolean doesOverrideExistingTag() {
166
return overrideExistingTag;
170
* Returns true to indicate that existing tag will be overridden.
172
public boolean isOverrideExistingTag() {
173
return overrideExistingTag;
177
* Sets whether existing tags should be overridden.
179
public void setOverrideExistingTag(boolean overrideExistingTag) {
180
this.overrideExistingTag = overrideExistingTag;
183
public boolean isMatchHeadIfRevisionNotFound() {
184
return matchHeadIfRevisionNotFound;
187
public void setMatchHeadIfRevisionNotFound(boolean matchHeadIfRevisionNotFound) {
188
this.matchHeadIfRevisionNotFound = matchHeadIfRevisionNotFound;
192
* Returns the tag that should be added or deleted.
194
public String getTag() {
199
* Sets the tag that should be added or deleted.
201
public void setTag(String tag) {
206
* Returns the latest date of a revision to be tagged.
207
* @return date value. the latest Revision not later ten date is tagged.
209
public String getTagByDate() {
214
* Sets the latest date of a revision to be tagged.
215
* @param tagDate New value of property tagDate.
217
public void setTagByDate(String tagDate) {
222
* Sets the latest date of a revision to be tagged. Can be both a number and a tag.
223
* @return Value of property tagRevision.
225
public String getTagByRevision() {
226
return tagByRevision;
230
* Sets the latest date of a revision to be tagged. Can be both a number and a tag.
231
* @param tagRevision New value of property tagRevision.
233
public void setTagByRevision(String tagRevision) {
234
tagByRevision = tagRevision;
238
* Execute the command.
240
* @param client the client services object that provides any necessary
241
* services to this command, including the ability to actually
242
* process all the requests.
244
public void execute(ClientServices client, EventManager eventManager)
245
throws CommandException, AuthenticationException {
246
client.ensureConnection();
248
this.eventManager = eventManager;
250
super.execute(client, eventManager);
253
requests.add(1, new ArgumentRequest(getTag()));
255
if (checkThatUnmodified) {
256
requests.add(1, new ArgumentRequest("-c")); //NOI18N
259
if (overrideExistingTag) {
260
requests.add(1, new ArgumentRequest("-F")); //NOI18N
263
if (matchHeadIfRevisionNotFound) {
264
requests.add(1, new ArgumentRequest("-f")); // NOI18N
268
requests.add(1, new ArgumentRequest("-b")); //NOI18N
272
requests.add(1, new ArgumentRequest("-d")); //NOI18N
274
if (tagByDate != null && tagByDate.length() > 0) {
275
requests.add(1, new ArgumentRequest("-D")); //NOI18N
276
requests.add(2, new ArgumentRequest(getTagByDate()));
278
if (tagByRevision != null && tagByRevision.length() > 0) {
279
requests.add(1, new ArgumentRequest("-r")); //NOI18N
280
requests.add(2, new ArgumentRequest(getTagByRevision()));
283
addRequestForWorkingDirectory(client);
284
addArgumentRequests();
285
addRequest(CommandRequest.TAG);
287
client.processRequests(requests);
289
catch (CommandException ex) {
292
catch (EOFException ex) {
293
throw new CommandException(ex, CommandException.getLocalMessage("CommandException.EndOfFile", null)); //NOI18N
295
catch (Exception ex) {
296
throw new CommandException(ex, ex.getLocalizedMessage());
304
* Called when server responses with "ok" or "error", (when the command
307
public void commandTerminated(TerminationEvent e) {
308
if (builder != null) {
309
builder.outputDone();
314
* This method returns how the tag command would looklike when typed on the
317
public String getCVSCommand() {
318
StringBuffer toReturn = new StringBuffer("tag "); //NOI18N
319
toReturn.append(getCVSArguments());
320
if (getTag() != null) {
321
toReturn.append(getTag());
322
toReturn.append(" "); //NOI18N
324
File[] files = getFiles();
326
for (int index = 0; index < files.length; index++) {
327
toReturn.append(files[index].getName());
328
toReturn.append(' ');
331
return toReturn.toString();
335
* Takes the arguments and sets the command.
336
* To be mainly used for automatic settings (like parsing the .cvsrc file)
337
* @return true if the option (switch) was recognized and set
339
public boolean setCVSCommand(char opt, String optArg) {
343
else if (opt == 'l') {
346
else if (opt == 'c') {
347
setCheckThatUnmodified(true);
349
else if (opt == 'd') {
352
else if (opt == 'F') {
353
setOverrideExistingTag(true);
355
else if (opt == 'f') {
356
setMatchHeadIfRevisionNotFound(true);
358
else if (opt == 'b') {
359
setMakeBranchTag(true);
361
else if (opt == 'D') {
362
setTagByDate(optArg.trim());
364
else if (opt == 'r') {
365
setTagByRevision(optArg.trim());
374
* String returned by this method defines which options are available for
377
public String getOptString() {
378
return "RlcFfbdD:r:"; //NOI18N
382
* Resets all switches in the command.
383
* After calling this method, the command should have no switches defined
384
* and should behave defaultly.
386
public void resetCVSCommand() {
388
setCheckThatUnmodified(false);
390
setMakeBranchTag(false);
391
setOverrideExistingTag(false);
392
setMatchHeadIfRevisionNotFound(false);
396
* Returns the arguments of the command in the command-line style.
397
* Similar to getCVSCommand() however without the files and command's name
399
public String getCVSArguments() {
400
StringBuffer toReturn = new StringBuffer();
401
if (!isRecursive()) {
402
toReturn.append("-l "); //NOI18N
404
if (isCheckThatUnmodified()) {
405
toReturn.append("-c "); //NOI18N
407
if (isOverrideExistingTag()) {
408
toReturn.append("-F "); //NOI18N
410
if (isMatchHeadIfRevisionNotFound()) {
411
toReturn.append("-f ");
413
if (isMakeBranchTag()) {
414
toReturn.append("-b "); //NOI18N
417
toReturn.append("-d "); //NOI18N
419
if (getTagByRevision() != null && getTagByRevision().length() > 0) {
420
toReturn.append("-r "); //NOI18N
421
toReturn.append(getTagByRevision());
422
toReturn.append(" "); //NOI18N
424
if (getTagByDate() != null && getTagByDate().length() > 0) {
425
toReturn.append("-D "); //NOI18N
426
toReturn.append(getTagByDate());
427
toReturn.append(" "); //NOI18N
429
return toReturn.toString();