Java Code Examples for org.eclipse.core.resources.IProjectDescription#setNatureIds()
The following examples show how to use
org.eclipse.core.resources.IProjectDescription#setNatureIds() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConfigureDeconfigureNatureJob.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Helper method to disable the given nature for the project. * * @throws CoreException * an error while removing the nature occured */ private void disableNature() throws CoreException { IProjectDescription desc = mProject.getDescription(); String[] natures = desc.getNatureIds(); // remove given nature from the array List<String> newNaturesList = new ArrayList<>(); for (int i = 0; i < natures.length; i++) { if (!mNatureId.equals(natures[i])) { newNaturesList.add(natures[i]); } } String[] newNatures = newNaturesList.toArray(new String[newNaturesList.size()]); // set natures desc.setNatureIds(newNatures); mProject.setDescription(desc, mMonitor); }
Example 2
Source File: ProjectUtilities.java From spotbugs with GNU Lesser General Public License v2.1 | 6 votes |
/** * Removes the FindBugs nature from a project. * * @param project * The project the nature will be removed from. * @param monitor * A progress monitor. Must not be null. * @throws CoreException */ public static void removeFindBugsNature(IProject project, IProgressMonitor monitor) throws CoreException { if (!hasFindBugsNature(project)) { return; } IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); ArrayList<String> newNaturesList = new ArrayList<>(); for (int i = 0; i < prevNatures.length; i++) { if (!FindbugsPlugin.NATURE_ID.equals(prevNatures[i])) { newNaturesList.add(prevNatures[i]); } } String[] newNatures = newNaturesList.toArray(new String[newNaturesList.size()]); description.setNatureIds(newNatures); project.setDescription(description, monitor); }
Example 3
Source File: IResourcesSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
public static void removeNature(IProject project, String nature) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (nature.equals(natures[i])) { // Remove the nature String[] newNatures = new String[natures.length - 1]; System.arraycopy(natures, 0, newNatures, 0, i); System.arraycopy(natures, i + 1, newNatures, i, natures.length - i - 1); description.setNatureIds(newNatures); project.setDescription(description, null); return; } } }
Example 4
Source File: ProjectFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected IProjectDescription createProjectDescription() { final IProjectDescription projectDescription = workspace.newProjectDescription(projectName); if (location != null && !Platform.getLocation().equals(location.removeLastSegments(1))) { projectDescription.setLocation(location); } if (referencedProjects != null && referencedProjects.size() != 0) { projectDescription .setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()])); } if (projectNatures != null) projectDescription.setNatureIds(projectNatures.toArray(new String[projectNatures.size()])); if (builderIds != null) setBuilder(projectDescription, builderIds.toArray(new String[builderIds.size()])); return projectDescription; }
Example 5
Source File: NatureUtils.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
public static void removeNature(IProject project, String nature) { try { IProjectDescription description = project.getDescription(); String[] currentNatures = description.getNatureIds(); int index = 0; for (int i = 0; i < currentNatures.length; i++) { if (nature.equals(currentNatures[i])) { index = i; break; } } if (index != -1) { String[] newNatures = new String[currentNatures.length - 1]; System.arraycopy(currentNatures, 0, newNatures, 0, index); System.arraycopy(currentNatures, index + 1, newNatures, index, newNatures.length - index); description.setNatureIds(newNatures); project.setDescription(description, null); } } catch (CoreException e) { LogHelper.logError(e); } }
Example 6
Source File: UserJavaProject.java From CogniCrypt with Eclipse Public License 2.0 | 6 votes |
/** * @param sourceProject The name of the project to be cloned * @param cloneName The name of the cloned project * @return a cloned project * @throws CoreException */ public static IProject cloneProject(final String sourceProject) throws CoreException { final IProgressMonitor m = new NullProgressMonitor(); final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); final IProject project = workspaceRoot.getProject(sourceProject); final IProjectDescription projectDescription = project.getDescription(); final String cloneName = sourceProject + "_copy"; // create clone project in workspace final IProjectDescription cloneDescription = workspaceRoot.getWorkspace().newProjectDescription(cloneName); // copy project files project.copy(cloneDescription, true, m); final 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; }
Example 7
Source File: NewDepanProjectWizard.java From depan with Apache License 2.0 | 6 votes |
@Override public boolean performFinish() { if (false == super.performFinish()) { return false; } try { IProject project = getNewProject(); IProjectDescription description = project.getDescription(); description.setNatureIds(DEPAN_NATURES); project.setDescription(description, null); buildAnalysisResources(); buildWorkResources(); } catch (CoreException errCore) { ApplicationLogger.LOG.error("Failed to create new project", errCore); } return true; }
Example 8
Source File: AbstractJunitLibClasspathAdderTestCase.java From xtext-xtend with Eclipse Public License 2.0 | 6 votes |
protected void removePluginNature() { try { final IProject project = this.workbenchHelper.getProject(); final IProjectDescription description = project.getDescription(); final Function1<String, Boolean> _function = (String it) -> { return Boolean.valueOf((!Objects.equal(it, "org.eclipse.pde.PluginNature"))); }; description.setNatureIds(((String[])Conversions.unwrapArray(IterableExtensions.<String>filter(((Iterable<String>)Conversions.doWrapArray(description.getNatureIds())), _function), String.class))); NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor(); project.setDescription(description, _nullProgressMonitor); IJavaProject _create = JavaCore.create(project); NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor(); this.xtendLibAdder.addLibsToClasspath(_create, _nullProgressMonitor_1); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }
Example 9
Source File: NatureUtils.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static void addNatures(IProject project, List<String> natureIds) throws CoreException { IProjectDescription description = project.getDescription(); List<String> newNatureIds = new ArrayList<String>( Arrays.asList(description.getNatureIds())); boolean natureAdded = false; for (String natureId : natureIds) { if (project.hasNature(natureId)) { continue; } natureAdded = true; newNatureIds.add(natureId); } if (natureAdded) { // Only do this if we added a nature description.setNatureIds(newNatureIds.toArray(new String[0])); project.setDescription(description, null); } }
Example 10
Source File: BuildPathsBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException { if (monitor != null && monitor.isCanceled()) { throw new OperationCanceledException(); } if (!project.hasNature(JavaCore.NATURE_ID)) { IProjectDescription description = project.getDescription(); String[] prevNatures= description.getNatureIds(); String[] newNatures= new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); newNatures[prevNatures.length]= JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, monitor); } else { if (monitor != null) { monitor.worked(1); } } }
Example 11
Source File: KickStartNewProjectAction.java From solidity-ide with Eclipse Public License 1.0 | 5 votes |
public void addNature(IProject project) { try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = XtextProjectHelper.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } }
Example 12
Source File: JavaProjectHelper.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
private static 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); }
Example 13
Source File: NatureUtils.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
/** * Removes the nature identified by {@code natureId}. If the {@code project} does not have the * nature, this method does nothing. * * @param monitor a progress monitor, or {@code null} if progress reporting is not desired */ public static void removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException { if (project.hasNature(natureId)) { // Remove the nature ID from the natures in the project description IProjectDescription description = project.getDescription(); List<String> natures = Lists.newArrayList(description.getNatureIds()); natures.remove(natureId); description.setNatureIds(natures.toArray(new String[0])); project.setDescription(description, monitor); } }
Example 14
Source File: NatureUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static void addNature(IProject project, String nature) { try { IProjectDescription description = project.getDescription(); String[] currentNatures = description.getNatureIds(); String[] newNatures = new String[currentNatures.length + 1]; System.arraycopy(currentNatures, 0, newNatures, 0, currentNatures.length); newNatures[currentNatures.length] = nature; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { LogHelper.logError(e); } }
Example 15
Source File: ProjectExplorerRefreshTest.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static void createCProject(String projectName) throws CoreException { IProgressMonitor monitor = new NullProgressMonitor(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName); project.create(monitor); project.open(monitor); IProjectDescription description = project.getDescription(); description.setNatureIds(new String[] { "org.eclipse.cdt.core.cnature" }); project.setDescription(description, monitor); project.open(monitor); }
Example 16
Source File: EclipseUtils.java From goclipse with Eclipse Public License 1.0 | 5 votes |
/** Adds a nature to the given project if it doesn't exist already. */ public static void addNature(IProject project, String natureID) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); if(ArrayUtil.contains(natures, natureID)) return; String[] newNatures = ArrayUtil.append(natures, natureID); description.setNatureIds(newNatures); project.setDescription(description, null); }
Example 17
Source File: IResourcesSetupUtil.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static void addNature(IProject project, String nature) throws CoreException { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); // Add the nature String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = nature; description.setNatureIds(newNatures); project.setDescription(description, null); }
Example 18
Source File: WorkspaceModelsManager.java From gama with GNU General Public License v3.0 | 5 votes |
static public void setValuesProjectDescription(final IProject proj, final boolean builtin, final boolean inPlugin, final boolean inTests, final Bundle bundle) { /* Modify the project description */ IProjectDescription desc = null; try { final List<String> ids = new ArrayList<>(); ids.add(XTEXT_NATURE); ids.add(GAMA_NATURE); if ( inTests ) { ids.add(TEST_NATURE); } else if ( inPlugin ) { ids.add(PLUGIN_NATURE); } else if ( builtin ) { ids.add(BUILTIN_NATURE); } desc = proj.getDescription(); desc.setNatureIds(ids.toArray(new String[ids.size()])); // Addition of a special nature to the project. if ( inTests && bundle == null ) { desc.setComment("user defined"); } else if ( (inPlugin || inTests) && bundle != null ) { String name = bundle.getSymbolicName(); final String[] ss = name.split("\\."); name = ss[ss.length - 1] + " plugin"; desc.setComment(name); } else { desc.setComment(""); } proj.setDescription(desc, IResource.FORCE, null); // Addition of a special persistent property to indicate that the project is built-in if ( builtin ) { proj.setPersistentProperty(BUILTIN_PROPERTY, Platform.getProduct().getDefiningBundle().getVersion().toString()); } } catch (final CoreException e) { e.printStackTrace(); } }
Example 19
Source File: ResourceUtil.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * @param projectPath * the project location * @param natureIds * the list of required natures * @param builderIds * the list of required builders * @return a project description for the project that includes the list of required natures and builders */ public static IProjectDescription getProjectDescription(IPath projectPath, String[] natureIds, String[] builderIds) { if (projectPath == null) { return null; } IProjectDescription description = null; IPath dotProjectPath = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); File dotProjectFile = dotProjectPath.toFile(); IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (dotProjectFile.exists()) { // loads description from the existing .project file try { description = workspace.loadProjectDescription(dotProjectPath); if (Platform.getLocation().isPrefixOf(projectPath)) { description.setLocation(null); } } catch (CoreException e) { IdeLog.logWarning(CorePlugin.getDefault(), "Failed to load the existing .project file.", e); //$NON-NLS-1$ } } if (description == null) { // creates a new project description description = workspace.newProjectDescription(projectPath.lastSegment()); if (Platform.getLocation().isPrefixOf(projectPath)) { description.setLocation(null); } else { description.setLocation(projectPath); } } // adds the required natures to the project description if (!ArrayUtil.isEmpty(natureIds)) { Set<String> natures = CollectionsUtil.newInOrderSet(natureIds); CollectionsUtil.addToSet(natures, description.getNatureIds()); description.setNatureIds(natures.toArray(new String[natures.size()])); } // adds the required builders to the project description if (!ArrayUtil.isEmpty(builderIds)) { ICommand[] existingBuilders = description.getBuildSpec(); List<ICommand> builders = CollectionsUtil.newList(existingBuilders); for (String builderId : builderIds) { if (!hasBuilder(builderId, existingBuilders)) { ICommand newBuilder = description.newCommand(); newBuilder.setBuilderName(builderId); builders.add(newBuilder); } } description.setBuildSpec(builders.toArray(new ICommand[builders.size()])); } return description; }
Example 20
Source File: MockJavaProjectProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
public static IJavaProject createJavaProject( final String projectName, String[] projectNatures) { IProject project = null; IJavaProject javaProject = null; try { project = IResourcesSetupUtil.root().getProject(projectName); deleteProject(project); javaProject = JavaCore.create(project); IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription( projectName); project.create(projectDescription, null); List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>(); projectDescription.setNatureIds(projectNatures); final ICommand java = projectDescription.newCommand(); java.setBuilderName(JavaCore.BUILDER_ID); final ICommand manifest = projectDescription.newCommand(); manifest.setBuilderName("org.eclipse.pde.ManifestBuilder"); final ICommand schema = projectDescription.newCommand(); schema.setBuilderName("org.eclipse.pde.SchemaBuilder"); projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema }); project.open(null); project.setDescription(projectDescription, null); classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); JavaProjectSetupUtil.addJreClasspathEntry(javaProject); makeJava8Compliant(javaProject); javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null); createManifest(projectName, project); refreshExternalArchives(javaProject); refresh(javaProject); } catch (final Exception exception) { throw new RuntimeException(exception); } return javaProject ; }