Search in sources :

Example 26 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class RPMProjectNature method addNature.

/**
 * Utility method for adding a nature to a project.
 *
 * @param proj
 *            the project to add the nature
 * @param natureId
 *            the id of the nature to assign to the project
 * @param monitor
 *            a progress monitor to indicate the duration of the operation,
 *            or <code>null</code> if progress reporting is not required.
 */
private static void addNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
    if (project.hasNature(natureId)) {
        return;
    }
    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] = natureId;
    description.setNatureIds(newNatures);
    project.setDescription(description, monitor);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 27 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class ToggleRpmlintNatureAction method toggleNature.

/**
 * Toggles rpmlint nature on a project.
 *
 * @param project
 *            The project on which to toggle the nature.
 */
private static void toggleNature(IProject project) {
    String rpmlintPath = new ScopedPreferenceStore(InstanceScope.INSTANCE, Activator.PLUGIN_ID).getString(PreferenceConstants.P_RPMLINT_PATH);
    if (!Files.exists(Paths.get(rpmlintPath))) {
        IStatus warning = new Status(IStatus.WARNING, Activator.PLUGIN_ID, 1, Messages.RunRpmlintAction_1, null);
        ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), Messages.RunRpmlintAction_2, null, warning);
        return;
    }
    try {
        IProjectDescription description = project.getDescription();
        String[] natures = description.getNatureIds();
        for (int i = 0; i < natures.length; ++i) {
            if (RpmlintNature.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] = RpmlintNature.NATURE_ID;
        description.setNatureIds(newNatures);
        project.setDescription(description, null);
    } catch (CoreException e) {
    // TODO log exception
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IProjectDescription(org.eclipse.core.resources.IProjectDescription) ScopedPreferenceStore(org.eclipse.ui.preferences.ScopedPreferenceStore)

Example 28 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class RpmlintNature method deconfigure.

@Override
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(RpmlintBuilder.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);
            // Remove rpmlint marks on all specfiles into the project.
            project.accept(new RpmlintMarkerRemoveVisitor());
            return;
        }
    }
}
Also used : ICommand(org.eclipse.core.resources.ICommand) IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 29 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class ChangeLogTestProject method addJavaNature.

/**
 * Add the Java nature to this project. I.e. make it a Java project.
 */
public IJavaProject addJavaNature() throws CoreException {
    IProjectDescription description = this.testProject.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);
    this.testProject.setDescription(description, null);
    return JavaCore.create(this.testProject);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Example 30 with IProjectDescription

use of org.eclipse.core.resources.IProjectDescription in project linuxtools by eclipse.

the class ChangeLogTestProject method addJavaNature.

/**
 * Add the Java nature to this project. I.e. make it a Java project.
 */
public IJavaProject addJavaNature() throws CoreException {
    IProjectDescription description = this.testProject.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);
    this.testProject.setDescription(description, null);
    return JavaCore.create(this.testProject);
}
Also used : IProjectDescription(org.eclipse.core.resources.IProjectDescription)

Aggregations

IProjectDescription (org.eclipse.core.resources.IProjectDescription)68 IProject (org.eclipse.core.resources.IProject)35 CoreException (org.eclipse.core.runtime.CoreException)18 IWorkspace (org.eclipse.core.resources.IWorkspace)16 IPath (org.eclipse.core.runtime.IPath)13 ICommand (org.eclipse.core.resources.ICommand)12 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)11 File (java.io.File)9 IStatus (org.eclipse.core.runtime.IStatus)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)8 Path (org.eclipse.core.runtime.Path)8 Status (org.eclipse.core.runtime.Status)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 URI (java.net.URI)5 IResource (org.eclipse.core.resources.IResource)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 InputStream (java.io.InputStream)3 IFile (org.eclipse.core.resources.IFile)3 Resource (org.eclipse.emf.ecore.resource.Resource)3