Java Code Examples for org.eclipse.core.filesystem.IFileStore#toLocalFile()
The following examples show how to use
org.eclipse.core.filesystem.IFileStore#toLocalFile() .
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: WorkspaceResolvingURIMapper.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
public URI resolve(IFileStore fileStore) { URI uri = baseMapper.resolve(fileStore); if (uri == null) { try { File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor()); if (file != null) { uri = baseMapper.resolve(EFSUtils.getLocalFileStore(file)); } } catch (CoreException e) { IdeLog.logError(WebServerCorePlugin.getDefault(), e); } } return uri; }
Example 2
Source File: GitUtils.java From orion.server with Eclipse Public License 1.0 | 5 votes |
/** * Returns the existing git repositories for the given file path, following the given traversal rule. * * @param path * expected format /file/{Workspace}/{projectName}[/{path}] * @return a map of all git repositories found, or <code>null</code> if the provided path format doesn't match the expected format. * @throws CoreException */ public static Map<IPath, File> getGitDirs(IPath path, Traverse traverse) throws CoreException { IPath p = path.removeFirstSegments(1);// remove /file IFileStore fileStore = NewFileServlet.getFileStore(null, p); if (fileStore == null) return null; Map<IPath, File> result = new HashMap<IPath, File>(); File file = fileStore.toLocalFile(EFS.NONE, null); // jgit can only handle a local file if (file == null) return result; switch (traverse) { case CURRENT: File gitDir = resolveGitDir(file); if (gitDir != null) { result.put(new Path(""), gitDir); //$NON-NLS-1$ } break; case GO_UP: getGitDirsInParents(file, result); break; case GO_DOWN: getGitDirsInChildren(file, p, result); break; } return result; }
Example 3
Source File: HTMLContentAssistProcessor.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Make a best guess as to whether the IFileStore is local or remote. Should be local for LocalFile and * WorkspaceFile. * * @param baseStore * @return */ private boolean isRemoteURI(IFileStore baseStore) { try { return baseStore.toLocalFile(EFS.NONE, new NullProgressMonitor()) == null; } catch (CoreException e) { IdeLog.logError(HTMLPlugin.getDefault(), e); } return true; }
Example 4
Source File: URIResolver.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Returns null if unable to resolve the path to a URI and grab the contents. */ public String resolveSource(String path, IProgressMonitor monitor) throws Exception { SubMonitor sub = SubMonitor.convert(monitor, 100); URI uri = resolveURI(path); if (uri == null) { return null; } sub.worked(5); // get the filesystem that can handle the URI IFileStore store = getFileStore(uri); int options = EFS.CACHE; // If file is local no need to cache if (store.getFileSystem().equals(EFS.getLocalFileSystem())) { options = EFS.NONE; } // grab down a local copy File aFile = store.toLocalFile(options, sub.newChild(90)); if (aFile == null || !aFile.exists()) { // Need to pass up correct original filename and says that's the one that doesn't exist throw new FileNotFoundException(uri.toString()); } // now read in the local copy return IOUtil.read(new FileInputStream(aFile)); }
Example 5
Source File: Util.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static File toLocalFile(URI uri, IProgressMonitor monitor) throws CoreException { IFileStore fileStore = EFS.getStore(uri); File localFile = fileStore.toLocalFile(EFS.NONE, monitor); if (localFile ==null) // non local file system localFile= fileStore.toLocalFile(EFS.CACHE, monitor); return localFile; }
Example 6
Source File: OpenUIDLogCommand.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public Boolean execute(ExecutionEvent event) throws ExecutionException { final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final Optional<File> logFile = UIDesignerServerManager.getInstance().getLogFile(); if (logFile.isPresent() && logFile.get().exists()) { try { IFileStore fileStore = EFS.getLocalFileSystem().getStore(logFile.get().toURI()); final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR); final long fileSize = localFile.length(); if (fileSize < MAX_FILE_SIZE) { IDE.openEditorOnFileStore(page, fileStore); } else { Program textEditor = Program.findProgram("log"); if (textEditor == null) { textEditor = Program.findProgram("txt"); } if (textEditor == null || !textEditor.execute(localFile.getAbsolutePath())) { showWarningMessage(localFile); } } return true; } catch (final Exception e) { BonitaStudioLog.error(e); return false; } } MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.unableTofindLogTitle, Messages.unableTofindLogMessage); return false; }
Example 7
Source File: OpenEngineLogCommand.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public Boolean execute(final ExecutionEvent event) throws ExecutionException { final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); final File logFile = BOSWebServerManager.getInstance().getBonitaLogFile(); if (logFile != null && logFile.exists()) { IFileStore fileStore; try { fileStore = EFS.getLocalFileSystem().getStore(logFile.toURI()); final File localFile = fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR); final long fileSize = localFile.length(); if (fileSize < MAX_FILE_SIZE) { IDE.openEditorOnFileStore(page, fileStore); } else { Program textEditor = Program.findProgram("log"); if (textEditor == null) { textEditor = Program.findProgram("txt"); } if (textEditor != null) { final boolean success = textEditor.execute(localFile.getAbsolutePath()); if (!success) { showWarningMessage(localFile); } } else { showWarningMessage(localFile); } } return Boolean.TRUE; } catch (final Exception e) { BonitaStudioLog.error(e); return Boolean.FALSE; } } else { MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.unableTofindLogTitle, Messages.unableTofindLogMessage); return Boolean.FALSE; } }
Example 8
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 9
Source File: OpenH2ConsoleHandler.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
protected File logFile() throws CoreException { final IFileStore fileStore = EFS.getLocalFileSystem().getStore(Platform.getLogFileLocation()); return fileStore.toLocalFile(EFS.NONE, Repository.NULL_PROGRESS_MONITOR); }