/** * The worker method. It will find the container, create the file if missing or just replace its * contents, and open the editor on the newly created file. */ private void doFinish(String containerName, String fileName, IProgressMonitor monitor) throws CoreException { // create a sample file monitor.beginTask("Creating " + fileName, 2); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource resource = root.findMember(new Path(containerName)); // if (!(resource.exists()) || !(resource instanceof IContainer)) { if (resource == null || !(resource.exists()) || !(resource instanceof IContainer)) { // throwCoreException("Container \"" + containerName + // "\" does not exist."); IProject datamapperProject = root.getProject(containerName); datamapperProject.create(null); datamapperProject.open(null); // datamapperProject. } IContainer container = (IContainer) resource; // // // final IFile file = container.getFile(new Path(fileName)); // try { // InputStream stream = openContentStream(); // if (file.exists()) { // // file.setContents(null, true, true, monitor); // } else { // file.create(null, true, monitor); // // } // stream.close();` // } catch (IOException e) { // } // monitor.worked(1); // monitor.setTaskName("Opening file for editing..."); // getShell().getDisplay().asyncExec(new Runnable() { // public void run() { // IWorkbenchPage page = // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); // try { // IDE.openEditor(page, file); // } catch (PartInitException e) { // } // } // }); // monitor.worked(1); }
private static void setUpProject() throws Exception { IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("test.rap"); if (!project.exists()) { project.create(null); project.open(null); } IFolder webInf = project.getFolder("WEB-INF"); if (!webInf.exists()) { webInf.create(true, true, null); } IFile file = webInf.getFile("web.xml"); if (!file.exists()) { File tempFile = File.createTempFile("test", ".xml"); FileInputStream stream = new FileInputStream(tempFile); file.create(stream, true, null); } }
public void testContainsServletBridgeLibrary() throws Exception { IWARProduct product = createBasicProduct(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wsRoot.getProject("warProduct"); if (!project.exists()) { project.create(null); project.open(null); } IFile jar = project.getFile(SERVLETBRIDGE + ".jar"); if (!jar.exists()) { File bridge = File.createTempFile(SERVLETBRIDGE, ".jar"); FileInputStream stream = new FileInputStream(bridge); jar.create(stream, true, null); } product.addLibrary(jar.getFullPath(), false); Validator validator = new Validator(product); Validation validation = validator.validate(); assertTrue(validation.isValid()); }
private IWARProduct createBasicProductWithLibraries() throws Exception { IWARProduct product = createBasicProduct(); IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = wsRoot.getProject("warProduct"); if (!project.exists()) { project.create(null); project.open(null); } IFile jar = project.getFile("test.jar"); if (!jar.exists()) { File testJar = File.createTempFile("test", ".jar"); FileInputStream stream = new FileInputStream(testJar); jar.create(stream, true, null); } product.addLibrary(jar.getFullPath(), false); IFile bridge = project.getFile(SERVLETBRIDGE + ".jar"); if (!bridge.exists()) { File bridgeJar = File.createTempFile(SERVLETBRIDGE, ".jar"); FileInputStream stream = new FileInputStream(bridgeJar); bridge.create(stream, true, null); } product.addLibrary(bridge.getFullPath(), false); return product; }
/** * Tries to delete a closed project containing an unremovable file. Works only for Linux with * natives. * * <p>TODO: enable this test once bug 48321 is fixed. */ public void testDeleteClosedProjectLinux() { if (!(Platform.getOS().equals(Platform.OS_LINUX))) return; IProject project = null; File projectRoot = null; IFolder folder = null; try { IWorkspace workspace = getWorkspace(); project = workspace.getRoot().getProject(getUniqueString()); folder = project.getFolder("a_folder"); IFile file1 = folder.getFile("file1.txt"); IFile file2 = project.getFile("file2.txt"); IFile projectFile = project.getFile(new Path(".project")); ensureExistsInWorkspace(new IResource[] {file1, file2}, true); projectRoot = project.getLocation().toFile(); // marks folder as read-only so its files cannot be removed on Linux setReadOnly(folder, true); try { project.close(getMonitor()); } catch (CoreException e) { fail("1.0", e); } try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); fail("2.0 - should have failed"); } catch (CoreException ce) { // success - a file couldn't be removed } assertTrue("3.0", project.exists()); assertTrue("3.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertExistsInFileSystem("3.2", projectFile); try { project.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } setReadOnly(folder, false); try { project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, getMonitor()); } catch (CoreException ce) { ce.printStackTrace(); fail("5.0", ce); } assertTrue("6.0", !project.exists()); assertTrue("6.1", project.isSynchronized(IResource.DEPTH_INFINITE)); assertTrue("6.2", !projectRoot.exists()); assertDoesNotExistInFileSystem("6.3", projectFile); } finally { if (folder != null && folder.exists()) setReadOnly(folder, false); if (projectRoot != null) ensureDoesNotExistInFileSystem(projectRoot); } }