public static void updateProjectReferences( IIncludePathEntry[] newEntries, IIncludePathEntry[] oldEntries, final IProject project, SubProgressMonitor monitor) { try { boolean changedReferences = false; final IProjectDescription projectDescription = project.getDescription(); List<IProject> referenced = new ArrayList<IProject>(); List<String> referencedNames = new ArrayList<String>(); IProject[] referencedProjects = projectDescription.getReferencedProjects(); for (IProject refProject : referencedProjects) { referenced.add(refProject); referencedNames.add(refProject.getName()); } for (IIncludePathEntry oldEntry : oldEntries) { if (oldEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) { String projectName = oldEntry.getPath().lastSegment(); if (!containsProject(newEntries, projectName)) { if (((IncludePathEntry) oldEntry).createdReference) { int index = referencedNames.indexOf(projectName); if (index >= 0) { changedReferences = true; referencedNames.remove(index); referenced.remove(index); } } } } } for (IIncludePathEntry newEntry : newEntries) { if (newEntry.getEntryKind() == IIncludePathEntry.IPE_PROJECT) { String projectName = newEntry.getPath().lastSegment(); if (!containsProject(oldEntries, projectName)) { if (!referencedNames.contains(projectName)) { changedReferences = true; ((IncludePathEntry) newEntry).createdReference = true; referenced.add(ResourcesPlugin.getWorkspace().getRoot().getProject(projectName)); referencedNames.add(projectName); } } } } if (changedReferences) { IProject[] referenceProjects = (IProject[]) referenced.toArray(new IProject[referenced.size()]); projectDescription.setReferencedProjects(referenceProjects); WorkspaceJob job = new WorkspaceJob(CoreMessages.getString("IncludePathEntry_2")) // $NON-NLS-1$ { public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { project.setDescription(projectDescription, monitor); return Status.OK_STATUS; } }; job.setRule(project.getParent()); job.schedule(); } } catch (CoreException e) { PHPEplPlugin.logError(e); } }
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(); } }