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 NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.lib.cvsclient.command.annotate;
47
import org.netbeans.lib.cvsclient.*;
48
import org.netbeans.lib.cvsclient.command.*;
49
import org.netbeans.lib.cvsclient.connection.*;
50
import org.netbeans.lib.cvsclient.event.*;
51
import org.netbeans.lib.cvsclient.request.*;
54
* The annotate command shows all lines of the file and annotates each line with cvs-related info.
55
* @author Milos Kleint
57
public class AnnotateCommand extends BasicCommand {
59
* The event manager to use
61
protected EventManager eventManager;
64
* Use head revision if a revision meeting criteria set by switches -r/-D
65
* (tag/date) is not found.
67
private boolean useHeadIfNotFound;
70
* equals the -D switch of command line cvs.
72
private String annotateByDate;
75
* Equals the -r switch of command-line cvs.
77
private String annotateByRevision;
80
* Construct a new diff command
82
public AnnotateCommand() {
86
* Create a builder for this command.
87
* @param eventMan the event manager used to receive events.
89
public Builder createBuilder(EventManager eventMan) {
90
return new AnnotateBuilder(eventMan, this);
95
* @param client the client services object that provides any necessary
96
* services to this command, including the ability to actually process
99
public void execute(ClientServices client, EventManager em)
100
throws CommandException, AuthenticationException {
103
client.ensureConnection();
105
super.execute(client, em);
107
excludeBinaryFiles(requests);
110
if (useHeadIfNotFound) {
111
requests.add(1, new ArgumentRequest("-f")); //NOI18N
113
if (annotateByDate != null && annotateByDate.length() > 0) {
114
requests.add(1, new ArgumentRequest("-D")); //NOI18N
115
requests.add(2, new ArgumentRequest(getAnnotateByDate()));
117
if (annotateByRevision != null && annotateByRevision.length() > 0) {
118
requests.add(1, new ArgumentRequest("-r")); //NOI18N
119
requests.add(2, new ArgumentRequest(getAnnotateByRevision()));
121
addRequestForWorkingDirectory(client);
122
addArgumentRequests();
123
addRequest(CommandRequest.ANNOTATE);
124
client.processRequests(requests);
126
catch (CommandException ex) {
129
catch (Exception ex) {
130
throw new CommandException(ex, ex.getLocalizedMessage());
137
private void excludeBinaryFiles(java.util.List requests) {
138
Iterator it = requests.iterator();
139
while (it.hasNext()) {
140
Object obj = it.next();
141
if (obj instanceof EntryRequest) {
142
EntryRequest req = (EntryRequest)obj;
143
if (req.getEntry().isBinary()) {
146
// removes also the follwoing modified/unchanged request
155
/** called when server responses with "ok" or "error", (when the command finishes)
157
public void commandTerminated(TerminationEvent e) {
158
if (builder != null) {
159
builder.outputDone();
164
* Getter for property useHeadIfNotFound.
165
* @return Value of property useHeadIfNotFound.
167
public boolean isUseHeadIfNotFound() {
168
return useHeadIfNotFound;
172
* Setter for property useHeadIfNotFound.
173
* @param useHeadIfNotFound New value of property useHeadIfNotFound.
175
public void setUseHeadIfNotFound(boolean useHeadIfNotFound) {
176
this.useHeadIfNotFound = useHeadIfNotFound;
180
* Getter for property annotateByDate.
181
* @return Value of property annotateByDate.
183
public String getAnnotateByDate() {
184
return annotateByDate;
188
* Setter for property annotateByDate.
189
* @param annotateByDate New value of property annotateByDate.
191
public void setAnnotateByDate(String annotateByDate) {
192
this.annotateByDate = annotateByDate;
196
* Getter for property annotateByRevision.
197
* @return Value of property annotateByRevision.
199
public String getAnnotateByRevision() {
200
return annotateByRevision;
204
* Setter for property annotateByRevision.
205
* @param annotateByRevision New value of property annotateByRevision.
207
public void setAnnotateByRevision(String annotateByRevision) {
208
this.annotateByRevision = annotateByRevision;
212
* This method returns how the command would looklike when typed on the command line.
213
* Each command is responsible for constructing this information.
214
* @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
216
public String getCVSCommand() {
217
StringBuffer toReturn = new StringBuffer("annotate "); //NOI18N
218
toReturn.append(getCVSArguments());
219
File[] files = getFiles();
221
for (int index = 0; index < files.length; index++) {
222
toReturn.append(files[index].getName() + " "); //NOI18N
225
return toReturn.toString();
228
/** takes the arguments and sets the command. To be mainly
229
* used for automatic settings (like parsing the .cvsrc file)
230
* @return true if the option (switch) was recognized and set
232
public boolean setCVSCommand(char opt, String optArg) {
236
else if (opt == 'l') {
239
else if (opt == 'r') {
240
setAnnotateByRevision(optArg);
242
else if (opt == 'D') {
243
setAnnotateByDate(optArg);
245
else if (opt == 'f') {
246
setUseHeadIfNotFound(true);
255
* String returned by this method defines which options are available for this particular command
257
public String getOptString() {
258
return "Rlr:D:f"; //NOI18N
262
* resets all switches in the command. After calling this method,
263
* the command should have no switches defined and should behave defaultly.
265
public void resetCVSCommand() {
267
setAnnotateByDate(null);
268
setAnnotateByRevision(null);
269
setUseHeadIfNotFound(false);
273
* Returns the arguments of the command in the command-line style.
274
* Similar to getCVSCommand() however without the files and command's name
276
public String getCVSArguments() {
277
StringBuffer toReturn = new StringBuffer(""); //NOI18N
278
if (!isRecursive()) {
279
toReturn.append("-l "); //NOI18N
281
if (getAnnotateByRevision() != null) {
282
toReturn.append("-r "); //NOI18N
283
toReturn.append(getAnnotateByRevision());
284
toReturn.append(" "); //NOI18N
286
if (getAnnotateByDate() != null) {
287
toReturn.append("-D "); //NOI18N
288
toReturn.append(getAnnotateByDate());
289
toReturn.append(" "); //NOI18N
291
if (isUseHeadIfNotFound()) {
292
toReturn.append("-f "); //NOI18N
294
return toReturn.toString();