Adding Git source, NetBeans project files, GPL v2 LICENSE, ant build file.
[nbgit.git] / src / org / netbeans / modules / git / FileInformation.java
blob9fe6381949749a094925f3468cdf509d97e623d9
1 /*
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]"
24 * Contributor(s):
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 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
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.
42 package org.netbeans.modules.git;
44 import java.io.File;
45 import java.io.Serializable;
46 import java.util.ResourceBundle;
47 import org.openide.util.NbBundle;
49 /**
50 * Immutable class encapsulating status of a file.
52 * @author Maros Sandor
54 public class FileInformation implements Serializable {
56 private static final long serialVersionUID = 1L;
58 /**
59 * There is nothing known about the file, it may not even exist.
60 */
61 public static final int STATUS_UNKNOWN = 0;
63 /**
64 * The file is not managed by the module, i.e. the user does not wish it to be under control of this
65 * versioning system module. All files except files under versioned roots have this status.
66 */
67 public static final int STATUS_NOTVERSIONED_NOTMANAGED = 1;
69 /**
70 * The file exists locally but is NOT under version control because it should not be (i.e. is has
71 * the Ignore property set or resides under an excluded folder). The file itself IS under a versioned root.
72 */
73 public static final int STATUS_NOTVERSIONED_EXCLUDED = 2;
75 /**
76 * The file exists locally but is NOT under version control, mostly because it has not been added
77 * to the repository yet.
78 */
79 public static final int STATUS_NOTVERSIONED_NEWLOCALLY = 4;
81 /**
82 * The file is under version control and is in sync with repository.
83 */
84 public static final int STATUS_VERSIONED_UPTODATE = 8;
86 /**
87 * The file is modified locally and was not yet modified in repository.
88 */
89 public static final int STATUS_VERSIONED_MODIFIEDLOCALLY = 16;
91 /**
92 * The file was not modified locally but an updated version exists in repository.
93 */
94 public static final int STATUS_VERSIONED_MODIFIEDINREPOSITORY = 32;
96 /**
97 * Merging during update resulted in merge conflict. Conflicts in the local copy must be resolved before
98 * the file can be commited.
99 */
100 public static final int STATUS_VERSIONED_CONFLICT = 64;
103 * The file was modified both locally and remotely and these changes may or may not result in
104 * merge conflict.
106 public static final int STATUS_VERSIONED_MERGE = 128;
109 * The file does NOT exist locally and exists in repository, it has beed removed locally, waits
110 * for commit.
112 public static final int STATUS_VERSIONED_REMOVEDLOCALLY = 256;
115 * The file does NOT exist locally but exists in repository and has not yet been downloaded.
117 public static final int STATUS_VERSIONED_NEWINREPOSITORY = 512;
120 * The file has been removed from repository.
122 public static final int STATUS_VERSIONED_REMOVEDINREPOSITORY = 1024;
125 * The file does NOT exist locally and exists in repository, it has beed removed locally.
127 public static final int STATUS_VERSIONED_DELETEDLOCALLY = 2048;
130 * The file exists locally and has beed scheduled for addition to repository. This status represents
131 * state after the 'add' command.
133 public static final int STATUS_VERSIONED_ADDEDLOCALLY = 4096;
135 public static final int STATUS_ALL = ~0;
138 * All statuses except <tt>STATUS_NOTVERSIONED_NOTMANAGED</tt>
140 * <p>Note: it covers ignored files.
142 public static final int STATUS_MANAGED = FileInformation.STATUS_ALL & ~FileInformation.STATUS_NOTVERSIONED_NOTMANAGED;
145 public static final int STATUS_VERSIONED = FileInformation.STATUS_VERSIONED_UPTODATE |
146 FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY |
147 FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY |
148 FileInformation.STATUS_VERSIONED_CONFLICT |
149 FileInformation.STATUS_VERSIONED_MERGE |
150 FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
151 FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY |
152 FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
153 FileInformation.STATUS_VERSIONED_ADDEDLOCALLY;
155 public static final int STATUS_IN_REPOSITORY = FileInformation.STATUS_VERSIONED_UPTODATE |
156 FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY |
157 FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY |
158 FileInformation.STATUS_VERSIONED_CONFLICT |
159 FileInformation.STATUS_VERSIONED_MERGE |
160 FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
161 FileInformation.STATUS_VERSIONED_NEWINREPOSITORY |
162 FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY |
163 FileInformation.STATUS_VERSIONED_DELETEDLOCALLY;
165 public static final int STATUS_LOCAL_CHANGE =
166 FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY |
167 FileInformation.STATUS_VERSIONED_ADDEDLOCALLY |
168 FileInformation.STATUS_VERSIONED_CONFLICT |
169 FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
170 FileInformation.STATUS_VERSIONED_MERGE |
171 FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
172 FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY;
175 * Modified, in conflict, scheduled for removal or addition;
176 * or deleted but with existing entry record.
178 public static final int STATUS_REVERTIBLE_CHANGE =
179 FileInformation.STATUS_VERSIONED_ADDEDLOCALLY |
180 FileInformation.STATUS_VERSIONED_CONFLICT |
181 FileInformation.STATUS_VERSIONED_MERGE |
182 FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
183 FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
184 FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY;
187 public static final int STATUS_REMOTE_CHANGE =
188 FileInformation.STATUS_VERSIONED_MERGE |
189 FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY |
190 FileInformation.STATUS_VERSIONED_NEWINREPOSITORY |
191 FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY;
195 * Status constant.
197 private final int status;
200 * More detailed information about a file, you may disregard the field if not needed.
202 private transient FileStatus entry;
205 * Directory indicator, mainly because of files that may have been deleted so file.isDirectory() won't work.
207 private final boolean isDirectory;
210 * For deserialization purposes only.
212 public FileInformation() {
213 status = 0;
214 isDirectory = false;
217 public FileInformation(int status, FileStatus entry, boolean isDirectory) {
218 this.status = status;
219 this.entry = entry;
220 this.isDirectory = isDirectory;
223 FileInformation(int status, boolean isDirectory) {
224 this(status, null, isDirectory);
228 * Retrieves the status constant representing status of the file.
230 * @return one of status constants
232 public int getStatus() {
233 return status;
236 public boolean isDirectory() {
237 return isDirectory;
241 * Retrieves file's Status.
243 * @param file file this information belongs to or null if you do not want the entry to be read from disk
244 * in case it is not loaded yet
245 * @return Status parsed entry form the .svn/entries file or null if the file does not exist,
246 * is not versioned or its entry is invalid
248 public FileStatus getStatus(File file) {
249 if (entry == null && file != null) {
250 readEntry(file);
252 return entry;
255 private void readEntry(File file) {
256 // Fetches File info from .svn directory:
257 // entry = Subversion.getInstance().getClient(true).getSingleStatus(file);
258 entry = null; // TODO: read your detailed information about the file here, or disregard the entry field
262 * Returns localized text representation of status.
264 * @return status name, for multistatuses prefers local
265 * status name.
267 public String getStatusText() {
268 return getStatusText(~0);
272 * Returns localized text representation of status.
274 * @param displayStatuses statuses bitmask
276 * @return status name, for multistatuses prefers local
277 * status name, for masked <tt>""</tt>. // NOI18N
279 public String getStatusText(int displayStatuses) {
280 int status = this.status & displayStatuses;
281 ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
282 if (status == FileInformation.STATUS_UNKNOWN) {
283 return loc.getString("CTL_FileInfoStatus_Unknown"); // NOI18N
284 } else if (FileInformation.match(status, FileInformation.STATUS_NOTVERSIONED_EXCLUDED)) {
285 return loc.getString("CTL_FileInfoStatus_Excluded"); // NOI18N
286 } else if (FileInformation.match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY)) {
287 return loc.getString("CTL_FileInfoStatus_NewLocally"); // NOI18N
288 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
289 if (entry != null && entry.isCopied()) {
290 return loc.getString("CTL_FileInfoStatus_AddedLocallyCopied"); // NOI18N
292 return loc.getString("CTL_FileInfoStatus_AddedLocally"); // NOI18N
293 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_UPTODATE)) {
294 return loc.getString("CTL_FileInfoStatus_UpToDate"); // NOI18N
295 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) {
296 return loc.getString("CTL_FileInfoStatus_Conflict"); // NOI18N
297 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_MERGE)) {
298 return loc.getString("CTL_FileInfoStatus_Merge"); // NOI18N
299 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_DELETEDLOCALLY)) {
300 return loc.getString("CTL_FileInfoStatus_DeletedLocally"); // NOI18N
301 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY)) {
302 return loc.getString("CTL_FileInfoStatus_RemovedLocally"); // NOI18N
303 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY)) {
304 return loc.getString("CTL_FileInfoStatus_ModifiedLocally"); // NOI18N
306 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
307 return loc.getString("CTL_FileInfoStatus_NewInRepository"); // NOI18N
308 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY)) {
309 return loc.getString("CTL_FileInfoStatus_ModifiedInRepository"); // NOI18N
310 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY)) {
311 return loc.getString("CTL_FileInfoStatus_RemovedInRepository"); // NOI18N
312 } else {
313 return ""; // NOI18N
318 * @return short status name for local changes, for remote
319 * changes returns <tt>""</tt> // NOI18N
321 public String getShortStatusText() {
322 ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
323 if (FileInformation.match(status, FileInformation.STATUS_NOTVERSIONED_EXCLUDED)) {
324 return loc.getString("CTL_FileInfoStatus_Excluded_Short"); // NOI18N
325 } else if (FileInformation.match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY)) {
326 return loc.getString("CTL_FileInfoStatus_NewLocally_Short"); // NOI18N
327 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
328 if (entry != null && entry.isCopied()) {
329 return loc.getString("CTL_FileInfoStatus_AddedLocallyCopied_Short"); // NOI18N
331 return loc.getString("CTL_FileInfoStatus_AddedLocally_Short"); // NOI18N
332 } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
333 return loc.getString("CTL_FileInfoStatus_RemovedLocally_Short"); // NOI18N
334 } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY) {
335 return loc.getString("CTL_FileInfoStatus_DeletedLocally_Short"); // NOI18N
336 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY)) {
337 return loc.getString("CTL_FileInfoStatus_ModifiedLocally_Short"); // NOI18N
338 } else if (FileInformation.match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) {
339 return loc.getString("CTL_FileInfoStatus_Conflict_Short"); // NOI18N
340 } else {
341 return ""; // NOI18N
345 private static boolean match(int status, int mask) {
346 return (status & mask) != 0;
349 @Override
350 public String toString() {
351 return "Text: " + status + " " + getStatusText(status); // NOI18N