001: /*****************************************************************************
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025:
026: * The Original Software is the CVS Client Library.
027: * The Initial Developer of the Original Software is Robert Greig.
028: * Portions created by Robert Greig are Copyright (C) 2000.
029: * All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041:
042: * Contributor(s): Robert Greig.
043: *****************************************************************************/package org.netbeans.lib.cvsclient.command.status;
044:
045: import java.io.*;
046:
047: import org.netbeans.lib.cvsclient.*;
048: import org.netbeans.lib.cvsclient.command.*;
049: import org.netbeans.lib.cvsclient.connection.*;
050: import org.netbeans.lib.cvsclient.event.*;
051: import org.netbeans.lib.cvsclient.request.*;
052:
053: /**
054: * The status command looks up the status of files in the repository
055: * @author Robert Greig
056: */
057: public class StatusCommand extends BasicCommand {
058: /**
059: * The event manager to use
060: */
061: private EventManager eventManager;
062:
063: /**
064: * Holds value of property includeTags.
065: */
066: private boolean includeTags;
067:
068: /**
069: * Construct a new status command
070: */
071: public StatusCommand() {
072: }
073:
074: /**
075: * Create a builder for this command.
076: * @param eventMan the event manager used to receive events.
077: */
078: public Builder createBuilder(EventManager eventManager) {
079: return new StatusBuilder(eventManager, this );
080: }
081:
082: /**
083: * Execute a command
084: * @param client the client services object that provides any necessary
085: * services to this command, including the ability to actually process
086: * all the requests.
087: */
088: public void execute(ClientServices client, EventManager em)
089: throws CommandException, AuthenticationException {
090: client.ensureConnection();
091:
092: eventManager = em;
093:
094: super .execute(client, em);
095:
096: try {
097: // parameters come now..
098: if (includeTags) {
099: requests.add(1, new ArgumentRequest("-v")); //NOI18N
100: }
101:
102: addRequestForWorkingDirectory(client);
103: addArgumentRequests();
104: addRequest(CommandRequest.STATUS);
105:
106: client.processRequests(requests);
107: } catch (CommandException ex) {
108: throw ex;
109: } catch (Exception e) {
110: throw new CommandException(e, e.getLocalizedMessage());
111: } finally {
112: requests.clear();
113: }
114: }
115:
116: /**
117: * Getter for property includeTags.
118: * @return Value of property includeTags.
119: */
120: public boolean isIncludeTags() {
121: return includeTags;
122: }
123:
124: /**
125: * Setter for property includeTags.
126: * @param includeTags New value of property includeTags.
127: */
128: public void setIncludeTags(boolean inclTags) {
129: includeTags = inclTags;
130: }
131:
132: /**
133: * called when server responses with "ok" or "error", (when the command finishes)
134: */
135: public void commandTerminated(TerminationEvent e) {
136: if (builder != null) {
137: builder.outputDone();
138: }
139: }
140:
141: /**
142: * This method returns how the command would looklike when typed on the command line.
143: * Each command is responsible for constructing this information.
144: * @returns <command's name> [<parameters>] files/dirs. Example: checkout -p CvsCommand.java
145: */
146: public String getCVSCommand() {
147: StringBuffer toReturn = new StringBuffer("status "); //NOI18N
148: toReturn.append(getCVSArguments());
149: File[] files = getFiles();
150: if (files != null) {
151: for (int index = 0; index < files.length; index++) {
152: toReturn.append(files[index].getName());
153: toReturn.append(' ');
154: }
155: }
156: return toReturn.toString();
157: }
158:
159: /**
160: * takes the arguments and sets the command. To be mainly
161: * used for automatic settings (like parsing the .cvsrc file)
162: * @return true if the option (switch) was recognized and set
163: */
164: public boolean setCVSCommand(char opt, String optArg) {
165: if (opt == 'R') {
166: setRecursive(true);
167: } else if (opt == 'l') {
168: setRecursive(false);
169: } else if (opt == 'v') {
170: setIncludeTags(true);
171: } else {
172: return false;
173: }
174: return true;
175: }
176:
177: /**
178: * String returned by this method defines which options are available for this particular command
179: */
180: public String getOptString() {
181: return "Rlv"; //NOI18N
182: }
183:
184: /**
185: * resets all switches in the command. After calling this method,
186: * the command should have no switches defined and should behave defaultly.
187: */
188: public void resetCVSCommand() {
189: setRecursive(true);
190: setIncludeTags(false);
191: }
192:
193: /**
194: * Returns the arguments of the command in the command-line style.
195: * Similar to getCVSCommand() however without the files and command's name
196: */
197: public String getCVSArguments() {
198: StringBuffer toReturn = new StringBuffer(""); //NOI18N
199: if (isIncludeTags()) {
200: toReturn.append("-v "); //NOI18N
201: }
202: if (!isRecursive()) {
203: toReturn.append("-l "); //NOI18N
204: }
205: return toReturn.toString();
206: }
207:
208: }
|