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

The following examples show how to use org.eclipse.core.filesystem.IFileStore#mkdir() . 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: 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 2
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 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: GitTest.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private static IFileStore getProjectStore(ProjectInfo project, String user) throws CoreException {
	IFileStore projectStore = OrionConfiguration.getMetaStore().getDefaultContentLocation(project);
	if (!projectStore.fetchInfo().exists()) {
		projectStore.mkdir(EFS.NONE, null);
	}
	return projectStore;
}
 
Example 5
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testArchiveEmptyOrganizationalFolder() 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 an empty organizational folder
	IFileStore rootLocation = OrionConfiguration.getRootLocation();
	String orgFolderName = "zz";
	IFileStore orgFolder = rootLocation.getChild(orgFolderName);
	assertFalse(orgFolder.fetchInfo().exists());
	orgFolder.mkdir(EFS.NONE, null);
	assertTrue(orgFolder.fetchInfo().exists());
	assertTrue(orgFolder.fetchInfo().isDirectory());

	// read all the users which will trigger the archive
	List<String> users = metaStore.readAllUsers();
	assertNotNull(users);

	// verify the invalid metadata folder has moved to the archive
	IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE);
	assertTrue(archiveFolder.fetchInfo().exists());
	assertTrue(archiveFolder.fetchInfo().isDirectory());
	IFileStore archivedOrgFolder = archiveFolder.getChild(orgFolderName);
	assertTrue(archivedOrgFolder.fetchInfo().exists());
	assertTrue(archivedOrgFolder.fetchInfo().isDirectory());
	assertFalse(orgFolder.fetchInfo().exists());
}
 
Example 6
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testArchiveInvalidMetaDataFolderInServerWorkspaceRoot() 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 a invalid metadata folder
	IFileStore rootLocation = OrionConfiguration.getRootLocation();
	String invalid = "delete.me";
	IFileStore invalidFolderAtRoot = rootLocation.getChild(invalid);
	assertFalse(invalidFolderAtRoot.fetchInfo().exists());
	invalidFolderAtRoot.mkdir(EFS.NONE, null);
	assertTrue(invalidFolderAtRoot.fetchInfo().exists());
	assertTrue(invalidFolderAtRoot.fetchInfo().isDirectory());

	// read all the users which will trigger the archive
	List<String> users = metaStore.readAllUsers();
	assertNotNull(users);

	// verify the invalid metadata folder has moved to the archive
	IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE);
	assertTrue(archiveFolder.fetchInfo().exists());
	assertTrue(archiveFolder.fetchInfo().isDirectory());
	IFileStore archivedFolder = archiveFolder.getChild(invalid);
	assertTrue(archivedFolder.fetchInfo().exists());
	assertFalse(invalidFolderAtRoot.fetchInfo().exists());
}
 
Example 7
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testCreateProjectUsingFileAPI() throws CoreException {
	IMetaStore metaStore = null;
	try {
		metaStore = OrionConfiguration.getMetaStore();
	} catch (NullPointerException e) {
		// expected when the workbench is not running
	}
	if (!(metaStore instanceof SimpleMetaStore)) {
		// the workbench is not running, just pass the test
		return;
	}

	// 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 a folder under the user on the filesystem
	String projectName = "Orion Project";
	ProjectInfo projectInfo = new ProjectInfo();
	projectInfo.setFullName(projectName);
	projectInfo.setWorkspaceId(workspaceInfo.getUniqueId());
	IFileStore projectFolder = metaStore.getDefaultContentLocation(projectInfo);
	assertFalse(projectFolder.fetchInfo().exists());
	projectFolder.mkdir(EFS.NONE, null);
	assertTrue(projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory());

	// read the project, project json will be created
	ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectName);
	assertNotNull(readProjectInfo);
}
 
Example 8
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testEncodedProjectContentLocation() 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 projectFolder = metaStore.getDefaultContentLocation(projectInfo);
	assertFalse(projectFolder.fetchInfo().exists());
	projectFolder.mkdir(EFS.NONE, null);
	assertTrue(projectFolder.fetchInfo().exists() && projectFolder.fetchInfo().isDirectory());
	projectInfo.setContentLocation(projectFolder.toURI());
	metaStore.createProject(projectInfo);

	// read the project
	ProjectInfo readProjectInfo = metaStore.readProject(workspaceInfo.getUniqueId(), projectInfo.getFullName());
	assertNotNull(readProjectInfo);
	assertEquals(readProjectInfo.getFullName(), projectInfo.getFullName());
	// ensure content location was written and read back successfully 
	assertEquals(projectInfo.getContentLocation(), readProjectInfo.getContentLocation());
}
 
Example 9
Source File: AbstractRepositoryTests.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
protected void saveSettings(IFileStore dir, Properties settings) throws IOException, CoreException {
    ByteArrayOutputStream rendered = new ByteArrayOutputStream();
    settings.store(rendered, null);
    dir.mkdir(EFS.NONE, null);
    FileUtils.writeByteArrayToFile(new File(dir.toLocalFile(EFS.NONE, null), IRepository.MDD_PROPERTIES),
            rendered.toByteArray());
}
 
Example 10
Source File: SimpleMetaStoreTests.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testArchiveInvalidMetaDataFolderInOrganizationalFolder() 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 a invalid metadata folder
	IFileStore rootLocation = OrionConfiguration.getRootLocation();
	String orgFolderName = "te";
	IFileStore orgFolder = rootLocation.getChild(orgFolderName);
	assertTrue(orgFolder.fetchInfo().exists());
	assertTrue(orgFolder.fetchInfo().isDirectory());
	String invalid = "delete.me";
	IFileStore invalidFolderInOrg = orgFolder.getChild(invalid);
	assertFalse(invalidFolderInOrg.fetchInfo().exists());
	invalidFolderInOrg.mkdir(EFS.NONE, null);
	assertTrue(invalidFolderInOrg.fetchInfo().exists());
	assertTrue(invalidFolderInOrg.fetchInfo().isDirectory());

	// read all the users which will trigger the archive
	List<String> users = metaStore.readAllUsers();
	assertNotNull(users);

	// verify the invalid metadata folder has moved to the archive
	IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE);
	assertTrue(archiveFolder.fetchInfo().exists());
	assertTrue(archiveFolder.fetchInfo().isDirectory());
	IFileStore archiveOrgFolder = archiveFolder.getChild(orgFolderName);
	assertTrue(archiveOrgFolder.fetchInfo().exists());
	assertTrue(archiveOrgFolder.fetchInfo().isDirectory());
	IFileStore archivedFolder = archiveOrgFolder.getChild(invalid);
	assertTrue(archivedFolder.fetchInfo().exists());
	assertTrue(archivedFolder.fetchInfo().isDirectory());
	assertFalse(invalidFolderInOrg.fetchInfo().exists());
}
 
Example 11
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 12
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());
}
 
Example 13
Source File: AbstractCodeCreationOperation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Creates a package fragment with the given name.
 *
 * @param store
 *            the file store
 * @param name
 *            the name of the package
 * @param monitor
 *            the progress monitor to use
 * @throws CoreException
 *             if an error occurs while creating the package fragment
 */
protected void createPackageFragment(final IFileStore store, final String name, final IProgressMonitor monitor) throws CoreException {
	store.mkdir(EFS.NONE, monitor);
}