KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > executor > RemoveExecutor


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.versioning.system.cvss.executor;
21
22 import org.openide.util.NbBundle;
23 import org.openide.ErrorManager;
24 import org.openide.filesystems.FileObject;
25 import org.openide.filesystems.FileUtil;
26 import org.netbeans.modules.versioning.system.cvss.*;
27 import org.netbeans.lib.cvsclient.command.GlobalOptions;
28 import org.netbeans.lib.cvsclient.command.Command;
29 import org.netbeans.lib.cvsclient.command.remove.RemoveCommand;
30 import org.netbeans.lib.cvsclient.command.remove.RemoveInformation;
31
32 import java.util.Set JavaDoc;
33 import java.util.HashSet JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.io.File JavaDoc;
37
38 /**
39  * Executes cvs remove command.
40  *
41  * @author Maros Sandor
42  */

43 public class RemoveExecutor extends ExecutorSupport {
44
45     private Set JavaDoc refreshedFiles;
46
47     /**
48      * Splits the original command into more commands if the original
49      * command would execute on incompatible files.
50      * See {@link #prepareBasicCommand(org.netbeans.lib.cvsclient.command.BasicCommand)}
51      * for more information.
52      *
53      * @param cmd command o execute
54      * @param cvs CVS engine to use
55      * @param options global option for the command
56      * @return array of executors that will execute the command (or array of splitted commands)
57      */

58     public static RemoveExecutor [] splitCommand(RemoveCommand cmd, CvsVersioningSystem cvs, GlobalOptions options) {
59         Command [] cmds = new org.netbeans.lib.cvsclient.command.Command[0];
60         if (cmd.getDisplayName() == null) cmd.setDisplayName(NbBundle.getMessage(RemoveExecutor.class, "MSG_RemoveExecutor_CmdDisplayName"));
61         try {
62             cmds = prepareBasicCommand(cmd);
63         } catch (IOException JavaDoc e) {
64             ErrorManager.getDefault().notify(e);
65             return null;
66         }
67         RemoveExecutor [] executors = new RemoveExecutor[cmds.length];
68         for (int i = 0; i < cmds.length; i++) {
69             Command command = cmds[i];
70             executors[i] = new RemoveExecutor(cvs, (RemoveCommand) command, options);
71         }
72         return executors;
73     }
74
75     private RemoveExecutor(CvsVersioningSystem cvs, RemoveCommand cmd, GlobalOptions options) {
76         super(cvs, cmd, options);
77     }
78
79     /**
80      * Refreshes statuse of relevant files after this command terminates.
81      */

82     protected void commandFinished(ClientRuntime.Result result) {
83
84         RemoveCommand xcmd = (RemoveCommand) cmd;
85
86         // files that we have information that changed
87
refreshedFiles = new HashSet JavaDoc(toRefresh.size());
88
89         for (Iterator JavaDoc i = toRefresh.iterator(); i.hasNext();) {
90             RemoveInformation info = (RemoveInformation) i.next();
91             if (info.getFile() == null) continue;
92             int repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
93             if (info.isRemoved()) {
94                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_REMOVED;
95             } else {
96                 repositoryStatus = FileStatusCache.REPOSITORY_STATUS_UNKNOWN;
97             }
98             cache.refreshCached(info.getFile(), repositoryStatus);
99             refreshedFiles.add(info.getFile());
100         }
101
102         if (cmd.hasFailed()) return;
103
104         // refresh all command roots
105
File JavaDoc [] files = xcmd.getFiles();
106         for (int i = 0; i < files.length; i++) {
107             refreshRecursively(files[i]);
108             FileObject fo = FileUtil.toFileObject(files[i]);
109             if (fo != null) {
110                 fo.refresh(true);
111             }
112         }
113     }
114
115     private void refreshRecursively(File JavaDoc file) {
116         if (cvs.isIgnoredFilename(file)) return;
117         if (refreshedFiles.contains(file)) return;
118         if (file.isDirectory()) {
119             File JavaDoc [] files = file.listFiles();
120             for (int i = 0; i < files.length; i++) {
121                 refreshRecursively(files[i]);
122             }
123             cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN);
124         } else {
125             cache.refreshCached(file, FileStatusCache.REPOSITORY_STATUS_UNKNOWN);
126         }
127     }
128 }
129
Popular Tags