1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/*******************************************************************************
* Copyright (c) 2005, 2009 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat - initial API and implementation
*******************************************************************************/
package org.eclipse.linuxtools.rpm.core;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
/**
* The RPM project nature.
*
*/
public class RPMProjectNature implements IProjectNature {
/**
* The unique nature ID associated with the RPM project nature.
*/
public static final String RPM_NATURE_ID = RPMCorePlugin.ID + ".rpmnature"; //$NON-NLS-1$
IProject project;
public RPMProjectNature() {
}
public RPMProjectNature(IProject project) {
this.project = project;
}
/**
* Adds the RPM project nature to a given workspace project.
* @param project the project
* @param mon a progress monitor, or <code>null</code> if progress monitoring
* is not desired
* @throws CoreException if adding the RPM project nature fails
*/
public static void addRPMNature(IProject project, IProgressMonitor mon) throws CoreException {
addNature(project, RPM_NATURE_ID, mon);
}
/**
* Removes the RPM project nature from a given workspace project.
* @param project the project
* @param mon a progress monitor, or <code>null</code> if progress monitoring
* is not desired
* @throws CoreException if removing the RPM project nature fails
*/
public static void removeRPMNature(IProject project, IProgressMonitor mon) throws CoreException {
removeNature(project, RPM_NATURE_ID, mon);
}
/**
* 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);
}
/**
* Utility method for removing a project nature from a project.
*
* @param proj
* the project to remove the nature from
* @param natureId
* the nature id to remove
* @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 removeNature(IProject project, String natureId, IProgressMonitor monitor) throws CoreException {
IProjectDescription description = project.getDescription();
String[] prevNatures = description.getNatureIds();
List<String> newNatures = new ArrayList<String>(Arrays.asList(prevNatures));
newNatures.remove(natureId);
description.setNatureIds(newNatures.toArray(new String[newNatures.size()]));
project.setDescription(description, monitor);
}
public void configure() throws CoreException {
}
public void deconfigure() throws CoreException {
}
public IProject getProject() {
return project;
}
public void setProject(IProject project) {
this.project = project;
}
}
|