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

« back to all changes in this revision

Viewing changes to javacvs/libsrc/org/netbeans/lib/cvsclient/command/status/StatusCommand.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 the CVS Client Library.
 
27
 * The Initial Developer of the Original Software is Robert Greig.
 
28
 * Portions created by Robert Greig are Copyright (C) 2000.
 
29
 * All Rights Reserved.
 
30
 *
 
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.
 
41
 
 
42
 * Contributor(s): Robert Greig.
 
43
 *****************************************************************************/
 
44
package org.netbeans.lib.cvsclient.command.status;
 
45
 
 
46
import java.io.*;
 
47
 
 
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.*;
 
53
 
 
54
/**
 
55
 * The status command looks up the status of files in the repository
 
56
 * @author  Robert Greig
 
57
 */
 
58
public class StatusCommand extends BasicCommand {
 
59
    /**
 
60
     * The event manager to use
 
61
     */
 
62
    private EventManager eventManager;
 
63
 
 
64
    /**
 
65
     * Holds value of property includeTags.
 
66
     */
 
67
    private boolean includeTags;
 
68
 
 
69
    /**
 
70
     * Construct a new status command
 
71
     */
 
72
    public StatusCommand() {
 
73
    }
 
74
 
 
75
    /**
 
76
     * Create a builder for this command.
 
77
     * @param eventMan the event manager used to receive events.
 
78
     */
 
79
    public Builder createBuilder(EventManager eventManager) {
 
80
        return new StatusBuilder(eventManager, this);
 
81
    }
 
82
 
 
83
    /**
 
84
     * Execute a command
 
85
     * @param client the client services object that provides any necessary
 
86
     * services to this command, including the ability to actually process
 
87
     * all the requests.
 
88
     */
 
89
    public void execute(ClientServices client, EventManager em)
 
90
            throws CommandException, AuthenticationException {
 
91
        client.ensureConnection();
 
92
 
 
93
        eventManager = em;
 
94
 
 
95
        super.execute(client, em);
 
96
 
 
97
        try {
 
98
            // parameters come now..
 
99
            if (includeTags) {
 
100
                requests.add(1, new ArgumentRequest("-v")); //NOI18N
 
101
            }
 
102
 
 
103
            addRequestForWorkingDirectory(client);
 
104
            addArgumentRequests();
 
105
            addRequest(CommandRequest.STATUS);
 
106
 
 
107
            client.processRequests(requests);
 
108
        }
 
109
        catch (CommandException ex) {
 
110
            throw ex;
 
111
        }
 
112
        catch (Exception e) {
 
113
            throw new CommandException(e, e.getLocalizedMessage());
 
114
        }
 
115
        finally {
 
116
            requests.clear();
 
117
        }
 
118
    }
 
119
 
 
120
    /**
 
121
     * Getter for property includeTags.
 
122
     * @return Value of property includeTags.
 
123
     */
 
124
    public boolean isIncludeTags() {
 
125
        return includeTags;
 
126
    }
 
127
 
 
128
    /**
 
129
     * Setter for property includeTags.
 
130
     * @param includeTags New value of property includeTags.
 
131
     */
 
132
    public void setIncludeTags(boolean inclTags) {
 
133
        includeTags = inclTags;
 
134
    }
 
135
 
 
136
    /**
 
137
     * called when server responses with "ok" or "error", (when the command finishes)
 
138
     */
 
139
    public void commandTerminated(TerminationEvent e) {
 
140
        if (builder != null) {
 
141
            builder.outputDone();
 
142
        }
 
143
    }
 
144
 
 
145
    /**
 
146
     * This method returns how the command would looklike when typed on the command line.
 
147
     * Each command is responsible for constructing this information.
 
148
     * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
 
149
     */
 
150
    public String getCVSCommand() {
 
151
        StringBuffer toReturn = new StringBuffer("status "); //NOI18N
 
152
        toReturn.append(getCVSArguments());
 
153
        File[] files = getFiles();
 
154
        if (files != null) {
 
155
            for (int index = 0; index < files.length; index++) {
 
156
                toReturn.append(files[index].getName());
 
157
                toReturn.append(' ');
 
158
            }
 
159
        }
 
160
        return toReturn.toString();
 
161
    }
 
162
 
 
163
    /**
 
164
     * takes the arguments and sets the command. To be mainly
 
165
     * used for automatic settings (like parsing the .cvsrc file)
 
166
     * @return true if the option (switch) was recognized and set
 
167
     */
 
168
    public boolean setCVSCommand(char opt, String optArg) {
 
169
        if (opt == 'R') {
 
170
            setRecursive(true);
 
171
        }
 
172
        else if (opt == 'l') {
 
173
            setRecursive(false);
 
174
        }
 
175
        else if (opt == 'v') {
 
176
            setIncludeTags(true);
 
177
        }
 
178
        else {
 
179
            return false;
 
180
        }
 
181
        return true;
 
182
    }
 
183
 
 
184
    /**
 
185
     * String returned by this method defines which options are available for this particular command
 
186
     */
 
187
    public String getOptString() {
 
188
        return "Rlv"; //NOI18N
 
189
    }
 
190
 
 
191
    /**
 
192
     * resets all switches in the command. After calling this method,
 
193
     * the command should have no switches defined and should behave defaultly.
 
194
     */
 
195
    public void resetCVSCommand() {
 
196
        setRecursive(true);
 
197
        setIncludeTags(false);
 
198
    }
 
199
 
 
200
    /**
 
201
     * Returns the arguments of the command in the command-line style.
 
202
     * Similar to getCVSCommand() however without the files and command's name
 
203
     */
 
204
    public String getCVSArguments() {
 
205
        StringBuffer toReturn = new StringBuffer(""); //NOI18N
 
206
        if (isIncludeTags()) {
 
207
            toReturn.append("-v "); //NOI18N
 
208
        }
 
209
        if (!isRecursive()) {
 
210
            toReturn.append("-l "); //NOI18N
 
211
        }
 
212
        return toReturn.toString();
 
213
    }
 
214
 
 
215
}