~ubuntu-branches/ubuntu/quantal/netbeans/quantal

« back to all changes in this revision

Viewing changes to javacvs/libsrc/org/netbeans/lib/cvsclient/command/log/LogCommand.java

  • Committer: Bazaar Package Importer
  • Author(s): Marek Slama
  • Date: 2008-01-29 14:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20080129141122-fnzjbo11ntghxfu7
Tags: upstream-6.0.1
ImportĀ upstreamĀ versionĀ 6.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 
3
 *
 
4
 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
 
5
 *
 
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]"
 
23
 *
 
24
 * Contributor(s):
 
25
 *
 
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.
 
29
 *
 
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.
 
40
 */
 
41
package org.netbeans.lib.cvsclient.command.log;
 
42
 
 
43
import java.io.*;
 
44
 
 
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.*;
 
50
 
 
51
/**
 
52
 * The log command looks up the log(history) of file(s) in the repository
 
53
 * @author  Milos Kleint
 
54
 */
 
55
public class LogCommand extends BasicCommand {
 
56
    /**
 
57
     * The event manager to use.
 
58
     */
 
59
    protected EventManager eventManager;
 
60
 
 
61
    /**
 
62
     * Holds value of property defaultBranch.
 
63
     */
 
64
    private boolean defaultBranch;
 
65
 
 
66
    /**
 
67
     * Holds value of property dateFilter.
 
68
     */
 
69
    private String dateFilter;
 
70
 
 
71
    /**
 
72
     * Holds value of property headerOnly.
 
73
     */
 
74
    private boolean headerOnly;
 
75
 
 
76
    /**
 
77
     * Holds value of property noTags.
 
78
     */
 
79
    private boolean noTags;
 
80
 
 
81
    /**
 
82
     * Holds value of property revisionFilter.
 
83
     */
 
84
    private String revisionFilter;
 
85
 
 
86
    /**
 
87
     * Holds value of property stateFilter.
 
88
     */
 
89
    private String stateFilter;
 
90
 
 
91
    /**
 
92
     * Holds value of property userFilter.
 
93
     */
 
94
    private String userFilter;
 
95
 
 
96
    /**
 
97
     * Holds value of property headerAndDescOnly.
 
98
     */
 
99
    private boolean headerAndDescOnly;
 
100
 
 
101
    /**
 
102
     * Construct a new status command
 
103
     */
 
104
    public LogCommand() {
 
105
        resetCVSCommand();
 
106
    }
 
107
 
 
108
    /**
 
109
     * Create a builder for this command.
 
110
     * @param eventMan the event manager used to receive events.
 
111
     */
 
112
    public Builder createBuilder(EventManager eventMan) {
 
113
        return new LogBuilder(eventMan, this);
 
114
    }
 
115
 
 
116
    /**
 
117
     * Execute a command
 
118
     * @param client the client services object that provides any necessary
 
119
     * services to this command, including the ability to actually process
 
120
     * all the requests.
 
121
     */
 
122
    public void execute(ClientServices client, EventManager em)
 
123
            throws CommandException, AuthenticationException {
 
124
        client.ensureConnection();
 
125
 
 
126
        eventManager = em;
 
127
 
 
128
        super.execute(client, em);
 
129
 
 
130
        try {
 
131
            // first send out all possible parameters..
 
132
            if (defaultBranch) {
 
133
                requests.add(1, new ArgumentRequest("-b")); //NOI18N
 
134
            }
 
135
            if (headerAndDescOnly) {
 
136
                requests.add(1, new ArgumentRequest("-t")); //NOI18N
 
137
            }
 
138
            if (headerOnly) {
 
139
                requests.add(1, new ArgumentRequest("-h")); //NOI18N
 
140
            }
 
141
            if (noTags) {
 
142
                requests.add(1, new ArgumentRequest("-N")); //NOI18N
 
143
            }
 
144
            if (userFilter != null) {
 
145
                requests.add(1, new ArgumentRequest("-w" + userFilter)); //NOI18N
 
146
            }
 
147
            if (revisionFilter != null) {
 
148
                requests.add(1, new ArgumentRequest("-r" + revisionFilter)); //NOI18N
 
149
            }
 
150
            if (stateFilter != null) {
 
151
                requests.add(1, new ArgumentRequest("-s" + stateFilter)); //NOI18N
 
152
            }
 
153
            if (dateFilter != null) {
 
154
                requests.add(1, new ArgumentRequest("-d" + dateFilter)); //NOI18N
 
155
            }
 
156
            addRequestForWorkingDirectory(client);
 
157
            addArgumentRequests();
 
158
            addRequest(CommandRequest.LOG);
 
159
 
 
160
            client.processRequests(requests);
 
161
        }
 
162
        catch (CommandException ex) {
 
163
            throw ex;
 
164
        }
 
165
        catch (Exception ex) {
 
166
            throw new CommandException(ex, ex.getLocalizedMessage());
 
167
        }
 
168
        finally {
 
169
            requests.clear();
 
170
            if (!isBuilderSet()) {
 
171
                builder = null;
 
172
            }
 
173
        }
 
174
    }
 
175
 
 
176
    /**
 
177
     * called when server responses with "ok" or "error", (when the command
 
178
     * finishes)
 
179
     */
 
180
    public void commandTerminated(TerminationEvent e) {
 
181
        if (builder != null) {
 
182
            builder.outputDone();
 
183
        }
 
184
    }
 
185
 
 
186
    /**
 
187
     * Getter for property defaultBranch, equals the command-line CVS switch
 
188
     * "-b".
 
189
     * @return Value of property defaultBranch.
 
190
     */
 
191
    public boolean isDefaultBranch() {
 
192
        return defaultBranch;
 
193
    }
 
194
 
 
195
    /**
 
196
     * Setter for property defaultBranch, equals the command-line CVS switch
 
197
     * "-b".
 
198
     * @param defaultBranch New value of property defaultBranch.
 
199
     */
 
200
    public void setDefaultBranch(boolean defaultBranch) {
 
201
        this.defaultBranch = defaultBranch;
 
202
    }
 
203
 
 
204
    /**
 
205
     * Getter for property dateFilter, equals the command-line CVS switch "-d".
 
206
     * @return Value of property dateFilter.
 
207
     */
 
208
    public String getDateFilter() {
 
209
        return dateFilter;
 
210
    }
 
211
 
 
212
    /** Setter for property dateFilter, equals the command-line CVS switch "-d".
 
213
     * @param dateFilter New value of property dateFilter.
 
214
     */
 
215
    public void setDateFilter(String dateFilter) {
 
216
        this.dateFilter = dateFilter;
 
217
    }
 
218
 
 
219
    /** Getter for property headerOnly, equals the command-line CVS switch "-h".
 
220
     * @return Value of property headerOnly.
 
221
     */
 
222
    public boolean isHeaderOnly() {
 
223
        return headerOnly;
 
224
    }
 
225
 
 
226
    /** Setter for property headerOnly, equals the command-line CVS switch "-h".
 
227
     * @param headerOnly New value of property headerOnly.
 
228
     */
 
229
    public void setHeaderOnly(boolean headerOnly) {
 
230
        this.headerOnly = headerOnly;
 
231
    }
 
232
 
 
233
    /** Getter for property noTags, equals the command-line CVS switch "-N".
 
234
     * @return Value of property noTags.
 
235
     */
 
236
    public boolean isNoTags() {
 
237
        return noTags;
 
238
    }
 
239
 
 
240
    /** Setter for property noTags, equals the command-line CVS switch "-N".
 
241
     * @param noTags New value of property noTags.
 
242
     */
 
243
    public void setNoTags(boolean noTags) {
 
244
        this.noTags = noTags;
 
245
    }
 
246
 
 
247
    /** Getter for property revisionFilter, equals the command-line CVS switch "-r".
 
248
     * @return Value of property revisionFilter.
 
249
     */
 
250
    public String getRevisionFilter() {
 
251
        return revisionFilter;
 
252
    }
 
253
 
 
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.
 
257
     */
 
258
    public void setRevisionFilter(String revisionFilter) {
 
259
        this.revisionFilter = revisionFilter;
 
260
    }
 
261
 
 
262
    /** Getter for property stateFilter, equals the command-line CVS switch "-s".
 
263
     * @return Value of property stateFilter.
 
264
     */
 
265
    public String getStateFilter() {
 
266
        return stateFilter;
 
267
    }
 
268
 
 
269
    /** Setter for property stateFilter, equals the command-line CVS switch "-s".
 
270
     * @param stateFilter New value of property stateFilter.
 
271
     */
 
272
    public void setStateFilter(String stateFilter) {
 
273
        this.stateFilter = stateFilter;
 
274
    }
 
275
 
 
276
    /** Getter for property userFilter, equals the command-line CVS switch "-w".
 
277
     * @return Value of property userFilter,  empty string means the current user.
 
278
     */
 
279
    public String getUserFilter() {
 
280
        return userFilter;
 
281
    }
 
282
 
 
283
    /** Setter for property userFilter, equals the command-line CVS switch "-w".
 
284
     * @param userFilter New value of property userFilter.
 
285
     */
 
286
    public void setUserFilter(String userFilter) {
 
287
        this.userFilter = userFilter;
 
288
    }
 
289
 
 
290
    /** Getter for property headerAndDescOnly, equals the command-line CVS switch "-t".
 
291
     * @return Value of property headerAndDescOnly.
 
292
     */
 
293
    public boolean isHeaderAndDescOnly() {
 
294
        return headerAndDescOnly;
 
295
    }
 
296
 
 
297
    /** Setter for property headerAndDescOnly, equals the command-line CVS switch "-t".
 
298
     * @param headerAndDescOnly New value of property headerAndDescOnly.
 
299
     */
 
300
    public void setHeaderAndDescOnly(boolean headerAndDescOnly) {
 
301
        this.headerAndDescOnly = headerAndDescOnly;
 
302
    }
 
303
 
 
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
 
307
     *
 
308
     */
 
309
    public String getCVSCommand() {
 
310
        StringBuffer toReturn = new StringBuffer("log "); //NOI18N
 
311
        toReturn.append(getCVSArguments());
 
312
        File[] files = getFiles();
 
313
        if (files != null) {
 
314
            for (int index = 0; index < files.length; index++) {
 
315
                toReturn.append(files[index].getName());
 
316
                toReturn.append(' ');
 
317
            }
 
318
        }
 
319
        return toReturn.toString();
 
320
    }
 
321
 
 
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
 
325
     */
 
326
    public boolean setCVSCommand(char opt, String optArg) {
 
327
        if (opt == 'R') {
 
328
            setRecursive(true);
 
329
        }
 
330
        else if (opt == 'l') {
 
331
            setRecursive(false);
 
332
        }
 
333
        else if (opt == 'b') {
 
334
            setDefaultBranch(true);
 
335
        }
 
336
        else if (opt == 'h') {
 
337
            setHeaderOnly(true);
 
338
        }
 
339
        else if (opt == 't') {
 
340
            setHeaderAndDescOnly(true);
 
341
        }
 
342
        else if (opt == 'N') {
 
343
            setNoTags(true);
 
344
        }
 
345
        else if (opt == 'd') {
 
346
            setDateFilter(optArg);
 
347
        }
 
348
        else if (opt == 'r') {
 
349
            setRevisionFilter(optArg == null ? "" : optArg); //NOI18N
 
350
            // for switches with optional args do that.. ^^^^
 
351
        }
 
352
        else if (opt == 's') {
 
353
            setStateFilter(optArg);
 
354
        }
 
355
        else if (opt == 'w') {
 
356
            setUserFilter(optArg == null ? "" : optArg); //NOI18N
 
357
        }
 
358
        else {
 
359
            return false;
 
360
        }
 
361
        return true;
 
362
    }
 
363
 
 
364
    public void resetCVSCommand() {
 
365
        setRecursive(true);
 
366
        setDefaultBranch(false);
 
367
        setHeaderOnly(false);
 
368
        setHeaderAndDescOnly(false);
 
369
        setNoTags(false);
 
370
        setDateFilter(null);
 
371
        setRevisionFilter(null);
 
372
        setStateFilter(null);
 
373
        setUserFilter(null);
 
374
    }
 
375
 
 
376
    /**
 
377
     * String returned by this method defines which options are available for this particular command
 
378
     */
 
379
    public String getOptString() {
 
380
        return "RlbhtNd:r:s:w:"; //NOI18N4
 
381
    }
 
382
 
 
383
    /**
 
384
     * Returns the arguments of the command in the command-line style.
 
385
     * Similar to getCVSCommand() however without the files and command's name
 
386
     */
 
387
    public String getCVSArguments() {
 
388
        StringBuffer toReturn = new StringBuffer(""); //NOI18N
 
389
        if (isDefaultBranch()) {
 
390
            toReturn.append("-b "); //NOI18N
 
391
        }
 
392
        if (isHeaderAndDescOnly()) {
 
393
            toReturn.append("-t "); //NOI18N
 
394
        }
 
395
        if (isHeaderOnly()) {
 
396
            toReturn.append("-h "); //NOI18N
 
397
        }
 
398
        if (isNoTags()) {
 
399
            toReturn.append("-N "); //NOI18N
 
400
        }
 
401
        if (!isRecursive()) {
 
402
            toReturn.append("-l "); //NOI18N
 
403
        }
 
404
        if (userFilter != null) {
 
405
            toReturn.append("-w"); //NOI18N
 
406
            toReturn.append(userFilter);
 
407
            toReturn.append(' ');
 
408
        }
 
409
        if (revisionFilter != null) {
 
410
            toReturn.append("-r"); //NOI18N
 
411
            toReturn.append(revisionFilter);
 
412
            toReturn.append(' ');
 
413
        }
 
414
        if (stateFilter != null) {
 
415
            toReturn.append("-s"); //NOI18N
 
416
            toReturn.append(stateFilter);
 
417
            toReturn.append(' ');
 
418
        }
 
419
        if (dateFilter != null) {
 
420
            toReturn.append("-d"); //NOI18N
 
421
            toReturn.append(dateFilter);
 
422
            toReturn.append(' ');
 
423
        }
 
424
        return toReturn.toString();
 
425
    }
 
426
 
 
427
}