1 11 package org.eclipse.team.internal.ccvs.core.resources; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 import java.util.NoSuchElementException ; 19 import java.util.StringTokenizer ; 20 21 import org.eclipse.core.runtime.*; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.team.core.TeamException; 24 import org.eclipse.team.internal.ccvs.core.*; 25 import org.eclipse.team.internal.ccvs.core.client.*; 26 import org.eclipse.team.internal.ccvs.core.client.Command.LocalOption; 27 import org.eclipse.team.internal.ccvs.core.syncinfo.FolderSyncInfo; 28 29 public class RemoteModule extends RemoteFolder { 30 31 private String label; 32 private ICVSRemoteResource[] referencedModules; 33 private LocalOption[] localOptions; 34 private boolean expandable; 35 36 public static RemoteModule[] getRemoteModules(ICVSRepositoryLocation repository, CVSTag tag, IProgressMonitor monitor) throws TeamException { 37 monitor = Policy.monitorFor(monitor); 38 monitor.beginTask(CVSMessages.RemoteModule_getRemoteModules, 100); 39 try { 40 RemoteModule[] modules; 41 Session s = new Session(repository, getRemoteRootFolder(repository), false); 42 s.open(Policy.subMonitorFor(monitor, 10), false ); 43 try { 44 modules = Command.CHECKOUT.getRemoteModules(s, tag, Policy.subMonitorFor(monitor, 90)); 45 } finally { 46 s.close(); 47 } 48 return modules; 49 } finally { 50 monitor.done(); 51 } 52 } 53 54 private static ICVSFolder getRemoteRootFolder(ICVSRepositoryLocation repository) { 55 return new RemoteFolder(null, repository, "/", null); } 57 58 63 public static RemoteModule[] createRemoteModules(String [] moduleDefinitionStrings, ICVSRepositoryLocation repository, CVSTag tag) { 64 65 Map modules = new HashMap (); 66 Map referencedModulesTable = new HashMap (); 67 Map moduleAliases = new HashMap (); 68 69 for (int i = 0; i < moduleDefinitionStrings.length; i++) { 71 72 StringTokenizer tokenizer = new StringTokenizer (moduleDefinitionStrings[i]); 74 String moduleName = tokenizer.nextToken(); 75 List localOptionsList; 76 String next; 77 try { 78 localOptionsList = new ArrayList (); 80 next = tokenizer.nextToken(); 81 while (next.charAt(0) == '-') { 82 switch (next.charAt(1)) { 83 case 'a': localOptionsList.add(Checkout.ALIAS); 85 break; 86 case 'l': localOptionsList.add(Command.DO_NOT_RECURSE); 88 break; 89 case 'd': localOptionsList.add(Checkout.makeDirectoryNameOption(tokenizer.nextToken())); 91 break; 92 case 'e': 93 case 'i': 94 case 'o': 95 case 't': 96 case 'u': tokenizer.nextToken(); 98 break; 99 case 's': localOptionsList.add(Checkout.makeStatusOption(tokenizer.nextToken())); 101 break; 102 default: } 104 next = tokenizer.nextToken(); 105 } 106 } catch (NoSuchElementException e) { 107 CVSProviderPlugin.log(IStatus.WARNING, NLS.bind(CVSMessages.RemoteModule_invalidDefinition, new String [] { moduleDefinitionStrings[i], repository.getLocation(true) }), null); 109 continue; 110 } 111 LocalOption[] localOptions = (LocalOption[]) localOptionsList.toArray(new LocalOption[localOptionsList.size()]); 112 113 if (Checkout.ALIAS.isElementOf(localOptions)) { 114 115 if (localOptions.length > 1) { 116 } 118 119 List expansions = new ArrayList (10); 121 expansions.add(next); 122 while (tokenizer.hasMoreTokens()) 123 expansions.add(tokenizer.nextToken()); 124 125 moduleAliases.put(moduleName, expansions.toArray(new String [expansions.size()])); 126 modules.put(moduleName, new RemoteModule(moduleName, null, repository, null, localOptions, tag, true)); 127 128 } else { 129 130 if (!(next.charAt(0) == '&')) { 132 String directory = next; 133 List files = new ArrayList (); 134 while (tokenizer.hasMoreTokens() && (next.charAt(0) != '&')) { 135 next = tokenizer.nextToken() ; 136 if ((next.charAt(0) != '&')) 137 files.add(next); 138 } 139 RemoteModule remoteModule = new RemoteModule(moduleName, null, repository, directory, localOptions, tag, ! files.isEmpty()); 140 modules.put(moduleName, remoteModule); 141 if ( ! files.isEmpty()) { 142 ICVSRemoteResource[] children = new ICVSRemoteResource[files.size()]; 143 for (int j = 0; j < children.length; j++) { 144 children[j] = new RemoteFile(remoteModule, Update.STATE_NONE, (String )files.get(j), null, null, tag); 145 remoteModule.setChildren(children); 146 } 147 } 148 } else { 149 modules.put(moduleName, new RemoteModule(moduleName, null, repository, null, localOptions, tag, true)); 150 } 151 152 if (next.charAt(0) == '&') { 154 List children = new ArrayList (10); 155 children.add(next); 156 while (tokenizer.hasMoreTokens()) 157 children.add(tokenizer.nextToken()); 158 referencedModulesTable.put(moduleName, children.toArray(new String [children.size()])); 159 } 160 } 161 } 162 163 Iterator iter = moduleAliases.keySet().iterator(); 166 while (iter.hasNext()) { 167 String moduleName = (String )iter.next(); 168 RemoteModule module = (RemoteModule)modules.get(moduleName); 169 String [] expansion = (String [])moduleAliases.get(moduleName); 170 List referencedFolders = new ArrayList (); 171 boolean expandable = true; 172 for (int i = 0; i < expansion.length; i++) { 173 if (expansion[i].charAt(0) == '!') { 174 expandable = false; 176 } else { 177 IPath path = new Path(null, expansion[i]); 178 if (path.segmentCount() > 1) { 179 expandable = false; 181 } else { 182 RemoteModule child = (RemoteModule)modules.get(expansion[i]); 183 if (child == null) { 184 referencedFolders.add(new RemoteFolder(null, repository, path.toString(), tag)); 185 } else { 186 if (child.isAlias()) { 188 expandable = false; 190 } else { 191 referencedFolders.add(child); 192 } 193 } 194 } 195 } 196 } 197 if (expandable) { 198 module.setChildren((ICVSRemoteResource[]) referencedFolders.toArray(new ICVSRemoteResource[referencedFolders.size()])); 200 } else { 201 module.setExpandable(false); 202 } 203 } 204 205 iter = modules.keySet().iterator(); 207 while (iter.hasNext()) { 208 String moduleName = (String )iter.next(); 209 String [] children = (String [])referencedModulesTable.get(moduleName); 210 if (children != null) { 211 RemoteModule module = (RemoteModule)modules.get(moduleName); 212 List referencedFolders = new ArrayList (); 213 boolean expandable = true; 214 for (int i = 0; i < children.length; i++) { 215 RemoteModule child = (RemoteModule)modules.get(children[i].substring(1)); 216 if (child == null) { 217 expandable = false; 219 } else if (child.isAlias()) { 220 expandable = false; 222 } else { 224 if (Command.findOption(child.getLocalOptions(), "-d") != null) { expandable = false; 227 } else { 228 referencedFolders.add(child); 229 } 230 } 231 } 232 if (expandable) { 233 module.setReferencedModules((ICVSRemoteResource[]) referencedFolders.toArray(new ICVSRemoteResource[referencedFolders.size()])); 234 } else { 235 module.setExpandable(false); 236 } 237 } 238 } 239 240 return (RemoteModule[])modules.values().toArray(new RemoteModule[modules.size()]); 241 } 242 243 public RemoteModule(String label, RemoteFolder parent, ICVSRepositoryLocation repository, String repositoryRelativePath, LocalOption[] localOptions, CVSTag tag, boolean isStatic) { 244 super(parent, 245 label, 246 repository, 247 repositoryRelativePath == null ? FolderSyncInfo.VIRTUAL_DIRECTORY : repositoryRelativePath, 248 tag, 249 isStatic); 250 this.localOptions = localOptions; 251 this.label = label; 252 this.expandable = true; 253 } 254 255 public LocalOption[] getLocalOptions() { 256 return localOptions; 257 } 258 261 public ICVSRemoteResource[] getMembers(CVSTag tagName, IProgressMonitor monitor) throws CVSException { 262 263 if ( ! expandable) return new ICVSRemoteResource[0]; 264 265 ICVSRemoteResource[] physicalChildren; 266 if ( folderInfo.getIsStatic()) { 267 physicalChildren = getChildren(); 268 } else { 269 physicalChildren = super.getMembers(tagName, monitor); 270 } 271 ICVSRemoteResource[] allChildren; 272 if (referencedModules != null && referencedModules.length > 0) { 273 if (physicalChildren == null) { 274 allChildren = referencedModules; 275 } else { 276 allChildren = new ICVSRemoteResource[physicalChildren.length + referencedModules.length]; 278 for (int i = 0; i < physicalChildren.length; i++) { 279 allChildren[i] = physicalChildren[i]; 280 } 281 for (int i = 0; i < referencedModules.length; i++) { 282 allChildren[i + physicalChildren.length] = referencedModules[i]; 283 } 284 } 285 } else if (physicalChildren != null) { 286 allChildren = physicalChildren; 287 } else { 288 allChildren = new ICVSRemoteResource[0]; 289 } 290 return allChildren; 291 } 292 293 private void setReferencedModules(ICVSRemoteResource[] referencedModules) { 294 this.referencedModules = referencedModules; 295 } 296 297 public boolean isAlias() { 298 return Checkout.ALIAS.isElementOf(localOptions); 299 } 300 301 304 public boolean isExpandable() { 305 return expandable; 306 } 307 308 private void setExpandable(boolean expandable) { 309 this.expandable = expandable; 310 } 311 312 315 public ICVSRemoteResource forTag(ICVSRemoteFolder parent, CVSTag tagName) { 316 RemoteModule r = new RemoteModule(label, (RemoteFolder)parent, getRepository(), folderInfo.getRepository(), localOptions, tagName, folderInfo.getIsStatic()); 317 r.setExpandable(expandable); 318 if (folderInfo.getIsStatic()) { 319 ICVSRemoteResource[] children = getChildren(); 320 if (children != null) { 321 List taggedChildren = new ArrayList (children.length); 322 for (int i = 0; i < children.length; i++) { 323 ICVSRemoteResource resource = children[i]; 324 taggedChildren.add(((RemoteResource)resource).forTag(r, tagName)); 325 } 326 r.setChildren((ICVSRemoteResource[]) taggedChildren.toArray(new ICVSRemoteResource[taggedChildren.size()])); 327 } 328 } 329 if (referencedModules != null) { 330 List taggedModules = new ArrayList (referencedModules.length); 331 for (int i = 0; i < referencedModules.length; i++) { 332 RemoteModule module = (RemoteModule)referencedModules[i]; 333 taggedModules.add(module.forTag(r, tagName)); 334 } 335 r.setReferencedModules((ICVSRemoteResource[]) taggedModules.toArray(new ICVSRemoteResource[taggedModules.size()])); 336 } 337 return r; 338 } 339 340 343 public boolean isDefinedModule() { 344 return true; 345 } 346 349 public boolean equals(Object arg0) { 350 if (arg0 instanceof RemoteModule) { 351 RemoteModule module = (RemoteModule) arg0; 352 return (getName().equals(module.getName()) && super.equals(module)); 353 } 354 return false; 355 } 356 357 360 public int hashCode() { 361 return super.hashCode() | getName().hashCode(); 362 } 363 364 367 public ICVSResource getChild(String path) throws CVSException { 368 if (path.equals(Session.CURRENT_LOCAL_FOLDER) || path.length() == 0) 369 return this; 370 if (referencedModules != null) { 375 if (path.indexOf(Session.SERVER_SEPARATOR) == -1) { 376 for (int i=0;i<referencedModules.length;i++) { 377 if (referencedModules[i].getName().equals(path)) 378 return referencedModules[i]; 379 } 380 } 381 } 382 return super.getChild(path); 383 } 384 385 } 386 | Popular Tags |