protected void execute(GeneralProjectMigration page, String libraryId, IProgressMonitor monitor2) throws Exception { IProject target = ToolingUtils.importLibrary(libraryId); IProject project2Update = this.project; // copy projects before as requested Boolean projectCopy = page.getFieldValueBoolean(GeneralProjectMigration.Fields.copybefore.toString()); if (projectCopy) { project2Update = null; String newNameParam = page.getFieldValueString(GeneralProjectMigration.Fields.newName.toString()); if (StringUtils.trimToNull(newNameParam) == null) { newNameParam = GeneralProjectMigration.DEFAULT_VALUE_NEWNAME; } IProjectDescription description = project.getDescription(); String newName = newNameParam; description.setName(newName); description.setLocationURI(null); System.out.println( "ModelMigrationWizard.execute() rename project " + project.getName() + " -> " + newName); project.copy(description, true, monitor2); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); project2Update = project; } // execute models conversion ModelMigrationHelper modelMigrationHelper = new ModelMigrationHelper(); modelMigrationHelper.updateProject(project2Update, target, libraryId, projectCopy, monitor2); monitor2.subTask("Refresh project"); IFileHelper.refreshFolder(project2Update); monitor2.done(); }
@BeforeClass public static void beforeTests() { // Local Declarations IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = null; String separator = System.getProperty("file.separator"); String userDir = System.getProperty("user.home") + separator + "ICETests" + separator + "caebatTesterWorkspace"; // Enable Debugging System.setProperty("DebugICE", ""); // Setup the project try { // Get the project handle IPath projectPath = new Path(userDir + separator + ".project"); // Create the project description IProjectDescription desc = ResourcesPlugin.getWorkspace().loadProjectDescription(projectPath); // Get the project handle and create it project = workspaceRoot.getProject(desc.getName()); // Get the project handle and create it project = workspaceRoot.getProject(desc.getName()); // Create the project if it doesn't exist if (!project.exists()) { project.create(desc, new NullProgressMonitor()); } // Open the project if it is not already open if (project.exists() && !project.isOpen()) { project.open(new NullProgressMonitor()); } // Refresh the workspace project.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { // Catch exception for creating the project e.printStackTrace(); fail(); } // Set the global project reference. projectSpace = project; return; }
public void test_newProjectDescription() throws Exception { MockWorkspaceRoot root = new MockWorkspaceRoot(); IProjectDescription description = IProjectUtilities.newDartProjectDescription(root, "foo", null); assertNotNull(description); assertEquals("foo", description.getName()); assertNull(description.getLocation()); }
@SuppressWarnings("deprecation") public void test_newProjectDescription_outsideWorkspace() throws Exception { MockWorkspaceRoot root = new MockWorkspaceRoot(); IPath loc = new Path("/some/other/place"); IProjectDescription description = IProjectUtilities.newDartProjectDescription(root, "foo", loc); assertNotNull(description); assertEquals("foo", description.getName()); assertFalse(root.getLocation().isPrefixOf(description.getLocation())); }
private void restoreWidgetValues() { if (description != null) { nameText.setText(description.getName()); nameText.setEnabled(false); } else { nameText.setText(repository.getName()); } locationText.setText(TernModuleHelper.getPath(repository.getBaseDir())); }
private void cloneFromGit( String gitURL, final IProject projectHandle, final IProjectDescription projectDescription) { IPath path = mainPage.getLocationPath(); // when default is used, getLocationPath() only returns the workspace root, so needs to append // the project name // to the path if (mainPage.useDefaults()) { path = path.append(projectDescription.getName()); } // Wipe the destination directory if it already exists, or git clone will fail. File directory = path.toFile(); if (directory.exists()) { FileUtil.deleteRecursively(directory); } // FIXME Run an IRunnableWithProgress in wizard container, have it just do job.run(monitor)! Job job = new CloneJob(gitURL, path.toOSString(), true, true); job.addJobChangeListener( new JobChangeAdapter() { @Override public void done(IJobChangeEvent event) { if (!event.getResult().isOK()) { return; } try { projectHandle.setDescription(projectDescription, null); projectHandle.refreshLocal(IResource.DEPTH_INFINITE, null); } catch (CoreException e) { IdeLog.logError(SamplesUIPlugin.getDefault(), e); } doPostProjectCreation(newProject); } }); job.schedule(500); }
private IProject openProject(final IPath projectPath) throws CoreException { final ResourceSet set = ScaResourceFactoryUtil.createResourceSet(); final IProgressMonitor progressMonitor = new NullProgressMonitor(); final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IWorkspaceRoot root = workspace.getRoot(); final IWorkspaceDescription description = workspace.getDescription(); final File projectPathFile = projectPath.toFile(); final IPath projectDescriptionPath = projectPath.append(".project"); if (!projectPathFile.isDirectory()) { throw new IllegalStateException("Provided project path must be a directory"); } if (!projectDescriptionPath.toFile().exists()) { throw new IllegalStateException("Provided project path must include .project file"); } final IProjectDescription projDesc = workspace.loadProjectDescription(projectDescriptionPath); final IProject project = root.getProject(projDesc.getName()); if (project.exists()) { // If the project exists, make sure that it is the same project the user requested // ...this should only happen if the user forced a workspace with -data // that already contained a project with the same name but different path // from the one provided on the command line if (!project.getLocation().equals(projectPath.makeAbsolute())) { throw new IllegalStateException( "Provided project path conflicts with existing project in workspace"); } } else { // If the project doesn't exist in the workspace, create a linked project projDesc.setName(projDesc.getName()); if (Platform.getLocation().isPrefixOf(projectPath)) { projDesc.setLocation(null); } else { projDesc.setLocation(projectPath); } final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { final SubMonitor progressMonitor = SubMonitor.convert(monitor, 1); System.out.println( "Loading project " + projDesc.getName() + " " + projDesc.getLocation()); project.create(projDesc, progressMonitor.newChild(1)); } }; try { operation.run(new NullProgressMonitor()); } catch (final InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (final InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } // Finally open the project Assert.isTrue(project.exists()); final WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { @Override protected void execute(final IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { project.open(monitor); } }; try { operation.run(new NullProgressMonitor()); } catch (final InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (final InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return project; }