KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > subversion > client > parser > SvnWcParser


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 package org.netbeans.modules.subversion.client.parser;
20
21 import java.io.File JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27 import org.tigris.subversion.svnclientadapter.ISVNInfo;
28 import org.tigris.subversion.svnclientadapter.ISVNStatus;
29 import org.tigris.subversion.svnclientadapter.SVNNodeKind;
30 import org.tigris.subversion.svnclientadapter.SVNScheduleKind;
31 import org.tigris.subversion.svnclientadapter.SVNStatusKind;
32 import org.xml.sax.SAXException JavaDoc;
33
34 /**
35  *
36  * @author Ed Hillmann
37  */

38 public class SvnWcParser {
39     
40     /** Creates a new instance of SvnWcParser */
41     public SvnWcParser() {
42     }
43
44     private WorkingCopyDetails getWCDetails(File JavaDoc file) throws IOException JavaDoc, SAXException JavaDoc {
45         Map JavaDoc<String JavaDoc, String JavaDoc> attributes = EntriesCache.getInstance().getFileAttributes(file);
46         return WorkingCopyDetails.createWorkingCopy(file, attributes);
47     }
48
49    /**
50      *
51      */

52     public ISVNStatus[] getStatus(File JavaDoc path, boolean descend, boolean getAll) throws LocalSubversionException {
53         List JavaDoc<ISVNStatus> l = getStatus(path, descend);
54 // List<ISVNStatus> ret = new ArrayList<ISVNStatus>(l.size());
55
// for(ISVNStatus status : l) {
56
// if(!getAll) {
57
// if(!status.getRepositoryTextStatus().equals(SVNStatusKind.NORMAL)) { // XXX does this mean !getAll
58
// ret.add(status);
59
// }
60
// } else {
61
// ret.add(status);
62
// }
63
// }
64
return l.toArray(new ISVNStatus[l.size()]);
65     }
66
67     private List JavaDoc<ISVNStatus> getStatus(File JavaDoc path, boolean descend) throws LocalSubversionException {
68         List JavaDoc<ISVNStatus> ret = new ArrayList JavaDoc<ISVNStatus>(20);
69                         
70         File JavaDoc[] children = path.listFiles();
71         if(children != null && children.length > 0) {
72             for (int i = 0; i < children.length; i++) {
73                 ret.add(getSingleStatus(children[i]));
74                 if(descend && children[i].isDirectory()) {
75                     ret.addAll(getStatus(children[i], descend));
76                 }
77             }
78         }
79         ret.add(getSingleStatus(path));
80         return ret;
81     }
82
83     public ISVNStatus getSingleStatus(File JavaDoc file) throws LocalSubversionException {
84         String JavaDoc finalTextStatus = SVNStatusKind.NORMAL.toString();
85         String JavaDoc finalPropStatus = SVNStatusKind.NONE.toString();
86
87         try {
88             WorkingCopyDetails wcDetails = getWCDetails(file);
89             if (wcDetails.isHandled()) {
90
91                 if (wcDetails.propertiesExist()) {
92                     finalPropStatus = SVNStatusKind.NORMAL.toString();
93                     //See if props have been modified
94
if (wcDetails.propertiesModified()) {
95                         finalPropStatus = SVNStatusKind.MODIFIED.toString();
96                     }
97                 }
98                 if (wcDetails.isFile()) {
99                     //Find Text Status
100
// XXX what if already added
101
if (wcDetails.textModified()) {
102                         finalTextStatus = SVNStatusKind.MODIFIED.toString();
103                     }
104                 }
105
106                 String JavaDoc value = wcDetails.getValue("schedule"); // NOI18N
107
if (value != null) {
108                     if (value.equals("add")) { // NOI18N
109
finalTextStatus = SVNStatusKind.ADDED.toString();
110                         finalPropStatus = SVNStatusKind.NONE.toString();
111                     } else if (value.equals("delete")) { // NOI18N
112
finalTextStatus = SVNStatusKind.DELETED.toString();
113                         finalPropStatus = SVNStatusKind.NONE.toString();
114                     }
115                     //status.c had a schedule="replace", but TSVN
116
//simply did a copy
117
}
118                 value = wcDetails.getValue("deleted"); // NOI18N
119
if (value != null) {
120                     if (value.equals("true")) { // NOI18N
121
finalTextStatus = SVNStatusKind.UNVERSIONED.toString();
122                         finalPropStatus = SVNStatusKind.NONE.toString();
123                     }
124                 }
125
126                 String JavaDoc fileUrl = wcDetails.getValue("url"); // NOI18N
127
long revision = wcDetails.getLongValue("revision"); // NOI18N
128
String JavaDoc nodeKind = wcDetails.getValue("kind", "normal"); // NOI18N
129
String JavaDoc lastCommitAuthor = wcDetails.getValue("last-author"); // NOI18N
130
long lastChangedRevision = wcDetails.getLongValue("committed-rev"); // NOI18N
131
Date JavaDoc lastCommittedDate = wcDetails.getDateValue("committed-date"); // NOI18N
132

133                 boolean isCopied = wcDetails.getBooleanValue("copied"); // NOI18N
134
String JavaDoc urlCopiedFrom = null;
135                 if (isCopied) {
136                     urlCopiedFrom = wcDetails.getValue("copyfrom-url"); // NOI18N
137
}
138
139                 File JavaDoc conflictNew = null;
140                 File JavaDoc conflictOld = null;
141                 File JavaDoc conflictWorking = null;
142                 value = wcDetails.getValue("conflict-wrk"); // NOI18N
143
if (value != null && ((String JavaDoc)value).length() > 0) {
144                     conflictWorking = new File JavaDoc(file.getParentFile(), value);
145                 }
146
147                 value = wcDetails.getValue("conflict-new"); // NOI18N
148
if (value != null && ((String JavaDoc)value).length() > 0) {
149                     conflictNew = new File JavaDoc(file.getParentFile(), value);
150                 }
151                 value = wcDetails.getValue("conflict-old"); // NOI18N
152
if (value != null && ((String JavaDoc)value).length() > 0) {
153                     conflictOld = new File JavaDoc(file.getParentFile(), value);
154                 }
155                 if ((conflictNew != null) || (conflictOld != null)) {
156                     finalTextStatus = SVNStatusKind.CONFLICTED.toString();
157                 }
158
159                 Date JavaDoc lockCreationDate = wcDetails.getDateValue("lock-creation-date"); // NOI18N
160
String JavaDoc lockComment = null;
161                 String JavaDoc lockOwner = null;
162                 if (lockCreationDate != null) {
163                     lockComment = wcDetails.getValue("lock-comment"); // NOI18N
164
lockOwner = wcDetails.getValue("lock-owner"); // NOI18N
165
}
166
167                 return new ParserSvnStatus(
168                         file,
169                         fileUrl,
170                         revision,
171                         nodeKind,
172                         finalTextStatus,
173                         finalPropStatus,
174                         lastCommitAuthor,
175                         lastChangedRevision,
176                         lastCommittedDate,
177                         isCopied,
178                         urlCopiedFrom,
179                         conflictNew,
180                         conflictOld,
181                         conflictWorking,
182                         lockCreationDate,
183                         lockComment,
184                         lockOwner);
185             } else {
186                 //File isn't handled.
187
return new ParserSvnStatus(
188                         file,
189                         wcDetails.getValue("url"), // NOI18N
190
0,
191                         "unknown", // NOI18N
192
SVNStatusKind.UNVERSIONED.toString(),
193                         SVNStatusKind.UNVERSIONED.toString(),
194                         null,
195                         0,
196                         null,
197                         false,
198                         null,
199                         null,
200                         null,
201                         null,
202                         null,
203                         null,
204                         null);
205             }
206
207         } catch (IOException JavaDoc ex) {
208             throw new LocalSubversionException(ex);
209         } catch (SAXException JavaDoc ex) {
210             throw new LocalSubversionException(ex);
211         } catch (IllegalArgumentException JavaDoc ex) {
212             throw new LocalSubversionException(ex);
213         }
214     }
215
216     public ISVNInfo getInfoFromWorkingCopy(File JavaDoc file) throws LocalSubversionException {
217
218         ISVNInfo returnValue = null;
219         try {
220             WorkingCopyDetails wcDetails = getWCDetails(file); // NOI18N
221
if (wcDetails.isHandled()) {
222                 String JavaDoc fileUrl = wcDetails.getValue("url"); // NOI18N
223
String JavaDoc reposUrl = wcDetails.getValue("repos"); // NOI18N
224
String JavaDoc reposUuid = wcDetails.getValue("uuid"); // NOI18N
225
String JavaDoc schedule = wcDetails.getValue("schedule"); // NOI18N
226
if (schedule == null) {
227                     schedule = SVNScheduleKind.NORMAL.toString();
228                 }
229
230                 long revision = wcDetails.getLongValue("revision"); // NOI18N
231
boolean isCopied = wcDetails.getBooleanValue("copied"); // NOI18N
232
String JavaDoc urlCopiedFrom = null;
233                 long revisionCopiedFrom = 0;
234                 if (isCopied) {
235                     urlCopiedFrom = wcDetails.getValue("copyfrom-url"); // NOI18N
236
revisionCopiedFrom = wcDetails.getLongValue("copyfrom-rev"); // NOI18N
237
}
238
239                 Date JavaDoc lastCommittedDate = wcDetails.getDateValue("committed-date"); // NOI18N
240
long lastChangedRevision = wcDetails.getLongValue("committed-rev"); // NOI18N
241
String JavaDoc lastCommitAuthor = wcDetails.getValue("last-author"); // NOI18N
242
Date JavaDoc lastDatePropsUpdate = wcDetails.getDateValue("prop-time"); // NOI18N
243
Date JavaDoc lastDateTextUpdate = wcDetails.getDateValue("text-time"); // NOI18N
244

245                 Date JavaDoc lockCreationDate = wcDetails.getDateValue("lock-creation-date"); // NOI18N
246
String JavaDoc lockComment = null;
247                 String JavaDoc lockOwner = null;
248                 if (lockCreationDate != null) {
249                     lockComment = wcDetails.getValue("lock-comment"); // NOI18N
250
lockOwner = wcDetails.getValue("lock-owner"); // NOI18N
251
}
252
253                 String JavaDoc nodeKind = wcDetails.getValue("kind", "normal"); // NOI18N
254
returnValue = new ParserSvnInfo(file, fileUrl, reposUrl, reposUuid,
255                     schedule, revision, isCopied, urlCopiedFrom, revisionCopiedFrom,
256                     lastCommittedDate, lastChangedRevision, lastCommitAuthor,
257                     lastDatePropsUpdate, lastDateTextUpdate, lockCreationDate,
258                     lockOwner, lockComment, nodeKind, wcDetails.getPropertiesFile(), wcDetails.getBasePropertiesFile());
259             } else {
260                 String JavaDoc fileUrl = wcDetails.getValue("url"); // NOI18N
261
String JavaDoc reposUrl = wcDetails.getValue("repos"); // NOI18N
262
String JavaDoc reposUuid = wcDetails.getValue("uuid"); // NOI18N
263
returnValue = new ParserSvnInfo(file, fileUrl, reposUrl, reposUuid,
264                     SVNScheduleKind.NORMAL.toString(), 0, false, null, 0, null, 0, null,
265                     null, null, null, null, null, SVNNodeKind.UNKNOWN.toString(), null, null);
266             }
267         } catch (IOException JavaDoc ex) {
268             throw new LocalSubversionException(ex);
269         } catch (SAXException JavaDoc ex) {
270             throw new LocalSubversionException(ex);
271         }
272         return returnValue;
273     }
274     
275 }
276
277
Popular Tags