1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.add; 21 22 import org.netbeans.modules.versioning.system.cvss.*; 23 import org.netbeans.lib.cvsclient.command.GlobalOptions; 24 import org.netbeans.lib.cvsclient.command.add.AddCommand; 25 import org.netbeans.lib.cvsclient.command.add.AddInformation; 26 import org.openide.ErrorManager; 27 import org.openide.util.NbBundle; 28 29 import java.util.*; 30 import java.io.File ; 31 import java.io.IOException ; 32 33 38 public class AddExecutor extends ExecutorSupport { 39 40 51 public static AddExecutor[] splitCommand(AddCommand cmd, CvsVersioningSystem cvs, GlobalOptions options) { 52 53 List fileSets = new ArrayList(); 54 55 File [] files = getNewDirectories(cmd.getFiles()); 56 if (files.length > 0) { 57 try { 58 File [][] sets = splitFiles(files); 59 for (int i = 0; i < sets.length; i++) { 60 File [] set = sets[i]; 61 Arrays.sort(set, byLengthComparator); 62 fileSets.add(set); 63 } 64 } catch (IOException e) { 65 ErrorManager.getDefault().notify(e); 66 return null; 67 } 68 } 69 70 try { 71 File [][] sets = splitFiles(cmd.getFiles()); 72 fileSets.addAll(Arrays.asList(sets)); 73 } catch (IOException e) { 74 ErrorManager.getDefault().notify(e); 75 return null; 76 } 77 78 AddCommand [] commands = new AddCommand[fileSets.size()]; 79 for (int i = 0; i < commands.length; i++) { 80 commands[i] = (AddCommand) cmd.clone(); 81 commands[i].setFiles((File []) fileSets.get(i)); 82 } 83 84 AddExecutor [] executors = new AddExecutor[commands.length]; 85 for (int i = 0; i < commands.length; i++) { 86 AddCommand command = commands[i]; 87 int len = command.getFiles().length; 88 String param = len == 1 ? 89 command.getFiles()[0].getName() : 90 NbBundle.getMessage(AddExecutor.class, "MSG_AddExecutor_CmdDisplayXfiles", Integer.toString(len)); 91 command.setDisplayName(NbBundle.getMessage(AddExecutor.class, "MSG_AddExecutor_CmdDisplayName", param)); 92 executors[i] = new AddExecutor(cvs, command, options); 93 } 94 return executors; 95 } 96 97 private static File [] getNewDirectories(File [] files) { 98 FileStatusCache cache = CvsVersioningSystem.getInstance().getStatusCache(); 99 Set newDirs = new HashSet(); 100 for (int i = 0; i < files.length; i++) { 101 File parent = files[i].getParentFile(); 102 for (;;) { 103 if (cache.getStatus(parent).getStatus() == FileInformation.STATUS_NOTVERSIONED_NEWLOCALLY) { 104 newDirs.add(parent); 105 } else { 106 break; 107 } 108 parent = parent.getParentFile(); 109 if (parent == null) break; 110 } 111 } 112 List dirs = new ArrayList(newDirs); 113 return (File []) dirs.toArray(new File [dirs.size()]); 114 } 115 116 private static final Comparator byLengthComparator = new Comparator() { 117 public int compare(Object o1, Object o2) { 118 File a = (File ) o1; 119 File b = (File ) o2; 120 return a.getAbsolutePath().length() - b.getAbsolutePath().length(); 121 } 122 }; 123 124 private AddExecutor(CvsVersioningSystem cvs, AddCommand cmd, GlobalOptions options) { 125 super(cvs, cmd, options); 126 } 127 128 protected void commandFinished(ClientRuntime.Result result) { 129 Set parents = new HashSet(); 130 for (Iterator i = toRefresh.iterator(); i.hasNext();) { 133 AddInformation addInformation = (AddInformation) i.next(); 134 File file = addInformation.getFile(); 135 cache.refreshCached(file, addInformation.getType().charAt(0)); 136 parents.add(file.getParentFile()); 137 } 138 toRefresh.clear(); 139 140 for (Iterator i = parents.iterator(); i.hasNext();) { 141 File dir = (File ) i.next(); 142 cache.refreshCached(dir, FileStatusCache.REPOSITORY_STATUS_UNKNOWN); 143 } 144 } 145 } 146 | Popular Tags |