Java Code Examples for org.eclipse.core.resources.IProjectDescription#getNatureIds()

The following examples show how to use org.eclipse.core.resources.IProjectDescription#getNatureIds() . 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 vote down vote up
/**
 * 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: SendPingJob.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
public void resourceChanged(IResourceChangeEvent event)
{
	if (event.getType() == IResourceChangeEvent.PRE_DELETE)
	{
		// check if it is a studio project and then send the ping out
		try
		{
			IProject project = event.getResource().getProject();
			IProjectDescription description = project.getDescription();
			String[] natures = description.getNatureIds();
			if (!ArrayUtil.isEmpty(natures))
			{
				// just checking the primary nature
				String projectType = STUDIO_NATURE_MAP.get(natures[0]);
				if (!StringUtil.isEmpty(projectType))
				{
					sendProjectDeleteEvent(project, projectType);
				}
			}
		}
		catch (Exception e)
		{
			UsagePlugin.logError(e);
		}
	}
}
 
Example 3
Source File: NatureUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
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 4
Source File: ResourceUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reurns a list of all the natures that belong to Aptana.
 * 
 * @param description
 * @return
 */
public static String[] getAptanaNatures(IProjectDescription description)
{
	String[] natures = description.getNatureIds();
	List<String> newNatures = new ArrayList<String>();
	// Add Aptana natures to list
	for (String nature : natures)
	{
		if (isAptanaNature(nature))
		{
			newNatures.add(nature);
		}
	}

	return newNatures.toArray(new String[newNatures.size()]);
}
 
Example 5
Source File: ProjectUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static void addNatureToProject(IProject project, boolean addToEnd, String...natureId) throws CoreException{
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();
	ArrayList<String> arrayList = new ArrayList<String>();
	if (addToEnd){
   		arrayList.addAll(Arrays.asList(natures));
   		arrayList.addAll(Arrays.asList(natureId));
	}else{
   		arrayList.addAll(Arrays.asList(natureId));
   		arrayList.addAll(Arrays.asList(natures));
	}
	String[] list=new String[arrayList.size()];
	list = arrayList.toArray(list);
	description.setNatureIds(list);
	project.setDescription(description, null);
}
 
Example 6
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
private void addHybrisNature(IProject project, IProgressMonitor monitor) throws CoreException {
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();

	for (int i = 0; i < natures.length; ++i) {
		if (HYBRIS_NATURE_ID.equals(natures[i])) {
			return;
		}
	}

	// Add the nature
	String[] newNatures = new String[natures.length + 1];
	System.arraycopy(natures, 0, newNatures, 0, natures.length);
	newNatures[natures.length] = HYBRIS_NATURE_ID;
	description.setNatureIds(newNatures);
	project.setDescription(description, monitor);
}
 
Example 7
Source File: ProjectCustomizer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the UIMA nature to a project
 * 
 * @param project
 *          an IProject
 * @throws PearException
 *           If a problem occurs
 */
public static void addUIMANature(IProject project) throws PearException {
  try {
    if (!project.hasNature(UIMA_NATURE_ID)) {
      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] = UIMA_NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
      project.close(null);
      project.open(null);
    }
  } catch (Throwable e) {
    PearException subEx = new PearException("The UIMA Nature could not be added properly.", e);
    throw subEx;
  }
}
 
Example 8
Source File: YangProjectSupport.java    From yang-design-studio with Eclipse Public License 1.0 6 votes vote down vote up
private static void addNature(IProject project)
  throws CoreException
{
  if (!project.hasNature("org.eclipse.xtext.ui.shared.xtextNature"))
  {
    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] = "org.eclipse.xtext.ui.shared.xtextNature";
    description.setNatureIds(newNatures);
    
    IProgressMonitor monitor = null;
   project.setDescription(description, monitor);
   System.out.println("nature Set!");
  }
}
 
Example 9
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
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 10
Source File: ConfigureDeconfigureNatureJob.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Helper method to enable the given nature for the project.
 * 
 * @throws CoreException
 *           an error while setting the nature occured
 */
private void enableNature() throws CoreException {

  // get the description
  IProjectDescription desc = mProject.getDescription();

  // copy existing natures and add the nature
  String[] natures = desc.getNatureIds();

  String[] newNatures = new String[natures.length + 1];
  System.arraycopy(natures, 0, newNatures, 0, natures.length);
  newNatures[natures.length] = mNatureId;

  // set natures
  desc.setNatureIds(newNatures);
  mProject.setDescription(desc, mMonitor);
}
 
Example 11
Source File: NewICEItemProjectWizard.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Make sure that the project has the ICEItemNature associated with it.
 * 
 * @param project
 */
public static void setNature(IProject project) throws CoreException {
	if (!project.hasNature(ICEItemNature.NATURE_ID)) {
		IProjectDescription description = project.getDescription();
		String[] projNatures = description.getNatureIds();
		projNatures = Arrays.copyOf(projNatures, projNatures.length + 1);
		projNatures[projNatures.length - 1] = ICEItemNature.NATURE_ID;
		description.setNatureIds(projNatures);
		project.setDescription(description, new NullProgressMonitor());
	}
}
 
Example 12
Source File: BazelProjectSupport.java    From eclipse with Apache License 2.0 5 votes vote down vote up
private static void addNature(IProject project, String nature) throws CoreException {
  if (!project.hasNature(nature)) {
    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);
  }
}
 
Example 13
Source File: KickStartNewProjectAction.java    From solidity-ide with Eclipse Public License 1.0 5 votes vote down vote up
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 14
Source File: CrySLBuilderUtils.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
public static void addCrySLBuilderToProject(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] = CrySLNature.NATURE_ID;

		// validate the natures
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		IStatus status = workspace.validateNatureSet(newNatures);

		// only apply new nature, if the status is ok
		if (status.getCode() == IStatus.OK) {
			description.setNatureIds(newNatures);
		}

		ICommand[] buildSpec = description.getBuildSpec();
		ICommand command = description.newCommand();
		command.setBuilderName(CrySLBuilder.BUILDER_ID);
		ICommand[] newbuilders = new ICommand[buildSpec.length + 1];
		System.arraycopy(buildSpec, 0, newbuilders, 0, buildSpec.length);
		newbuilders[buildSpec.length] = command;
		description.setBuildSpec(newbuilders);
		project.setDescription(description, null);
	}
	catch (CoreException e) {
		Activator.getDefault().logError(e);
	}
}
 
Example 15
Source File: EclipseUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/** Remove nature from given project, if project has given nature. */
public static void removeNature(IProject project, String natureID) throws CoreException {
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();
	
	String[] newNatures = ArrayUtil.remove(natures, natureID);
	if(newNatures != natures) {
		description.setNatureIds(newNatures);
		project.setDescription(description, null);
	}
}
 
Example 16
Source File: JavaProjectHelper.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 17
Source File: SlrProjectSupport.java    From slr-toolkit with Eclipse Public License 1.0 5 votes vote down vote up
public static void addNature(IProject project) throws CoreException {
	String xtextNatureId = "org.eclipse.xtext.ui.shared.xtextNature";
	if (!project.hasNature(xtextNatureId)) {
		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] = xtextNatureId;
		description.setNatureIds(newNatures);

		project.setDescription(description, null);
	}
}
 
Example 18
Source File: StatechartDiagramEditor.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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 19
Source File: GamlUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void addNature(final IProject project, final String nature) throws CoreException {
	final IProjectDescription description = project.getDescription();
	final String[] natures = description.getNatureIds();

	// Add the nature
	final 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 20
Source File: WizardFolderImportPage.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Input validation.
 */
protected boolean validate()
{
	if (directoryPathField.getText().trim().length() == 0)
	{
		setErrorMessage(EplMessages.WizardFolderImportPage_ERR_NoFolderSelected);
		return false;
	}
	else if (!new File(directoryPathField.getText()).exists())
	{
		setErrorMessage(EplMessages.WizardFolderImportPage_ERR_FolderNotExist);
		return false;
	}
	else
	{
		String name = projectNameField.getText().trim();
		if (name.length() == 0)
		{
			setErrorMessage(EplMessages.WizardFolderImportPage_ERR_NoProjectName);
			return false;
		}
		if (projectsNames.contains(name))
		{
			setErrorMessage(EplMessages.WizardFolderImportPage_ERR_ProjectNameExists);
			return false;
		}

		IPath path = Path.fromOSString(directoryPathField.getText());
		setPrimaryNatureFromContributions(path);

		// Set a warning message if the imported project already contain certain project natures.
		IPath dotProjectPath = path.append(IProjectDescription.DESCRIPTION_FILE_NAME);

		IProjectDescription description = null;
		if (dotProjectPath.toFile().exists())
		{
			try
			{
				description = IDEWorkbenchPlugin.getPluginWorkspace().loadProjectDescription(dotProjectPath);
				if (description != null && description.getNatureIds().length > 0)
				{
					String delimiter = StringUtil.EMPTY;
					StringBuilder natures = new StringBuilder();
					for (String natureId : description.getNatureIds())
					{
						String nature = fLabelProvider.getText(natureId);
						if (StringUtil.isEmpty(nature))
						{
							nature = natureId;
						}
						natures.append(delimiter).append(nature);
						delimiter = ", "; //$NON-NLS-1$
					}
					String[] natureIds = description.getNatureIds();
					if (natureIds.length > 0 && !natureIds[0].equals(fPrimaryNature))
					{
						String[] oldNatures = natureIds;
						natureIds = new String[description.getNatureIds().length + 1];
						System.arraycopy(oldNatures, 0, natureIds, 1, oldNatures.length);
						natureIds[0] = fPrimaryNature;
					}
					// set the natures checked in the nature table as they are the most relevant ones.
					fTableViewer.setCheckedElements(natureIds);
					setMessage(EplMessages.WizardFolderImportPage_override_project_nature + natures.toString(),
							WARNING);
					setErrorMessage(null);
					return true;
				}
			}
			catch (CoreException e)
			{
				IdeLog.logWarning(UIEplPlugin.getDefault(), "Error reading project description for " + name, e); //$NON-NLS-1$
			}
		}
	}
	setMessage(null);
	setErrorMessage(null);
	return true;
}