org.eclipse.core.filesystem.EFS Java Examples

The following examples show how to use org.eclipse.core.filesystem.EFS. 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: CoreFilesTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testListenerCopyFile() throws Exception {
	String directoryPath = "testCopyFile/directory/path" + System.currentTimeMillis();
	String sourcePath = directoryPath + "/source.txt";
	String destName = "destination.txt";
	String destPath = directoryPath + "/" + destName;
	createDirectory(directoryPath);
	IFileStore sourceStore = createFile(sourcePath, "This is the contents");

	modListener = new TestFilesystemModificationListener();

	JSONObject requestObject = new JSONObject();
	addSourceLocation(requestObject, sourcePath);
	WebRequest request = getPostFilesRequest(directoryPath, requestObject.toString(), "destination.txt");
	request.setHeaderField("X-Create-Options", "copy");
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	IFileStore destStore = EFS.getStore(makeLocalPathAbsolute(destPath));

	modListener.assertListenerNotified(sourceStore, destStore, ChangeType.COPY_INTO);
}
 
Example #2
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testGetUserHome() throws CoreException {
	// create the MetaStore
	IMetaStore metaStore = OrionConfiguration.getMetaStore();

	// create the user
	UserInfo userInfo = new UserInfo();
	userInfo.setUserName(testUserLogin);
	userInfo.setFullName(testUserLogin);
	metaStore.createUser(userInfo);

	// get the user home
	IFileStore userHome = metaStore.getUserHome(userInfo.getUniqueId());
	String location = userHome.toLocalFile(EFS.NONE, null).toString();

	IFileStore root = OrionConfiguration.getRootLocation();
	IFileStore child = root.getChild("te/testGetUserHome");
	String correctLocation = child.toLocalFile(EFS.NONE, null).toString();

	assertEquals(correctLocation, location);
}
 
Example #3
Source File: PlatformUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Copy a resource a the bundle to the destination path
 *
 * @param destinationFolder
 * @param bundle
 * @param resourceName
 * @return the copied resource
 */
public static void copyResourceDirectory(final File destFolder, final File sourceFolder,
        final IProgressMonitor monitor) {
    if (fileSystem == null) {
        fileSystem = EFS.getLocalFileSystem();
    }
    if (sourceFolder.isDirectory()) {
        final IFileStore sourceStore = fileSystem.fromLocalFile(sourceFolder);
        final IFileStore destStore = fileSystem.fromLocalFile(destFolder);
        try {
            sourceStore.copy(destStore, EFS.OVERWRITE, new NullProgressMonitor());
        } catch (final CoreException e) {
            BonitaStudioLog.error(e);
        }
    } else {
        copyResource(destFolder, sourceFolder.toURI(), monitor);
    }
}
 
Example #4
Source File: FileGrepper.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void handleFile(File file, int depth, Collection<SearchResult> results) {
	if(options.isExcluded(file.getName())) {
		return;
	}
	if (results.size() >= options.getRows()) {
		// stop if we already have the max number of results to return
		return;
	}
	// Check if the path is acceptable
	if (!acceptFilename(file.getName()))
		return;
	// Add if it is a filename search or search the file contents.
	if (!options.isFileContentsSearch() || searchFile(file)) {
		IFileStore fileStore;
		try {
			fileStore = EFS.getStore(file.toURI());
		} catch (CoreException e) {
			logger.error("FileGrepper.handleFile: " + e.getLocalizedMessage(), e);
			return;
		}
		results.add(new SearchResult(fileStore, currentWorkspace, currentProject));
	}
}
 
Example #5
Source File: WorkspaceUtils.java    From JReFrameworker with MIT License 6 votes vote down vote up
public static void openFileInEclipseEditor(File file) {
	if (file.exists() && file.isFile()) {
		IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		try {
			IDE.openEditorOnFileStore(page, fileStore);
		} catch (PartInitException e) {
			Log.error("Could not display file: " + file.getAbsolutePath(), e);
		}
	} else {
		MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.OK);
		mb.setText("Alert");
		mb.setMessage("Could not find file: " + file.getAbsolutePath());
		mb.open();
	}
}
 
Example #6
Source File: CompilationDirectorCLI.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
private void compile(IRepository repository, final String inputPathAsString, final String outputPathAsString)
		throws CoreException {
	IFileSystem localFS = EFS.getLocalFileSystem();
	final IFileStore outputPath = localFS.getStore(new Path(outputPathAsString));
	LocationContext context = new LocationContext(outputPath);
	final IFileStore sourcePath = localFS.getStore(new Path(inputPathAsString));
	if (!sourcePath.fetchInfo().exists()) {
		System.err.println(sourcePath + " does not exist");
		System.exit(1);
	}
	context.addSourcePath(sourcePath, outputPath);
	int mode = ICompilationDirector.CLEAN | ICompilationDirector.FULL_BUILD;
	if (Boolean.getBoolean("args.debug"))
		mode |= ICompilationDirector.DEBUG;
	IProblem[] problems = CompilationDirector.getInstance().compile(null, repository, context, mode, null);
	if (problems.length > 0) {
		MultiStatus parent = new MultiStatus(FrontEnd.PLUGIN_ID, IStatus.OK, "Problems occurred", null);
		for (int i = 0; i < problems.length; i++) {
			String message = problems[i].toString();
			parent.add(buildStatus(message, null));
		}
		LogUtils.log(parent);
	} else
		LogUtils.logInfo(FrontEnd.PLUGIN_ID, "Done", null);
}
 
Example #7
Source File: EditorSearchHyperlink.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void open()
{
	try
	{
		final IFileStore store = EFS.getStore(document);
		// Now open an editor to this file (and highlight the occurrence if possible)
		IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
		IEditorPart part = IDE.openEditorOnFileStore(page, store);
		// Now select the occurrence if we can
		IFindReplaceTarget target = (IFindReplaceTarget) part.getAdapter(IFindReplaceTarget.class);
		if (target != null && target.canPerformFind())
		{
			target.findAndSelect(0, searchString, true, caseSensitive, wholeWord);
		}
	}
	catch (Exception e)
	{
		IdeLog.logError(CommonEditorPlugin.getDefault(), e);
	}
}
 
Example #8
Source File: CreateFileChange.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
	RefactoringStatus result= new RefactoringStatus();
	IFile file= ResourcesPlugin.getWorkspace().getRoot().getFile(fPath);

	URI location= file.getLocationURI();
	if (location == null) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_unknownLocation,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}

	IFileInfo jFile= EFS.getStore(location).fetchInfo();
	if (jFile.exists()) {
		result.addFatalError(Messages.format(
			NLSChangesMessages.CreateFileChange_error_exists,
			BasicElementLabels.getPathLabel(file.getFullPath(), false)));
		return result;
	}
	return result;
}
 
Example #9
Source File: OpenJavaSourceAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void run( )
{
	String fileName = ChartExamples.getClassName( );
	if ( fileName != null )
	{
		IFileStore fileStore = EFS.getLocalFileSystem( )
				.getStore( new Path( getPath( fileName ) ) );
		fileStore = fileStore.getChild( fileName + JAVA_EXTENSION );
		if ( !fileStore.fetchInfo( ).isDirectory( )
				&& fileStore.fetchInfo( ).exists( ) )
		{
			IEditorInput input = createEditorInput( fileStore );
			// no org.eclipse.jdt.ui.CompilationUnitEditor in RCP
			// so it will open the java source with external editor.
			String editorId = getEditorId( fileStore );
			try
			{
				window.getActivePage( ).openEditor( input, editorId );
			}
			catch ( PartInitException e )
			{
				e.printStackTrace( );
			}
		}
	}
}
 
Example #10
Source File: BuildPathManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * If a build path entry is added, we schedule a job to make sure the entry gets indexed (or it's index is
 * up-to-date).
 * 
 * @param entry
 */
private void index(IBuildPathEntry entry)
{
	try
	{
		IFileStore fileStore = EFS.getStore(entry.getPath());
		if (fileStore != null)
		{
			if (fileStore.fetchInfo().isDirectory())
			{
				new IndexContainerJob(entry.getDisplayName(), entry.getPath()).schedule();
			}
			else
			{
				new IndexFileJob(entry.getDisplayName(), entry.getPath()).schedule();
			}
		}
	}
	catch (Throwable e)
	{
		IdeLog.logError(BuildPathCorePlugin.getDefault(), e);
	}
}
 
Example #11
Source File: FileHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private void handlePutContents(HttpServletRequest request, ServletInputStream requestStream, HttpServletResponse response, IFileStore file)
		throws IOException, CoreException, NoSuchAlgorithmException, JSONException {
	String source = request.getParameter(ProtocolConstants.PARM_SOURCE);
	if (!file.getParent().fetchInfo().exists()) {
		// make sure the parent folder exists
		file.getParent().mkdir(EFS.NONE, null);
	}
	if (source != null) {
		// if source is specified, read contents from different URL rather than from this request stream
		IOUtilities.pipe(new URL(source).openStream(), file.openOutputStream(EFS.NONE, null), true, true);
	} else {
		// read from the request stream
		IOUtilities.pipe(requestStream, file.openOutputStream(EFS.NONE, null), false, true);
	}

	// return metadata with the new Etag
	handleGetMetadata(request, response, file);
}
 
Example #12
Source File: OpenLogCommand.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public Object execute(ExecutionEvent event) throws ExecutionException {
	IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
	IFileStore fileStore = EFS.getLocalFileSystem().getStore(Platform.getLogFileLocation());
	try {
		IDE.openEditorOnFileStore(page, fileStore);
	} catch (PartInitException e) {
		BonitaStudioLog.error(e);
		try {
			IDE.openInternalEditorOnFileStore(page, fileStore);
		} catch (PartInitException e1) {
			BonitaStudioLog.error(e1);
			BonitaStudioLog.log("Can't open .log file in editor. You should associate .log to a program at OS level.");
		}
	}		
	return null;
}
 
Example #13
Source File: FileOpener.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
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 #14
Source File: DirectoryHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
private boolean handleGet(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws IOException, CoreException {
	URI location = getURI(request);
	JSONObject result = ServletFileStoreHandler.toJSON(dir, dir.fetchInfo(EFS.NONE, null), location);
	String depthString = request.getParameter(ProtocolConstants.PARM_DEPTH);
	int depth = 0;
	if (depthString != null) {
		try {
			depth = Integer.parseInt(depthString);
		} catch (NumberFormatException e) {
			// ignore
		}
	}
	encodeChildren(dir, location, result, depth);
	OrionServlet.writeJSONResponse(request, response, result);
	return true;
}
 
Example #15
Source File: NavigatorLinkHelper.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IStructuredSelection findSelection(IEditorInput input) {
  IFile file = ResourceUtil.getFile(input);

  if (file != null) {
    return new StructuredSelection(file);
  }

  IFileStore fileStore = (IFileStore) input.getAdapter(IFileStore.class);

  if (fileStore == null && input instanceof FileStoreEditorInput) {
    URI uri = ((FileStoreEditorInput)input).getURI();
    
    try {
      fileStore = EFS.getStore(uri);
    } catch (CoreException e) {

    }
  }
  
  if (fileStore != null) {
    return new StructuredSelection(fileStore);
  }

  return StructuredSelection.EMPTY;
}
 
Example #16
Source File: URLtoURIMapper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Resolves URI relative to server base URL
 * 
 * @param uri
 * @return
 */
private IFileStore resolve(IPath path)
{
	if (!isValid())
	{
		return null;
	}
	try
	{
		return EFS.getStore(documentRoot).getFileStore(path);
	}
	catch (CoreException e)
	{
		IdeLog.logError(WebServerCorePlugin.getDefault(), e);
		return null;
	}
}
 
Example #17
Source File: PackagerTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testCFIgnoreRules() throws Exception {

	ZipOutputStream mockZos = mock(ZipOutputStream.class);

	String LOCATION = "testData/packagerTest/01"; //$NON-NLS-1$
	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(LOCATION);
	IFileStore source = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath()));

	PackageUtils.writeZip(source, mockZos);

	/* what is... */
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("test2.in")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry(".cfignore")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("A")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/test2.in")))); //$NON-NLS-1$
	verify(mockZos).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/inner2/test3.in")))); //$NON-NLS-1$

	/* ... and what should never be */
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("test1.in")))); //$NON-NLS-1$
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/test1.in")))); //$NON-NLS-1$
	verify(mockZos, never()).putNextEntry(argThat(new ZipArgumentMatcher(new ZipEntry("inner/inner2/inner3/test2.in")))); //$NON-NLS-1$
}
 
Example #18
Source File: GitTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
protected IPath createTempDir() throws CoreException {
	// get a temporary folder location, do not use /tmp
	File workspaceRoot = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
	File tmpDir = new File(workspaceRoot, SimpleMetaStoreUtil.ARCHIVE);
	if (!tmpDir.exists()) {
		tmpDir.mkdirs();
	}
	if (!tmpDir.exists() || !tmpDir.isDirectory()) {
		fail("Cannot find the default temporary-file directory: " + tmpDir.toString());
	}

	// get a temporary folder name
	SecureRandom random = new SecureRandom();
	long n = random.nextLong();
	n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n);
	String tmpDirStr = Long.toString(n);
	File tempDir = new File(tmpDir, tmpDirStr);
	if (!tempDir.mkdir()) {
		fail("Cannot create a temporary directory at " + tempDir.toString());
	}
	return Path.fromOSString(tempDir.toString());
}
 
Example #19
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSingleInheritancePropagation() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/01"; //$NON-NLS-1$
	String manifestName = "prod-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(4, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("path")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$
	}
}
 
Example #20
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testSingleRelativeInheritance() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/02/inner"; //$NON-NLS-1$
	String manifestName = "prod-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent().getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(2, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("path")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$
	}
}
 
Example #21
Source File: PlatformUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void move(final File fileToMove, final File toDir, final IProgressMonitor monitor) {
    if (fileToMove == null || !fileToMove.exists()) {
        return;
    }

    if (fileSystem == null) {
        fileSystem = EFS.getLocalFileSystem();
    }

    final IFileStore fileToMoveStore = fileSystem.fromLocalFile(fileToMove);
    final IFileStore dest = fileSystem.fromLocalFile(toDir);
    try {
        fileToMoveStore.move(dest.getChild(fileToMoveStore.getName()), EFS.OVERWRITE, new NullProgressMonitor());
        monitor.worked(1);
    } catch (final CoreException e) {
        BonitaStudioLog.error(e);
    }

}
 
Example #22
Source File: PyEditorInputFactory.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public IAdaptable createElement(IMemento memento) {
    String fileStr = memento.getString(TAG_FILE);
    if (fileStr == null || fileStr.length() == 0) {
        return null;
    }

    String zipPath = memento.getString(TAG_ZIP_PATH);
    final File file = new File(fileStr);
    if (zipPath == null || zipPath.length() == 0) {
        //return EditorInputFactory.create(new File(file), false);
        final URI uri = file.toURI();
        IFile[] ret = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri,
                IContainer.INCLUDE_HIDDEN | IContainer.INCLUDE_PHANTOMS | IContainer.INCLUDE_TEAM_PRIVATE_MEMBERS);
        if (ret != null && ret.length > 0) {
            return new FileEditorInput(ret[0]);
        }
        try {
            return new FileStoreEditorInput(EFS.getStore(uri));
        } catch (CoreException e) {
            return new PydevFileEditorInput(file);
        }
    }

    return new PydevZipFileEditorInput(new PydevZipFileStorage(file, zipPath));
}
 
Example #23
Source File: DirectoryHandlerV1.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Performs the actual modification corresponding to a POST request. All preconditions
 * are assumed to be satisfied.
 * @return <code>true</code> if the operation was successful, and <code>false</code> otherwise.
 */
private boolean performPost(HttpServletRequest request, HttpServletResponse response, JSONObject requestObject, IFileStore toCreate, int options) throws CoreException, IOException, ServletException {
	boolean isCopy = (options & CREATE_COPY) != 0;
	boolean isMove = (options & CREATE_MOVE) != 0;
	try {
		if (isCopy || isMove)
			return performCopyMove(request, response, requestObject, toCreate, isCopy, options);
		if (requestObject.optBoolean(ProtocolConstants.KEY_DIRECTORY))
			toCreate.mkdir(EFS.NONE, null);
		else
			toCreate.openOutputStream(EFS.NONE, null).close();
	} catch (CoreException e) {
		IStatus status = e.getStatus();
		if (status != null && status.getCode() == EFS.ERROR_WRITE) {
			// Sanitize message, as it might contain the filepath.
			statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Failed to create: " + toCreate.getName(), null));
			return false;
		}
		throw e;
	}
	return true;
}
 
Example #24
Source File: ManifestUtilsTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testFlatComplexInheritance() throws Exception {
	String MANIFEST_LOCATION = "testData/manifestTest/inheritance/06"; //$NON-NLS-1$
	String manifestName = "final-manifest.yml"; //$NON-NLS-1$

	URL entry = ServerTestsActivator.getContext().getBundle().getEntry(MANIFEST_LOCATION);
	IFileStore fs = EFS.getStore(URIUtil.toURI(FileLocator.toFileURL(entry).getPath().concat(manifestName)));

	ManifestParseTree manifest = ManifestUtils.parse(fs.getParent(), fs);
	ManifestParseTree applications = manifest.get("applications"); //$NON-NLS-1$
	assertEquals(2, applications.getChildren().size());

	for (ManifestParseTree application : applications.getChildren()) {
		assertTrue(application.has("domain")); //$NON-NLS-1$
		assertTrue(application.has("instances")); //$NON-NLS-1$
		assertTrue(application.has("memory")); //$NON-NLS-1$

		if ("A".equals(application.get("name").getValue())) //$NON-NLS-1$ //$NON-NLS-2$
			assertTrue("2".equals(application.get("instances").getValue())); //$NON-NLS-1$ //$NON-NLS-2$
	}
}
 
Example #25
Source File: SimpleMetaStoreUtilTest.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void initializeTempDir() throws CoreException {
	// get the temporary folder location, do not use /tmp
	File workspaceRoot = OrionConfiguration.getRootLocation().toLocalFile(EFS.NONE, null);
	File tmpDir = new File(workspaceRoot, SimpleMetaStoreUtil.ARCHIVE);
	if (!tmpDir.exists()) {
		tmpDir.mkdirs();
	}
	if (!tmpDir.exists() || !tmpDir.isDirectory()) {
		fail("Cannot find the default temporary-file directory: " + tmpDir.toString());
	}

	// get a temporary folder name
	long n = random.nextLong();
	n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n);
	String tmpDirStr = Long.toString(n);
	tempDir = new File(tmpDir, tmpDirStr);
	if (!tempDir.mkdir()) {
		fail("Cannot create a temporary directory at " + tempDir.toString());
	}
}
 
Example #26
Source File: WorkspaceResolvingURIMapper.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public IFileStore resolve(URI uri)
{
	IFileStore fileStore = baseMapper.resolve(uri);
	if (fileStore != null && fileStore.getFileSystem() == EFS.getLocalFileSystem()) // $codepro.audit.disable
																					// useEquals
	{
		try
		{
			fileStore = EFSUtils.fromLocalFile(fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor()));
		}
		catch (CoreException e)
		{
			IdeLog.logError(WebServerCorePlugin.getDefault(), e);
		}
	}
	return fileStore;
}
 
Example #27
Source File: WorkspaceFile.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private IResource ensureResource(Class<? extends IResource> resourceClass) throws CoreException {
	if (resource != null && (!resource.isSynchronized(IResource.DEPTH_ZERO) || !resource.exists())) {
		resource = null;
		localFileStore = null;
	}
	if (resource == null) {
		IContainer container = workspaceRoot;
		if (path.segmentCount() > 2) {
			container = workspaceRoot.getFolder(path.removeLastSegments(1));
		} else if (path.segmentCount() == 2) {
			container = workspaceRoot.getProject(path.segment(0));
		}
		if (path.isRoot()) {
			resource = workspaceRoot;
		} else {
			resource = container.findMember(path.lastSegment());
		}
		if (resource == null) {
			if (IFile.class.equals(resourceClass)) {
				resource = workspaceRoot.getFile(path);
			} else if (IFolder.class.equals(resourceClass)) {
				resource = workspaceRoot.getFolder(path);
			}
		}
		if (resourceClass != null && !resourceClass.isInstance(resource)) {
			resource = null;
			Policy.error(EFS.ERROR_WRONG_TYPE, NLS.bind(Messages.failedCreateWrongType, path));
		}
	}
	return resource;
}
 
Example #28
Source File: AddOrEditCatalogDialog.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 选择文件 ;
 */
public void browseFiles() {
	FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE);
	dialog.setMessage(Messages.getString("dialogs.AddOrEditCatalogDialog.dialogMsg"));
	dialog.setDoubleClickSelects(true);

	try {
		dialog.setInput(EFS.getStore(URIUtil.toURI(root.getLocation().append(ADConstants.cataloguePath))));

	} catch (CoreException e1) {
		e1.printStackTrace();
	}
	dialog.create();
	dialog.getShell().setText(Messages.getString("dialogs.AddOrEditCatalogDialog.dialogTitle"));
	dialog.open();
	if (dialog.getFirstResult() != null) {
		Object object = dialog.getFirstResult();
		if (object instanceof LocalFile) {
			LocalFile localFile = (LocalFile) object;
			String location = localFile.toString();
			String catalogurePath = root.getLocation().append(ADConstants.cataloguePath).toOSString();
			String uriStr = "";
			if (location.indexOf(catalogurePath) != -1) {
				uriStr = location.substring(location.indexOf(catalogurePath) + catalogurePath.length(), location.length());
			}
			uriStr = uriStr.substring(1, uriStr.length());
			urlTxt.setText(uriStr);
		}
	}
}
 
Example #29
Source File: WorkspaceFile.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void putInfo(IFileInfo info, int options, IProgressMonitor monitor) throws CoreException {
	ensureLocalFileStore();
	if (localFileStore != null) {
		localFileStore.putInfo(info, options, monitor);
	} else {
		Policy.error(EFS.ERROR_NOT_EXISTS, NLS.bind(Messages.fileNotFound, path));
	}
}
 
Example #30
Source File: ResourceUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static String toString(IFileStore fileStore, IProgressMonitor monitor) throws CoreException {
  	try {
  		if (fileStore.fetchInfo().exists()) {
  			try(InputStream stream = fileStore.openInputStream(EFS.NONE , monitor)){
  				return IOUtils.toString(stream);
  			}
  		}
} catch (IOException e) {
	ExceptionHelper.rethrowAsCoreException(e);
}
  	return null;
  }