1 13 package org.eclipse.core.internal.resources; 14 15 import java.net.URI ; 16 import java.util.HashMap ; 17 import java.util.Iterator ; 18 import org.eclipse.core.filesystem.*; 19 import org.eclipse.core.internal.events.LifecycleEvent; 20 import org.eclipse.core.internal.localstore.FileSystemResourceManager; 21 import org.eclipse.core.internal.properties.IPropertyManager; 22 import org.eclipse.core.internal.utils.*; 23 import org.eclipse.core.internal.watson.*; 24 import org.eclipse.core.resources.*; 25 import org.eclipse.core.resources.team.IMoveDeleteHook; 26 import org.eclipse.core.runtime.*; 27 import org.eclipse.core.runtime.jobs.ISchedulingRule; 28 import org.eclipse.core.runtime.jobs.MultiRule; 29 import org.eclipse.osgi.util.NLS; 30 31 public abstract class Resource extends PlatformObject implements IResource, ICoreConstants, Cloneable , IPathRequestor { 32 IPath path; 33 Workspace workspace; 34 35 protected Resource(IPath path, Workspace workspace) { 36 this.path = path.removeTrailingSeparator(); 37 this.workspace = workspace; 38 } 39 40 43 public void accept(final IResourceProxyVisitor visitor, final int memberFlags) throws CoreException { 44 final boolean includePhantoms = (memberFlags & IContainer.INCLUDE_PHANTOMS) != 0; 46 checkAccessible(getFlags(getResourceInfo(includePhantoms, false))); 47 48 final ResourceProxy proxy = new ResourceProxy(); 49 IElementContentVisitor elementVisitor = new IElementContentVisitor() { 50 public boolean visitElement(ElementTree tree, IPathRequestor requestor, Object contents) { 51 ResourceInfo info = (ResourceInfo) contents; 52 if (!isMember(getFlags(info), memberFlags)) 53 return false; 54 proxy.requestor = requestor; 55 proxy.info = info; 56 try { 57 return visitor.visit(proxy); 58 } catch (CoreException e) { 59 throw new WrappedRuntimeException(e); 61 } finally { 62 proxy.reset(); 63 } 64 } 65 }; 66 try { 67 new ElementTreeIterator(workspace.getElementTree(), getFullPath()).iterate(elementVisitor); 68 } catch (WrappedRuntimeException e) { 69 throw (CoreException) e.getTargetException(); 70 } catch (OperationCanceledException e) { 71 throw e; 72 } catch (RuntimeException e) { 73 String msg = Messages.resources_errorVisiting; 74 IResourceStatus errorStatus = new ResourceStatus(IResourceStatus.INTERNAL_ERROR, getFullPath(), msg, e); 75 Policy.log(errorStatus); 76 throw new ResourceException(errorStatus); 77 } finally { 78 proxy.requestor = null; 79 proxy.info = null; 80 } 81 } 82 83 86 public void accept(IResourceVisitor visitor) throws CoreException { 87 accept(visitor, IResource.DEPTH_INFINITE, 0); 88 } 89 90 93 public void accept(IResourceVisitor visitor, int depth, boolean includePhantoms) throws CoreException { 94 accept(visitor, depth, includePhantoms ? IContainer.INCLUDE_PHANTOMS : 0); 95 } 96 97 100 public void accept(final IResourceVisitor visitor, int depth, int memberFlags) throws CoreException { 101 if (depth == IResource.DEPTH_INFINITE) { 103 accept(new IResourceProxyVisitor() { 104 public boolean visit(IResourceProxy proxy) throws CoreException { 105 return visitor.visit(proxy.requestResource()); 106 } 107 }, memberFlags); 108 return; 109 } 110 final boolean includePhantoms = (memberFlags & IContainer.INCLUDE_PHANTOMS) != 0; 112 ResourceInfo info = getResourceInfo(includePhantoms, false); 113 int flags = getFlags(info); 114 checkAccessible(flags); 115 116 if (!isMember(flags, memberFlags)) 118 return; 119 if (!visitor.visit(this) || depth == DEPTH_ZERO) 121 return; 122 info = getResourceInfo(includePhantoms, false); 124 if (info == null) 125 return; 126 int type = info.getType(); 128 if (type == FILE) 129 return; 130 IContainer resource = getType() != type ? (IContainer) workspace.newResource(getFullPath(), type) : (IContainer) this; 132 IResource[] members = resource.members(memberFlags); 133 for (int i = 0; i < members.length; i++) 134 members[i].accept(visitor, DEPTH_ZERO, memberFlags); 135 } 136 137 protected void assertCopyRequirements(IPath destination, int destinationType, int updateFlags) throws CoreException { 138 IStatus status = checkCopyRequirements(destination, destinationType, updateFlags); 139 if (!status.isOK()) { 140 Assert.isTrue(false, status.getChildren()[0].getMessage()); 143 } 144 } 145 146 151 protected IFileInfo assertLinkRequirements(URI localLocation, int updateFlags) throws CoreException { 152 boolean allowMissingLocal = (updateFlags & IResource.ALLOW_MISSING_LOCAL) != 0; 153 if ((updateFlags & IResource.REPLACE) == 0) 154 checkDoesNotExist(getFlags(getResourceInfo(false, false)), true); 155 IStatus locationStatus = workspace.validateLinkLocationURI(this, localLocation); 156 final boolean variableUndefined = locationStatus.getCode() == IResourceStatus.VARIABLE_NOT_DEFINED_WARNING; 158 if (locationStatus.getSeverity() == IStatus.ERROR || (variableUndefined && !allowMissingLocal)) 159 throw new ResourceException(locationStatus); 160 Container parent = (Container) getParent(); 162 parent.checkAccessible(getFlags(parent.getResourceInfo(false, false))); 163 if (variableUndefined) 165 return null; 166 URI resolved = workspace.getPathVariableManager().resolveURI(localLocation); 168 IFileStore store = EFS.getStore(resolved); 169 IFileInfo fileInfo = store.fetchInfo(); 170 boolean localExists = fileInfo.exists(); 171 if (!allowMissingLocal && !localExists) { 172 String msg = NLS.bind(Messages.links_localDoesNotExist, store.toString()); 173 throw new ResourceException(IResourceStatus.NOT_FOUND_LOCAL, getFullPath(), msg, null); 174 } 175 if (localExists && ((getType() == IResource.FOLDER) != fileInfo.isDirectory())) { 177 String msg = NLS.bind(Messages.links_wrongLocalType, getFullPath()); 178 throw new ResourceException(IResourceStatus.WRONG_TYPE_LOCAL, getFullPath(), msg, null); 179 } 180 return fileInfo; 181 } 182 183 protected void assertMoveRequirements(IPath destination, int destinationType, int updateFlags) throws CoreException { 184 IStatus status = checkMoveRequirements(destination, destinationType, updateFlags); 185 if (!status.isOK()) { 186 Assert.isTrue(false, status.getChildren()[0].getMessage()); 189 } 190 } 191 192 public void checkAccessible(int flags) throws CoreException { 193 checkExists(flags, true); 194 } 195 196 208 public IStatus checkCopyRequirements(IPath destination, int destinationType, int updateFlags) throws CoreException { 209 String message = Messages.resources_copyNotMet; 210 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INVALID_VALUE, message, null); 211 if (destination == null) { 212 message = Messages.resources_destNotNull; 213 return new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), message); 214 } 215 destination = makePathAbsolute(destination); 216 if (getFullPath().isPrefixOf(destination)) { 217 message = NLS.bind(Messages.resources_copyDestNotSub, getFullPath()); 218 status.add(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), message)); 219 } 220 checkValidPath(destination, destinationType, false); 221 222 ResourceInfo info = getResourceInfo(false, false); 223 int flags = getFlags(info); 224 checkAccessible(flags); 225 checkLocal(flags, DEPTH_INFINITE); 226 227 Resource dest = workspace.newResource(destination, destinationType); 228 dest.checkDoesNotExist(); 229 230 if (getType() == IResource.FILE && destinationType == IResource.PROJECT) { 232 message = Messages.resources_fileToProj; 233 throw new ResourceException(IResourceStatus.INVALID_VALUE, getFullPath(), message, null); 234 } 235 236 if (destinationType != IResource.PROJECT) { 238 Project project = (Project) dest.getProject(); 239 info = project.getResourceInfo(false, false); 240 project.checkAccessible(getFlags(info)); 241 Container parent = (Container) dest.getParent(); 242 if (!parent.equals(project)) { 243 info = parent.getResourceInfo(false, false); 244 parent.checkExists(getFlags(info), true); 245 } 246 } 247 if (isUnderLink() || dest.isUnderLink()) { 248 URI sourceLocation = getLocationURI(); 251 if (sourceLocation == null) { 252 message = NLS.bind(Messages.localstore_locationUndefined, getFullPath()); 253 throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, getFullPath(), message, null); 254 } 255 URI destLocation = dest.getLocationURI(); 256 if (destLocation == null) { 257 message = NLS.bind(Messages.localstore_locationUndefined, dest.getFullPath()); 258 throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, dest.getFullPath(), message, null); 259 } 260 if (getStore().isParentOf(dest.getStore())) { 263 message = NLS.bind(Messages.resources_copyDestNotSub, getFullPath()); 264 throw new ResourceException(IResourceStatus.INVALID_VALUE, getFullPath(), message, null); 265 } 266 } 267 268 return status.isOK() ? Status.OK_STATUS : (IStatus) status; 269 } 270 271 275 protected void checkDoesNotExist() throws CoreException { 276 checkDoesNotExist(getFlags(getResourceInfo(false, false)), false); 277 } 278 279 285 public void checkDoesNotExist(int flags, boolean checkType) throws CoreException { 286 if (exists(flags, checkType)) { 288 String message = NLS.bind(Messages.resources_mustNotExist, getFullPath()); 289 throw new ResourceException(checkType ? IResourceStatus.RESOURCE_EXISTS : IResourceStatus.PATH_OCCUPIED, getFullPath(), message, null); 290 } 291 if (Workspace.caseSensitive) 292 return; 293 IResource variant = findExistingResourceVariant(getFullPath()); 295 if (variant == null) 296 return; 297 String msg = NLS.bind(Messages.resources_existsDifferentCase, variant.getFullPath()); 298 throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, variant.getFullPath(), msg, null); 299 } 300 301 307 public void checkExists(int flags, boolean checkType) throws CoreException { 308 if (!exists(flags, checkType)) { 309 String message = NLS.bind(Messages.resources_mustExist, getFullPath()); 310 throw new ResourceException(IResourceStatus.RESOURCE_NOT_FOUND, getFullPath(), message, null); 311 } 312 } 313 314 319 public void checkLocal(int flags, int depth) throws CoreException { 320 if (!isLocal(flags, depth)) { 321 String message = NLS.bind(Messages.resources_mustBeLocal, getFullPath()); 322 throw new ResourceException(IResourceStatus.RESOURCE_NOT_LOCAL, getFullPath(), message, null); 323 } 324 } 325 326 340 protected IStatus checkMoveRequirements(IPath destination, int destinationType, int updateFlags) throws CoreException { 341 String message = Messages.resources_moveNotMet; 342 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.INVALID_VALUE, message, null); 343 if (destination == null) { 344 message = Messages.resources_destNotNull; 345 return new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), message); 346 } 347 destination = makePathAbsolute(destination); 348 if (getFullPath().isPrefixOf(destination)) { 349 message = NLS.bind(Messages.resources_moveDestNotSub, getFullPath()); 350 status.add(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), message)); 351 } 352 checkValidPath(destination, destinationType, false); 353 354 ResourceInfo info = getResourceInfo(false, false); 355 int flags = getFlags(info); 356 checkAccessible(flags); 357 checkLocal(flags, DEPTH_INFINITE); 358 359 Resource dest = workspace.newResource(destination, destinationType); 360 361 IResource variant = Workspace.caseSensitive ? null : findExistingResourceVariant(destination); 363 if (variant == null || !this.equals(variant)) 364 dest.checkDoesNotExist(); 365 366 if (getType() == IResource.FILE && dest.getType() == IResource.PROJECT) { 368 message = Messages.resources_fileToProj; 369 throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), message)); 370 } 371 372 if (destinationType != IResource.PROJECT) { 374 Project project = (Project) dest.getProject(); 375 info = project.getResourceInfo(false, false); 376 project.checkAccessible(getFlags(info)); 377 Container parent = (Container) dest.getParent(); 378 if (!parent.equals(project)) { 379 info = parent.getResourceInfo(false, false); 380 parent.checkExists(getFlags(info), true); 381 } 382 } 383 if (isUnderLink() || dest.isUnderLink()) { 384 URI sourceLocation = getLocationURI(); 387 if (sourceLocation == null) { 388 message = NLS.bind(Messages.localstore_locationUndefined, getFullPath()); 389 throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, getFullPath(), message, null); 390 } 391 URI destLocation = dest.getLocationURI(); 392 if (destLocation == null) { 393 message = NLS.bind(Messages.localstore_locationUndefined, dest.getFullPath()); 394 throw new ResourceException(IResourceStatus.FAILED_READ_LOCAL, dest.getFullPath(), message, null); 395 } 396 if (getStore().isParentOf(dest.getStore())) { 399 message = NLS.bind(Messages.resources_moveDestNotSub, getFullPath()); 400 throw new ResourceException(IResourceStatus.INVALID_VALUE, getFullPath(), message, null); 401 } 402 } 403 404 return status.isOK() ? Status.OK_STATUS : (IStatus) status; 405 } 406 407 412 public void checkValidPath(IPath toValidate, int type, boolean lastSegmentOnly) throws CoreException { 413 IStatus result = workspace.locationValidator.validatePath(toValidate, type, lastSegmentOnly); 414 if (!result.isOK()) 415 throw new ResourceException(result); 416 } 417 418 421 public void clearHistory(IProgressMonitor monitor) { 422 getLocalManager().getHistoryStore().remove(getFullPath(), monitor); 423 } 424 425 429 public boolean contains(ISchedulingRule rule) { 430 if (this == rule) 431 return true; 432 if (rule.getClass().equals(WorkManager.NotifyRule.class)) 434 return true; 435 if (rule instanceof MultiRule) { 436 MultiRule multi = (MultiRule) rule; 437 ISchedulingRule[] children = multi.getChildren(); 438 for (int i = 0; i < children.length; i++) 439 if (!contains(children[i])) 440 return false; 441 return true; 442 } 443 if (!(rule instanceof IResource)) 444 return false; 445 return path.isPrefixOf(((IResource) rule).getFullPath()); 446 } 447 448 public void convertToPhantom() throws CoreException { 449 ResourceInfo info = getResourceInfo(false, true); 450 if (info == null || isPhantom(getFlags(info))) 451 return; 452 info.clearSessionProperties(); 453 info.set(M_PHANTOM); 454 getLocalManager().updateLocalSync(info, I_NULL_SYNC_INFO); 455 info.clearModificationStamp(); 456 info.setMarkers(null); 459 } 460 461 464 public void copy(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException { 465 int updateFlags = force ? IResource.FORCE : IResource.NONE; 466 copy(destination, updateFlags, monitor); 467 } 468 469 472 public void copy(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException { 473 try { 474 monitor = Policy.monitorFor(monitor); 475 String message = NLS.bind(Messages.resources_copying, getFullPath()); 476 monitor.beginTask(message, Policy.totalWork); 477 Policy.checkCanceled(monitor); 478 destination = makePathAbsolute(destination); 479 checkValidPath(destination, getType(), false); 480 Resource destResource = workspace.newResource(destination, getType()); 481 final ISchedulingRule rule = workspace.getRuleFactory().copyRule(this, destResource); 482 try { 483 workspace.prepareOperation(rule, monitor); 484 assertCopyRequirements(destination, getType(), updateFlags); 487 workspace.beginOperation(true); 488 getLocalManager().copy(this, destResource, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); 489 } catch (OperationCanceledException e) { 490 workspace.getWorkManager().operationCanceled(); 491 throw e; 492 } finally { 493 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 494 } 495 } finally { 496 monitor.done(); 497 } 498 } 499 500 503 public void copy(IProjectDescription destDesc, boolean force, IProgressMonitor monitor) throws CoreException { 504 int updateFlags = force ? IResource.FORCE : IResource.NONE; 505 copy(destDesc, updateFlags, monitor); 506 } 507 508 512 public void copy(IProjectDescription destDesc, int updateFlags, IProgressMonitor monitor) throws CoreException { 513 Assert.isNotNull(destDesc); 514 monitor = Policy.monitorFor(monitor); 515 try { 516 String message = NLS.bind(Messages.resources_copying, getFullPath()); 517 monitor.beginTask(message, Policy.totalWork); 518 try { 519 workspace.prepareOperation(workspace.getRoot(), monitor); 520 IPath destPath = new Path(destDesc.getName()).makeAbsolute(); 523 assertCopyRequirements(destPath, getType(), updateFlags); 524 Project destProject = (Project) workspace.getRoot().getProject(destPath.lastSegment()); 525 workspace.beginOperation(true); 526 527 destProject.create(destDesc, Policy.subMonitorFor(monitor, Policy.opWork * 5 / 100)); 529 destProject.open(Policy.subMonitorFor(monitor, Policy.opWork * 5 / 100)); 530 531 IResource[] children = ((IContainer) this).members(IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS); 534 for (int i = 0; i < children.length; i++) { 535 Resource child = (Resource) children[i]; 536 child.copy(destPath.append(child.getName()), updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 60 / 100 / children.length)); 537 } 538 539 getPropertyManager().copy(this, destProject, DEPTH_ZERO); 541 monitor.worked(Policy.opWork * 15 / 100); 542 543 } catch (OperationCanceledException e) { 544 workspace.getWorkManager().operationCanceled(); 545 throw e; 546 } finally { 547 workspace.endOperation(workspace.getRoot(), true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 548 } 549 } finally { 550 monitor.done(); 551 } 552 } 553 554 559 public int countResources(int depth, boolean phantom) { 560 return workspace.countResources(path, depth, phantom); 561 } 562 563 567 public void createLink(IPath localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException { 568 Assert.isNotNull(localLocation); 569 createLink(URIUtil.toURI(localLocation), updateFlags, monitor); 570 } 571 572 576 public void createLink(URI localLocation, int updateFlags, IProgressMonitor monitor) throws CoreException { 577 Assert.isNotNull(localLocation); 578 monitor = Policy.monitorFor(monitor); 579 try { 580 String message = NLS.bind(Messages.links_creating, getFullPath()); 581 monitor.beginTask(message, Policy.totalWork); 582 Policy.checkCanceled(monitor); 583 checkValidPath(path, FOLDER, true); 584 final ISchedulingRule rule = workspace.getRuleFactory().createRule(this); 585 try { 586 workspace.prepareOperation(rule, monitor); 587 IFileInfo fileInfo = assertLinkRequirements(localLocation, updateFlags); 588 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_CREATE, this)); 589 workspace.beginOperation(true); 590 if ((updateFlags & REPLACE) != 0) { 592 IResource existing = workspace.getRoot().findMember(getFullPath()); 593 if (existing != null) 594 workspace.deleteResource(existing); 595 } 596 ResourceInfo info = workspace.createResource(this, false); 597 info.set(M_LINK); 598 localLocation = FileUtil.canonicalURI(localLocation); 599 getLocalManager().link(this, localLocation, fileInfo); 600 monitor.worked(Policy.opWork * 5 / 100); 601 Project project = (Project) getProject(); 603 project.internalGetDescription().setLinkLocation(getProjectRelativePath(), new LinkDescription(this, localLocation)); 604 project.writeDescription(IResource.NONE); 605 monitor.worked(Policy.opWork * 5 / 100); 606 607 if (getType() != IResource.FILE) { 609 if ((updateFlags & IResource.BACKGROUND_REFRESH) != 0) { 611 workspace.refreshManager.refresh(this); 612 monitor.worked(Policy.opWork * 90 / 100); 613 } else { 614 refreshLocal(DEPTH_INFINITE, Policy.subMonitorFor(monitor, Policy.opWork * 90 / 100)); 615 } 616 } else 617 monitor.worked(Policy.opWork * 90 / 100); 618 } catch (OperationCanceledException e) { 619 workspace.getWorkManager().operationCanceled(); 620 throw e; 621 } finally { 622 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 623 } 624 } finally { 625 monitor.done(); 626 } 627 } 628 629 632 public IMarker createMarker(String type) throws CoreException { 633 Assert.isNotNull(type); 634 final ISchedulingRule rule = workspace.getRuleFactory().markerRule(this); 635 try { 636 workspace.prepareOperation(rule, null); 637 checkAccessible(getFlags(getResourceInfo(false, false))); 638 workspace.beginOperation(true); 639 MarkerInfo info = new MarkerInfo(); 640 info.setType(type); 641 info.setCreationTime(System.currentTimeMillis()); 642 workspace.getMarkerManager().add(this, info); 643 return new Marker(this, info.getId()); 644 } finally { 645 workspace.endOperation(rule, false, null); 646 } 647 } 648 649 public IResourceProxy createProxy() { 650 ResourceProxy result = new ResourceProxy(); 651 result.info = getResourceInfo(false, false); 652 result.requestor = this; 653 result.resource = this; 654 return result; 655 } 656 657 662 public void delete(boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException { 663 int updateFlags = force ? IResource.FORCE : IResource.NONE; 664 updateFlags |= keepHistory ? IResource.KEEP_HISTORY : IResource.NONE; 665 delete(updateFlags, monitor); 666 } 667 668 671 public void delete(boolean force, IProgressMonitor monitor) throws CoreException { 672 delete(force ? IResource.FORCE : IResource.NONE, monitor); 673 } 674 675 678 public void delete(int updateFlags, IProgressMonitor monitor) throws CoreException { 679 monitor = Policy.monitorFor(monitor); 680 try { 681 String message = NLS.bind(Messages.resources_deleting, getFullPath()); 682 monitor.beginTask("", Policy.totalWork * 1000); monitor.subTask(message); 684 final ISchedulingRule rule = workspace.getRuleFactory().deleteRule(this); 685 try { 686 workspace.prepareOperation(rule, monitor); 687 if (!exists()) 689 return; 690 workspace.beginOperation(true); 691 final IFileStore originalStore = getStore(); 692 boolean wasLinked = isLinked(); 693 message = Messages.resources_deleteProblem; 694 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IResourceStatus.FAILED_DELETE_LOCAL, message, null); 695 WorkManager workManager = workspace.getWorkManager(); 696 ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags); 697 int depth = 0; 698 try { 699 depth = workManager.beginUnprotected(); 700 unprotectedDelete(tree, updateFlags, monitor); 701 } finally { 702 workManager.endUnprotected(depth); 703 } 704 if (getType() == ROOT) { 705 workspace.getMarkerManager().removeMarkers(this, IResource.DEPTH_ZERO); 707 getPropertyManager().deleteProperties(this, IResource.DEPTH_ZERO); 708 getResourceInfo(false, false).clearSessionProperties(); 709 } 710 tree.makeInvalid(); 712 if (!tree.getStatus().isOK()) 713 throw new ResourceException(tree.getStatus()); 714 if (!wasLinked) 717 workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor); 718 if (getType() == PROJECT) 720 ((Rules) workspace.getRuleFactory()).setRuleFactory((IProject) this, null); 721 } catch (OperationCanceledException e) { 722 workspace.getWorkManager().operationCanceled(); 723 throw e; 724 } finally { 725 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork * 1000)); 726 } 727 } finally { 728 monitor.done(); 729 } 730 } 731 732 735 public void deleteMarkers(String type, boolean includeSubtypes, int depth) throws CoreException { 736 final ISchedulingRule rule = workspace.getRuleFactory().markerRule(this); 737 try { 738 workspace.prepareOperation(rule, null); 739 ResourceInfo info = getResourceInfo(false, false); 740 checkAccessible(getFlags(info)); 741 742 workspace.beginOperation(true); 743 workspace.getMarkerManager().removeMarkers(this, type, includeSubtypes, depth); 744 } finally { 745 workspace.endOperation(rule, false, null); 746 } 747 } 748 749 754 public void deleteResource(boolean convertToPhantom, MultiStatus status) throws CoreException { 755 if (exists()) 757 getMarkerManager().removeMarkers(this, IResource.DEPTH_INFINITE); 758 final boolean wasLinked = isLinked(); 760 if (wasLinked) 762 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_DELETE, this)); 763 764 ProjectPreferences.deleted(this); 766 767 769 if (convertToPhantom && getType() != PROJECT && synchronizing(getResourceInfo(true, false))) 770 convertToPhantom(); 771 else 772 workspace.deleteResource(this); 773 774 if (wasLinked) { 776 Project project = (Project) getProject(); 777 ProjectDescription description = project.internalGetDescription(); 778 description.setLinkLocation(getProjectRelativePath(), null); 779 project.internalSetDescription(description, true); 780 project.writeDescription(IResource.FORCE); 781 } 782 783 CoreException err = null; 785 try { 786 getPropertyManager().deleteResource(this); 787 } catch (CoreException e) { 788 if (status != null) 789 status.add(e.getStatus()); 790 else 791 err = e; 792 } 793 if (err != null) 794 throw err; 795 } 796 797 800 public boolean equals(Object target) { 801 if (this == target) 802 return true; 803 if (!(target instanceof Resource)) 804 return false; 805 Resource resource = (Resource) target; 806 return getType() == resource.getType() && path.equals(resource.path) && workspace.equals(resource.workspace); 807 } 808 809 812 public boolean exists() { 813 ResourceInfo info = getResourceInfo(false, false); 814 return exists(getFlags(info), true); 815 } 816 817 public boolean exists(int flags, boolean checkType) { 818 return flags != NULL_FLAG && !(checkType && ResourceInfo.getType(flags) != getType()); 819 } 820 821 826 public IResource findExistingResourceVariant(IPath target) { 827 if (!workspace.tree.includesIgnoreCase(target)) 828 return null; 829 ResourceInfo info = (ResourceInfo) workspace.tree.getElementDataIgnoreCase(target); 831 if (info != null && info.isSet(M_PHANTOM)) 832 return null; 833 IPath result = Path.ROOT; 835 int segmentCount = target.segmentCount(); 836 for (int i = 0; i < segmentCount; i++) { 837 String [] childNames = workspace.tree.getNamesOfChildren(result); 838 String name = findVariant(target.segment(i), childNames); 839 if (name == null) 840 return null; 841 result = result.append(name); 842 } 843 return workspace.getRoot().findMember(result); 844 } 845 846 849 public IMarker findMarker(long id) { 850 return workspace.getMarkerManager().findMarker(this, id); 851 } 852 853 856 public IMarker[] findMarkers(String type, boolean includeSubtypes, int depth) throws CoreException { 857 ResourceInfo info = getResourceInfo(false, false); 858 checkAccessible(getFlags(info)); 859 return workspace.getMarkerManager().findMarkers(this, type, includeSubtypes, depth); 863 } 864 865 868 public int findMaxProblemSeverity(String type, boolean includeSubtypes, int depth) throws CoreException { 869 ResourceInfo info = getResourceInfo(false, false); 870 checkAccessible(getFlags(info)); 871 return workspace.getMarkerManager().findMaxProblemSeverity(this, type, includeSubtypes, depth); 875 } 876 877 882 private String findVariant(String target, String [] list) { 883 for (int i = 0; i < list.length; i++) { 884 if (target.equalsIgnoreCase(list[i])) 885 return list[i]; 886 } 887 return null; 888 } 889 890 protected void fixupAfterMoveSource() throws CoreException { 891 ResourceInfo info = getResourceInfo(true, true); 892 if (isLinked()) { 894 Project project = (Project) getProject(); 895 project.internalGetDescription().setLinkLocation(getProjectRelativePath(), null); 896 project.writeDescription(IResource.NONE); 897 } 898 899 ProjectPreferences.deleted(this); 901 902 if (!synchronizing(info)) { 903 workspace.deleteResource(this); 904 return; 905 } 906 info.clearSessionProperties(); 907 info.clear(M_LOCAL_EXISTS); 908 info.setLocalSyncInfo(I_NULL_SYNC_INFO); 909 info.set(M_PHANTOM); 910 info.clearModificationStamp(); 911 info.setMarkers(null); 912 } 913 914 917 public String getFileExtension() { 918 String name = getName(); 919 int index = name.lastIndexOf('.'); 920 if (index == -1) 921 return null; 922 if (index == (name.length() - 1)) 923 return ""; return name.substring(index + 1); 925 } 926 927 public int getFlags(ResourceInfo info) { 928 return (info == null) ? NULL_FLAG : info.getFlags(); 929 } 930 931 934 public IPath getFullPath() { 935 return path; 936 } 937 938 public FileSystemResourceManager getLocalManager() { 939 return workspace.getFileSystemManager(); 940 } 941 942 945 public long getLocalTimeStamp() { 946 ResourceInfo info = getResourceInfo(false, false); 947 return info == null ? IResource.NULL_STAMP : info.getLocalSyncInfo(); 948 } 949 950 953 public IPath getLocation() { 954 IProject project = getProject(); 955 if (project != null && !project.exists()) 956 return null; 957 return getLocalManager().locationFor(this); 958 } 959 960 963 public URI getLocationURI() { 964 IProject project = getProject(); 965 if (project != null && !project.exists()) 966 return null; 967 return getLocalManager().locationURIFor(this); 968 } 969 970 973 public IMarker getMarker(long id) { 974 return new Marker(this, id); 975 } 976 977 protected MarkerManager getMarkerManager() { 978 return workspace.getMarkerManager(); 979 } 980 981 984 public long getModificationStamp() { 985 ResourceInfo info = getResourceInfo(false, false); 986 return info == null ? IResource.NULL_STAMP : info.getModificationStamp(); 987 } 988 989 992 public String getName() { 993 return path.lastSegment(); 994 } 995 996 999 public IContainer getParent() { 1000 int segments = path.segmentCount(); 1001 Assert.isLegal(segments > 1, path.toString()); 1003 if (segments == 2) 1004 return workspace.getRoot().getProject(path.segment(0)); 1005 return (IFolder) workspace.newResource(path.removeLastSegments(1), IResource.FOLDER); 1006 } 1007 1008 1011 public String getPersistentProperty(QualifiedName key) throws CoreException { 1012 ResourceInfo info = getResourceInfo(false, false); 1013 int flags = getFlags(info); 1014 checkAccessible(flags); 1015 checkLocal(flags, DEPTH_ZERO); 1016 return getPropertyManager().getProperty(this, key); 1017 } 1018 1019 1022 public IProject getProject() { 1023 return workspace.getRoot().getProject(path.segment(0)); 1024 } 1025 1026 1029 public IPath getProjectRelativePath() { 1030 return getFullPath().removeFirstSegments(ICoreConstants.PROJECT_SEGMENT_LENGTH); 1031 } 1032 1033 public IPropertyManager getPropertyManager() { 1034 return workspace.getPropertyManager(); 1035 } 1036 1037 1040 public IPath getRawLocation() { 1041 if (isLinked()) 1042 return FileUtil.toPath(((Project) getProject()).internalGetDescription().getLinkLocationURI(getProjectRelativePath())); 1043 return getLocation(); 1044 } 1045 1046 1049 public URI getRawLocationURI() { 1050 if (isLinked()) 1051 return ((Project) getProject()).internalGetDescription().getLinkLocationURI(getProjectRelativePath()); 1052 return getLocationURI(); 1053 } 1054 1055 1058 public ResourceAttributes getResourceAttributes() { 1059 if (!isAccessible()) 1060 return null; 1061 return getLocalManager().attributes(this); 1062 } 1063 1064 1069 public ResourceInfo getResourceInfo(boolean phantom, boolean mutable) { 1070 return workspace.getResourceInfo(getFullPath(), phantom, mutable); 1071 } 1072 1073 1076 public Object getSessionProperty(QualifiedName key) throws CoreException { 1077 ResourceInfo info = getResourceInfo(false, false); 1078 int flags = getFlags(info); 1079 checkAccessible(flags); 1080 checkLocal(flags, DEPTH_ZERO); 1081 return info.getSessionProperty(key); 1082 } 1083 1084 public IFileStore getStore() { 1085 return getLocalManager().getStore(this); 1086 } 1087 1088 1091 public abstract int getType(); 1092 1093 public String getTypeString() { 1094 switch (getType()) { 1095 case FILE : 1096 return "L"; case FOLDER : 1098 return "F"; case PROJECT : 1100 return "P"; case ROOT : 1102 return "R"; } 1104 return ""; } 1106 1107 1110 public IWorkspace getWorkspace() { 1111 return workspace; 1112 } 1113 1114 public int hashCode() { 1115 return getFullPath().hashCode(); 1118 } 1119 1120 1124 protected void internalSetLocal(boolean flag, int depth) throws CoreException { 1125 ResourceInfo info = getResourceInfo(true, true); 1126 if (info.isSet(M_LOCAL_EXISTS) != flag) { 1128 if (flag && !isPhantom(getFlags(info))) { 1129 info.set(M_LOCAL_EXISTS); 1130 workspace.updateModificationStamp(info); 1131 } else { 1132 info.clear(M_LOCAL_EXISTS); 1133 info.clearModificationStamp(); 1134 } 1135 } 1136 if (getType() == IResource.FILE || depth == IResource.DEPTH_ZERO) 1137 return; 1138 if (depth == IResource.DEPTH_ONE) 1139 depth = IResource.DEPTH_ZERO; 1140 IResource[] children = ((IContainer) this).members(); 1141 for (int i = 0; i < children.length; i++) 1142 ((Resource) children[i]).internalSetLocal(flag, depth); 1143 } 1144 1145 1148 public boolean isAccessible() { 1149 return exists(); 1150 } 1151 1152 1155 public boolean isConflicting(ISchedulingRule rule) { 1156 if (rule.getClass().equals(WorkManager.NotifyRule.class)) 1158 return true; 1159 if (!(rule instanceof IResource)) 1160 return false; 1161 IPath otherPath = ((IResource) rule).getFullPath(); 1162 return path.isPrefixOf(otherPath) || otherPath.isPrefixOf(path); 1163 } 1164 1165 1168 public boolean isDerived() { 1169 ResourceInfo info = getResourceInfo(false, false); 1170 return isDerived(getFlags(info)); 1171 } 1172 1173 1180 public boolean isDerived(int flags) { 1181 return flags != NULL_FLAG && ResourceInfo.isSet(flags, ICoreConstants.M_DERIVED); 1182 } 1183 1184 1187 public boolean isLinked() { 1188 return isLinked(NONE); 1189 } 1190 1191 1194 public boolean isLinked(int options) { 1195 if ((options & CHECK_ANCESTORS) != 0) { 1196 IProject project = getProject(); 1197 if (project == null) 1198 return false; 1199 ProjectDescription desc = ((Project) project).internalGetDescription(); 1200 if (desc == null) 1201 return false; 1202 HashMap links = desc.getLinks(); 1203 if (links == null) 1204 return false; 1205 IPath myPath = getProjectRelativePath(); 1206 for (Iterator it = links.values().iterator(); it.hasNext();) { 1207 if (((LinkDescription) it.next()).getProjectRelativePath().isPrefixOf(myPath)) 1208 return true; 1209 } 1210 return false; 1211 } 1212 ResourceInfo info = getResourceInfo(false, false); 1214 return info != null && info.isSet(M_LINK); 1215 } 1216 1217 1221 public boolean isLocal(int depth) { 1222 ResourceInfo info = getResourceInfo(false, false); 1223 return isLocal(getFlags(info), depth); 1224 } 1225 1226 1231 public boolean isLocal(int flags, int depth) { 1232 return flags != NULL_FLAG && ResourceInfo.isSet(flags, M_LOCAL_EXISTS); 1233 } 1234 1235 1243 protected boolean isMember(int flags, int memberFlags) { 1244 int excludeMask = 0; 1245 if ((memberFlags & IContainer.INCLUDE_PHANTOMS) == 0) 1246 excludeMask |= M_PHANTOM; 1247 if ((memberFlags & IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS) == 0) 1248 excludeMask |= M_TEAM_PRIVATE_MEMBER; 1249 if ((memberFlags & IContainer.EXCLUDE_DERIVED) != 0) 1250 excludeMask |= M_DERIVED; 1251 return flags != NULL_FLAG && (flags & excludeMask) == 0; 1253 } 1254 1255 1258 public boolean isPhantom() { 1259 ResourceInfo info = getResourceInfo(true, false); 1260 return isPhantom(getFlags(info)); 1261 } 1262 1263 public boolean isPhantom(int flags) { 1264 return flags != NULL_FLAG && ResourceInfo.isSet(flags, M_PHANTOM); 1265 } 1266 1267 1271 public boolean isReadOnly() { 1272 final ResourceAttributes attributes = getResourceAttributes(); 1273 return attributes == null ? false : attributes.isReadOnly(); 1274 } 1275 1276 1279 public boolean isSynchronized(int depth) { 1280 return getLocalManager().isSynchronized(this, depth); 1281 } 1282 1283 1286 public boolean isTeamPrivateMember() { 1287 ResourceInfo info = getResourceInfo(false, false); 1288 int flags = getFlags(info); 1289 return flags != NULL_FLAG && ResourceInfo.isSet(flags, ICoreConstants.M_TEAM_PRIVATE_MEMBER); 1290 } 1291 1292 1296 public boolean isUnderLink() { 1297 int depth = path.segmentCount(); 1298 if (depth < 2) 1299 return false; 1300 if (depth == 2) 1301 return isLinked(); 1302 IPath linkParent = path.removeLastSegments(depth - 2); 1304 return workspace.getResourceInfo(linkParent, false, false).isSet(ICoreConstants.M_LINK); 1305 } 1306 1307 protected IPath makePathAbsolute(IPath target) { 1308 if (target.isAbsolute()) 1309 return target; 1310 return getParent().getFullPath().append(target); 1311 } 1312 1313 1317 public void move(IPath destination, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException { 1318 int updateFlags = force ? IResource.FORCE : IResource.NONE; 1319 updateFlags |= keepHistory ? IResource.KEEP_HISTORY : IResource.NONE; 1320 move(destination, updateFlags, monitor); 1321 } 1322 1323 1326 public void move(IPath destination, boolean force, IProgressMonitor monitor) throws CoreException { 1327 move(destination, force ? IResource.FORCE : IResource.NONE, monitor); 1328 } 1329 1330 1333 public void move(IPath destination, int updateFlags, IProgressMonitor monitor) throws CoreException { 1334 monitor = Policy.monitorFor(monitor); 1335 try { 1336 String message = NLS.bind(Messages.resources_moving, getFullPath()); 1337 monitor.beginTask(message, Policy.totalWork); 1338 Policy.checkCanceled(monitor); 1339 destination = makePathAbsolute(destination); 1340 checkValidPath(destination, getType(), false); 1341 Resource destResource = workspace.newResource(destination, getType()); 1342 final ISchedulingRule rule = workspace.getRuleFactory().moveRule(this, destResource); 1343 try { 1344 workspace.prepareOperation(rule, monitor); 1345 assertMoveRequirements(destination, getType(), updateFlags); 1348 workspace.beginOperation(true); 1349 IFileStore originalStore = getStore(); 1350 message = Messages.resources_moveProblem; 1351 MultiStatus status = new MultiStatus(ResourcesPlugin.PI_RESOURCES, IStatus.ERROR, message, null); 1352 WorkManager workManager = workspace.getWorkManager(); 1353 ResourceTree tree = new ResourceTree(workspace.getFileSystemManager(), workManager.getLock(), status, updateFlags); 1354 boolean success = false; 1355 int depth = 0; 1356 try { 1357 depth = workManager.beginUnprotected(); 1358 success = unprotectedMove(tree, destResource, updateFlags, monitor); 1359 } finally { 1360 workManager.endUnprotected(depth); 1361 } 1362 tree.makeInvalid(); 1364 if (success) { 1366 workspace.getAliasManager().updateAliases(this, originalStore, IResource.DEPTH_INFINITE, monitor); 1367 workspace.getAliasManager().updateAliases(destResource, destResource.getStore(), IResource.DEPTH_INFINITE, monitor); 1368 } 1369 if (!tree.getStatus().isOK()) 1370 throw new ResourceException(tree.getStatus()); 1371 } catch (OperationCanceledException e) { 1372 workspace.getWorkManager().operationCanceled(); 1373 throw e; 1374 } finally { 1375 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 1376 } 1377 } finally { 1378 monitor.done(); 1379 } 1380 } 1381 1382 1385 public void move(IProjectDescription description, boolean force, boolean keepHistory, IProgressMonitor monitor) throws CoreException { 1386 int updateFlags = force ? IResource.FORCE : IResource.NONE; 1387 updateFlags |= keepHistory ? IResource.KEEP_HISTORY : IResource.NONE; 1388 move(description, updateFlags, monitor); 1389 } 1390 1391 1394 public void move(IProjectDescription description, int updateFlags, IProgressMonitor monitor) throws CoreException { 1395 Assert.isNotNull(description); 1396 if (getType() != IResource.PROJECT) { 1397 String message = NLS.bind(Messages.resources_moveNotProject, getFullPath(), description.getName()); 1398 throw new ResourceException(IResourceStatus.INVALID_VALUE, getFullPath(), message, null); 1399 } 1400 ((Project) this).move(description, updateFlags, monitor); 1401 } 1402 1403 1406 public void refreshLocal(int depth, IProgressMonitor monitor) throws CoreException { 1407 monitor = Policy.monitorFor(monitor); 1408 try { 1409 boolean isRoot = getType() == ROOT; 1410 String message = isRoot ? Messages.resources_refreshingRoot : NLS.bind(Messages.resources_refreshing, getFullPath()); 1411 monitor.beginTask("", Policy.totalWork); monitor.subTask(message); 1413 boolean build = false; 1414 final ISchedulingRule rule = workspace.getRuleFactory().refreshRule(this); 1415 try { 1416 workspace.prepareOperation(rule, monitor); 1417 if (!isRoot && !getProject().isAccessible()) 1418 return; 1419 workspace.beginOperation(true); 1420 build = getLocalManager().refresh(this, depth, true, Policy.subMonitorFor(monitor, Policy.opWork)); 1421 } catch (OperationCanceledException e) { 1422 workspace.getWorkManager().operationCanceled(); 1423 throw e; 1424 } catch (Error e) { 1425 Policy.log(e); 1427 throw e; 1428 } catch (RuntimeException e) { 1429 Policy.log(e); 1431 throw e; 1432 } finally { 1433 workspace.endOperation(rule, build, Policy.subMonitorFor(monitor, Policy.endOpWork)); 1434 } 1435 } finally { 1436 monitor.done(); 1437 } 1438 } 1439 1440 1443 public String requestName() { 1444 return getName(); 1445 } 1446 1447 1450 public IPath requestPath() { 1451 return getFullPath(); 1452 } 1453 1454 1457 public void revertModificationStamp(long value) throws CoreException { 1458 if (value < 0) 1459 throw new IllegalArgumentException ("Illegal value: " + value); ResourceInfo info = getResourceInfo(false, false); 1463 int flags = getFlags(info); 1464 checkAccessible(flags); 1465 checkLocal(flags, DEPTH_ZERO); 1466 info.setModificationStamp(value); 1467 } 1468 1469 1472 public void setDerived(boolean isDerived) throws CoreException { 1473 ResourceInfo info = getResourceInfo(false, false); 1477 int flags = getFlags(info); 1478 checkAccessible(flags); 1479 if (info.getType() == FILE || info.getType() == FOLDER) { 1481 if (isDerived) { 1482 info.set(ICoreConstants.M_DERIVED); 1483 } else { 1484 info.clear(ICoreConstants.M_DERIVED); 1485 } 1486 } 1487 } 1488 1489 1493 public void setLocal(boolean flag, int depth, IProgressMonitor monitor) throws CoreException { 1494 monitor = Policy.monitorFor(monitor); 1495 try { 1496 String message = Messages.resources_setLocal; 1497 monitor.beginTask(message, Policy.totalWork); 1498 try { 1499 workspace.prepareOperation(null, monitor); 1500 workspace.beginOperation(true); 1501 internalSetLocal(flag, depth); 1502 monitor.worked(Policy.opWork); 1503 } finally { 1504 workspace.endOperation(null, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 1505 } 1506 } finally { 1507 monitor.done(); 1508 } 1509 } 1510 1511 1514 public long setLocalTimeStamp(long value) throws CoreException { 1515 if (value < 0) 1516 throw new IllegalArgumentException ("Illegal value: " + value); ResourceInfo info = getResourceInfo(false, false); 1520 int flags = getFlags(info); 1521 checkAccessible(flags); 1522 checkLocal(flags, DEPTH_ZERO); 1523 return getLocalManager().setLocalTimeStamp(this, info, value); 1524 } 1525 1526 1529 public void setPersistentProperty(QualifiedName key, String value) throws CoreException { 1530 ResourceInfo info = getResourceInfo(false, false); 1531 int flags = getFlags(info); 1532 checkAccessible(flags); 1533 checkLocal(flags, DEPTH_ZERO); 1534 getPropertyManager().setProperty(this, key, value); 1535 } 1536 1537 1541 public void setReadOnly(boolean readonly) { 1542 ResourceAttributes attributes = new ResourceAttributes(); 1543 attributes.setReadOnly(readonly); 1544 try { 1545 setResourceAttributes(attributes); 1546 } catch (CoreException e) { 1547 } 1549 } 1550 1551 1554 public void setResourceAttributes(ResourceAttributes attributes) throws CoreException { 1555 ResourceInfo info = getResourceInfo(false, false); 1556 int flags = getFlags(info); 1557 checkAccessible(flags); 1558 checkLocal(flags, DEPTH_ZERO); 1559 getLocalManager().setResourceAttributes(this, attributes); 1560 } 1561 1562 1565 public void setSessionProperty(QualifiedName key, Object value) throws CoreException { 1566 ResourceInfo info = getResourceInfo(false, false); 1570 int flags = getFlags(info); 1571 checkAccessible(flags); 1572 checkLocal(flags, DEPTH_ZERO); 1573 info.setSessionProperty(key, value); 1574 } 1575 1576 1579 public void setTeamPrivateMember(boolean isTeamPrivate) throws CoreException { 1580 ResourceInfo info = getResourceInfo(false, false); 1584 int flags = getFlags(info); 1585 checkAccessible(flags); 1586 if (info.getType() == FILE || info.getType() == FOLDER) { 1588 if (isTeamPrivate) { 1589 info.set(ICoreConstants.M_TEAM_PRIVATE_MEMBER); 1590 } else { 1591 info.clear(ICoreConstants.M_TEAM_PRIVATE_MEMBER); 1592 } 1593 } 1594 } 1595 1596 1600 public boolean synchronizing(ResourceInfo info) { 1601 return info != null && info.getSyncInfo(false) != null; 1602 } 1603 1604 1607 public String toString() { 1608 return getTypeString() + getFullPath().toString(); 1609 } 1610 1611 1614 public void touch(IProgressMonitor monitor) throws CoreException { 1615 monitor = Policy.monitorFor(monitor); 1616 try { 1617 String message = NLS.bind(Messages.resources_touch, getFullPath()); 1618 monitor.beginTask(message, Policy.totalWork); 1619 final ISchedulingRule rule = workspace.getRuleFactory().modifyRule(this); 1620 try { 1621 workspace.prepareOperation(rule, monitor); 1622 ResourceInfo info = getResourceInfo(false, false); 1623 int flags = getFlags(info); 1624 checkAccessible(flags); 1625 checkLocal(flags, DEPTH_ZERO); 1626 1627 workspace.beginOperation(true); 1628 info = getResourceInfo(false, true); 1630 info.incrementContentId(); 1631 info.clear(M_CONTENT_CACHE); 1633 workspace.updateModificationStamp(info); 1634 monitor.worked(Policy.opWork); 1635 } catch (OperationCanceledException e) { 1636 workspace.getWorkManager().operationCanceled(); 1637 throw e; 1638 } finally { 1639 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 1640 } 1641 } finally { 1642 monitor.done(); 1643 } 1644 } 1645 1646 1650 private void unprotectedDelete(ResourceTree tree, int updateFlags, IProgressMonitor monitor) throws CoreException { 1651 IMoveDeleteHook hook = workspace.getMoveDeleteHook(); 1652 switch (getType()) { 1653 case IResource.FILE : 1654 if (!hook.deleteFile(tree, (IFile) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2))) 1655 tree.standardDeleteFile((IFile) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000)); 1656 break; 1657 case IResource.FOLDER : 1658 if (!hook.deleteFolder(tree, (IFolder) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2))) 1659 tree.standardDeleteFolder((IFolder) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000)); 1660 break; 1661 case IResource.PROJECT : 1662 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, this)); 1663 if (!hook.deleteProject(tree, (IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / 2))) 1664 tree.standardDeleteProject((IProject) this, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000)); 1665 break; 1666 case IResource.ROOT : 1667 IProject[] projects = ((IWorkspaceRoot) this).getProjects(); 1668 for (int i = 0; i < projects.length; i++) { 1669 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_DELETE, projects[i])); 1670 if (!hook.deleteProject(tree, projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length / 2))) 1671 tree.standardDeleteProject(projects[i], updateFlags, Policy.subMonitorFor(monitor, Policy.opWork * 1000 / projects.length)); 1672 } 1673 } 1674 } 1675 1676 1681 private boolean unprotectedMove(ResourceTree tree, final IResource destination, int updateFlags, IProgressMonitor monitor) throws CoreException, ResourceException { 1682 IMoveDeleteHook hook = workspace.getMoveDeleteHook(); 1683 switch (getType()) { 1684 case IResource.FILE : 1685 if (isLinked()) 1686 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); 1687 if (!hook.moveFile(tree, (IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) 1688 tree.standardMoveFile((IFile) this, (IFile) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); 1689 break; 1690 case IResource.FOLDER : 1691 if (isLinked()) 1692 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_LINK_MOVE, this, destination, updateFlags)); 1693 if (!hook.moveFolder(tree, (IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) 1694 tree.standardMoveFolder((IFolder) this, (IFolder) destination, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); 1695 break; 1696 case IResource.PROJECT : 1697 IProject project = (IProject) this; 1698 if (getName().equals(destination.getName())) 1700 return false; 1701 workspace.broadcastEvent(LifecycleEvent.newEvent(LifecycleEvent.PRE_PROJECT_MOVE, this, destination, updateFlags)); 1703 IProjectDescription description = project.getDescription(); 1704 description.setName(destination.getName()); 1705 if (!hook.moveProject(tree, project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork / 2))) 1706 tree.standardMoveProject(project, description, updateFlags, Policy.subMonitorFor(monitor, Policy.opWork)); 1707 break; 1708 case IResource.ROOT : 1709 String msg = Messages.resources_moveRoot; 1710 throw new ResourceException(new ResourceStatus(IResourceStatus.INVALID_VALUE, getFullPath(), msg)); 1711 } 1712 return true; 1713 } 1714} 1715 | Popular Tags |