/** * Sets or clears the Mule UMO Configuration nature to this project * * @param project The project to set. * @param setIt True if the nature should be added, false if it should be removed * @throws CoreException If something goes wrong */ public void setMuleNature(IProject project, boolean setIt) throws CoreException { /* * Four possible outcomes: A - transition to on B - already on C - transition to off D - already off */ if (project == null) return; IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (MuleNature.NATURE_ID.equals(natures[i])) { if (setIt) return; // outcome B - Already had the nature // Outcome C - 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; // Outcome C - No longer has the nature } } if (!setIt) return; // Outcome D - didn't have it, just do nothing // Outcome A - add the nature String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 1, natures.length); newNatures[0] = MuleNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); }
/** * Toggles sample nature on a project * * @param project to have sample nature added or removed */ private void toggleNature(IProject project) { try { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); for (int i = 0; i < natures.length; ++i) { if (QSARNature.NATURE_ID.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; } } // Add the nature String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 0, natures.length); newNatures[natures.length] = QSARNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); project.hasNature(QSARNature.NATURE_ID); } catch (CoreException e) { } }
private void configureProject(IProject newProject) { try { final IProjectDescription desc = newProject.getDescription(); desc.setNatureIds(new String[0]); newProject.setDescription(desc, null); desc.setNatureIds(MODEL_NATURES); if (ProductCustomizerMgr.getInstance() != null) { String productName = ProductCustomizerMgr.getInstance().getProductName(); if (!CoreStringUtil.isEmpty(productName)) { desc.setComment(productName + ", version " + ModelerCore.ILicense.VERSION); // $NON-NLS-1$ } } newProject.setDescription(desc, null); if (!ProductCustomizerMgr.getInstance() .getProductCharacteristics() .isHiddenProjectCentric()) { // Defect 11480 - closing and opening the project sets the overlay icon properly newProject.close(null); } newProject.open(null); } catch (final CoreException err) { UiConstants.Util.log(IStatus.ERROR, err, err.getMessage()); } }
private void setProjectNatures(IProject project, IFeatureModel model, IProgressMonitor monitor) throws CoreException { IProjectDescription desc = project.getDescription(); if (needsJavaNature(model)) { desc.setNatureIds(new String[] {JavaCore.NATURE_ID, MDE.FEATURE_NATURE}); } else { desc.setNatureIds(new String[] {MDE.FEATURE_NATURE}); } project.setDescription(desc, new SubProgressMonitor(monitor, 1)); }
/** * Add a Java Nature to a project when creating * * @param project * @throws CoreException */ private static void addJavaNature(final IProject project) throws CoreException { if (!project.hasNature(JavaCore.NATURE_ID)) { final IProjectDescription description = project.getDescription(); final String[] prevNatures = description.getNatureIds(); final 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, null); IFolder sourceFolder = project.getFolder("/src"); sourceFolder.create(true, true, null); IJavaProject javaProject = JavaCore.create(project); javaProject.setRawClasspath( new IClasspathEntry[] { JavaCore.newSourceEntry(sourceFolder.getFullPath()), JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER")) }, null); @SuppressWarnings("unchecked") Hashtable<String, String> javaOptions = JavaCore.getOptions(); javaOptions.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); javaOptions.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); javaOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); javaProject.setOptions(javaOptions); } }
@Override public boolean performFinish() { boolean res = super.performFinish(); if (res == true) { final IProject project = getNewProject(); try { if (project != null) { 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] = PopeNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); PopeCore.create(project); } } catch (CoreException e) { StatusManager.getManager().handle(e.getStatus()); } } return res; }
@Override public boolean performFinish() { if (!super.performFinish()) { return false; } IProject newProject = getNewProject(); try { IProjectDescription description = newProject.getDescription(); String[] newNatures = new String[2]; newNatures[0] = JavaCore.NATURE_ID; newNatures[1] = ActivitiConstants.NATURE_ID; description.setNatureIds(newNatures); newProject.setDescription(description, null); IJavaProject javaProject = JavaCore.create(newProject); createSourceFolders(newProject); createOutputLocation(javaProject); IClasspathEntry[] entries = createClasspathEntries(javaProject); javaProject.setRawClasspath(entries, null); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
/** * @see org.teiid.designer.core.workspace.ModelWorkspace#createModelProject(java.lang.String, * java.lang.String, org.eclipse.core.runtime.IProgressMonitor) * @since 4.0 */ @Override public ModelProject createModelProject( final String name, final IPath path, final IProgressMonitor monitor) throws CoreException { CoreArgCheck.isNotNull(name); // Check if project already exists if (findModelProject(name) != null) { throw new ModelWorkspaceException( ModelerCore.Util.getString( "ModelWorkspaceImpl.cannotCreateModelProject", name)); // $NON-NLS-1$ } // Validate name final IWorkspace workspace = ModelerCore.getWorkspace(); final IStatus status = workspace.validateName(name, IResource.PROJECT); if (!status.isOK()) { throw new ModelWorkspaceException( new ModelStatusImpl(status.getSeverity(), status.getCode(), status.getMessage())); } // Create new model project final IProject project = workspace.getRoot().getProject(name); final IProjectDescription desc = workspace.newProjectDescription(project.getName()); desc.setLocation(path); desc.setNatureIds(MODEL_NATURES); final IWorkspaceRunnable op = new IWorkspaceRunnable() { @Override public void run(final IProgressMonitor monitor) throws CoreException { project.create(desc, monitor); project.open(monitor); } }; workspace.run(op, monitor); return new ModelProjectImpl(project, this); }
private void addProjectNature(final IProject proj, final IProgressMonitor monitor) throws CoreException { monitor.subTask(Messages.getString("GridProjectCreationOperation.nature_task")); // $NON-NLS-1$ IProjectDescription desc = proj.getDescription(); String[] natureIDs = desc.getNatureIds(); String gridNatureID = GridProjectNature.getID(); boolean found = false; for (int i = 0; (i < natureIDs.length) && (!found); i++) { if (natureIDs[i].equals(gridNatureID)) { found = true; } } if (!found) { String[] newNatureIDs = new String[natureIDs.length + 1]; System.arraycopy(natureIDs, 0, newNatureIDs, 1, natureIDs.length); newNatureIDs[0] = gridNatureID; desc.setNatureIds(newNatureIDs); proj.setDescription(desc, new SubProgressMonitor(monitor, 100)); } if (monitor.isCanceled()) { throw new OperationCanceledException(); } }
public static void removeNatureFromProject(IProject project, String natureId) throws CoreException { IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); int natureIndex = -1; for (int i = 0; i < prevNatures.length; i++) { if (prevNatures[i].equals(natureId)) { natureIndex = i; i = prevNatures.length; } } // Remove nature only if it exists... if (natureIndex != -1) { String[] newNatures = new String[prevNatures.length - 1]; System.arraycopy(prevNatures, 0, newNatures, 0, natureIndex); System.arraycopy( prevNatures, natureIndex + 1, newNatures, natureIndex, prevNatures.length - (natureIndex + 1)); description.setNatureIds(newNatures); project.setDescription(description, null); } TapestryCore.getDefault().getCoreListeners().fireCoreListenerEvent(); }
/** {@inheritDoc} */ public Object execute(CommandLine commandLine) throws Exception { String name = commandLine.getValue(Options.PROJECT_OPTION); IProject project = ProjectUtils.getProject(name); String[] aliases = StringUtils.split(commandLine.getValue(Options.NATURE_OPTION), ','); IProjectDescription desc = project.getDescription(); String[] natureIds = desc.getNatureIds(); ArrayList<String> modified = new ArrayList<String>(); ArrayList<String> newNatures = new ArrayList<String>(); CollectionUtils.addAll(modified, natureIds); for (String alias : aliases) { String natureId = ProjectNatureFactory.getNatureForAlias(alias); if (natureId != null && !modified.contains(natureId)) { modified.add(natureId); newNatures.add(natureId); } } desc.setNatureIds((String[]) modified.toArray(new String[modified.size()])); project.setDescription(desc, new NullProgressMonitor()); for (String nature : newNatures) { ProjectManager manager = ProjectManagement.getProjectManager(nature); if (manager != null) { manager.create(project, commandLine); } } return Services.getMessage("project.nature.added"); }
public static void addNature(IProject project) { if (!project.isOpen()) { return; } // Get the description IProjectDescription description; try { description = project.getDescription(); } catch (CoreException e) { JsonLog.logError("Error get project description: ", e); return; } List<String> newIds = new ArrayList<String>(); String[] natureIds = description.getNatureIds(); for (String natureId : natureIds) { if (natureId.equals(NATURE_ID)) { return; } } newIds.addAll(Arrays.asList(natureIds)); newIds.add(NATURE_ID); // Save description description.setNatureIds(newIds.toArray(new String[newIds.size()])); try { project.setDescription(description, null); } catch (CoreException e) { JsonLog.logError("Error set project description: ", e); } }
public static void enableNature(IProject project, boolean b) throws CoreException { 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] = Constants.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, null); }
/** * @param project * @throws CoreException */ public void addJavaNature(IProject project) throws CoreException { 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] = JavaCore.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, new NullProgressMonitor()); }
/** * adds the Camel nature to the project * * @param project * @param monitor * @throws CoreException */ private void addCamelNature(IProject project, IProgressMonitor monitor) throws CoreException { IProjectDescription projectDescription = project.getDescription(); String[] ids = projectDescription.getNatureIds(); String[] newIds = new String[ids.length + 1]; System.arraycopy(ids, 0, newIds, 0, ids.length); newIds[ids.length] = Activator.CAMEL_NATURE_ID; projectDescription.setNatureIds(newIds); project.setDescription(projectDescription, monitor); }
private static IProjectDescription createProjectDescription(IProject project, URI location) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IProjectDescription description = workspace.newProjectDescription(project.getName()); description.setLocationURI(location); description.setNatureIds(new String[] {DartCore.DART_PROJECT_NATURE}); ICommand command = description.newCommand(); command.setBuilderName(DartCore.DART_BUILDER_ID); description.setBuildSpec(new ICommand[] {command}); return description; }
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); }
public static IJavaProject createJavaProject(final String projectName, String[] projectNatures) { IProject project = null; IJavaProject javaProject = null; try { IWorkspace workspace = ResourcesPlugin.getWorkspace(); project = workspace.getRoot().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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"))); classpathEntries.add( JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins"))); javaProject.setRawClasspath( classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]), null); makeJava5Compliant(javaProject); javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null); createManifest(projectName, project); // project.build(IncrementalProjectBuilder.FULL_BUILD, null); refreshExternalArchives(javaProject); refresh(javaProject); } catch (final Exception exception) { throw new RuntimeException(exception); } return javaProject; }
public static void addNature(IProject project, String nature) { try { 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] = nature; description.setNatureIds(newNatures); project.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } }
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(); } }
/** @param project */ private void migrateProjectNatures(IProject project) { try { List<String> natureIds = new ArrayList<String>(); natureIds.addAll(Arrays.asList(newProject.getDescription().getNatureIds())); for (String natureId : project.getDescription().getNatureIds()) { if (!natureIds.contains(natureId)) natureIds.add(natureId); } IProjectDescription description = newProject.getDescription(); description.setNatureIds(natureIds.toArray(new String[natureIds.size()])); newProject.setDescription(description, null); } catch (CoreException e) { e.printStackTrace(); } }
/** Utility routine to remove a PythonNature from a project. */ public static synchronized void removeNature(IProject project, IProgressMonitor monitor) throws CoreException { if (monitor == null) { monitor = new NullProgressMonitor(); } PythonNature nature = PythonNature.getPythonNature(project); if (nature == null) { return; } try { // we have to set the nature store to stop listening changes to .pydevproject nature.pythonNatureStore.setProject(null); } catch (Exception e) { Log.log(e); } try { // we have to remove the project from the pythonpath nature too... nature.pythonPathNature.setProject(null, null); } catch (Exception e) { Log.log(e); } // notify listeners that the pythonpath nature is now empty for this project try { PythonNatureListenersManager.notifyPythonPathRebuilt(project, null); } catch (Exception e) { Log.log(e); } try { // actually remove the pydev configurations IResource member = project.findMember(".pydevproject"); if (member != null) { member.delete(true, null); } } catch (CoreException e) { Log.log(e); } // and finally... remove the nature IProjectDescription description = project.getDescription(); List<String> natures = new ArrayList<String>(Arrays.asList(description.getNatureIds())); natures.remove(PYTHON_NATURE_ID); description.setNatureIds(natures.toArray(new String[natures.size()])); project.setDescription(description, monitor); }
/** * @see * it.unitn.disi.unagi.application.services.IManageProjectsService#createNewProject(org.eclipse.core.runtime.IProgressMonitor, * java.lang.String) */ @Override public IProject createNewProject(IProgressMonitor progressMonitor, String name) throws CouldNotSaveUnagiProjectException { LogUtil.log.info("Creating a new project: {0}.", name); // $NON-NLS-1$ // Obtains a project descriptor with the desired name from the workspace. IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject(name); // If the project already exists, throws a Unagi exception. if (project.exists()) { LogUtil.log.warn( "A project with the same name already exists in the workspace: {0}.", name); //$NON-NLS-1$ throw new CouldNotSaveUnagiProjectException(project); } try { // Creates and opens the project. project.create(progressMonitor); project.open(progressMonitor); // Sets the Unagi project nature. 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] = UnagiProjectNature.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, progressMonitor); // Creates the project's subfolders. for (String subdir : PROJECT_SUBDIRS) { IFolder folder = project.getFolder(subdir); folder.create(true, true, progressMonitor); } } // If any other errors occurred, throw an exception. catch (CoreException e) { LogUtil.log.error( "Unagi caught an Eclipse exception while trying to create project: {0}.", e, name); // $NON-NLS-1$ throw new CouldNotSaveUnagiProjectException(project, e); } LogUtil.log.info("Successfully created and opened Unagi project: {0}.", name); // $NON-NLS-1$ return project; }
public static void addNaturesToProject( IProject proj, String[] natureIds, IProgressMonitor monitor) throws CoreException { IProjectDescription description = proj.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + natureIds.length]; System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); for (int i = prevNatures.length; i < newNatures.length; i++) { newNatures[i] = natureIds[i - prevNatures.length]; } description.setNatureIds(newNatures); proj.setDescription(description, monitor); }
public static void addNatureToProject(IProject project, String natureId, boolean forceOrder) throws CoreException { IProjectDescription description = project.getDescription(); List<String> natures = new ArrayList<String>(Arrays.asList(description.getNatureIds())); if (!natures.contains(natureId)) { if (forceOrder) { // changes so that the project overlay icon shows up! natures.add(0, natureId); } else { natures.add(natureId); } description.setNatureIds((String[]) natures.toArray()); project.setDescription(description, null); } TapestryCore.getDefault().getCoreListeners().fireCoreListenerEvent(); }
public IProject createProject() throws CoreException { IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); if (!project.exists()) { project.create(null); } if (!project.isOpen()) { project.open(null); } IProjectDescription description = project.getDescription(); description.setNatureIds(natures); project.setDescription(description, null); return project; }
protected boolean createProject( final IProgressMonitor monitor, final IPath projectLocation, final String projectName, final Collection<IPath> includeDirs, final Collection<IPath> sourceDirs, final IPath outputDir) throws InvocationTargetException { final IWorkspace workspace = ResourcesPlugin.getWorkspace(); final IProject project = workspace.getRoot().getProject(projectName); final IProjectDescription description = workspace.newProjectDescription(projectName); description.setLocation(projectLocation); final ICommand[] old = description.getBuildSpec(), specs = new ICommand[old.length + 1]; System.arraycopy(old, 0, specs, 0, old.length); final ICommand command = description.newCommand(); command.setBuilderName(ErlangPlugin.BUILDER_ID); specs[old.length] = command; description.setBuildSpec(specs); description.setNatureIds(new String[] {ErlangPlugin.NATURE_ID}); try { monitor.beginTask(WizardMessages.WizardProjectsImportPage_CreateProjectsTask, 1000); project.create(description, monitor); // final int subTicks = 600 / fileSystemObjects.size(); // createLinks(theProjectPath, fileSystemObjects, monitor, project, // subTicks); // project.create(description, IResource.REPLACE, // new SubProgressMonitor(monitor, 30)); project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(monitor, 300)); final OldErlangProjectProperties erlangProjectProperties = new OldErlangProjectProperties(project); erlangProjectProperties.setIncludeDirs(includeDirs); erlangProjectProperties.setSourceDirs(sourceDirs); erlangProjectProperties.setOutputDir(outputDir); } catch (final CoreException e) { throw new InvocationTargetException(e); } finally { monitor.done(); } return true; }
private void addNature(IProject project, IProgressMonitor monitor) throws CoreException { monitor = Util.getNonNullMonitor(monitor); try { monitor.beginTask("", 1); IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); String[] newNatures = new String[prevNatures.length + 1]; System.arraycopy(prevNatures, 0, newNatures, 1, prevNatures.length); newNatures[0] = Constants.NATURE_ID; description.setNatureIds(newNatures); project.setDescription(description, IResource.FORCE, null); } finally { monitor.done(); } }
public static synchronized void setupProjectNatures(IProject project, IProgressMonitor monitor) throws CoreException { if ((project == null) || (!project.isOpen())) return; if (monitor == null) monitor = new NullProgressMonitor(); String natureId = "org.jil.ide.widgetNature"; if (!project.hasNature(natureId)) { IProjectDescription description = project.getDescription(); String[] natures = description.getNatureIds(); String[] newNatures = new String[natures.length + 1]; System.arraycopy(natures, 0, newNatures, 1, natures.length); newNatures[0] = natureId; description.setNatureIds(newNatures); project.setDescription(description, new SubProgressMonitor(monitor, 10)); } JavaScriptNature jsNature = new JavaScriptNature(project, monitor); jsNature.configure(); }
@Override public void configure() throws CoreException { IProjectDescription desc = getProject().getDescription(); ICommand[] commands = desc.getBuildSpec(); boolean found = false; for (ICommand command : commands) { if (RadlBuilder.BUILDER_ID.equals(command.getBuilderName())) { found = true; break; } } if (!found) { ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(RadlBuilder.BUILDER_ID); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); } desc.setNatureIds(ensureNature(desc.getNatureIds())); getProject().setDescription(desc, null); }