KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > FileInformation


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.subversion;
21
22 import org.openide.util.NbBundle;
23
24 import java.util.*;
25 import java.io.Serializable JavaDoc;
26 import java.io.File JavaDoc;
27 import org.tigris.subversion.svnclientadapter.ISVNStatus;
28 import org.tigris.subversion.svnclientadapter.SVNClientException;
29 import org.tigris.subversion.svnclientadapter.SVNNodeKind;
30
31 /**
32  * Immutable class encapsulating status of a file.
33  *
34  * @author Maros Sandor
35  */

36 public class FileInformation implements Serializable JavaDoc {
37
38     private static final long serialVersionUID = 1L;
39
40     /**
41      * There is nothing known about the file, it may not even exist.
42      */

43     public static final int STATUS_UNKNOWN = 0;
44
45     /**
46      * The file is not managed by the module, i.e. the user does not wish it to be under control of this
47      * versioning system module. All files except files under versioned roots have this status.
48      */

49     public static final int STATUS_NOTVERSIONED_NOTMANAGED = 1;
50     
51     /**
52      * The file exists locally but is NOT under version control because it should not be (i.e. is has
53      * the Ignore property set or resides under an excluded folder). The file itself IS under a versioned root.
54      */

55     public static final int STATUS_NOTVERSIONED_EXCLUDED = 2;
56
57     /**
58      * The file exists locally but is NOT under version control, mostly because it has not been added
59      * to the repository yet.
60      */

61     public static final int STATUS_NOTVERSIONED_NEWLOCALLY = 4;
62         
63     /**
64      * The file is under version control and is in sync with repository.
65      */

66     public static final int STATUS_VERSIONED_UPTODATE = 8;
67     
68     /**
69      * The file is modified locally and was not yet modified in repository.
70      */

71     public static final int STATUS_VERSIONED_MODIFIEDLOCALLY = 16;
72     
73     /**
74      * The file was not modified locally but an updated version exists in repository.
75      */

76     public static final int STATUS_VERSIONED_MODIFIEDINREPOSITORY = 32;
77     
78     /**
79      * Merging during update resulted in merge conflict. Conflicts in the local copy must be resolved before
80      * the file can be commited.
81      */

82     public static final int STATUS_VERSIONED_CONFLICT = 64;
83
84     /**
85      * The file was modified both locally and remotely and these changes may or may not result in
86      * merge conflict.
87      */

88     public static final int STATUS_VERSIONED_MERGE = 128;
89     
90     /**
91      * The file does NOT exist locally and exists in repository, it has beed removed locally, waits
92      * for commit.
93      */

94     public static final int STATUS_VERSIONED_REMOVEDLOCALLY = 256;
95     
96     /**
97      * The file does NOT exist locally but exists in repository and has not yet been downloaded.
98      */

99     public static final int STATUS_VERSIONED_NEWINREPOSITORY = 512;
100
101     /**
102      * The file has been removed from repository.
103      */

104     public static final int STATUS_VERSIONED_REMOVEDINREPOSITORY = 1024;
105
106     /**
107      * The file does NOT exist locally and exists in repository, it has beed removed locally.
108      */

109     public static final int STATUS_VERSIONED_DELETEDLOCALLY = 2048;
110     
111     /**
112      * The file exists locally and has beed scheduled for addition to repository. This status represents
113      * state after the 'add' command.
114      */

115     public static final int STATUS_VERSIONED_ADDEDLOCALLY = 4096;
116
117     public static final int STATUS_ALL = ~0;
118
119     /**
120      * All statuses except <tt>STATUS_NOTVERSIONED_NOTMANAGED</tt>
121      *
122      * <p>Note: it covers ignored files.
123      */

124     public static final int STATUS_MANAGED = STATUS_ALL & ~STATUS_NOTVERSIONED_NOTMANAGED;
125
126
127     /** Has local metadata under .svn/ */
128     public static final int STATUS_VERSIONED = STATUS_VERSIONED_UPTODATE |
129             STATUS_VERSIONED_MODIFIEDLOCALLY |
130             STATUS_VERSIONED_MODIFIEDINREPOSITORY |
131             STATUS_VERSIONED_CONFLICT |
132             STATUS_VERSIONED_MERGE |
133             STATUS_VERSIONED_REMOVEDLOCALLY |
134             STATUS_VERSIONED_REMOVEDINREPOSITORY |
135             STATUS_VERSIONED_DELETEDLOCALLY |
136             STATUS_VERSIONED_ADDEDLOCALLY;
137
138     public static final int STATUS_IN_REPOSITORY = STATUS_VERSIONED_UPTODATE |
139             STATUS_VERSIONED_MODIFIEDLOCALLY |
140             STATUS_VERSIONED_MODIFIEDINREPOSITORY |
141             STATUS_VERSIONED_CONFLICT |
142             STATUS_VERSIONED_MERGE |
143             STATUS_VERSIONED_REMOVEDLOCALLY |
144             STATUS_VERSIONED_NEWINREPOSITORY |
145             STATUS_VERSIONED_REMOVEDINREPOSITORY |
146             STATUS_VERSIONED_DELETEDLOCALLY;
147
148     public static final int STATUS_LOCAL_CHANGE =
149             FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY |
150             FileInformation.STATUS_VERSIONED_ADDEDLOCALLY |
151             FileInformation.STATUS_VERSIONED_CONFLICT |
152             FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
153             FileInformation.STATUS_VERSIONED_MERGE |
154             FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
155             FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY;
156
157     /**
158      * Modified, in conflict, scheduled for removal or addition;
159      * or deleted but with existing entry record.
160      */

161     public static final int STATUS_REVERTIBLE_CHANGE =
162             FileInformation.STATUS_VERSIONED_ADDEDLOCALLY |
163             FileInformation.STATUS_VERSIONED_CONFLICT |
164             FileInformation.STATUS_VERSIONED_MERGE |
165             FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY |
166             FileInformation.STATUS_VERSIONED_DELETEDLOCALLY |
167             FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY;
168
169
170     public static final int STATUS_REMOTE_CHANGE =
171             FileInformation.STATUS_VERSIONED_MERGE |
172             FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY |
173             FileInformation.STATUS_VERSIONED_NEWINREPOSITORY |
174             FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY;
175     
176     
177     /**
178      * Status constant.
179      */

180     private final int status;
181
182     /**
183      * Status constant for properties.
184      */

185     private final int propStatus;
186     
187     /**
188      * Entry from the .svn directory, if it exists and has been read.
189      */

190     private transient ISVNStatus entry;
191
192     /**
193      * Directory indicator.
194      */

195     private final boolean isDirectory;
196     
197     private static final String JavaDoc STATUS_UNKNOWN_EXT = "W"; // NOI18N
198
private static final String JavaDoc STATUS_NOTVERSIONED_NOTMANAGED_EXT = "Z"; // NOI18N
199
private static final String JavaDoc STATUS_NOTVERSIONED_EXCLUDED_EXT = "I"; // NOI18N
200
private static final String JavaDoc STATUS_NOTVERSIONED_NEWLOCALLY_EXT = "?"; // NOI18N
201
private static final String JavaDoc STATUS_VERSIONED_UPTODATE_EXT = "S"; // NOI18N
202
private static final String JavaDoc STATUS_VERSIONED_MODIFIEDLOCALLY_EXT = "M"; // NOI18N
203
private static final String JavaDoc STATUS_VERSIONED_MODIFIEDINREPOSITORY_EXT = "G"; // NOI18N
204
private static final String JavaDoc STATUS_VERSIONED_CONFLICT_EXT = "C"; // NOI18N
205
private static final String JavaDoc STATUS_VERSIONED_MERGE_EXT = "P"; // NOI18N
206
private static final String JavaDoc STATUS_VERSIONED_REMOVEDLOCALLY_EXT = "R"; // NOI18N
207
private static final String JavaDoc STATUS_VERSIONED_NEWINREPOSITORY_EXT = "N"; // NOI18N
208
private static final String JavaDoc STATUS_VERSIONED_REMOVEDINREPOSITORY_EXT = "D"; // NOI18N
209
private static final String JavaDoc STATUS_VERSIONED_DELETEDLOCALLY_EXT = "E"; // NOI18N
210
private static final String JavaDoc STATUS_VERSIONED_ADDEDLOCALLY_EXT = "A"; // NOI18N
211

212     // for debuging purposes
213
private final Exception JavaDoc origin;
214
215     /**
216      * For deserialization purposes only.
217      */

218     public FileInformation() {
219         status = 0;
220         propStatus = 0;
221         isDirectory = false;
222         origin = new RuntimeException JavaDoc("allocated at:"); // NOI18N
223
}
224
225     private FileInformation(int status, int propStatus, ISVNStatus entry, boolean isDirectory) {
226         this.status = status;
227         this.propStatus = propStatus;
228         this.entry = entry;
229         this.isDirectory = isDirectory;
230         origin = new RuntimeException JavaDoc("allocated at:"); // NOI18N
231
}
232
233     FileInformation(int status, ISVNStatus entry) {
234         this(status, 0, entry, entry.getNodeKind() == SVNNodeKind.DIR);
235     }
236
237     FileInformation(int status, boolean isDirectory) {
238         this(status, 0, null, isDirectory);
239     }
240     
241     FileInformation(int status, int propStatus, boolean isDirectory) {
242         this(status, propStatus, null, isDirectory);
243     }
244     
245     /**
246      * Retrieves the status constant representing status of the file.
247      *
248      * @return one of status constants
249      */

250     public int getStatus() {
251         return status;
252     }
253
254     public boolean isDirectory() {
255         return isDirectory;
256     }
257     
258     /**
259      * Retrieves file's Entry.
260      *
261      * @param file file this information belongs to or null if you do not want the entry to be read from disk
262      * in case it is not loaded yet
263      * @return Status parsed entry form the .svn/entries file or null if the file does not exist,
264      * is not versioned or its entry is invalid
265      */

266     public ISVNStatus getEntry(File JavaDoc file) {
267         if (entry == null && file != null) {
268             readEntry(file);
269         }
270         return entry;
271     }
272     
273     private void readEntry(File JavaDoc file) {
274         try {
275             entry = Subversion.getInstance().getClient(true).getSingleStatus(file);
276         } catch (SVNClientException e) {
277             // no entry for this file, ignore
278
}
279     }
280
281     /**
282      * Returns localized text representation of status.
283      *
284      * @return status name, for multistatuses prefers local
285      * status name.
286      */

287     public String JavaDoc getStatusText() {
288         return getStatusText(~0);
289     }
290
291     /**
292      * Returns localized text representation of status.
293      *
294      * @param displayStatuses statuses bitmask
295      *
296      * @return status name, for multistatuses prefers local
297      * status name, for masked <tt>""</tt>.
298      */

299     public String JavaDoc getStatusText(int displayStatuses) {
300         int status = this.status & displayStatuses;
301         ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
302         if (status == FileInformation.STATUS_UNKNOWN) {
303             return loc.getString("CTL_FileInfoStatus_Unknown");
304         } else if (match(status, FileInformation.STATUS_NOTVERSIONED_EXCLUDED)) {
305             return loc.getString("CTL_FileInfoStatus_Excluded");
306         } else if (match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY)) {
307             return loc.getString("CTL_FileInfoStatus_NewLocally");
308         } else if (match(status, FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
309             if (entry != null && entry.isCopied()) {
310                 return loc.getString("CTL_FileInfoStatus_AddedLocallyCopied");
311             }
312             return loc.getString("CTL_FileInfoStatus_AddedLocally");
313         } else if (match(status, FileInformation.STATUS_VERSIONED_UPTODATE)) {
314             return loc.getString("CTL_FileInfoStatus_UpToDate");
315         } else if (match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) {
316             return loc.getString("CTL_FileInfoStatus_Conflict");
317         } else if (match(status, FileInformation.STATUS_VERSIONED_MERGE)) {
318             return loc.getString("CTL_FileInfoStatus_Merge");
319         } else if (match(status, FileInformation.STATUS_VERSIONED_DELETEDLOCALLY)) {
320             return loc.getString("CTL_FileInfoStatus_DeletedLocally");
321         } else if (match(status, FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY)) {
322             return loc.getString("CTL_FileInfoStatus_RemovedLocally");
323         } else if (match(status, FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY)) {
324             return loc.getString("CTL_FileInfoStatus_ModifiedLocally");
325
326         } else if (match(status, FileInformation.STATUS_VERSIONED_NEWINREPOSITORY)) {
327             return loc.getString("CTL_FileInfoStatus_NewInRepository");
328         } else if (match(status, FileInformation.STATUS_VERSIONED_MODIFIEDINREPOSITORY)) {
329             return loc.getString("CTL_FileInfoStatus_ModifiedInRepository");
330         } else if (match(status, FileInformation.STATUS_VERSIONED_REMOVEDINREPOSITORY)) {
331             return loc.getString("CTL_FileInfoStatus_RemovedInRepository");
332         } else {
333             return ""; // NOI18N
334
}
335     }
336
337     /**
338      * @return short status name for local changes, for remote
339      * changes returns <tt>""</tt>
340      */

341     public String JavaDoc getShortStatusText() {
342         ResourceBundle loc = NbBundle.getBundle(FileInformation.class);
343         if (match(status, FileInformation.STATUS_NOTVERSIONED_EXCLUDED)) {
344             return loc.getString("CTL_FileInfoStatus_Excluded_Short");
345         } else if (match(status, FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY)) {
346             return loc.getString("CTL_FileInfoStatus_NewLocally_Short");
347         } else if (match(status, FileInformation.STATUS_VERSIONED_ADDEDLOCALLY)) {
348             if (entry != null && entry.isCopied()) {
349                 return loc.getString("CTL_FileInfoStatus_AddedLocallyCopied_Short");
350             }
351             return loc.getString("CTL_FileInfoStatus_AddedLocally_Short");
352         } else if (status == FileInformation.STATUS_VERSIONED_REMOVEDLOCALLY) {
353             return loc.getString("CTL_FileInfoStatus_RemovedLocally_Short");
354         } else if (status == FileInformation.STATUS_VERSIONED_DELETEDLOCALLY) {
355             return loc.getString("CTL_FileInfoStatus_DeletedLocally_Short");
356         } else if (match(status, FileInformation.STATUS_VERSIONED_MODIFIEDLOCALLY)) {
357             return loc.getString("CTL_FileInfoStatus_ModifiedLocally_Short");
358         } else if (match(status, FileInformation.STATUS_VERSIONED_CONFLICT)) {
359             return loc.getString("CTL_FileInfoStatus_Conflict_Short");
360         } else {
361             return ""; // NOI18N
362
}
363     }
364
365     private static boolean match(int status, int mask) {
366         return (status & mask) != 0;
367     }
368
369     public String JavaDoc toString() {
370         return "Text: " + status + " " + getStatusText(status) + "\nProp: " + propStatus + " " + getStatusText(propStatus); // NOI18N
371
}
372 }
373
374
Popular Tags