Refine search
private void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { IProjectDescription description = proj.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); newNatures[prevNatures.length] = natureId; description.setNatureIds(newNatures); proj.setDescription(description, monitor); }
public static void addBuilder(IProject project, String builderId) throws CoreException { IProjectDescription description = project.getDescription(); ICommand[] specs = description.getBuildSpec(); ICommand command = description.newCommand(); command.setBuilderName(builderId); // Add the nature ICommand[] specsModified = new ICommand[specs.length + 1]; System.arraycopy(specs, 0, specsModified, 0, specs.length); specsModified[specs.length] = command; description.setBuildSpec(specsModified); project.setDescription(description, monitor()); }
private void createProj(IProject newProj, boolean isJavaProject) throws CoreException { newProj.create(null); IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(newProj.getName()); // if (isJavaProject) // description.setNatureIds(new String[]{JavaCore.NATURE_ID}); description.setLocation(null); newProj.open(null); newProj.setDescription(description, null); }
public static void addJavaNature(IProjectDescription projectDescription) { List<String> list = new ArrayList<String>(); list.addAll(Arrays.asList(projectDescription.getNatureIds())); list.add("org.eclipse.jdt.core.javanature"); projectDescription.setNatureIds((String[]) list.toArray(new String[list.size()])); }
public static IProject copyProject(String projectName) throws CoreException { IProgressMonitor m = new NullProgressMonitor(); IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); IProject project = workspaceRoot.getProject(projectName); IProjectDescription projectDescription = project.getDescription(); String cloneName = projectName + "_copy"; // create clone project in workspace IProjectDescription cloneDescription = workspaceRoot.getWorkspace().newProjectDescription(cloneName); // copy project files project.copy(cloneDescription, true, m); IProject clone = workspaceRoot.getProject(cloneName); // copy the project properties cloneDescription.setNatureIds(projectDescription.getNatureIds()); cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects()); cloneDescription.setDynamicReferences(projectDescription.getDynamicReferences()); cloneDescription.setBuildSpec(projectDescription.getBuildSpec()); cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects()); clone.setDescription(cloneDescription, null); return clone; }
public static void createProject(IProject project, IPath location, IProgressMonitor monitor) throws CoreException { if (!Platform.getLocation().equals(location)) { IProjectDescription desc = project.getWorkspace() .newProjectDescription(project.getName()); desc.setLocation(location); project.create(desc, monitor); } else project.create(monitor); }
private IProject configNewProject(IWorkspaceRoot root, String name, String[] natureIds, IProject[] referencedProjects, IProgressMonitor monitor) throws InvocationTargetException { try { IProject project = root.getProject(name); if (!project.exists()) { project.create(null); } if (!project.isOpen()) { project.open(null); } IProjectDescription desc = project.getDescription(); desc.setLocation(null); desc.setNatureIds(natureIds); desc.setReferencedProjects(referencedProjects); project.setDescription(desc, new SubProgressMonitor(monitor, 1)); return project; } catch (CoreException e) { throw new InvocationTargetException(e); } }
@Override protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { IProjectDescription projectDescription = from.getDescription(); IProject[] projects = projectDescription .getReferencedProjects(); IProject[] newProjects = new IProject[projects.length + 1]; System.arraycopy(projects, 0, newProjects, 0, projects.length); newProjects[projects.length] = to; projectDescription.setReferencedProjects(newProjects); from.setDescription(projectDescription, monitor()); } }.run(monitor());
protected void updateRequiredProjects(IJavaProject jproject, String[] prevRequiredProjects, IProgressMonitor monitor) throws CoreException { String[] newRequiredProjects = jproject.getRequiredProjectNames(); ArrayList prevEntries = new ArrayList(Arrays.asList(prevRequiredProjects)); ArrayList newEntries = new ArrayList(Arrays.asList(newRequiredProjects)); IProject proj = jproject.getProject(); IProjectDescription projDesc = proj.getDescription(); ArrayList newRefs = new ArrayList(); IProject[] referencedProjects = projDesc.getReferencedProjects(); for (int i = 0; i < referencedProjects.length; i++) { String curr = referencedProjects[i].getName(); if (newEntries.remove(curr) || !prevEntries.contains(curr)) { newRefs.add(referencedProjects[i]); } } IWorkspaceRoot root = proj.getWorkspace().getRoot(); for (int i = 0; i < newEntries.size(); i++) { String curr = (String) newEntries.get(i); newRefs.add(root.getProject(curr)); } projDesc.setReferencedProjects((IProject[]) newRefs.toArray(new IProject[newRefs.size()])); proj.setDescription(projDesc, monitor); } }
public boolean doUpdateClasspath(IProgressMonitor monitor, IPluginModelBase[] models) throws CoreException { monitor.beginTask(PDEUIMessages.UpdateClasspathJob_task, models.length); try { for (IPluginModelBase model : models) { monitor.subTask(model.getPluginBase().getId()); // no reason to compile classpath for a non-Java model IProject project = model.getUnderlyingResource().getProject(); if (!project.hasNature(JavaCore.NATURE_ID)) { monitor.worked(1); continue; } IProjectDescription projDesc = project.getDescription(); if (projDesc == null) continue; projDesc.setReferencedProjects(new IProject[0]); project.setDescription(projDesc, null); IFile file = project.getFile(".project"); //$NON-NLS-1$ if (file.exists()) file.deleteMarkers(PDEMarkerFactory.MARKER_ID, true, IResource.DEPTH_ZERO); ClasspathComputer.setClasspath(project, model); monitor.worked(1); if (monitor.isCanceled()) return false; } } finally { monitor.done(); } return true; }
private boolean hasJavaBuilder(IProject project) throws CoreException { ICommand[] buildCommands = project.getDescription().getBuildSpec(); for (int i = 0, l = buildCommands.length; i < l; i++) if (buildCommands[i].getBuilderName().equals(JavaCore.BUILDER_ID)) return true; return false; }
/** * Adds a builder to the build spec for the given project. */ protected void addToBuildSpec(String builderID) throws CoreException { IProjectDescription description = this.project.getDescription(); int javaCommandIndex = getJavaCommandIndex(description.getBuildSpec()); if (javaCommandIndex == -1) { // Add a Java command to the build spec ICommand command = description.newCommand(); command.setBuilderName(builderID); setJavaCommand(description, command); } } /**
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription(new Path(BuildPath + "/.project")); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName()); IProject[] array = ResourcesPlugin.getWorkspace().getRoot().getProjects(); for(int count = 0; count <= array.length - 1; count ++){ if(project.equals(array[count])){ array[count].close(null); array[count].delete(true, null); } } project.create(description, null); project.open(null);
public static String[] getNatures(IProject[] projects) throws CoreException { Set<String> result= new HashSet<>(); for (int i= 0; i < projects.length; i++) { String[] pns= projects[i].getDescription().getNatureIds(); for (int p = 0; p < pns.length; p++) { result.add(pns[p]); } } return result.toArray(new String[result.size()]); } }
private void setProjectNatures(IProject project, IFeatureModel model, SubMonitor subMonitor) throws CoreException { IProjectDescription desc = project.getDescription(); if (needsJavaNature(model)) { desc.setNatureIds(new String[] {JavaCore.NATURE_ID, PDE.FEATURE_NATURE}); } else { desc.setNatureIds(new String[] {PDE.FEATURE_NATURE}); } subMonitor.setWorkRemaining(1); project.setDescription(desc, subMonitor.split(1)); }
public void deconfigure() throws CoreException { IProjectDescription description = getProject().getDescription(); ICommand[] commands = description.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(BndBuilder.BUILDER_ID)) { ICommand[] newCommands = new ICommand[commands.length - 1]; System.arraycopy(commands, 0, newCommands, 0, i); System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); description.setBuildSpec(newCommands); return; } } }
public static void addBuilders(IProject project, String[] id, IProgressMonitor monitor) throws CoreException { IProjectDescription desc = project.getDescription(); List<ICommand> newCommands = getCommands(desc, id); for (int i = 0; i < id.length; i++) { ICommand command = desc.newCommand(); command.setBuilderName(id[i]); newCommands.add(command); } setCommands(desc, newCommands); project.setDescription(desc, monitor); }
@Override public Collection<IProjectDescription> getNewProjectDescriptions() { Collection<IProjectDescription> result = new ArrayList<IProjectDescription> (); IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProject project = getProjectHandle(); IPath newPath = useDefaults() ? null : getLocationPath(); IProjectDescription description = workspace.newProjectDescription(project.getName()); description.setLocation(newPath); result.add(description); return result; }
@Override public void run(IMarker marker) { try { IProject project = marker.getResource().getProject(); if (project == null) return; IProjectDescription projDesc = project.getDescription(); if (projDesc == null) return; projDesc.setReferencedProjects(new IProject[0]); project.setDescription(projDesc, null); } catch (CoreException e) { } }