Java Code Examples for org.eclipse.core.filesystem.IFileStore#delete()

The following examples show how to use org.eclipse.core.filesystem.IFileStore#delete() . 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: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Configures the classpath of the project before refactoring.
 *
 * @param project
 *            the java project
 * @param root
 *            the package fragment root to refactor
 * @param folder
 *            the temporary source folder
 * @param monitor
 *            the progress monitor to use
 * @throws IllegalStateException
 *             if the plugin state location does not exist
 * @throws CoreException
 *             if an error occurs while configuring the class path
 */
private static void configureClasspath(final IJavaProject project, final IPackageFragmentRoot root, final IFolder folder, final IProgressMonitor monitor) throws IllegalStateException, CoreException {
	try {
		monitor.beginTask(JarImportMessages.JarImportWizard_prepare_import, 200);
		final IClasspathEntry entry= root.getRawClasspathEntry();
		final IClasspathEntry[] entries= project.getRawClasspath();
		final List<IClasspathEntry> list= new ArrayList<IClasspathEntry>();
		list.addAll(Arrays.asList(entries));
		final IFileStore store= EFS.getLocalFileSystem().getStore(JavaPlugin.getDefault().getStateLocation().append(STUB_FOLDER).append(project.getElementName()));
		if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
			store.delete(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		store.mkdir(EFS.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		folder.createLink(store.toURI(), IResource.NONE, new SubProgressMonitor(monitor, 25, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		addExclusionPatterns(list, folder.getFullPath());
		for (int index= 0; index < entries.length; index++) {
			if (entries[index].equals(entry))
				list.add(index, JavaCore.newSourceEntry(folder.getFullPath()));
		}
		project.setRawClasspath(list.toArray(new IClasspathEntry[list.size()]), false, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
	} finally {
		monitor.done();
	}
}
 
Example 2
Source File: AbstractRepositoryBuildingTests.java    From textuml with Eclipse Public License 1.0 6 votes vote down vote up
protected void clearLocation(IFileStore toDelete) {
    for (int tries = 0; tries < 5; tries++) {
        try {
            toDelete.delete(EFS.NONE, null);
            break;
        } catch (CoreException e) {
            // sometimes delete fails for no apparent reason (maybe other
            // threads?), but if we try again after some wait, it just
            // works...
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                // break;
            }
            if (Boolean.getBoolean("debug"))
                System.out.println("Failed deleting " + toDelete.toURI() + "(attempt #" + (tries + 1) + ")");
        }
    }
}
 
Example 3
Source File: WorkspaceResourceHandler.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Generates a file system location for newly created project. Creates a new
 * folder in the file system and ensures it is empty.
 */
private static URI generateProjectLocation(ProjectInfo project, String user) throws CoreException {
	IFileStore projectStore = OrionConfiguration.getMetaStore().getDefaultContentLocation(project);
	if (projectStore.fetchInfo().exists()) {
		//This folder must be empty initially or we risk showing another user's old private data
		projectStore.delete(EFS.NONE, null);
	}
	projectStore.mkdir(EFS.NONE, null);
	return projectStore.toURI();
}
 
Example 4
Source File: WorkspaceResourceHandler.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public static void removeProject(String user, WorkspaceInfo workspace, ProjectInfo project) throws CoreException {
	// remove the project folder
	URI contentURI = project.getContentLocation();

	// only delete project contents if they are in default location
	IFileStore projectStore = OrionConfiguration.getMetaStore().getDefaultContentLocation(project);
	URI defaultLocation = projectStore.toURI();
	if (URIUtil.sameURI(defaultLocation, contentURI)) {
		projectStore.delete(EFS.NONE, null);
	}

	OrionConfiguration.getMetaStore().deleteProject(workspace.getUniqueId(), project.getFullName());
}
 
Example 5
Source File: DirectoryHandlerV1.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private boolean handleDelete(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException {
	Path path = new Path(request.getPathInfo());
	dir.delete(EFS.NONE, null);
	if (path.segmentCount() == 2) {
		// The folder is a project, remove the metadata
		OrionConfiguration.getMetaStore().deleteProject(path.segment(0), path.segment(1));
	} else if (path.segmentCount() == 1) {
		// The folder is a workspace, remove the metadata
		String workspaceId = path.segment(0);
		OrionConfiguration.getMetaStore().deleteWorkspace(request.getRemoteUser(), workspaceId);
	}
	return true;
}
 
Example 6
Source File: WorkspaceServiceTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@After
public void tearDown() {
	for (IFileStore file : toDelete) {
		try {
			file.delete(EFS.NONE, null);
		} catch (CoreException e) {
			//skip
		}
	}
	toDelete.clear();
}
 
Example 7
Source File: AdvancedFilesTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testETagDeletedFile() throws JSONException, IOException, SAXException, CoreException {
	String fileName = "testfile.txt";

	//setup: create a file
	WebRequest request = getPostFilesRequest("", getNewFileJSON(fileName).toString(), fileName);
	WebResponse response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

	//obtain file metadata and ensure data is correct
	request = getGetFilesRequest(fileName + "?parts=meta");
	response = webConversation.getResponse(request);
	assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
	String etag = response.getHeaderField(ProtocolConstants.KEY_ETAG);
	assertNotNull(etag);

	//delete the file on disk
	IFileStore fileStore = EFS.getStore(makeLocalPathAbsolute(fileName));
	fileStore.delete(EFS.NONE, null);

	//now a PUT should fail
	request = getPutFileRequest(fileName, "something");
	request.setHeaderField(ProtocolConstants.HEADER_IF_MATCH, etag);
	try {
		response = webConversation.getResponse(request);
	} catch (IOException e) {
		//inexplicably HTTPUnit throws IOException on PRECON_FAILED rather than just giving us response
		assertTrue(e.getMessage().indexOf(Integer.toString(HttpURLConnection.HTTP_PRECON_FAILED)) > 0);
	}
}
 
Example 8
Source File: BinaryRefactoringHistoryWizard.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deconfigures the classpath of the project after refactoring.
 *
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             if an error occurs while deconfiguring the classpath
 */
private void deconfigureClasspath(final IProgressMonitor monitor) throws CoreException {
	try {
		monitor.beginTask(JarImportMessages.JarImportWizard_cleanup_import, 300);
		if (fJavaProject != null) {
			final IClasspathEntry[] entries= fJavaProject.readRawClasspath();
			final boolean changed= deconfigureClasspath(entries, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			final RefactoringHistory history= getRefactoringHistory();
			final boolean valid= history != null && !history.isEmpty();
			if (valid)
				RefactoringCore.getUndoManager().flush();
			if (valid || changed)
				fJavaProject.setRawClasspath(entries, changed, new SubProgressMonitor(monitor, 60, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
		}
		if (fSourceFolder != null) {
			final IFileStore store= EFS.getStore(fSourceFolder.getRawLocationURI());
			if (store.fetchInfo(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL)).exists())
				store.delete(EFS.NONE, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder.delete(true, false, new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder.clearHistory(new SubProgressMonitor(monitor, 10, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			fSourceFolder= null;
		}
		if (fJavaProject != null) {
			try {
				fJavaProject.getResource().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 100, SubProgressMonitor.SUPPRESS_SUBTASK_LABEL));
			} catch (CoreException exception) {
				JavaPlugin.log(exception);
			}
		}
	} finally {
		fJavaProject= null;
		monitor.done();
	}
}
 
Example 9
Source File: NewJavaProjectWizardPageTwo.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void deleteProjectFile(URI projectLocation) throws CoreException {
	IFileStore file= EFS.getStore(projectLocation);
	if (file.fetchInfo().exists()) {
		IFileStore projectFile= file.getChild(FILENAME_PROJECT);
		if (projectFile.fetchInfo().exists()) {
			projectFile.delete(EFS.NONE, null);
		}
	}
}
 
Example 10
Source File: BuildSettingWizardPage.java    From sarl with Apache License 2.0 5 votes vote down vote up
private static void deleteProjectFile(URI projectLocation) throws CoreException {
	final IFileStore file = EFS.getStore(projectLocation);
	if (file.fetchInfo().exists()) {
		final IFileStore projectFile = file.getChild(FILENAME_PROJECT);
		if (projectFile.fetchInfo().exists()) {
			projectFile.delete(EFS.NONE, null);
		}
	}
}
 
Example 11
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void clean(IFileStore root, boolean deleteIfEmpty, IProgressMonitor monitor) throws CoreException {
    if (monitor.isCanceled())
        throw new OperationCanceledException();
    if (isUMLFile(root) && MDDUtil.isGenerated(root.toURI())) {
        safeDelete(root);
        return;
    }
    IFileStore[] children = root.childStores(EFS.NONE, null);
    for (int i = 0; i < children.length; i++)
        clean(children[i], false, monitor);
    if (deleteIfEmpty && root.childStores(EFS.NONE, null).length == 0)
        root.delete(EFS.NONE, null);
}
 
Example 12
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private void safeDelete(IFileStore root) throws CoreException {
    for (int i = 0; i < 3; i++)
        try {
            root.delete(EFS.NONE, null);
            // worked!
            return;
        } catch (CoreException e) {
            try {
                Thread.sleep(50 + 100 * i);
            } catch (InterruptedException e1) {
                // nah
            }
        }
    root.delete(EFS.NONE, null);
}
 
Example 13
Source File: WorkspaceResourceHandler.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public static void removeWorkspace(String user, WorkspaceInfo workspace) throws CoreException {
	String workspaceId = workspace.getUniqueId();
	IFileStore workspaceStore = OrionConfiguration.getMetaStore().getWorkspaceContentLocation(workspaceId);
	workspaceStore.delete(EFS.NONE, null);
	OrionConfiguration.getMetaStore().deleteWorkspace(user, workspaceId);
}
 
Example 14
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testMoveProjectLinked() 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);

	// create the workspace
	String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME;
	WorkspaceInfo workspaceInfo = new WorkspaceInfo();
	workspaceInfo.setFullName(workspaceName);
	workspaceInfo.setUserId(userInfo.getUniqueId());
	metaStore.createWorkspace(workspaceInfo);

	// create the project
	String projectName = "Orion Project";
	ProjectInfo projectInfo = new ProjectInfo();
	projectInfo.setFullName(projectName);
	projectInfo.setWorkspaceId(workspaceInfo.getUniqueId());
	IFileStore linkedFolder = metaStore.getUserHome(userInfo.getUniqueId()).getChild("Linked Project");
	projectInfo.setContentLocation(linkedFolder.toURI());

	metaStore.createProject(projectInfo);

	// create a project directory and file
	IFileStore projectFolder = projectInfo.getProjectStore();
	if (!projectFolder.fetchInfo().exists()) {
		projectFolder.mkdir(EFS.NONE, null);
	}
	assertTrue(projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory());
	String fileName = "file.html";
	IFileStore file = projectFolder.getChild(fileName);
	try {
		OutputStream outputStream = file.openOutputStream(EFS.NONE, null);
		outputStream.write("<!doctype html>".getBytes());
		outputStream.close();
	} catch (IOException e) {
		fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage());
	}
	assertTrue("the file in the project folder should exist.", file.fetchInfo().exists());

	// move the project by renaming the project by changing the projectName
	String movedProjectName = "Moved Orion Project";
	projectInfo.setFullName(movedProjectName);

	// update the project
	metaStore.updateProject(projectInfo);

	// read the project back again
	ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName());
	assertNotNull(readProjectInfo);
	assertTrue(readProjectInfo.getFullName().equals(movedProjectName));

	// linked folder hasn't moved
	projectFolder = readProjectInfo.getProjectStore();
	assertTrue("the linked project folder should stay the same", projectFolder.equals(linkedFolder));
	assertTrue("the linked project folder should exist.", projectFolder.fetchInfo().exists());
	file = projectFolder.getChild(fileName);
	assertTrue("the file in the linked project folder should exist.", file.fetchInfo().exists());

	// delete the project contents
	file.delete(EFS.NONE, null);
	assertFalse("the file in the project folder should not exist.", file.fetchInfo().exists());
	// delete the linked project
	projectFolder.delete(EFS.NONE, null);
	assertFalse("the linked project should not exist.", projectFolder.fetchInfo().exists());
}
 
Example 15
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testMoveSimpleProject() 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);

	// create the workspace
	String workspaceName = SimpleMetaStore.DEFAULT_WORKSPACE_NAME;
	WorkspaceInfo workspaceInfo = new WorkspaceInfo();
	workspaceInfo.setFullName(workspaceName);
	workspaceInfo.setUserId(userInfo.getUniqueId());
	metaStore.createWorkspace(workspaceInfo);

	// create the project
	String projectName = "Orion Project";
	ProjectInfo projectInfo = new ProjectInfo();
	projectInfo.setFullName(projectName);
	projectInfo.setWorkspaceId(workspaceInfo.getUniqueId());
	metaStore.createProject(projectInfo);

	// create a project directory and file
	IFileStore projectFolder = metaStore.getDefaultContentLocation(projectInfo);
	if (!projectFolder.fetchInfo().exists()) {
		projectFolder.mkdir(EFS.NONE, null);
	}
	assertTrue(projectFolder.fetchInfo().exists());
	assertTrue(projectFolder.fetchInfo().isDirectory());
	String fileName = "file.html";
	IFileStore file = projectFolder.getChild(fileName);
	try {
		OutputStream outputStream = file.openOutputStream(EFS.NONE, null);
		outputStream.write("<!doctype html>".getBytes());
		outputStream.close();
	} catch (IOException e) {
		fail("Count not create a test file in the Orion Project:" + e.getLocalizedMessage());
	}
	assertTrue("the file in the project folder should exist.", file.fetchInfo().exists());

	// update the project with the content location
	projectInfo.setContentLocation(projectFolder.toLocalFile(EFS.NONE, null).toURI());
	metaStore.updateProject(projectInfo);

	// move the project by renaming the project by changing the projectName
	String movedProjectName = "Moved Orion Project";
	projectInfo.setFullName(movedProjectName);

	// update the project
	metaStore.updateProject(projectInfo);

	// read the project back again
	ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName());
	assertNotNull(readProjectInfo);
	assertTrue(readProjectInfo.getFullName().equals(movedProjectName));

	// verify the local project has moved
	IFileStore workspaceFolder = metaStore.getWorkspaceContentLocation(workspaceInfo.getUniqueId());
	projectFolder = workspaceFolder.getChild(projectName);
	assertFalse("the original project folder should not exist.", projectFolder.fetchInfo().exists());
	projectFolder = workspaceFolder.getChild(movedProjectName);
	assertTrue("the new project folder should exist.", projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory());
	file = projectFolder.getChild(fileName);
	assertTrue("the file in the project folder should exist.", file.fetchInfo().exists());
	assertEquals("The ContentLocation should have been updated.", projectFolder.toLocalFile(EFS.NONE, null).toURI(), projectInfo.getContentLocation());

	// delete the project contents
	file.delete(EFS.NONE, null);
	assertFalse("the file in the project folder should not exist.", file.fetchInfo().exists());
}