Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 11 package org.eclipse.core.internal.localstore; 12 13 import java.io.File ; 14 import java.net.URI ; 15 import org.eclipse.core.filesystem.EFS; 16 import org.eclipse.core.filesystem.IFileStore; 17 import org.eclipse.core.internal.utils.FileUtil; 18 import org.eclipse.core.resources.IPathVariableManager; 19 import org.eclipse.core.resources.ResourcesPlugin; 20 import org.eclipse.core.runtime.*; 21 22 26 public class FileStoreRoot { 27 private int chop; 28 32 private boolean isValid = true; 33 38 private IPath localRoot = null; 39 40 private URI root; 41 42 private final IPathVariableManager variableManager; 43 44 51 FileStoreRoot(URI rootURI, IPath workspacePath) { 52 Assert.isNotNull(rootURI); 53 Assert.isNotNull(workspacePath); 54 this.variableManager = ResourcesPlugin.getWorkspace().getPathVariableManager(); 55 this.root = rootURI; 56 this.chop = workspacePath.segmentCount(); 57 this.localRoot = toLocalPath(root); 58 } 59 60 65 public URI computeURI(IPath workspacePath) { 66 IPath childPath = workspacePath.removeFirstSegments(chop); 67 final URI rootURI = variableManager.resolveURI(root); 68 if (childPath.segmentCount() == 0) 69 return rootURI; 70 try { 71 return EFS.getStore(rootURI).getChild(childPath).toURI(); 72 } catch (CoreException e) { 73 return null; 74 } 75 } 76 77 81 IFileStore createStore(IPath workspacePath) throws CoreException { 82 IPath childPath = workspacePath.removeFirstSegments(chop); 83 IFileStore rootStore; 84 final URI uri = variableManager.resolveURI(root); 85 if (!uri.isAbsolute()) { 86 return EFS.getNullFileSystem().getStore(workspacePath); 89 } 90 rootStore = EFS.getStore(uri); 91 if (childPath.segmentCount() == 0) 92 return rootStore; 93 return rootStore.getChild(childPath); 94 } 95 96 boolean isValid() { 97 return isValid; 98 } 99 100 IPath localLocation(IPath workspacePath) { 101 if (localRoot == null) 102 return null; 103 IPath location; 104 if (workspacePath.segmentCount() <= chop) 105 location = localRoot; 106 else 107 location = localRoot.append(workspacePath.removeFirstSegments(chop)); 108 location = variableManager.resolvePath(location); 109 if (!location.isAbsolute()) 111 return null; 112 return location; 113 } 114 115 void setValid(boolean value) { 116 this.isValid = value; 117 } 118 119 122 private IPath toLocalPath(URI uri) { 123 try { 124 final File localFile = EFS.getStore(uri).toLocalFile(EFS.NONE, null); 125 return localFile == null ? null : new Path(localFile.getAbsolutePath()); 126 } catch (CoreException e) { 127 return FileUtil.toPath(uri); 128 } 129 } 130 } 131
| Popular Tags
|