Java Code Examples for org.eclipse.core.filesystem.EFS

The following examples show how to use org.eclipse.core.filesystem.EFS. These examples are extracted from open source projects. 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 Project: birt   Source File: OpenJavaSourceAction.java    License: 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 2
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 3
Source Project: textuml   Source File: CompilationDirectorCLI.java    License: 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 4
Source Project: JReFrameworker   Source File: WorkspaceUtils.java    License: 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 5
/**
 * 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 6
Source Project: orion.server   Source File: FileGrepper.java    License: 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 7
Source Project: bonita-studio   Source File: PlatformUtil.java    License: 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 8
Source Project: orion.server   Source File: FileHandlerV1.java    License: 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 9
Source Project: gama   Source File: FileOpener.java    License: 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 10
Source Project: orion.server   Source File: DirectoryHandlerV1.java    License: 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 11
Source Project: orion.server   Source File: DirectoryHandlerV1.java    License: 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 12
Source Project: Pydev   Source File: PyEditorInputFactory.java    License: 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 13
Source Project: orion.server   Source File: GitTest.java    License: 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 14
Source Project: orion.server   Source File: CoreFilesTest.java    License: 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 15
/**
 * 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 16
Source Project: orion.server   Source File: PackagerTest.java    License: 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 17
Source Project: orion.server   Source File: ManifestUtilsTest.java    License: 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 18
Source Project: orion.server   Source File: ManifestUtilsTest.java    License: 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 19
Source Project: bonita-studio   Source File: PlatformUtil.java    License: 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 20
Source Project: orion.server   Source File: ManifestUtilsTest.java    License: 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 21
@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 22
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 23
Source Project: bonita-studio   Source File: OpenLogCommand.java    License: 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 24
Source Project: goclipse   Source File: NavigatorLinkHelper.java    License: 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 25
Source Project: orion.server   Source File: SimpleMetaStoreTests.java    License: 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 26
Source Project: eclipse.jdt.ls   Source File: CreateFileChange.java    License: 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 27
Source Project: xds-ide   Source File: ResourceUtils.java    License: 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;
  }
 
Example 28
public static IFileSystem getInstance() {
	if (instance == null) {
		try {
			instance = EFS.getFileSystem(SCHEME_WORKSPACE);
		} catch (CoreException e) {
			throw new RuntimeException(e);
		}
	}
	return instance;
}
 
Example 29
@Override
public IFileStore getStore(URI uri) {
	if (SCHEME_VIRTUAL.equals(uri.getScheme())) {
		URI rootURI = VirtualConnectionManager.getVirtualRootURI(uri);
		IConnectionFileManager fileManager = VirtualConnectionManager.getInstance().getVirtualFileManager(rootURI);
		if (fileManager != null) {
			return new VirtualFile(fileManager, rootURI, new Path(uri.getPath()));
		}
	}
	return EFS.getNullFileSystem().getStore(uri);
}
 
Example 30
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}