Lines 1-7
Link Here
|
1 |
/* |
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
3 |
* |
4 |
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved. |
4 |
* Copyright 1997-2010 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
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 |
7 |
* General Public License Version 2 only ("GPL") or the Common |
Lines 41-46
Link Here
|
41 |
|
41 |
|
42 |
package org.netbeans.modules.versioning.system.cvss; |
42 |
package org.netbeans.modules.versioning.system.cvss; |
43 |
|
43 |
|
|
|
44 |
import org.netbeans.lib.cvsclient.command.CommandException; |
45 |
import org.netbeans.lib.cvsclient.connection.AuthenticationException; |
44 |
import org.netbeans.modules.versioning.spi.VCSInterceptor; |
46 |
import org.netbeans.modules.versioning.spi.VCSInterceptor; |
45 |
import org.netbeans.modules.versioning.util.Utils; |
47 |
import org.netbeans.modules.versioning.util.Utils; |
46 |
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; |
48 |
import org.netbeans.lib.cvsclient.admin.StandardAdminHandler; |
Lines 51-69
Link Here
|
51 |
import java.io.File; |
53 |
import java.io.File; |
52 |
import java.io.IOException; |
54 |
import java.io.IOException; |
53 |
import java.util.*; |
55 |
import java.util.*; |
54 |
import javax.swing.SwingUtilities; |
|
|
55 |
import org.netbeans.lib.cvsclient.command.GlobalOptions; |
56 |
import org.netbeans.lib.cvsclient.command.GlobalOptions; |
|
|
57 |
import org.netbeans.lib.cvsclient.command.Watch; |
58 |
import org.netbeans.lib.cvsclient.command.edit.EditCommand; |
56 |
import org.netbeans.lib.cvsclient.command.update.UpdateCommand; |
59 |
import org.netbeans.lib.cvsclient.command.update.UpdateCommand; |
|
|
60 |
import org.netbeans.modules.versioning.system.cvss.ui.actions.edit.EditExecutor; |
57 |
import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateExecutor; |
61 |
import org.netbeans.modules.versioning.system.cvss.ui.actions.update.UpdateExecutor; |
58 |
import org.openide.util.RequestProcessor; |
62 |
import org.openide.util.Exceptions; |
59 |
|
63 |
|
60 |
/** |
64 |
/** |
61 |
* Handles events fired from the filesystem such as file/folder create/delete/move. |
65 |
* Handles events fired from the filesystem such as file/folder create/delete/move. |
62 |
* |
66 |
* |
63 |
* @author Maros Sandor |
67 |
* @author Maros Sandor |
64 |
*/ |
68 |
*/ |
65 |
class FilesystemHandler extends VCSInterceptor { |
69 |
class FilesystemHandler extends VCSInterceptor { |
66 |
|
70 |
|
67 |
private final FileStatusCache cache; |
71 |
private final FileStatusCache cache; |
68 |
private static Thread ignoredThread; |
72 |
private static Thread ignoredThread; |
69 |
|
73 |
|
Lines 73-91
Link Here
|
73 |
|
77 |
|
74 |
/** |
78 |
/** |
75 |
* We save all CVS metadata to be able to commit files that were in that directory. |
79 |
* We save all CVS metadata to be able to commit files that were in that directory. |
76 |
* |
80 |
* |
77 |
* @param file File, we are only interested in files inside CVS directory |
81 |
* @param file File, we are only interested in files inside CVS directory |
78 |
*/ |
82 |
*/ |
|
|
83 |
@Override |
79 |
public boolean beforeDelete(File file) { |
84 |
public boolean beforeDelete(File file) { |
80 |
return !ignoringEvents(); |
85 |
return !ignoringEvents(); |
81 |
} |
86 |
} |
82 |
|
87 |
|
|
|
88 |
@Override |
83 |
public void doDelete(File file) throws IOException { |
89 |
public void doDelete(File file) throws IOException { |
84 |
if (file.isDirectory() && hasMetadata(file)) { |
90 |
if (file.isDirectory() && hasMetadata(file)) { |
85 |
CvsVisibilityQuery.hideFolder(file); |
91 |
CvsVisibilityQuery.hideFolder(file); |
86 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, true); |
92 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, true); |
87 |
} else if (org.netbeans.modules.versioning.system.cvss.util.Utils.isPartOfCVSMetadata(file)) { |
93 |
} else if (org.netbeans.modules.versioning.system.cvss.util.Utils.isPartOfCVSMetadata(file)) { |
88 |
// medatada are never deleted |
94 |
// metadata are never deleted |
89 |
} else { |
95 |
} else { |
90 |
if (!file.delete()) { |
96 |
if (!file.delete()) { |
91 |
throw new IOException("Failed to delete file: " + file.getAbsolutePath()); |
97 |
throw new IOException("Failed to delete file: " + file.getAbsolutePath()); |
Lines 94-103
Link Here
|
94 |
} |
100 |
} |
95 |
} |
101 |
} |
96 |
|
102 |
|
|
|
103 |
@Override |
97 |
public void afterDelete(File file) { |
104 |
public void afterDelete(File file) { |
98 |
refreshDeleted(file, false); |
105 |
refreshDeleted(file, false); |
99 |
} |
106 |
} |
100 |
|
107 |
|
101 |
private void refreshDeleted(File file, boolean refreshNow) { |
108 |
private void refreshDeleted(File file, boolean refreshNow) { |
102 |
if (refreshNow) { |
109 |
if (refreshNow) { |
103 |
cache.refreshNow(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, false); |
110 |
cache.refreshNow(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, false); |
Lines 110-126
Link Here
|
110 |
/** |
117 |
/** |
111 |
* We handle directory renames that are managed by CVS. |
118 |
* We handle directory renames that are managed by CVS. |
112 |
*/ |
119 |
*/ |
|
|
120 |
@Override |
113 |
public boolean beforeMove(File from, File to) { |
121 |
public boolean beforeMove(File from, File to) { |
114 |
File destDir = to.getParentFile(); |
122 |
File destDir = to.getParentFile(); |
115 |
return from != null && destDir != null && org.netbeans.modules.versioning.system.cvss.util.Utils.containsMetadata(from); |
123 |
return from != null && destDir != null && org.netbeans.modules.versioning.system.cvss.util.Utils.containsMetadata(from); |
116 |
} |
124 |
} |
117 |
|
125 |
|
118 |
/** |
126 |
/** |
119 |
* We only handle directories, file renames are examined ex post. Both directories share the same parent. |
127 |
* We only handle directories, file renames are examined ex post. Both directories share the same parent. |
120 |
* |
128 |
* |
121 |
* @param from source directory to be renamed |
129 |
* @param from source directory to be renamed |
122 |
* @param to new directory to be created |
130 |
* @param to new directory to be created |
123 |
*/ |
131 |
*/ |
|
|
132 |
@Override |
124 |
public void doMove(File from, File to) throws IOException { |
133 |
public void doMove(File from, File to) throws IOException { |
125 |
List<File> affectedFiles = new ArrayList<File>(); |
134 |
List<File> affectedFiles = new ArrayList<File>(); |
126 |
moveRecursively(affectedFiles, from, to); |
135 |
moveRecursively(affectedFiles, from, to); |
Lines 161-167
Link Here
|
161 |
} catch (IOException e) { |
170 |
} catch (IOException e) { |
162 |
// the Entry is not available, continue with no Entry |
171 |
// the Entry is not available, continue with no Entry |
163 |
} |
172 |
} |
164 |
|
173 |
|
165 |
if (entries != null) { |
174 |
if (entries != null) { |
166 |
for (Entry entry : entries) { |
175 |
for (Entry entry : entries) { |
167 |
if (entry != null && !entry.isDirectory() && !entry.isUserFileToBeRemoved()) { |
176 |
if (entry != null && !entry.isDirectory() && !entry.isUserFileToBeRemoved()) { |
Lines 170-197
Link Here
|
170 |
} |
179 |
} |
171 |
} |
180 |
} |
172 |
} |
181 |
} |
173 |
|
182 |
|
174 |
File [] files = dir.listFiles(); |
183 |
File [] files = dir.listFiles(); |
175 |
for (File file : files) { |
184 |
for (File file : files) { |
176 |
if (file.isDirectory()) cvsRemoveRecursively(file); |
185 |
if (file.isDirectory()) cvsRemoveRecursively(file); |
177 |
} |
186 |
} |
178 |
} |
187 |
} |
179 |
|
188 |
|
|
|
189 |
@Override |
180 |
public void afterMove(final File from, final File to) { |
190 |
public void afterMove(final File from, final File to) { |
181 |
if (ignoringEvents()) return; |
191 |
if (ignoringEvents()) return; |
182 |
Utils.post(new Runnable() { |
192 |
Utils.post(new Runnable() { |
|
|
193 |
@Override |
183 |
public void run() { |
194 |
public void run() { |
184 |
fileDeletedImpl(from, true); |
195 |
fileDeletedImpl(from, true); |
185 |
fileCreatedImpl(to); |
196 |
fileCreatedImpl(to); |
186 |
} |
197 |
} |
187 |
}); |
198 |
}); |
188 |
} |
199 |
} |
189 |
|
200 |
|
|
|
201 |
@Override |
190 |
public boolean beforeCreate(File file, boolean isDirectory) { |
202 |
public boolean beforeCreate(File file, boolean isDirectory) { |
191 |
if (ignoringEvents()) return false; |
203 |
if (ignoringEvents()) return false; |
192 |
return isDirectory && file.getName().equals(CvsVersioningSystem.FILENAME_CVS); |
204 |
return isDirectory && file.getName().equals(CvsVersioningSystem.FILENAME_CVS); |
193 |
} |
205 |
} |
194 |
|
206 |
|
|
|
207 |
@Override |
195 |
public void doCreate(File file, boolean isDirectory) throws IOException { |
208 |
public void doCreate(File file, boolean isDirectory) throws IOException { |
196 |
file.mkdir(); |
209 |
file.mkdir(); |
197 |
File f = new File(file, CvsLiteAdminHandler.INVALID_METADATA_MARKER); |
210 |
File f = new File(file, CvsLiteAdminHandler.INVALID_METADATA_MARKER); |
Lines 202-219
Link Here
|
202 |
} |
215 |
} |
203 |
} |
216 |
} |
204 |
|
217 |
|
|
|
218 |
@Override |
205 |
public void afterCreate(final File file) { |
219 |
public void afterCreate(final File file) { |
206 |
if (ignoringEvents()) return; |
220 |
if (ignoringEvents()) return; |
207 |
Utils.post(new Runnable() { |
221 |
Utils.post(new Runnable() { |
|
|
222 |
@Override |
208 |
public void run() { |
223 |
public void run() { |
209 |
fileCreatedImpl(file); |
224 |
fileCreatedImpl(file); |
210 |
} |
225 |
} |
211 |
}); |
226 |
}); |
212 |
} |
227 |
} |
213 |
|
228 |
|
|
|
229 |
@Override |
214 |
public void afterChange(final File file) { |
230 |
public void afterChange(final File file) { |
215 |
if (ignoringEvents()) return; |
231 |
if (ignoringEvents()) return; |
216 |
Utils.post(new Runnable() { |
232 |
Utils.post(new Runnable() { |
|
|
233 |
@Override |
217 |
public void run() { |
234 |
public void run() { |
218 |
cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); |
235 |
cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); |
219 |
if (file.getName().equals(CvsVersioningSystem.FILENAME_CVSIGNORE)) cache.directoryContentChanged(file.getParentFile()); |
236 |
if (file.getName().equals(CvsVersioningSystem.FILENAME_CVSIGNORE)) cache.directoryContentChanged(file.getParentFile()); |
Lines 225-230
Link Here
|
225 |
public Object getAttribute(final File file, String attrName) { |
242 |
public Object getAttribute(final File file, String attrName) { |
226 |
if("ProvidedExtensions.Refresh".equals(attrName)) { |
243 |
if("ProvidedExtensions.Refresh".equals(attrName)) { |
227 |
return new Runnable() { |
244 |
return new Runnable() { |
|
|
245 |
@Override |
228 |
public void run() { |
246 |
public void run() { |
229 |
UpdateCommand cmd = new UpdateCommand(); |
247 |
UpdateCommand cmd = new UpdateCommand(); |
230 |
GlobalOptions options = CvsVersioningSystem.createGlobalOptions(); |
248 |
GlobalOptions options = CvsVersioningSystem.createGlobalOptions(); |
Lines 238-248
Link Here
|
238 |
final ExecutorGroup refreshCommandGroup = new ExecutorGroup(null); |
256 |
final ExecutorGroup refreshCommandGroup = new ExecutorGroup(null); |
239 |
refreshCommandGroup.addExecutors(UpdateExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), options, null)); |
257 |
refreshCommandGroup.addExecutors(UpdateExecutor.splitCommand(cmd, CvsVersioningSystem.getInstance(), options, null)); |
240 |
CvsVersioningSystem.getInstance().getParallelRequestProcessor().post(new Runnable() { |
258 |
CvsVersioningSystem.getInstance().getParallelRequestProcessor().post(new Runnable() { |
|
|
259 |
@Override |
241 |
public void run() { |
260 |
public void run() { |
242 |
refreshCommandGroup.execute(); |
261 |
refreshCommandGroup.execute(); |
243 |
} |
262 |
} |
244 |
}); |
263 |
}); |
245 |
|
264 |
|
246 |
} |
265 |
} |
247 |
}; |
266 |
}; |
248 |
} else { |
267 |
} else { |
Lines 250-255
Link Here
|
250 |
} |
269 |
} |
251 |
} |
270 |
} |
252 |
|
271 |
|
|
|
272 |
@Override |
273 |
public void beforeEdit(File file) { |
274 |
EditCommand cmd = new EditCommand(); |
275 |
cmd.setDisplayName("CVS edit"); |
276 |
cmd.setFiles(new File[]{file}); |
277 |
cmd.setTemporaryWatch(Watch.EDIT); |
278 |
|
279 |
CvsVersioningSystem cvs = CvsVersioningSystem.getInstance(); |
280 |
EditExecutor[] executors = EditExecutor.splitCommand(cmd, cvs, null); |
281 |
try { |
282 |
cvs.post(cmd, executors[0]); |
283 |
} catch (CommandException ex) { |
284 |
Exceptions.printStackTrace(ex); |
285 |
} catch (AuthenticationException ex) { |
286 |
Exceptions.printStackTrace(ex); |
287 |
} catch (NotVersionedException ex) { |
288 |
Exceptions.printStackTrace(ex); |
289 |
} catch (IllegalCommandException ex) { |
290 |
Exceptions.printStackTrace(ex); |
291 |
} catch (IOException ex) { |
292 |
Exceptions.printStackTrace(ex); |
293 |
} |
294 |
} |
295 |
|
253 |
// private methods --------------------------- |
296 |
// private methods --------------------------- |
254 |
|
297 |
|
255 |
private void fileCreatedImpl(File file) { |
298 |
private void fileCreatedImpl(File file) { |
Lines 267-273
Link Here
|
267 |
// the Entry is not available, continue with no Entry |
310 |
// the Entry is not available, continue with no Entry |
268 |
} |
311 |
} |
269 |
if (entry != null && !entry.isDirectory() && entry.isUserFileToBeRemoved()) { |
312 |
if (entry != null && !entry.isDirectory() && entry.isUserFileToBeRemoved()) { |
270 |
cvsUndoRemoveLocally(sah, file, entry); |
313 |
cvsUndoRemoveLocally(sah, file, entry); |
271 |
} |
314 |
} |
272 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); |
315 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); |
273 |
} |
316 |
} |
Lines 277-288
Link Here
|
277 |
|
320 |
|
278 |
/** |
321 |
/** |
279 |
* If a regular file is deleted then update its Entries as if it has been removed. |
322 |
* If a regular file is deleted then update its Entries as if it has been removed. |
280 |
* |
323 |
* |
281 |
* @param file deleted file |
324 |
* @param file deleted file |
282 |
*/ |
325 |
*/ |
283 |
private void fileDeletedImpl(File file, boolean refreshNow) { |
326 |
private void fileDeletedImpl(File file, boolean refreshNow) { |
284 |
if (file == null) return; |
327 |
if (file == null) return; |
285 |
|
328 |
|
286 |
StandardAdminHandler sah = new StandardAdminHandler(); |
329 |
StandardAdminHandler sah = new StandardAdminHandler(); |
287 |
Entry entry = null; |
330 |
Entry entry = null; |
288 |
try { |
331 |
try { |
Lines 291-310
Link Here
|
291 |
// the Entry is not available, continue with no Entry |
334 |
// the Entry is not available, continue with no Entry |
292 |
} |
335 |
} |
293 |
if (entry != null && !entry.isDirectory() && !entry.isUserFileToBeRemoved()) { |
336 |
if (entry != null && !entry.isDirectory() && !entry.isUserFileToBeRemoved()) { |
294 |
cvsRemoveLocally(sah, file, entry); |
337 |
cvsRemoveLocally(sah, file, entry); |
295 |
} |
338 |
} |
296 |
|
339 |
|
297 |
refreshDeleted(file, refreshNow); |
340 |
refreshDeleted(file, refreshNow); |
298 |
} |
341 |
} |
299 |
|
342 |
|
300 |
/** |
343 |
/** |
301 |
* Emulates the 'cvs remove' command by modifying Entries. We do this to avoid contacting the |
344 |
* Emulates the 'cvs remove' command by modifying Entries. We do this to avoid contacting the |
302 |
* server. |
345 |
* server. |
303 |
* |
346 |
* |
304 |
* @param ah |
347 |
* @param ah |
305 |
* @param file |
348 |
* @param file |
306 |
* @param entry |
349 |
* @param entry |
307 |
*/ |
350 |
*/ |
308 |
private void cvsRemoveLocally(AdminHandler ah, File file, Entry entry) { |
351 |
private void cvsRemoveLocally(AdminHandler ah, File file, Entry entry) { |
309 |
try { |
352 |
try { |
310 |
if (entry.isNewUserFile()) { |
353 |
if (entry.isNewUserFile()) { |
Lines 328-344
Link Here
|
328 |
// failed to set entry, the file will be probably resurrected during update |
371 |
// failed to set entry, the file will be probably resurrected during update |
329 |
} |
372 |
} |
330 |
} |
373 |
} |
331 |
|
374 |
|
332 |
private void refresh(List<File> files) { |
375 |
private void refresh(List<File> files) { |
333 |
for (File file : files) { |
376 |
for (File file : files) { |
334 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, true); |
377 |
cache.refresh(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN, true); |
335 |
} |
378 |
} |
336 |
} |
379 |
} |
337 |
|
380 |
|
338 |
private boolean hasMetadata(File file) { |
381 |
private boolean hasMetadata(File file) { |
339 |
return new File(file, "CVS/Repository").canRead(); |
382 |
return new File(file, "CVS/Repository").canRead(); |
340 |
} |
383 |
} |
341 |
|
384 |
|
342 |
/** |
385 |
/** |
343 |
* Ignores (internal) events from current thread. E.g.: |
386 |
* Ignores (internal) events from current thread. E.g.: |
344 |
* <pre> |
387 |
* <pre> |
Lines 364-370
Link Here
|
364 |
|
407 |
|
365 |
/** |
408 |
/** |
366 |
* @return true if filesystem events are ignored in current thread, false otherwise |
409 |
* @return true if filesystem events are ignored in current thread, false otherwise |
367 |
*/ |
410 |
*/ |
368 |
private static boolean ignoringEvents() { |
411 |
private static boolean ignoringEvents() { |
369 |
return ignoredThread == Thread.currentThread(); |
412 |
return ignoredThread == Thread.currentThread(); |
370 |
} |
413 |
} |