1 11 package org.eclipse.core.internal.resources; 12 13 import java.net.URI ; 14 import org.eclipse.core.filesystem.IFileInfo; 15 import org.eclipse.core.filesystem.IFileStore; 16 import org.eclipse.core.internal.utils.Messages; 17 import org.eclipse.core.internal.utils.Policy; 18 import org.eclipse.core.resources.*; 19 import org.eclipse.core.runtime.*; 20 import org.eclipse.core.runtime.jobs.ISchedulingRule; 21 import org.eclipse.osgi.util.NLS; 22 23 public class Folder extends Container implements IFolder { 24 protected Folder(IPath path, Workspace container) { 25 super(path, container); 26 } 27 28 protected void assertCreateRequirements(IFileStore store, IFileInfo localInfo, int updateFlags) throws CoreException { 29 checkDoesNotExist(); 30 Container parent = (Container) getParent(); 31 ResourceInfo info = parent.getResourceInfo(false, false); 32 parent.checkAccessible(getFlags(info)); 33 34 final boolean force = (updateFlags & IResource.FORCE) != 0; 35 if (!force && localInfo.exists()) { 36 if (!Workspace.caseSensitive) { 38 String name = getLocalManager().getLocalName(store); 39 if (name != null && !store.getName().equals(name)) { 40 String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString()); 41 throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null); 42 } 43 } 44 String msg = NLS.bind(Messages.resources_fileExists, store.toString()); 45 throw new ResourceException(IResourceStatus.FAILED_WRITE_LOCAL, getFullPath(), msg, null); 46 } 47 } 48 49 59 public IFile changeToFile() throws CoreException { 60 getPropertyManager().deleteProperties(this, IResource.DEPTH_INFINITE); 61 IFile result = workspace.getRoot().getFile(path); 62 if (isLinked()) { 63 URI location = getRawLocationURI(); 64 delete(IResource.NONE, null); 65 result.createLink(location, IResource.ALLOW_MISSING_LOCAL, null); 66 } else { 67 workspace.deleteResource(this); 68 workspace.createResource(result, false); 69 } 70 return result; 71 } 72 73 76 public void create(int updateFlags, boolean local, IProgressMonitor monitor) throws CoreException { 77 final boolean force = (updateFlags & IResource.FORCE) != 0; 78 monitor = Policy.monitorFor(monitor); 79 try { 80 String message = NLS.bind(Messages.resources_creating, getFullPath()); 81 monitor.beginTask(message, Policy.totalWork); 82 checkValidPath(path, FOLDER, true); 83 final ISchedulingRule rule = workspace.getRuleFactory().createRule(this); 84 try { 85 workspace.prepareOperation(rule, monitor); 86 IFileStore store = getStore(); 87 IFileInfo localInfo = store.fetchInfo(); 88 assertCreateRequirements(store, localInfo, updateFlags); 89 workspace.beginOperation(true); 90 if (force && !Workspace.caseSensitive && localInfo.exists()) { 91 String name = getLocalManager().getLocalName(store); 92 if (name == null || localInfo.getName().equals(name)) { 93 delete(true, null); 94 } else { 95 String msg = NLS.bind(Messages.resources_existsLocalDifferentCase, new Path(store.toString()).removeLastSegments(1).append(name).toOSString()); 97 throw new ResourceException(IResourceStatus.CASE_VARIANT_EXISTS, getFullPath(), msg, null); 98 } 99 } 100 internalCreate(updateFlags, local, Policy.subMonitorFor(monitor, Policy.opWork)); 101 workspace.getAliasManager().updateAliases(this, getStore(), IResource.DEPTH_ZERO, monitor); 102 } catch (OperationCanceledException e) { 103 workspace.getWorkManager().operationCanceled(); 104 throw e; 105 } finally { 106 workspace.endOperation(rule, true, Policy.subMonitorFor(monitor, Policy.endOpWork)); 107 } 108 } finally { 109 monitor.done(); 110 } 111 } 112 113 116 public void create(boolean force, boolean local, IProgressMonitor monitor) throws CoreException { 117 create((force ? IResource.FORCE : IResource.NONE), local, monitor); 119 } 120 121 126 public void ensureExists(IProgressMonitor monitor) throws CoreException { 127 ResourceInfo info = getResourceInfo(false, false); 128 int flags = getFlags(info); 129 if (exists(flags, true)) 130 return; 131 if (exists(flags, false)) { 132 String message = NLS.bind(Messages.resources_folderOverFile, getFullPath()); 133 throw new ResourceException(IResourceStatus.RESOURCE_WRONG_TYPE, getFullPath(), message, null); 134 } 135 Container parent = (Container) getParent(); 136 if (parent.getType() == PROJECT) { 137 info = parent.getResourceInfo(false, false); 138 parent.checkExists(getFlags(info), true); 139 } else 140 ((Folder) parent).ensureExists(monitor); 141 internalCreate(IResource.FORCE, true, monitor); 142 } 143 144 147 public String getDefaultCharset(boolean checkImplicit) { 148 if (!exists()) 150 return checkImplicit ? workspace.getCharsetManager().getCharsetFor(getFullPath().removeLastSegments(1), true) : null; 151 return workspace.getCharsetManager().getCharsetFor(getFullPath(), checkImplicit); 152 } 153 154 157 public int getType() { 158 return FOLDER; 159 } 160 161 public void internalCreate(int updateFlags, boolean local, IProgressMonitor monitor) throws CoreException { 162 monitor = Policy.monitorFor(monitor); 163 try { 164 String message = NLS.bind(Messages.resources_creating, getFullPath()); 165 monitor.beginTask(message, Policy.totalWork); 166 workspace.createResource(this, updateFlags); 167 if (local) { 168 try { 169 final boolean force = (updateFlags & IResource.FORCE) != 0; 170 getLocalManager().write(this, force, Policy.subMonitorFor(monitor, Policy.totalWork)); 171 } catch (CoreException e) { 172 workspace.deleteResource(this); 174 throw e; } 176 } 177 internalSetLocal(local, DEPTH_ZERO); 178 if (!local) 179 getResourceInfo(true, true).clearModificationStamp(); 180 } finally { 181 monitor.done(); 182 } 183 } 184 } 185 | Popular Tags |