/** * 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()); }
/** Test for Bug #5102. Never reproduced but interesting little test, worth keeping around */ public void testPR() throws Exception { // create a project with a RefreshLocalJavaFileBuilder and a SortBuilder on the classpath IProject project = getWorkspace().getRoot().getProject("P1"); project.create(null); project.open(null); IProjectDescription desc = project.getDescription(); ICommand one = desc.newCommand(); one.setBuilderName(RefreshLocalJavaFileBuilder.BUILDER_NAME); ICommand two = desc.newCommand(); two.setBuilderName(SortBuilder.BUILDER_NAME); desc.setBuildSpec(new ICommand[] {one, two}); project.setDescription(desc, null); // do a full build project.build(IncrementalProjectBuilder.FULL_BUILD, null); // do an incremental build by creating a file IFile file = project.getFile("Foo"); file.create(getRandomContents(), true, getMonitor()); }
public void testDeleteProjectWithVirtualFolderAndLink() { IPath folderLocation = getRandomLocation(); IFolder virtualFolder = existingProject.getFolder(getUniqueString()); IFolder linkedFolder = virtualFolder.getFolder("a_link"); try { try { folderLocation.toFile().mkdir(); virtualFolder.create(IResource.VIRTUAL, true, null); linkedFolder.createLink(folderLocation, IResource.NONE, getMonitor()); existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor()); existingProject.create(getMonitor()); } catch (CoreException e) { fail("1.0", e); } // virtual folder should not exist until the project is open assertTrue("2.0", !virtualFolder.exists()); assertTrue("3.0", !linkedFolder.exists()); try { existingProject.open(getMonitor()); } catch (CoreException e) { fail("4.0", e); } // virtual folder should now exist assertTrue("5.0", virtualFolder.exists()); assertTrue("6.0", virtualFolder.isVirtual()); // link should now exist assertTrue("7.0", linkedFolder.exists()); assertTrue("8.0", linkedFolder.isLinked()); assertEquals("9.0", folderLocation, linkedFolder.getLocation()); } finally { Workspace.clear(folderLocation.toFile()); } }
public void testDeleteProjectWithVirtualFolder() { IFolder virtualFolder = existingProject.getFolder(getUniqueString()); try { virtualFolder.create(IResource.VIRTUAL, true, null); existingProject.delete(IResource.NEVER_DELETE_PROJECT_CONTENT, getMonitor()); existingProject.create(getMonitor()); } catch (CoreException e) { fail("1.0", e); } // virtual folder should not exist until the project is open assertTrue("2.0", !virtualFolder.exists()); try { existingProject.open(getMonitor()); } catch (CoreException e) { fail("3.0", e); } // virtual folder should now exist assertTrue("4.0", virtualFolder.exists()); assertTrue("5.0", virtualFolder.isVirtual()); }
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; }
/** * The worker method. It will create a new project, then create the appropriate Soar heirarchy and * files. */ private void doFinish(String projectName, IProgressMonitor monitor) throws CoreException { monitor.beginTask("Creating " + projectName, 7); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject newProject = root.getProject(projectName); // creation of the project if (newProject.exists()) { throwCoreException("Project \"" + projectName + "\" already exists"); } else { newProject.create(monitor); newProject.open(monitor); try { IProjectDescription description = newProject.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = SoarProjectNature.NATURE_ID; description.setNatureIds(newNatures); newProject.setDescription(description, IResource.FORCE, monitor); newProject.setPersistentProperty(DataMap.VERTEX_ID, "0"); } catch (CoreException e) { e.printStackTrace(); } // catch } // else monitor.worked(2); // Create the contents of the project's root directory IFolder folderAll = newProject.getFolder("all"); if (!folderAll.exists()) { folderAll.create(true, true, monitor); } // if FileMarker.markResource(folderAll, "file"); IFolder folderElaborations = newProject.getFolder("elaborations"); if (!folderElaborations.exists()) { folderElaborations.create(true, true, monitor); } // if FileMarker.markResource(folderElaborations, "file"); IFile file_firstload = newProject.getFile("_firstload.soar"); if (!file_firstload.exists()) { file_firstload.create( Utility.getFileTemplate(file_firstload, "_firstload.soar"), true, monitor); } // if FileMarker.markResource(file_firstload, "file"); IFile filedatamap = newProject.getFile("datamap.xdm"); if (!filedatamap.exists()) { filedatamap.create(Utility.getFileTemplate(filedatamap, "datamap.xdm"), true, monitor); } // if monitor.worked(3); // Create the contents of the elaborations folder IFile file_all = folderElaborations.getFile("_all.soar"); if (!file_all.exists()) { file_all.create(Utility.getFileTemplate(file_all, "_all.soar"), true, monitor); } // if FileMarker.markResource(file_all, "file"); IFile filetopstate = folderElaborations.getFile("top-state.soar"); if (!filetopstate.exists()) { filetopstate.create(Utility.getFileTemplate(filetopstate, "top-state.soar"), true, monitor); } // if FileMarker.markResource(filetopstate, "file"); SourcingFile.createSourcingFile(newProject, monitor); newProject.close(monitor); newProject.open(monitor); monitor.worked(2); monitor.done(); } // void doFinish(...)
private void createProject(IFeatureModel model, IProgressMonitor monitor) throws CoreException { String name = model.getFeature().getId(); IFeaturePlugin[] plugins = model.getFeature().getPlugins(); for (int i = 0; i < plugins.length; i++) { if (name.equals(plugins[i].getId())) { name += "-feature"; // $NON-NLS-1$ break; } } String task = NLS.bind(MDEUIMessages.FeatureImportWizard_operation_creating2, name); monitor.beginTask(task, 9); try { IProject project = fRoot.getProject(name); if (project.exists() || new File(project.getParent().getLocation().toFile(), name).exists()) { if (queryReplace(project)) { if (!project.exists()) project.create(new SubProgressMonitor(monitor, 1)); project.delete(true, true, new SubProgressMonitor(monitor, 1)); try { RepositoryProvider.unmap(project); } catch (TeamException e) { } } else { return; } } else { monitor.worked(1); } IProjectDescription description = MDEPlugin.getWorkspace().newProjectDescription(name); if (fTargetPath != null) description.setLocation(fTargetPath.append(name)); project.create(description, new SubProgressMonitor(monitor, 1)); if (!project.isOpen()) { project.open(null); } File featureDir = new File(model.getInstallLocation()); importContent( featureDir, project.getFullPath(), FileSystemStructureProvider.INSTANCE, null, new SubProgressMonitor(monitor, 1)); IFolder folder = project.getFolder("META-INF"); // $NON-NLS-1$ if (folder.exists()) { folder.delete(true, null); } if (fBinary) { // Mark this project so that we can show image overlay // using the label decorator project.setPersistentProperty( MDECore.EXTERNAL_PROJECT_PROPERTY, MDECore.BINARY_PROJECT_VALUE); } createBuildProperties(project); setProjectNatures(project, model, monitor); if (project.hasNature(JavaCore.NATURE_ID)) setClasspath(project, model, monitor); } finally { monitor.done(); } }