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(); }
public void testCopyProjectWithVirtualFolder() { IPath fileLocation = getRandomLocation(); IPath folderLocation = getRandomLocation(); IFile linkedFile = existingVirtualFolderInExistingProject.getFile(getUniqueString()); IFolder linkedFolder = existingVirtualFolderInExistingProject.getFolder(getUniqueString()); try { try { createFileInFileSystem(fileLocation, getRandomContents()); folderLocation.toFile().mkdir(); linkedFolder.createLink(folderLocation, IResource.NONE, getMonitor()); linkedFile.createLink(fileLocation, IResource.NONE, getMonitor()); } catch (CoreException e) { fail("1.0", e); } // copy the project IProject destinationProject = getWorkspace().getRoot().getProject("CopyTargetProject"); try { existingProject.copy(destinationProject.getFullPath(), IResource.SHALLOW, getMonitor()); } catch (CoreException e) { fail("2.0", e); } IFile newFile = destinationProject.getFile(linkedFile.getProjectRelativePath()); assertTrue("3.0", newFile.isLinked()); assertEquals("3.1", linkedFile.getLocation(), newFile.getLocation()); assertTrue("3.2", newFile.getParent().isVirtual()); IFolder newFolder = destinationProject.getFolder(linkedFolder.getProjectRelativePath()); assertTrue("4.0", newFolder.isLinked()); assertEquals("4.1", linkedFolder.getLocation(), newFolder.getLocation()); assertTrue("4.2", newFolder.getParent().isVirtual()); // test project deep copy try { destinationProject.delete(IResource.NONE, getMonitor()); existingProject.copy(destinationProject.getFullPath(), IResource.NONE, getMonitor()); } catch (CoreException e) { fail("5.0", e); } assertTrue("5.1", newFile.isLinked()); assertEquals("5.2", linkedFile.getLocation(), newFile.getLocation()); assertTrue("5.3", newFile.getParent().isVirtual()); assertTrue("5.4", newFolder.isLinked()); assertEquals("5.5", linkedFolder.getLocation(), newFolder.getLocation()); assertTrue("5.6", newFolder.getParent().isVirtual()); try { destinationProject.delete(IResource.NONE, getMonitor()); } catch (CoreException e) { fail("6.0", e); } } finally { Workspace.clear(fileLocation.toFile()); Workspace.clear(folderLocation.toFile()); } }