1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.selectors; 21 22 import org.netbeans.lib.cvsclient.CVSRoot; 23 import org.netbeans.lib.cvsclient.Client; 24 import org.netbeans.lib.cvsclient.admin.AdminHandler; 25 import org.netbeans.lib.cvsclient.event.*; 26 import org.netbeans.lib.cvsclient.connection.*; 27 import org.netbeans.lib.cvsclient.command.checkout.CheckoutCommand; 28 import org.netbeans.lib.cvsclient.command.checkout.ModuleListInformation; 29 import org.netbeans.lib.cvsclient.command.GlobalOptions; 30 import org.netbeans.lib.cvsclient.command.CommandException; 31 import org.netbeans.lib.cvsclient.command.update.UpdateCommand; 32 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 33 import org.openide.nodes.*; 34 import org.openide.util.UserCancelException; 35 import org.openide.util.HelpCtx; 36 import org.openide.filesystems.FileUtil; 37 38 import java.util.*; 39 import java.util.List ; 40 import java.io.File ; 41 42 47 public final class ModuleSelector { 48 49 54 public Set selectModules(CVSRoot root) { 55 56 58 Children.Array kids = new Children.Array(); 59 Client.Factory clientFactory = Kit.createClientFactory(root); 60 Node aliasesNode = AliasesNode.create(clientFactory, root); 61 Node pathsNode = RepositoryPathNode.create(clientFactory, root, ""); kids.add(new Node[] {aliasesNode, pathsNode}); 63 Node rootNode = new AbstractNode(kids); 64 65 try { 66 NodeOperation2 op = new NodeOperation2(); 67 op.setRootVisible(false); 68 op.setHelpCtx(new HelpCtx(ModuleSelector.class)); 69 Node[] selected = op.select(org.openide.util.NbBundle.getMessage(ModuleSelector.class, "BK2019"), 70 org.openide.util.NbBundle.getMessage(ModuleSelector.class, "BK2020"), 71 org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSD_ModuleSelect"), 72 rootNode, 73 org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSN_ModulesTree"), 74 org.openide.util.NbBundle.getMessage(BranchSelector.class, "ACSD_ModulesTree"), 75 new NodeAcceptor() { 76 public boolean acceptNodes(Node[] nodes) { 77 boolean ret = nodes.length > 0; 78 for (int i = 0; i < nodes.length; i++) { 79 Node node = nodes[i]; 80 String path = (String ) node.getLookup().lookup(String .class); 81 ret &= path != null; 82 } 83 return ret; 84 } 85 }); 86 87 Set modules = new LinkedHashSet(); 88 for (int i = 0; i < selected.length; i++) { 89 Node node = selected[i]; 90 String path = (String ) node.getLookup().lookup(String .class); 91 modules.add(path); 92 } 93 return modules; 94 } catch (UserCancelException e) { 95 return Collections.EMPTY_SET; 96 } 97 } 98 99 107 public String selectRepositoryPath(CVSRoot root) { 108 109 Client.Factory clientFactory = Kit.createClientFactory(root); 110 Node pathsNode = RepositoryPathNode.create(clientFactory, root, ""); 112 try { 113 Node[] selected = NodeOperation.getDefault().select(org.openide.util.NbBundle.getMessage(ModuleSelector.class, "BK2021"), org.openide.util.NbBundle.getMessage(ModuleSelector.class, "BK2022"), pathsNode, new NodeAcceptor() { 114 public boolean acceptNodes(Node[] nodes) { 115 if (nodes.length == 1) { 116 String path = (String ) nodes[0].getLookup().lookup(String .class); 117 return path != null; 118 } 119 return false; 120 } 121 }); 122 123 String path = null; 124 if (selected.length == 1) { 125 path = (String ) selected[0].getLookup().lookup(String .class); 126 } 127 return path; 128 } catch (UserCancelException e) { 129 return null; 130 } 131 } 132 133 private static final String MAGIC_START = ": New directory `"; private static final String MAGIC_END = "' -- ignored"; 136 144 public static List listRepositoryPath(Client client, CVSRoot root, String path) throws CommandException, AuthenticationException { 145 146 final List list = new ArrayList(); 147 GlobalOptions gtx = CvsVersioningSystem.createGlobalOptions(); 148 gtx.setCVSRoot(root.toString()); 149 gtx.setDoNoChanges(true); 150 151 UpdateCommand blindUpdate = new UpdateCommand(); 152 blindUpdate.setBuildDirectories(true); 153 154 AdminHandler localEnv = new VirtualAdminHandler(root, path); client.setAdminHandler(localEnv); 156 String tmpDir = System.getProperty("java.io.tmpdir"); File tmp = new File (tmpDir); 158 tmp = FileUtil.normalizeFile(tmp); 159 client.setLocalPath(tmp.getAbsolutePath()); 160 EventManager mgr = client.getEventManager(); 161 mgr.addCVSListener(new CVSListener() { 162 public void messageSent(MessageEvent e) { 163 if (e.isError()) { 164 String message = e.getMessage(); 165 if (message.endsWith(MAGIC_END)) { int start = message.indexOf(MAGIC_START); 167 if (start != -1) { 168 int pathStart = start + MAGIC_START.length(); 169 int pathEnd = message.length() - MAGIC_END.length(); 170 String path = message.substring(pathStart, pathEnd); 171 list.add(path); 172 } 173 } 174 } 175 } 176 public void messageSent(BinaryMessageEvent e) { 177 } 178 public void fileAdded(FileAddedEvent e) { 179 } 180 public void fileToRemove(FileToRemoveEvent e) { 181 } 182 public void fileRemoved(FileRemovedEvent e) { 183 } 184 public void fileUpdated(FileUpdatedEvent e) { 185 } 186 public void fileInfoGenerated(FileInfoEvent e) { 187 } 188 public void commandTerminated(TerminationEvent e) { 189 } 190 public void moduleExpanded(ModuleExpansionEvent e) { 191 } 192 }); 193 client.executeCommand(blindUpdate, gtx); 194 195 return list; 196 } 197 198 203 public static List listAliases(Client client, CVSRoot root) throws CommandException, AuthenticationException { 204 205 CheckoutCommand checkout = new CheckoutCommand(); 206 checkout.setShowModules(true); 207 final List modules = new LinkedList(); 208 EventManager mgr = client.getEventManager(); 209 mgr.addCVSListener(new CVSListener() { 210 public void messageSent(MessageEvent e) { 211 } 212 public void messageSent(BinaryMessageEvent e) { 213 } 214 public void fileAdded(FileAddedEvent e) { 215 } 216 public void fileToRemove(FileToRemoveEvent e) { 217 } 218 public void fileRemoved(FileRemovedEvent e) { 219 } 220 public void fileUpdated(FileUpdatedEvent e) { 221 } 222 public void fileInfoGenerated(FileInfoEvent e) { 223 ModuleListInformation moduleList = (ModuleListInformation) e.getInfoContainer(); 224 modules.add(moduleList); 225 } 226 public void commandTerminated(TerminationEvent e) { 227 } 228 public void moduleExpanded(ModuleExpansionEvent e) { 229 } 230 }); 231 232 GlobalOptions gtx = CvsVersioningSystem.createGlobalOptions(); 233 gtx.setCVSRoot(root.toString()); client.executeCommand(checkout, gtx); 235 236 return modules; 237 } 238 } 239 | Popular Tags |