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.
41
package org.netbeans.lib.cvsclient.command.log;
45
import org.netbeans.lib.cvsclient.*;
46
import org.netbeans.lib.cvsclient.command.*;
47
import org.netbeans.lib.cvsclient.connection.*;
48
import org.netbeans.lib.cvsclient.event.*;
49
import org.netbeans.lib.cvsclient.request.*;
52
* The log command looks up the log(history) of file(s) in the repository
53
* @author Milos Kleint
55
public class LogCommand extends BasicCommand {
57
* The event manager to use.
59
protected EventManager eventManager;
62
* Holds value of property defaultBranch.
64
private boolean defaultBranch;
67
* Holds value of property dateFilter.
69
private String dateFilter;
72
* Holds value of property headerOnly.
74
private boolean headerOnly;
77
* Holds value of property noTags.
79
private boolean noTags;
82
* Holds value of property revisionFilter.
84
private String revisionFilter;
87
* Holds value of property stateFilter.
89
private String stateFilter;
92
* Holds value of property userFilter.
94
private String userFilter;
97
* Holds value of property headerAndDescOnly.
99
private boolean headerAndDescOnly;
102
* Construct a new status command
104
public LogCommand() {
109
* Create a builder for this command.
110
* @param eventMan the event manager used to receive events.
112
public Builder createBuilder(EventManager eventMan) {
113
return new LogBuilder(eventMan, this);
118
* @param client the client services object that provides any necessary
119
* services to this command, including the ability to actually process
122
public void execute(ClientServices client, EventManager em)
123
throws CommandException, AuthenticationException {
124
client.ensureConnection();
128
super.execute(client, em);
131
// first send out all possible parameters..
133
requests.add(1, new ArgumentRequest("-b")); //NOI18N
135
if (headerAndDescOnly) {
136
requests.add(1, new ArgumentRequest("-t")); //NOI18N
139
requests.add(1, new ArgumentRequest("-h")); //NOI18N
142
requests.add(1, new ArgumentRequest("-N")); //NOI18N
144
if (userFilter != null) {
145
requests.add(1, new ArgumentRequest("-w" + userFilter)); //NOI18N
147
if (revisionFilter != null) {
148
requests.add(1, new ArgumentRequest("-r" + revisionFilter)); //NOI18N
150
if (stateFilter != null) {
151
requests.add(1, new ArgumentRequest("-s" + stateFilter)); //NOI18N
153
if (dateFilter != null) {
154
requests.add(1, new ArgumentRequest("-d" + dateFilter)); //NOI18N
156
addRequestForWorkingDirectory(client);
157
addArgumentRequests();
158
addRequest(CommandRequest.LOG);
160
client.processRequests(requests);
162
catch (CommandException ex) {
165
catch (Exception ex) {
166
throw new CommandException(ex, ex.getLocalizedMessage());
170
if (!isBuilderSet()) {
177
* called when server responses with "ok" or "error", (when the command
180
public void commandTerminated(TerminationEvent e) {
181
if (builder != null) {
182
builder.outputDone();
187
* Getter for property defaultBranch, equals the command-line CVS switch
189
* @return Value of property defaultBranch.
191
public boolean isDefaultBranch() {
192
return defaultBranch;
196
* Setter for property defaultBranch, equals the command-line CVS switch
198
* @param defaultBranch New value of property defaultBranch.
200
public void setDefaultBranch(boolean defaultBranch) {
201
this.defaultBranch = defaultBranch;
205
* Getter for property dateFilter, equals the command-line CVS switch "-d".
206
* @return Value of property dateFilter.
208
public String getDateFilter() {
212
/** Setter for property dateFilter, equals the command-line CVS switch "-d".
213
* @param dateFilter New value of property dateFilter.
215
public void setDateFilter(String dateFilter) {
216
this.dateFilter = dateFilter;
219
/** Getter for property headerOnly, equals the command-line CVS switch "-h".
220
* @return Value of property headerOnly.
222
public boolean isHeaderOnly() {
226
/** Setter for property headerOnly, equals the command-line CVS switch "-h".
227
* @param headerOnly New value of property headerOnly.
229
public void setHeaderOnly(boolean headerOnly) {
230
this.headerOnly = headerOnly;
233
/** Getter for property noTags, equals the command-line CVS switch "-N".
234
* @return Value of property noTags.
236
public boolean isNoTags() {
240
/** Setter for property noTags, equals the command-line CVS switch "-N".
241
* @param noTags New value of property noTags.
243
public void setNoTags(boolean noTags) {
244
this.noTags = noTags;
247
/** Getter for property revisionFilter, equals the command-line CVS switch "-r".
248
* @return Value of property revisionFilter.
250
public String getRevisionFilter() {
251
return revisionFilter;
254
/** Setter for property revisionFilter, equals the command-line CVS switch "-r".
255
* @param revisionFilter New value of property revisionFilter.
256
empty string means latest revision of default branch.
258
public void setRevisionFilter(String revisionFilter) {
259
this.revisionFilter = revisionFilter;
262
/** Getter for property stateFilter, equals the command-line CVS switch "-s".
263
* @return Value of property stateFilter.
265
public String getStateFilter() {
269
/** Setter for property stateFilter, equals the command-line CVS switch "-s".
270
* @param stateFilter New value of property stateFilter.
272
public void setStateFilter(String stateFilter) {
273
this.stateFilter = stateFilter;
276
/** Getter for property userFilter, equals the command-line CVS switch "-w".
277
* @return Value of property userFilter, empty string means the current user.
279
public String getUserFilter() {
283
/** Setter for property userFilter, equals the command-line CVS switch "-w".
284
* @param userFilter New value of property userFilter.
286
public void setUserFilter(String userFilter) {
287
this.userFilter = userFilter;
290
/** Getter for property headerAndDescOnly, equals the command-line CVS switch "-t".
291
* @return Value of property headerAndDescOnly.
293
public boolean isHeaderAndDescOnly() {
294
return headerAndDescOnly;
297
/** Setter for property headerAndDescOnly, equals the command-line CVS switch "-t".
298
* @param headerAndDescOnly New value of property headerAndDescOnly.
300
public void setHeaderAndDescOnly(boolean headerAndDescOnly) {
301
this.headerAndDescOnly = headerAndDescOnly;
304
/** This method returns how the command would looklike when typed on the command line.
305
* Each command is responsible for constructing this information.
306
* @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
309
public String getCVSCommand() {
310
StringBuffer toReturn = new StringBuffer("log "); //NOI18N
311
toReturn.append(getCVSArguments());
312
File[] files = getFiles();
314
for (int index = 0; index < files.length; index++) {
315
toReturn.append(files[index].getName());
316
toReturn.append(' ');
319
return toReturn.toString();
322
/** takes the arguments and sets the command. To be mainly
323
* used for automatic settings (like parsing the .cvsrc file)
324
* @return true if the option (switch) was recognized and set
326
public boolean setCVSCommand(char opt, String optArg) {
330
else if (opt == 'l') {
333
else if (opt == 'b') {
334
setDefaultBranch(true);
336
else if (opt == 'h') {
339
else if (opt == 't') {
340
setHeaderAndDescOnly(true);
342
else if (opt == 'N') {
345
else if (opt == 'd') {
346
setDateFilter(optArg);
348
else if (opt == 'r') {
349
setRevisionFilter(optArg == null ? "" : optArg); //NOI18N
350
// for switches with optional args do that.. ^^^^
352
else if (opt == 's') {
353
setStateFilter(optArg);
355
else if (opt == 'w') {
356
setUserFilter(optArg == null ? "" : optArg); //NOI18N
364
public void resetCVSCommand() {
366
setDefaultBranch(false);
367
setHeaderOnly(false);
368
setHeaderAndDescOnly(false);
371
setRevisionFilter(null);
372
setStateFilter(null);
377
* String returned by this method defines which options are available for this particular command
379
public String getOptString() {
380
return "RlbhtNd:r:s:w:"; //NOI18N4
384
* Returns the arguments of the command in the command-line style.
385
* Similar to getCVSCommand() however without the files and command's name
387
public String getCVSArguments() {
388
StringBuffer toReturn = new StringBuffer(""); //NOI18N
389
if (isDefaultBranch()) {
390
toReturn.append("-b "); //NOI18N
392
if (isHeaderAndDescOnly()) {
393
toReturn.append("-t "); //NOI18N
395
if (isHeaderOnly()) {
396
toReturn.append("-h "); //NOI18N
399
toReturn.append("-N "); //NOI18N
401
if (!isRecursive()) {
402
toReturn.append("-l "); //NOI18N
404
if (userFilter != null) {
405
toReturn.append("-w"); //NOI18N
406
toReturn.append(userFilter);
407
toReturn.append(' ');
409
if (revisionFilter != null) {
410
toReturn.append("-r"); //NOI18N
411
toReturn.append(revisionFilter);
412
toReturn.append(' ');
414
if (stateFilter != null) {
415
toReturn.append("-s"); //NOI18N
416
toReturn.append(stateFilter);
417
toReturn.append(' ');
419
if (dateFilter != null) {
420
toReturn.append("-d"); //NOI18N
421
toReturn.append(dateFilter);
422
toReturn.append(' ');
424
return toReturn.toString();