Java Code Examples for org.eclipse.core.resources.IProject#setDescription()

The following examples show how to use org.eclipse.core.resources.IProject#setDescription() . 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: BuilderUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a builder with the specified ID to the project if the project does not
 * already have the builder.
 * 
 * @param project project to add the builder to
 * @param builderId id of the builder to add
 * @throws CoreException
 */
public static void addBuilderToProject(IProject project, String builderId)
    throws CoreException {

  if (hasBuilder(project, builderId)) {
    return;
  }

  IProjectDescription description = project.getDescription();
  List<ICommand> builders = new ArrayList<ICommand>(
      Arrays.asList(description.getBuildSpec()));

  ICommand newBuilder = description.newCommand();
  newBuilder.setBuilderName(builderId);
  builders.add(newBuilder);

  description.setBuildSpec(builders.toArray(new ICommand[builders.size()]));
  project.setDescription(description, null);
}
 
Example 2
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void unconfigure(IProject project, IProgressMonitor monitor) throws CoreException {
	try {
		final SubMonitor mon = SubMonitor.convert(monitor, 4);
		final IProjectDescription description = project.getDescription();
		final List<String> natures = new LinkedList<>(Arrays.asList(description.getNatureIds()));
		natures.remove(SARLEclipseConfig.XTEXT_NATURE_ID);
		natures.remove(SARLEclipseConfig.NATURE_ID);
		final String[] newNatures = natures.toArray(new String[natures.size()]);
		mon.worked(1);
		final IStatus status = ResourcesPlugin.getWorkspace().validateNatureSet(newNatures);
		mon.worked(1);
		if (status.getCode() == IStatus.OK) {
			description.setNatureIds(newNatures);
			project.setDescription(description, mon.newChild(1));
			safeRefresh(project, mon.newChild(1));
		} else {
			throw new CoreException(status);
		}
	} finally {
		monitor.done();
	}
}
 
Example 3
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void removeBuilder(IProject project, String builderId) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] builderSpecs = description.getBuildSpec();

	for (int i = 0; i < builderSpecs.length; ++i) {
		if (builderId.equals(builderSpecs[i].getBuilderName())) {
			// Remove the builder
			ICommand[] modifiedSpecs = new ICommand[builderSpecs.length - 1];
			System.arraycopy(builderSpecs, 0, modifiedSpecs, 0, i);
			System.arraycopy(builderSpecs, i + 1, modifiedSpecs, i, builderSpecs.length - i - 1);
			description.setBuildSpec(modifiedSpecs);
			project.setDescription(description, null);
			return;
		}
	}

}
 
Example 4
Source File: TexlipseProjectCreationOperation.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add a nature to the project.
 * 
 * @param project project
 * @param monitor progress monitor
 * @throws CoreException
 */
public static void addProjectNature(IProject project, IProgressMonitor monitor)
        throws CoreException {

    monitor.subTask(TexlipsePlugin.getResourceString("projectWizardProgressNature"));

    IProjectDescription desc = project.getDescription();
    String[] natures = desc.getNatureIds();
    for (int i = 0; i < natures.length; i++) {
        // don't add if already there
        if (TexlipseNature.NATURE_ID.equals(natures[i])) {
            return;
        }
    }
    
    String[] newNatures = new String[natures.length + 1];
    System.arraycopy(natures, 0, newNatures, 1, natures.length);
    newNatures[0] = TexlipseNature.NATURE_ID;
    desc.setNatureIds(newNatures);
    project.setDescription(desc, monitor);
}
 
Example 5
Source File: GamlUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void removeNature(final IProject project, final String nature) throws CoreException {
	final IProjectDescription description = project.getDescription();
	final String[] natures = description.getNatureIds();

	for (int i = 0; i < natures.length; ++i) {
		if (nature.equals(natures[i])) {
			// Remove the nature
			final 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 6
Source File: ProjectUtilities.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * 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 7
Source File: AddBuilder.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) {
	final IProject project = getProject(event);

	if (project != null) {
		try {
			// verify already registered builders
			if (hasBuilder(project))
				// already enabled
				return null;

			// add builder to project properties
			IProjectDescription description = project.getDescription();
			final ICommand buildCommand = description.newCommand();
			buildCommand.setBuilderName(SolidityBuilder.BUILDER_ID);

			final List<ICommand> commands = new ArrayList<ICommand>();
			commands.addAll(Arrays.asList(description.getBuildSpec()));
			commands.add(buildCommand);

			description.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
			project.setDescription(description, null);

		} catch (final CoreException e) {
			Activator.logError("Error adding solc builder", e);
		}
	}
	return null;
}
 
Example 8
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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());
}
 
Example 9
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
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 10
Source File: EclipseUtils.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/** 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 11
Source File: ResourceUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Remove a builder from the given project. Return boolean indicating if it was removed (if doesn't exist on the
 * project we'll return a false. if there's an error, we'll throw a CoreException).
 * 
 * @param project
 * @param id
 * @throws CoreException
 */
public static boolean removeBuilder(IProject project, String id) throws CoreException
{
	IProjectDescription desc = project.getDescription();
	if (removeBuilder(desc, id))
	{
		project.setDescription(desc, null);
		return true;
	}
	return false;
}
 
Example 12
Source File: ProjectExplorerRefreshTest.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
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 13
Source File: WorkspaceModelsManager.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
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 14
Source File: ResourceUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add a builder to the given project. Return boolean indicating if it was added (if already exists on project we'll
 * return a false. if there's an error, we'll throw a CoreException).
 * 
 * @param project
 * @param id
 * @throws CoreException
 */
public static boolean addBuilder(IProject project, String id) throws CoreException
{
	IProjectDescription desc = project.getDescription();
	if (addBuilder(desc, id))
	{
		project.setDescription(desc, null);
		return true;
	}
	return false;
}
 
Example 15
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 16
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 17
Source File: FullSourceWorkspaceModelTests.java    From dacapobench with Apache License 2.0 5 votes vote down vote up
private IJavaProject createJavaProject(String name) throws CoreException {
  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
  if (project.exists())
    project.delete(true, null);
  project.create(null);
  project.open(null);
  IProjectDescription description = project.getDescription();
  description.setNatureIds(new String[] { JavaCore.NATURE_ID });
  project.setDescription(description, null);
  IJavaProject javaProject = JavaCore.create(project);
  javaProject.setRawClasspath(new IClasspathEntry[] { JavaCore.newVariableEntry(new Path("JRE_LIB"), null, null) }, null);
  return javaProject;
}
 
Example 18
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 19
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
public static void removeTypeScriptBuilder(IProject project) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] commands = description.getBuildSpec();
	for (int i = 0; i < commands.length; i++) {
		if (TypeScriptBuilder.ID.equals(commands[i].getBuilderName())) {
			// Remove the builder
			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);
			project.setDescription(description, null);
		}
	}
}
 
Example 20
Source File: TestedWorkspaceWithJDT.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Deprecated
private void addDynamicProjectReference(IProject from, IProject to) throws CoreException {
	IProjectDescription description = from.getDescription();
	List<IProject> dynamicReferences = new ArrayList<>(Arrays.asList(description.getDynamicReferences()));
	dynamicReferences.add(to);
	description.setDynamicReferences(dynamicReferences.toArray(new IProject[0]));
	from.setDescription(description, null);
}