Java Code Examples for org.eclipse.core.filesystem.IFileStore#getChild()
The following examples show how to use
org.eclipse.core.filesystem.IFileStore#getChild() .
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: NodeJSDeploymentPlanner.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Looks for a Procfile and parses the web command. * @return <code>null</code> iff there is no Procfile present or it does not contain a web command. */ protected String getProcfileCommand(IFileStore contentLocation) { IFileStore procfileStore = contentLocation.getChild(ManifestConstants.PROCFILE); if (!procfileStore.fetchInfo().exists()) return null; InputStream is = null; try { is = procfileStore.openInputStream(EFS.NONE, null); Procfile procfile = Procfile.load(is); return procfile.get(ManifestConstants.WEB); } catch (Exception ex) { /* can't parse the file, fail */ return null; } finally { IOUtilities.safeClose(is); } }
Example 2
Source File: NewJavaProjectWizardPageTwo.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void rememberExistingFiles(URI projectLocation) throws CoreException { fDotProjectBackup= null; fDotClasspathBackup= null; IFileStore file= EFS.getStore(projectLocation); if (file.fetchInfo().exists()) { IFileStore projectFile= file.getChild(FILENAME_PROJECT); if (projectFile.fetchInfo().exists()) { fDotProjectBackup= createBackup(projectFile, "project-desc"); //$NON-NLS-1$ } IFileStore classpathFile= file.getChild(FILENAME_CLASSPATH); if (classpathFile.fetchInfo().exists()) { fDotClasspathBackup= createBackup(classpathFile, "classpath-desc"); //$NON-NLS-1$ } } }
Example 3
Source File: GenericDeploymentPlanner.java From orion.server with Eclipse Public License 1.0 | 6 votes |
/** * Looks for a Procfile and parses the web command. * @return <code>null</code> iff there is no Procfile present or it does not contain a web command. */ private String getProcfileCommand(IFileStore contentLocation) { IFileStore procfileStore = contentLocation.getChild(ManifestConstants.PROCFILE); if (!procfileStore.fetchInfo().exists()) return null; InputStream is = null; try { is = procfileStore.openInputStream(EFS.NONE, null); Procfile procfile = Procfile.load(is); return procfile.get(ManifestConstants.WEB); } catch (Exception ex) { /* can't parse the file, fail */ return null; } finally { IOUtilities.safeClose(is); } }
Example 4
Source File: SimpleMetaStore.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@Override public IFileStore getWorkspaceContentLocation(String workspaceId) throws CoreException { if (workspaceId == null) { throw new CoreException( new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.getWorkspaceContentLocation: workspace id is null.", null)); } String userId = SimpleMetaStoreUtil.decodeUserIdFromWorkspaceId(workspaceId); if (userId == null) { throw new CoreException( new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.getWorkspaceContentLocation: there's no user id in workspace id '" + workspaceId + "'", null)); } String encodedWorkspaceName = SimpleMetaStoreUtil.decodeWorkspaceNameFromWorkspaceId(workspaceId); File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(getRootLocation(), userId); File workspaceMetaFolder = SimpleMetaStoreUtil.readMetaFolder(userMetaFolder, encodedWorkspaceName); IFileStore userHome = getUserHome(userId); IFileStore workspaceFolder = userHome.getChild(workspaceMetaFolder.getName()); return workspaceFolder; }
Example 5
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 6 votes |
@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 6
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public static void encodeChildren(IFileStore dir, URI location, JSONObject result, int depth, boolean addLocation) throws CoreException { if (depth <= 0) return; JSONArray children = new JSONArray(); //more efficient to ask for child information in bulk for certain file systems IFileInfo[] childInfos = dir.childInfos(EFS.NONE, null); for (IFileInfo childInfo : childInfos) { IFileStore childStore = dir.getChild(childInfo.getName()); String name = childInfo.getName(); if (childInfo.isDirectory()) name += "/"; //$NON-NLS-1$ URI childLocation = URIUtil.append(location, name); JSONObject childResult = ServletFileStoreHandler.toJSON(childStore, childInfo, addLocation ? childLocation : null); if (childInfo.isDirectory()) encodeChildren(childStore, childLocation, childResult, depth - 1); children.put(childResult); } try { result.put(ProtocolConstants.KEY_CHILDREN, children); } catch (JSONException e) { // cannot happen throw new RuntimeException(e); } }
Example 7
Source File: DirectoryHandlerV1.java From orion.server with Eclipse Public License 1.0 | 6 votes |
private boolean handlePost(HttpServletRequest request, HttpServletResponse response, IFileStore dir) throws JSONException, CoreException, ServletException, IOException { //setup and precondition checks JSONObject requestObject = OrionServlet.readJSONRequest(request); String name = computeName(request, requestObject); if (name.length() == 0) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "File name not specified.", null)); IFileStore toCreate = dir.getChild(name); if (!name.equals(toCreate.getName()) || name.contains(":")) return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Bad file name: " + name, null)); int options = getCreateOptions(request); boolean destinationExists = toCreate.fetchInfo(EFS.NONE, null).exists(); if (!validateOptions(request, response, toCreate, destinationExists, options)) return true; //perform the operation if (performPost(request, response, requestObject, toCreate, options)) { //write the response URI location = URIUtil.append(getURI(request), name); JSONObject result = ServletFileStoreHandler.toJSON(toCreate, toCreate.fetchInfo(EFS.NONE, null), location); result.append("FileEncoding", System.getProperty("file.encoding")); OrionServlet.writeJSONResponse(request, response, result); response.setHeader(ProtocolConstants.HEADER_LOCATION, ServletResourceHandler.resovleOrionURI(request, location).toASCIIString()); //response code should indicate if a new resource was actually created or not response.setStatus(destinationExists ? HttpServletResponse.SC_OK : HttpServletResponse.SC_CREATED); } return true; }
Example 8
Source File: ResourceUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static IFileStore getSibling(IFileStore file, String name) { IFileStore parent = file.getParent(); if (parent == null) { return null; } return parent.getChild(name); }
Example 9
Source File: Packager.java From orion.server with Eclipse Public License 1.0 | 5 votes |
protected void writeZip(IFileStore source, IPath path, ZipOutputStream zos) throws CoreException, IOException { /* load .cfignore if present */ IFileStore cfIgnoreFile = source.getChild(CF_IGNORE_FILE); if (cfIgnoreFile.fetchInfo().exists()) { IgnoreNode node = new IgnoreNode(); InputStream is = null; try { is = cfIgnoreFile.openInputStream(EFS.NONE, null); node.parse(is); cfIgnore.put(source.toURI(), node); } finally { if (is != null) is.close(); } } IFileInfo info = source.fetchInfo(EFS.NONE, null); if (info.isDirectory()) { if (!isIgnored(source, path, true)) for (IFileStore child : source.childStores(EFS.NONE, null)) writeZip(child, path.append(child.getName()), zos); } else { if (!isIgnored(source, path, false)) { ZipEntry entry = new ZipEntry(path.toString()); zos.putNextEntry(entry); IOUtilities.pipe(source.openInputStream(EFS.NONE, null), zos, true, false); } } }
Example 10
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@Test public void testGetWorkspaceContentLocation() 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); // get the workspace content location IFileStore workspaceHome = metaStore.getWorkspaceContentLocation(workspaceInfo.getUniqueId()); String location = workspaceHome.toLocalFile(EFS.NONE, null).toString(); IFileStore root = OrionConfiguration.getRootLocation(); IFileStore childLocation = root.getChild("te/testGetWorkspaceContentLocation/OrionContent"); String correctLocation = childLocation.toLocalFile(EFS.NONE, null).toString(); assertEquals(correctLocation, location); }
Example 11
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@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 12
Source File: PackageTests.java From textuml with Eclipse Public License 1.0 | 5 votes |
public void testModelPath() throws CoreException, IOException { String librarySource = ""; librarySource += "model library;\n"; librarySource += "class BaseClass end;\n"; librarySource += "end."; parseAndCheck(librarySource); IFileStore originalLocation = getRepositoryDir(); IFileStore destination = originalLocation.getParent().getChild(getName() + "_library"); originalLocation.move(destination, EFS.NONE, null); IFileStore loadedModelLocation = destination.getChild("library.uml"); assertTrue(loadedModelLocation.fetchInfo().exists()); IFileStore projectRoot = originalLocation; Properties settings = createDefaultSettings(); settings.put(IRepository.LOADED_PACKAGES, loadedModelLocation.toURI().toString()); saveSettings(projectRoot, settings); String source = ""; source += "model someModel;\n"; source += "import library;\n"; source += "class MyClass specializes library::BaseClass end;\n"; source += "end."; parseAndCheck(source); assertTrue(originalLocation.getChild("someModel.uml").fetchInfo().exists()); assertFalse(originalLocation.getChild("library.uml").fetchInfo().exists()); assertNotNull(getRepository().findPackage("someModel", IRepository.PACKAGE.getModel())); assertNotNull(getRepository().findNamedElement("library::BaseClass", IRepository.PACKAGE.getClass_(), null)); Package someModel = getRepository().findPackage("someModel", null); Package library = getRepository().findPackage("library", null); assertTrue(someModel.getImportedPackages().contains(library)); }
Example 13
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 5 votes |
@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 14
Source File: FileListDirectoryWalker.java From orion.server with Eclipse Public License 1.0 | 5 votes |
private void init(WorkspaceInfo workspaceInfo, String filterPath) { String workspaceId = workspaceInfo.getUniqueId(); filter = filterPath; IFileStore userHome = OrionConfiguration.getMetaStore().getUserHome(workspaceInfo.getUserId()); workspaceHome = userHome.getChild(workspaceId.substring(workspaceId.indexOf('-') + 1)); try { workspaceRoot = workspaceHome.toLocalFile(EFS.NONE, null); } catch (CoreException e) { // should never happen throw new RuntimeException(e); } workspacePath = "/file/" + workspaceId; workspaceRootSuffixLength = workspaceRoot.getAbsolutePath().length(); }
Example 15
Source File: BuildSettingWizardPage.java From sarl with Apache License 2.0 | 5 votes |
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 16
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@Test public void testArchiveInvalidMetaDataFileInServerWorkspaceRoot() 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 file IFileStore rootLocation = OrionConfiguration.getRootLocation(); String invalid = "delete.html"; IFileStore invalidFileAtRoot = rootLocation.getChild(invalid); try { OutputStream outputStream = invalidFileAtRoot.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(invalidFileAtRoot.fetchInfo().exists()); // read all the users which will trigger the archive List<String> users = metaStore.readAllUsers(); assertNotNull(users); // verify the invalid metadata file has moved to the archive IFileStore archiveFolder = rootLocation.getChild(SimpleMetaStoreUtil.ARCHIVE); assertTrue(archiveFolder.fetchInfo().exists()); assertTrue(archiveFolder.fetchInfo().isDirectory()); IFileStore archivedFile = archiveFolder.getChild(invalid); assertTrue(archivedFile.fetchInfo().exists()); assertFalse(invalidFileAtRoot.fetchInfo().exists()); }
Example 17
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@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 18
Source File: LocalWebServerHttpRequestHandler.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
private void handleRequest(HttpRequest request, HttpResponse response, boolean head) throws HttpException, IOException, CoreException, URISyntaxException { String target = URLDecoder.decode(request.getRequestLine().getUri(), IOUtil.UTF_8); URI uri = URIUtil.fromString(target); IFileStore fileStore = uriMapper.resolve(uri); IFileInfo fileInfo = fileStore.fetchInfo(); if (fileInfo.isDirectory()) { fileInfo = getIndex(fileStore); if (fileInfo.exists()) { fileStore = fileStore.getChild(fileInfo.getName()); } } if (!fileInfo.exists()) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); response.setEntity(createTextEntity(MessageFormat.format( Messages.LocalWebServerHttpRequestHandler_FILE_NOT_FOUND, uri.getPath()))); } else if (fileInfo.isDirectory()) { response.setStatusCode(HttpStatus.SC_FORBIDDEN); response.setEntity(createTextEntity(Messages.LocalWebServerHttpRequestHandler_FORBIDDEN)); } else { response.setStatusCode(HttpStatus.SC_OK); if (head) { response.setEntity(null); } else { File file = fileStore.toLocalFile(EFS.NONE, new NullProgressMonitor()); final File temporaryFile = (file == null) ? fileStore.toLocalFile(EFS.CACHE, new NullProgressMonitor()) : null; response.setEntity(new NFileEntity((file != null) ? file : temporaryFile, getMimeType(fileStore .getName())) { @Override public void close() throws IOException { try { super.close(); } finally { if (temporaryFile != null && !temporaryFile.delete()) { temporaryFile.deleteOnExit(); } } } }); } } }
Example 19
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@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 20
Source File: SimpleMetaStoreTests.java From orion.server with Eclipse Public License 1.0 | 4 votes |
@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()); }