Java Code Examples for org.eclipse.core.filesystem.IFileStore#fetchInfo()
The following examples show how to use
org.eclipse.core.filesystem.IFileStore#fetchInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BuildSettingWizardPage.java From sarl with Apache License 2.0 | 6 votes |
private void rememberExisitingFolders(URI projectLocation) { this.orginalFolders = new TreeMap<>(); try { final IFileStore[] children = EFS.getStore(projectLocation).childStores(EFS.NONE, null); for (int i = 0; i < children.length; i++) { final IFileStore child = children[i]; final IFileInfo info = child.fetchInfo(); if (info.isDirectory() && info.exists() && !this.orginalFolders.containsKey(info.getName())) { this.orginalFolders.put(info.getName(), child); } } } catch (CoreException e) { SARLEclipsePlugin.getDefault().log(e); } }
Example 2
Source File: NewJavaProjectWizardPageTwo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void rememberExisitingFolders(URI projectLocation) { fOrginalFolders= new HashSet<IFileStore>(); try { IFileStore[] children= EFS.getStore(projectLocation).childStores(EFS.NONE, null); for (int i= 0; i < children.length; i++) { IFileStore child= children[i]; IFileInfo info= child.fetchInfo(); if (info.isDirectory() && info.exists() && !fOrginalFolders.contains(child.getName())) { fOrginalFolders.add(child); } } } catch (CoreException e) { JavaPlugin.log(e); } }
Example 3
Source File: Storage2UriMapperImpl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
private Iterable<Pair<IStorage, IProject>> getStorages(/* @NonNull */ URI uri, IFile file) { if (file == null || !file.isAccessible()) { Iterable<Pair<IStorage, IProject>> result = contribution.getStorages(uri); if (result == null || !result.iterator().hasNext()) { // Handle files external to the workspace. But check contribution first to be backwards compatible. if (uri.isFile()) { Path filePath = new Path(uri.toFileString()); IFileStore fileStore = EFS.getLocalFileSystem().getStore(filePath); IFileInfo fileInfo = fileStore.fetchInfo(); if (fileInfo.exists() && !fileInfo.isDirectory()) { return Collections.singletonList( Tuples.<IStorage, IProject> create(new FileStoreStorage(fileStore, fileInfo, filePath), (IProject) null)); } } } return result; } return Collections.singleton(Tuples.<IStorage, IProject> create(file, file.getProject())); }
Example 4
Source File: FileOpener.java From gama with GNU General Public License v3.0 | 6 votes |
public static IEditorPart openFileInFileSystem(final URI uri) throws PartInitException { if (uri == null) { return null; } IFileStore fileStore; try { fileStore = EFS.getLocalFileSystem().getStore(Path.fromOSString(uri.toFileString())); } catch (final Exception e1) { MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "The file'" + uri.toString() + "' cannot be found."); return null; } IFileInfo info; try { info = fileStore.fetchInfo(); } catch (final Exception e) { MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "The file'" + uri.toString() + "' cannot be found."); return null; } if (!info.exists()) { MessageDialog.openWarning(WorkbenchHelper.getShell(), "No file found", "The file'" + uri.toString() + "' cannot be found."); } return IDE.openInternalEditorOnFileStore(PAGE, fileStore); }
Example 5
Source File: Packager.java From orion.server with Eclipse Public License 1.0 | 5 votes |
protected void writeZip(IFileStore source, IPath path, ZipOutputStream zos) throws CoreException, IOException { /* load .cfignore if present */ IFileStore cfIgnoreFile = source.getChild(CF_IGNORE_FILE); if (cfIgnoreFile.fetchInfo().exists()) { IgnoreNode node = new IgnoreNode(); InputStream is = null; try { is = cfIgnoreFile.openInputStream(EFS.NONE, null); node.parse(is); cfIgnore.put(source.toURI(), node); } finally { if (is != null) is.close(); } } IFileInfo info = source.fetchInfo(EFS.NONE, null); if (info.isDirectory()) { if (!isIgnored(source, path, true)) for (IFileStore child : source.childStores(EFS.NONE, null)) writeZip(child, path.append(child.getName()), zos); } else { if (!isIgnored(source, path, false)) { ZipEntry entry = new ZipEntry(path.toString()); zos.putNextEntry(entry); IOUtilities.pipe(source.openInputStream(EFS.NONE, null), zos, true, false); } } }
Example 6
Source File: ResourceManager.java From gama with GNU General Public License v3.0 | 5 votes |
public boolean validateLocation(final IFile resource) { if (!resource.isLinked()) { return true; } if (DEBUG.IS_ON()) { DEBUG.OUT("Validating link location of " + resource); } final boolean internal = ResourcesPlugin.getWorkspace().validateLinkLocation(resource, resource.getLocation()).isOK(); if (!internal) { return false; } final IFileStore file = EFS.getLocalFileSystem().getStore(resource.getLocation()); final IFileInfo info = file.fetchInfo(); return info.exists(); }
Example 7
Source File: FileUtils.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Returns a best guess URI based on the target string and an optional URI specifying from where the relative URI * should be run. If existingResource is null, then the root of the workspace is used as the relative URI * * @param target * a String giving the path * @param existingResource * the URI of the resource from which relative URIs should be interpreted * @author Alexis Drogoul, July 2018 * @return an URI or null if it cannot be determined. */ public static URI getURI(final String target, final URI existingResource) { if (target == null) { return null; } try { final IPath path = Path.fromOSString(target); final IFileStore file = EFS.getLocalFileSystem().getStore(path); final IFileInfo info = file.fetchInfo(); if (info.exists()) { // We have an absolute file final URI fileURI = URI.createFileURI(target); return fileURI; } else { final URI first = URI.createURI(target, false); URI root; if (!existingResource.isPlatformResource()) { root = URI.createPlatformResourceURI(existingResource.toString(), false); } else { root = existingResource; } if (root == null) { root = WORKSPACE_URI; } final URI iu = first.resolve(root); if (isFileExistingInWorkspace(iu)) { return iu; } return null; } } catch (final Exception e) { return null; } }
Example 8
Source File: FileUtils.java From gama with GNU General Public License v3.0 | 5 votes |
private static String findOutsideWorkspace(final String fp, final URI modelBase, final boolean mustExist) { if (!mustExist) { return fp; } final IFileStore file = FILE_SYSTEM.getStore(new Path(fp)); final IFileInfo info = file.fetchInfo(); if (info.exists()) { final IFile linkedFile = createLinkToExternalFile(fp, modelBase); if (linkedFile == null) { return fp; } return linkedFile.getLocation().toFile().getAbsolutePath(); } return null; }
Example 9
Source File: RemoteImportTracesOperation.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private IResource downloadFileTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException { IFolder folder = traceFolder; String traceName = trace.getName(); traceName = TmfTraceCoreUtils.validateName(traceName); IResource resource = folder.findMember(traceName); if ((resource != null) && resource.exists()) { String newName = fConflictHandler.checkAndHandleNameClash(resource.getFullPath(), monitor); if (newName == null) { return null; } traceName = newName; } SubMonitor subMonitor = SubMonitor.convert(monitor, 1); subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, 1); IPath destination = folder.getLocation().addTrailingSeparator().append(traceName); IFileInfo info = trace.fetchInfo(); subMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + trace.getName()); try (InputStream in = trace.openInputStream(EFS.NONE, new NullProgressMonitor())) { copy(in, folder, destination, subMonitor, info.getLength()); } folder.refreshLocal(IResource.DEPTH_INFINITE, null); return folder.findMember(traceName); }
Example 10
Source File: XtextDocumentProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public long getModificationStamp(Object element) { if (isWorkspaceExternalEditorInput(element)) { IFileStore fileStore = Adapters.adapt(element, IFileStore.class); if (fileStore != null) { IFileInfo info = fileStore.fetchInfo(); if (info.exists()) { return info.getLastModified(); } } return IDocumentExtension4.UNKNOWN_MODIFICATION_STAMP; } else { return super.getModificationStamp(element); } }
Example 11
Source File: NewFileServlet.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { traceRequest(req); String pathInfo = req.getPathInfo(); IPath path = pathInfo == null ? Path.ROOT : new Path(pathInfo); // prevent path canonicalization hacks if (pathInfo != null && !pathInfo.equals(path.toString())) { handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", pathInfo), null)); return; } //don't allow anyone to mess with metadata if (path.segmentCount() > 0 && ".metadata".equals(path.segment(0))) { //$NON-NLS-1$ handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", pathInfo), null)); return; } IFileStore file = getFileStore(req, path); IFileStore testLink = file; while (testLink != null) { IFileInfo info = testLink.fetchInfo(); if (info.getAttribute(EFS.ATTRIBUTE_SYMLINK)) { if (file == testLink) { handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_FORBIDDEN, NLS.bind("Forbidden: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null)); } else { handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("File not found: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null)); } return; } testLink = testLink.getParent(); } if (file == null) { handleException(resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, NLS.bind("File not found: {0}", EncodingUtils.encodeForHTML(pathInfo.toString())), null)); return; } if (fileSerializer.handleRequest(req, resp, file)) return; // finally invoke super to return an error for requests we don't know how to handle super.doGet(req, resp); }
Example 12
Source File: FileHandlerV1.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private void handlePutMetadata(BufferedReader reader, String boundary, IFileStore file) throws IOException, CoreException, JSONException { StringBuffer buf = new StringBuffer(); String line; while ((line = reader.readLine()) != null && !line.equals(boundary)) buf.append(line); // merge with existing metadata FileInfo info = (FileInfo) file.fetchInfo(EFS.NONE, null); ServletFileStoreHandler.copyJSONToFileInfo(new JSONObject(buf.toString()), info); file.putInfo(info, EFS.SET_ATTRIBUTES, null); }
Example 13
Source File: IDEEditputProvider.java From birt with Eclipse Public License 1.0 | 5 votes |
public IEditorInput createEditorInput( Object file ) { if (file instanceof File) { File handle = (File)file; String fileName = handle.getAbsolutePath( ); IWorkspace space = ResourcesPlugin.getWorkspace( ); IWorkspaceRoot root = space.getRoot( ); try { //IFile[] resources = root.findFilesForLocationURI( new URL("file:///" + fileName ).toURI( ) ); //$NON-NLS-1$ IFile[] resources = root.findFilesForLocationURI(new File( fileName ).toURI( ) ); //$NON-NLS-1$ if (resources != null && resources.length > 0) { IEditorInput input = new FileEditorInput(resources[0]); return input; } else { IFileStore fileStore = EFS.getLocalFileSystem().getStore(new Path(fileName)); IFileInfo fetchInfo = fileStore.fetchInfo(); if (!fetchInfo.isDirectory() && fetchInfo.exists()) { return new FileStoreEditorInput(fileStore); } } } catch(Exception e) { return null; } } return null; }
Example 14
Source File: DocumentUtils.java From KaiZen-OpenAPI-Editor with Eclipse Public License 1.0 | 4 votes |
public static IFileStore getExternalFile(IPath path) { IFileStore fileStore = EFS.getLocalFileSystem().getStore(path); IFileInfo fileInfo = fileStore.fetchInfo(); return fileInfo != null && fileInfo.exists() ? fileStore : null; }
Example 15
Source File: RemoteImportTracesOperation.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
private IResource downloadDirectoryTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException { IFileStore[] sources = trace.childStores(EFS.NONE, monitor); // Don't import just the metadata file if (sources.length > 1) { String traceName = trace.getName(); traceName = TmfTraceCoreUtils.validateName(traceName); IFolder folder = traceFolder.getFolder(traceName); String newName = fConflictHandler.checkAndHandleNameClash(folder.getFullPath(), monitor); if (newName == null) { return null; } folder = traceFolder.getFolder(newName); folder.create(true, true, null); SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length); subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, sources.length); for (IFileStore source : sources) { if (subMonitor.isCanceled()) { throw new InterruptedException(); } IPath destination = folder.getLocation().addTrailingSeparator().append(source.getName()); IFileInfo info = source.fetchInfo(); // TODO allow for downloading index directory and files if (!info.isDirectory()) { SubMonitor childMonitor = subMonitor.newChild(1); childMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + source.getName()); try (InputStream in = source.openInputStream(EFS.NONE, new NullProgressMonitor())) { copy(in, folder, destination, childMonitor, info.getLength()); } } } folder.refreshLocal(IResource.DEPTH_INFINITE, null); return folder; } return null; }
Example 16
Source File: RemoteGenerateManifestOperation.java From tracecompass with Eclipse Public License 2.0 | 4 votes |
/** * Scan traceFolder for files that match the patterns specified in the * template file. When there is a match, the trace package element is used * to determine the trace name and trace type. * * @param traceGroup * The parent trace group element * @param parentElement * The immediate parent trace group or folder element * @param traceFolder * The folder to scan * @param recursionLevel * The recursion level (needed to find directory traces under the traceFolder * @param monitor * The progress monitor * @throws CoreException * Thrown by the file system implementation * @throws InterruptedException * Thrown if operation was cancelled */ private void generateElementsFromArchive( final RemoteImportTraceGroupElement traceGroup, final TracePackageElement parentElement, final IFileStore traceFolder, final int recursionLevel, IProgressMonitor monitor) throws CoreException, InterruptedException { int localRecursionLevel = recursionLevel + 1; IFileStore[] sources = traceFolder.childStores(EFS.NONE, monitor); for (int i = 0; i < sources.length; i++) { ModalContext.checkCanceled(monitor); SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length); IFileStore fileStore = sources[i]; IPath fullArchivePath = TmfTraceCoreUtils.newSafePath(fileStore.toURI().getPath()); IFileInfo sourceInfo = fileStore.fetchInfo(); if (!sourceInfo.isDirectory()) { String rootPathString = traceGroup.getRootImportPath(); IPath rootPath = TmfTraceCoreUtils.newSafePath(rootPathString); IPath relativeTracePath = Path.EMPTY; if (rootPath.isPrefixOf(fullArchivePath)) { relativeTracePath = fullArchivePath.makeRelativeTo(rootPath); } Entry<Pattern, TracePackageTraceElement> matchingTemplateEntry = getMatchingTemplateElement(relativeTracePath); if (matchingTemplateEntry != null) { TracePackageTraceElement matchingTemplateElement = matchingTemplateEntry.getValue(); String traceType = matchingTemplateElement.getTraceType(); // If a single file is part of a directory trace, use the parent directory instead TracePackageElement parent = parentElement; if (matchesDirectoryTrace(relativeTracePath, matchingTemplateEntry)) { fullArchivePath = fullArchivePath.removeLastSegments(1); fDirectoryTraces.add(fullArchivePath); fileStore = fileStore.getParent(); sourceInfo = fileStore.fetchInfo(); parent = parentElement.getParent(); // Let the auto-detection choose the best trace type traceType = null; } else if ((localRecursionLevel > 1) && (!traceGroup.isRecursive())) { // Don't consider file traces on level 2 if it's not recursive continue; } if (sourceInfo.getLength() > 0 || sourceInfo.isDirectory()) { // Only add non-empty files String traceName = fullArchivePath.lastSegment(); String fileName = fileStore.getName(); // create new elements to decouple from input elements TracePackageTraceElement traceElement = new TracePackageTraceElement(parent, traceName, traceType); RemoteImportTraceFilesElement tracePackageFilesElement = new RemoteImportTraceFilesElement(traceElement, fileName, fileStore); tracePackageFilesElement.setVisible(false); } } } else { if (traceGroup.isRecursive() || localRecursionLevel < 2) { RemoteImportFolderElement folder = new RemoteImportFolderElement(parentElement, fileStore.getName()); generateElementsFromArchive(traceGroup, folder, fileStore, localRecursionLevel, subMonitor); } } } }
Example 17
Source File: FileUtils.java From gama with GNU General Public License v3.0 | 4 votes |
public static boolean isDirectoryOrNullExternalFile(final String path) { final IFileStore external = FILE_SYSTEM.getStore(new Path(path)); final IFileInfo info = external.fetchInfo(); if (info.isDirectory() || !info.exists()) { return true; } return false; }
Example 18
Source File: LocalWebServerHttpRequestHandler.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void handleRequest(HttpRequest request, HttpResponse response, boolean head) throws HttpException, IOException, CoreException, URISyntaxException { String target = URLDecoder.decode(request.getRequestLine().getUri(), IOUtil.UTF_8); URI uri = URIUtil.fromString(target); IFileStore fileStore = uriMapper.resolve(uri); IFileInfo fileInfo = fileStore.fetchInfo(); if (fileInfo.isDirectory()) { fileInfo = getIndex(fileStore); if (fileInfo.exists()) { fileStore = fileStore.getChild(fileInfo.getName()); } } if (!fileInfo.exists()) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); response.setEntity(createTextEntity(MessageFormat.format( Messages.LocalWebServerHttpRequestHandler_FILE_NOT_FOUND, uri.getPath()))); } else if (fileInfo.isDirectory()) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_FORBIDDEN)); } else { response.setStatusCode(HttpStatus.SC_OK); if (head) { response.setEntity(null); } else { File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor()); final File temporaryFile = (file == null) ? fileStore.toLocalFile(EFS.CACHE, new NullProgressMonitor()) : null; response.setEntity(new NFileEntity((file != null) ? file : temporaryFile, getMimeType(fileStore .getName())) { @Override public void close() throws IOException { try { super.close(); } finally { if (temporaryFile != null && !temporaryFile.delete()) { temporaryFile.deleteOnExit(); } } } }); } } }
Example 19
Source File: HTMLContentAssistProcessor.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * @param offset * @param valuePrefix * @param editorStoreURI * The URI of the current file. We use this to eliminate it from list of possible completions. * @param parent * The parent we're grabbing children for. * @return * @throws CoreException */ protected List<ICompletionProposal> suggestChildrenOfFileStore(int offset, String valuePrefix, URI editorStoreURI, IFileStore parent) throws CoreException { IFileStore[] children = parent.childStores(EFS.NONE, new NullProgressMonitor()); if (children == null || children.length == 0) { return Collections.emptyList(); } List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); Image[] userAgentIcons = this.getAllUserAgentIcons(); for (IFileStore f : children) { String name = f.getName(); // Don't include the current file in the list // FIXME this is a possible perf issue. We really only need to check for editor store on local URIs if (name.charAt(0) == '.' || f.toURI().equals(editorStoreURI)) { continue; } if (valuePrefix != null && valuePrefix.length() > 0 && !name.startsWith(valuePrefix)) { continue; } IFileInfo info = f.fetchInfo(); boolean isDir = false; if (info.isDirectory()) { isDir = true; } // build proposal int replaceOffset = offset; int replaceLength = 0; if (this._replaceRange != null) { replaceOffset = this._replaceRange.getStartingOffset(); replaceLength = this._replaceRange.getLength(); } CommonCompletionProposal proposal = new URIPathProposal(name, replaceOffset, replaceLength, isDir, userAgentIcons); proposals.add(proposal); } return proposals; }
Example 20
Source File: CompilationDirector.java From textuml with Eclipse Public License 1.0 | 4 votes |
private boolean isUMLFile(IFileStore toCheck) { IFileInfo info = toCheck.fetchInfo(); return info.exists() && !info.isDirectory() && toCheck.getName().endsWith('.' + UMLResource.FILE_EXTENSION); }