Line 0
Link Here
|
|
|
1 |
|
2 |
package org.maven.ide.eclipse.project; |
3 |
|
4 |
import java.io.File; |
5 |
import java.util.ArrayList; |
6 |
import java.util.Arrays; |
7 |
import java.util.HashMap; |
8 |
import java.util.HashSet; |
9 |
import java.util.Iterator; |
10 |
import java.util.List; |
11 |
import java.util.Map; |
12 |
import java.util.Properties; |
13 |
import java.util.Set; |
14 |
import java.util.jar.Attributes; |
15 |
import java.util.jar.JarFile; |
16 |
import java.util.jar.Manifest; |
17 |
|
18 |
import org.apache.maven.SettingsConfigurationException; |
19 |
import org.apache.maven.embedder.MavenEmbedder; |
20 |
import org.apache.maven.execution.DefaultMavenExecutionRequest; |
21 |
import org.apache.maven.execution.MavenExecutionRequest; |
22 |
import org.apache.maven.model.Plugin; |
23 |
import org.apache.maven.model.Resource; |
24 |
import org.apache.maven.project.MavenProject; |
25 |
import org.apache.maven.settings.Settings; |
26 |
|
27 |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
28 |
import org.eclipse.core.resources.IContainer; |
29 |
import org.eclipse.core.resources.IFile; |
30 |
import org.eclipse.core.resources.IProject; |
31 |
import org.eclipse.core.resources.IProjectDescription; |
32 |
import org.eclipse.core.resources.IResource; |
33 |
import org.eclipse.core.runtime.CoreException; |
34 |
import org.eclipse.core.runtime.IPath; |
35 |
import org.eclipse.core.runtime.IProgressMonitor; |
36 |
import org.eclipse.core.runtime.IStatus; |
37 |
import org.eclipse.core.runtime.OperationCanceledException; |
38 |
import org.eclipse.core.runtime.Path; |
39 |
import org.eclipse.core.runtime.Status; |
40 |
import org.eclipse.core.runtime.SubProgressMonitor; |
41 |
import org.eclipse.core.runtime.jobs.Job; |
42 |
import org.eclipse.jdt.core.IClasspathContainer; |
43 |
import org.eclipse.jdt.core.IClasspathEntry; |
44 |
import org.eclipse.jdt.core.IJavaProject; |
45 |
import org.eclipse.jdt.core.JavaCore; |
46 |
import org.eclipse.jdt.launching.IVMInstall; |
47 |
import org.eclipse.jdt.launching.IVMInstallType; |
48 |
import org.eclipse.jdt.launching.JavaRuntime; |
49 |
import org.eclipse.jdt.launching.LibraryLocation; |
50 |
import org.maven.ide.eclipse.Maven2Plugin; |
51 |
import org.maven.ide.eclipse.MavenEmbedderCallback; |
52 |
import org.maven.ide.eclipse.PluginConsoleEventMonitor; |
53 |
import org.maven.ide.eclipse.TransferListenerAdapter; |
54 |
import org.maven.ide.eclipse.container.Maven2ClasspathContainer; |
55 |
import org.maven.ide.eclipse.container.Maven2ClasspathContainerInitializer; |
56 |
import org.maven.ide.eclipse.preferences.Maven2PreferenceConstants; |
57 |
|
58 |
|
59 |
/** |
60 |
* Basic helper class that can be used to enable the Maven tooling on a project and also programatically |
61 |
* update the source folders for the projects |
62 |
* |
63 |
* @author Philip Dodds |
64 |
*/ |
65 |
public class MavenEclipseProject { |
66 |
|
67 |
private static final class UpdateSourcesJob extends Job implements MavenEmbedderCallback { |
68 |
|
69 |
private final IProject project; |
70 |
|
71 |
private Set sources = new HashSet(); |
72 |
|
73 |
private List sourceEntries = new ArrayList(); |
74 |
|
75 |
private Map options = new HashMap(); |
76 |
|
77 |
UpdateSourcesJob(IProject project) { |
78 |
super("Updating " + project.getName() + " Sources"); |
79 |
this.project = project; |
80 |
} |
81 |
|
82 |
protected IStatus run(IProgressMonitor monitor) { |
83 |
IFile pom = project.getFile(Maven2Plugin.POM_FILE_NAME); |
84 |
if(!pom.exists()) { |
85 |
return Status.OK_STATUS; |
86 |
} |
87 |
|
88 |
monitor.beginTask("Updating sources " + project.getName(), IProgressMonitor.UNKNOWN); |
89 |
try { |
90 |
Maven2Plugin.getDefault().executeInEmbedder(this, monitor); |
91 |
|
92 |
// TODO optimize project refresh |
93 |
monitor.subTask("Refreshing"); |
94 |
project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 1)); |
95 |
|
96 |
monitor.subTask("Configuring Build Path"); |
97 |
IJavaProject javaProject = JavaCore.create(project); |
98 |
|
99 |
setOption(javaProject, options, JavaCore.COMPILER_COMPLIANCE); |
100 |
setOption(javaProject, options, JavaCore.COMPILER_SOURCE); |
101 |
setOption(javaProject, options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM); |
102 |
|
103 |
String source = (String) options.get(JavaCore.COMPILER_SOURCE); |
104 |
if(source == null) { |
105 |
sourceEntries.add(JavaRuntime.getDefaultJREContainerEntry()); |
106 |
} else { |
107 |
sourceEntries.add(getJREContainer(source)); |
108 |
} |
109 |
|
110 |
IClasspathEntry[] currentClasspath = javaProject.getRawClasspath(); |
111 |
for(int i = 0; i < currentClasspath.length; i++ ) { |
112 |
// Delete all non container (e.g. JRE library) entries. See MNGECLIPSE-9 |
113 |
IClasspathEntry entry = currentClasspath[i]; |
114 |
if(entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { |
115 |
if(!JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) { |
116 |
sourceEntries.add(entry); |
117 |
} |
118 |
} |
119 |
} |
120 |
|
121 |
IClasspathEntry[] entries = (IClasspathEntry[]) sourceEntries |
122 |
.toArray(new IClasspathEntry[sourceEntries.size()]); |
123 |
javaProject.setRawClasspath(entries, monitor); |
124 |
|
125 |
Maven2Plugin.getDefault().getConsole().logMessage("Updated source folders for project " + project.getName()); |
126 |
|
127 |
} catch(Exception ex) { |
128 |
String msg = "Unable to update source folders " + project.getName() + "; " + ex.toString(); |
129 |
Maven2Plugin.getDefault().getConsole().logMessage(msg); |
130 |
// Maven2Plugin.log( msg, ex); |
131 |
} finally { |
132 |
monitor.done(); |
133 |
} |
134 |
|
135 |
return Status.OK_STATUS; |
136 |
} |
137 |
|
138 |
private void setOption(IJavaProject javaProject, Map options, String name) { |
139 |
String newValue = (String) options.get(name); |
140 |
if(newValue == null) { |
141 |
return; |
142 |
} |
143 |
String currentValue = javaProject.getOption(name, false); |
144 |
if(!newValue.equals(currentValue)) { |
145 |
javaProject.setOption(name, newValue); |
146 |
} |
147 |
} |
148 |
|
149 |
private IClasspathEntry getJREContainer(String version) { |
150 |
int n = VERSIONS.indexOf(version); |
151 |
if(n > -1) { |
152 |
Map jreContainers = getJREContainers(); |
153 |
for(int i = n; i < VERSIONS.size(); i++ ) { |
154 |
IClasspathEntry entry = (IClasspathEntry) jreContainers.get(version); |
155 |
if(entry != null) { |
156 |
Maven2Plugin.getDefault().getConsole().logMessage("JRE compliant to " + version + ". " + entry); |
157 |
return entry; |
158 |
} |
159 |
} |
160 |
} |
161 |
IClasspathEntry entry = JavaRuntime.getDefaultJREContainerEntry(); |
162 |
Maven2Plugin.getDefault().getConsole().logMessage( |
163 |
"No JRE compliant to " + version + ". Using default JRE container " + entry); |
164 |
return entry; |
165 |
} |
166 |
|
167 |
private Map getJREContainers() { |
168 |
Map jreContainers = new HashMap(); |
169 |
|
170 |
jreContainers.put(getJREVersion(JavaRuntime.getDefaultVMInstall()), JavaRuntime.getDefaultJREContainerEntry()); |
171 |
|
172 |
IVMInstallType[] installTypes = JavaRuntime.getVMInstallTypes(); |
173 |
for(int i = 0; i < installTypes.length; i++ ) { |
174 |
IVMInstall[] installs = installTypes[i].getVMInstalls(); |
175 |
for(int j = 0; j < installs.length; j++ ) { |
176 |
IVMInstall install = installs[j]; |
177 |
String version = getJREVersion(install); |
178 |
if(!jreContainers.containsKey(version)) { |
179 |
// in Eclipse 3.2 one could use JavaRuntime.newJREContainerPath(install) |
180 |
IPath jreContainerPath = new Path(JavaRuntime.JRE_CONTAINER).append(install.getVMInstallType().getId()) |
181 |
.append(install.getName()); |
182 |
jreContainers.put(version, JavaCore.newContainerEntry(jreContainerPath)); |
183 |
} |
184 |
} |
185 |
} |
186 |
|
187 |
return jreContainers; |
188 |
} |
189 |
|
190 |
private String getJREVersion(IVMInstall install) { |
191 |
LibraryLocation[] libraryLocations = JavaRuntime.getLibraryLocations(install); |
192 |
if(libraryLocations != null) { |
193 |
for(int k = 0; k < libraryLocations.length; k++ ) { |
194 |
IPath path = libraryLocations[k].getSystemLibraryPath(); |
195 |
String jarName = path.lastSegment(); |
196 |
if("rt.jar".equals(jarName)) { |
197 |
try { |
198 |
JarFile jarFile = new JarFile(path.toFile()); |
199 |
Manifest manifest = jarFile.getManifest(); |
200 |
Attributes attributes = manifest.getMainAttributes(); |
201 |
return attributes.getValue(Attributes.Name.SPECIFICATION_VERSION); |
202 |
} catch(Exception ex) { |
203 |
Maven2Plugin.getDefault().getConsole().logError("Unable to read " + path + " " + ex.getMessage()); |
204 |
} |
205 |
} |
206 |
} |
207 |
} |
208 |
return null; |
209 |
} |
210 |
|
211 |
/** |
212 |
* @see MavenEmbedderCallback#run(MavenEmbedder, IProgressMonitor) |
213 |
*/ |
214 |
public Object run(MavenEmbedder mavenEmbedder, IProgressMonitor monitor) { |
215 |
resolve(project.getFile(Maven2Plugin.POM_FILE_NAME), mavenEmbedder, monitor); |
216 |
return null; |
217 |
} |
218 |
|
219 |
private void resolve(IResource pomResource, MavenEmbedder mavenEmbedder, IProgressMonitor monitor) { |
220 |
if(monitor.isCanceled()) { |
221 |
throw new OperationCanceledException(); |
222 |
} |
223 |
|
224 |
Maven2Plugin plugin = Maven2Plugin.getDefault(); |
225 |
|
226 |
String msg = "Reading " + pomResource.getFullPath(); |
227 |
plugin.getConsole().logMessage(msg); |
228 |
|
229 |
monitor.subTask("Reading " + pomResource.getFullPath()); |
230 |
File pomFile = pomResource.getLocation().toFile(); |
231 |
|
232 |
MavenProject mavenProject; |
233 |
try { |
234 |
mavenProject = mavenEmbedder.readProject(pomFile); |
235 |
} catch(Exception ex) { |
236 |
plugin.getConsole().logError("Unable to read project " + pomResource.getFullPath() + "; " + ex.toString()); |
237 |
return; |
238 |
} |
239 |
|
240 |
String source = getBuildOption(mavenProject, "maven-compiler-plugin", "source"); |
241 |
if(source != null) { |
242 |
plugin.getConsole().logMessage("Setting source compatibility: " + source); |
243 |
setVersion(options, JavaCore.COMPILER_SOURCE, source); |
244 |
setVersion(options, JavaCore.COMPILER_COMPLIANCE, source); |
245 |
} |
246 |
|
247 |
String target = getBuildOption(mavenProject, "maven-compiler-plugin", "target"); |
248 |
if(target != null) { |
249 |
plugin.getConsole().logMessage("Setting target compatibility: " + source); |
250 |
setVersion(options, JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, target); |
251 |
} |
252 |
|
253 |
monitor.subTask("Generating Sources " + pomResource.getFullPath()); |
254 |
try { |
255 |
plugin.getConsole().logMessage("Generating sources " + pomResource.getFullPath()); |
256 |
|
257 |
mavenEmbedder.execute(getExecutionRequest(pomFile, monitor, mavenEmbedder)); |
258 |
// TODO hook up console view |
259 |
// EventMonitor eventMonitor = new PluginConsoleEventMonitor(); |
260 |
// mavenEmbedder.execute(mavenProject, goals, eventMonitor, transferListener, properties, f.getParentFile()); |
261 |
|
262 |
} catch(Exception ex) { |
263 |
plugin.getConsole().logError( |
264 |
"Failed to run generate source goals " + pomResource.getFullPath() + " " + ex.getMessage()); |
265 |
} |
266 |
|
267 |
File basedir = pomResource.getLocation().toFile().getParentFile(); |
268 |
File projectBaseDir = project.getLocation().toFile(); |
269 |
|
270 |
extractSourceDirs(project, mavenProject.getCompileSourceRoots(), basedir, projectBaseDir); |
271 |
extractSourceDirs(project, mavenProject.getTestCompileSourceRoots(), basedir, projectBaseDir); |
272 |
|
273 |
extractResourceDirs(project, mavenProject.getBuild().getResources(), basedir, projectBaseDir); |
274 |
extractResourceDirs(project, mavenProject.getBuild().getTestResources(), basedir, projectBaseDir); |
275 |
|
276 |
IContainer parent = pomResource.getParent(); |
277 |
List modules = mavenProject.getModules(); |
278 |
for(Iterator it = modules.iterator(); it.hasNext() && !monitor.isCanceled();) { |
279 |
if(monitor.isCanceled()) { |
280 |
throw new OperationCanceledException(); |
281 |
} |
282 |
String module = (String) it.next(); |
283 |
IResource memberPom = parent.findMember(module + "/" + Maven2Plugin.POM_FILE_NAME); //$NON-NLS-1$ |
284 |
if(memberPom != null) { |
285 |
resolve(memberPom, mavenEmbedder, monitor); |
286 |
} |
287 |
} |
288 |
} |
289 |
|
290 |
private MavenExecutionRequest getExecutionRequest(File pomFile, IProgressMonitor monitor, MavenEmbedder embedder) |
291 |
throws SettingsConfigurationException { |
292 |
List goals = Arrays.asList("generate-sources,generate-resources,generate-test-sources,generate-test-resources" |
293 |
.split(",")); |
294 |
|
295 |
Properties properties = new Properties(); |
296 |
|
297 |
File userSettingsPath = embedder.getUserSettingsPath(null); |
298 |
File globalSettingsFile = embedder.getGlobalSettingsPath(); |
299 |
|
300 |
Settings settings = embedder.buildSettings(userSettingsPath, globalSettingsFile, false, // interactive |
301 |
false, // offline, |
302 |
false, // usePluginRegistry, |
303 |
Boolean.FALSE); // pluginUpdateOverride ); |
304 |
|
305 |
String localRepositoryPath = System.getProperty(Maven2PreferenceConstants.P_LOCAL_REPOSITORY_DIR); |
306 |
if(localRepositoryPath == null || localRepositoryPath.trim().length() == 0) { |
307 |
localRepositoryPath = embedder.getLocalRepositoryPath(settings); |
308 |
} |
309 |
|
310 |
MavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest().setPomFile(pomFile.getAbsolutePath()) |
311 |
.setBasedir(pomFile.getParentFile()).setGoals(goals).setSettings(settings) |
312 |
// TODO |
313 |
.setProperties(properties).setLocalRepositoryPath(localRepositoryPath).setReactorActive(false).setRecursive( |
314 |
true).setShowErrors(true) |
315 |
// TODO |
316 |
.setInteractive(false).setLoggingLevel(MavenExecutionRequest.LOGGING_LEVEL_INFO) |
317 |
.activateDefaultEventMonitor().addEventMonitor(new PluginConsoleEventMonitor()).setTransferListener( |
318 |
new TransferListenerAdapter(monitor)).setFailureBehavior(MavenExecutionRequest.REACTOR_FAIL_AT_END) |
319 |
// .addActiveProfiles( activeProfiles ) |
320 |
// .addInactiveProfiles( inactiveProfiles ) |
321 |
.setOffline(Boolean.getBoolean(Maven2PreferenceConstants.P_OFFLINE)).setGlobalChecksumPolicy( |
322 |
System.getProperty(Maven2PreferenceConstants.P_GLOBAL_CHECKSUM_POLICY)); |
323 |
// .setUpdateSnapshots( updateSnapshots ) // TODO |
324 |
; |
325 |
|
326 |
return executionRequest; |
327 |
} |
328 |
|
329 |
public static final List VERSIONS = Arrays.asList("1.1,1.2,1.3,1.4,1.5,1.6,1.7".split(",")); |
330 |
|
331 |
static void setVersion(Map options, String name, String value) { |
332 |
if(value == null) { |
333 |
return; |
334 |
} |
335 |
String current = (String) options.get(name); |
336 |
if(current == null) { |
337 |
options.put(name, value); |
338 |
} else { |
339 |
int oldIndex = VERSIONS.indexOf(current); |
340 |
int newIndex = VERSIONS.indexOf(value.trim()); |
341 |
if(newIndex > oldIndex) { |
342 |
options.put(name, value); |
343 |
} |
344 |
} |
345 |
} |
346 |
|
347 |
void extractSourceDirs(IProject project, List sourceRoots, File basedir, File projectBaseDir) { |
348 |
for(Iterator it = sourceRoots.iterator(); it.hasNext();) { |
349 |
String sourceRoot = (String) it.next(); |
350 |
if(new File(sourceRoot).isDirectory()) { |
351 |
IResource r = project.findMember(toRelativeAndFixSeparator(projectBaseDir, sourceRoot)); |
352 |
if(r != null && sources.add(r.getFullPath().toString())) { |
353 |
sourceEntries.add(JavaCore |
354 |
.newSourceEntry(r.getFullPath() /*, new IPath[] { new Path( "**"+"/.svn/"+"**")} */)); |
355 |
Maven2Plugin.getDefault().getConsole().logMessage("Adding source folder " + r.getFullPath()); |
356 |
} |
357 |
} |
358 |
} |
359 |
} |
360 |
|
361 |
void extractResourceDirs(IProject project, List resources, File basedir, File projectBaseDir) { |
362 |
for(Iterator it = resources.iterator(); it.hasNext();) { |
363 |
Resource resource = (Resource) it.next(); |
364 |
File resourceDirectory = new File(resource.getDirectory()); |
365 |
if(resourceDirectory.exists() && resourceDirectory.isDirectory()) { |
366 |
IResource r = project.findMember(toRelativeAndFixSeparator(projectBaseDir, resource.getDirectory())); |
367 |
if(r != null && sources.add(r.getFullPath().toString())) { |
368 |
sourceEntries.add(JavaCore.newSourceEntry(r.getFullPath(), new IPath[] {new Path("**")}, r.getFullPath())); //, new IPath[] { new Path( "**"+"/.svn/"+"**")} ) ); |
369 |
Maven2Plugin.getDefault().getConsole().logMessage("Adding resource folder " + r.getFullPath()); |
370 |
} |
371 |
} |
372 |
} |
373 |
} |
374 |
|
375 |
private String toRelativeAndFixSeparator(File basedir, String absolutePath) { |
376 |
String relative; |
377 |
if(absolutePath.equals(basedir.getAbsolutePath())) { |
378 |
relative = "."; |
379 |
} else if(absolutePath.startsWith(basedir.getAbsolutePath())) { |
380 |
relative = absolutePath.substring(basedir.getAbsolutePath().length() + 1); |
381 |
} else { |
382 |
relative = absolutePath; |
383 |
} |
384 |
return relative.replace('\\', '/'); //$NON-NLS-1$ //$NON-NLS-2$ |
385 |
} |
386 |
|
387 |
public static String getBuildOption(MavenProject project, String artifactId, String optionName) { |
388 |
for(Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext();) { |
389 |
Plugin plugin = (Plugin) it.next(); |
390 |
if(artifactId.equals(plugin.getArtifactId())) { |
391 |
Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration(); |
392 |
if(o != null && o.getChild(optionName) != null) { |
393 |
return o.getChild(optionName).getValue(); |
394 |
} |
395 |
} |
396 |
} |
397 |
return null; |
398 |
} |
399 |
|
400 |
} |
401 |
|
402 |
public static void scheduleUpdateSources(IProject project) { |
403 |
new UpdateSourcesJob(project).schedule(); |
404 |
} |
405 |
|
406 |
public static void updateSources(IProject project) throws InterruptedException { |
407 |
UpdateSourcesJob job = new UpdateSourcesJob(project); |
408 |
job.schedule(); |
409 |
job.join(); |
410 |
} |
411 |
|
412 |
public static void enableNature(IProject project) { |
413 |
try { |
414 |
ArrayList newNatures = new ArrayList(); |
415 |
newNatures.add(JavaCore.NATURE_ID); |
416 |
newNatures.add(Maven2Plugin.NATURE_ID); |
417 |
|
418 |
IProjectDescription description = project.getDescription(); |
419 |
String[] natures = description.getNatureIds(); |
420 |
for(int i = 0; i < natures.length; ++i) { |
421 |
String id = natures[i]; |
422 |
if(!Maven2Plugin.NATURE_ID.equals(id) && !JavaCore.NATURE_ID.equals(natures[i])) { |
423 |
newNatures.add(natures[i]); |
424 |
} |
425 |
} |
426 |
description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()])); |
427 |
project.setDescription(description, null); |
428 |
|
429 |
IJavaProject javaProject = JavaCore.create(project); |
430 |
if(javaProject != null) { |
431 |
IClasspathContainer maven2ClasspathContainer = Maven2ClasspathContainerInitializer |
432 |
.getMaven2ClasspathContainer(javaProject); |
433 |
IClasspathEntry[] containerEntries = maven2ClasspathContainer.getClasspathEntries(); |
434 |
HashSet containerEntrySet = new HashSet(); |
435 |
for(int i = 0; i < containerEntries.length; i++ ) { |
436 |
containerEntrySet.add(containerEntries[i].getPath().toString()); |
437 |
} |
438 |
|
439 |
// remove classpath container from JavaProject |
440 |
IClasspathEntry[] entries = javaProject.getRawClasspath(); |
441 |
ArrayList newEntries = new ArrayList(); |
442 |
for(int i = 0; i < entries.length; i++ ) { |
443 |
IClasspathEntry entry = entries[i]; |
444 |
if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entry.getPath()) |
445 |
&& !containerEntrySet.contains(entry.getPath().toString())) { |
446 |
newEntries.add(entry); |
447 |
} |
448 |
} |
449 |
newEntries.add(JavaCore.newContainerEntry(new Path(Maven2Plugin.CONTAINER_ID))); |
450 |
|
451 |
javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]), |
452 |
null); |
453 |
} |
454 |
|
455 |
} catch(CoreException ex) { |
456 |
Maven2Plugin.getDefault().getConsole().logError("Can't enable nature " + ex.toString()); |
457 |
Maven2Plugin.log(ex); |
458 |
|
459 |
} |
460 |
} |
461 |
|
462 |
public static void disableNature(IProject project) { |
463 |
try { |
464 |
project.deleteMarkers(Maven2Plugin.MARKER_ID, true, IResource.DEPTH_INFINITE); |
465 |
|
466 |
IProjectDescription description = project.getDescription(); |
467 |
String[] natures = description.getNatureIds(); |
468 |
ArrayList newNatures = new ArrayList(); |
469 |
for(int i = 0; i < natures.length; ++i) { |
470 |
if(!Maven2Plugin.NATURE_ID.equals(natures[i])) { |
471 |
newNatures.add(natures[i]); |
472 |
} |
473 |
} |
474 |
description.setNatureIds((String[]) newNatures.toArray(new String[newNatures.size()])); |
475 |
project.setDescription(description, null); |
476 |
|
477 |
IJavaProject javaProject = JavaCore.create(project); |
478 |
if(javaProject != null) { |
479 |
// remove classpatch container from JavaProject |
480 |
IClasspathEntry[] entries = javaProject.getRawClasspath(); |
481 |
ArrayList newEntries = new ArrayList(); |
482 |
for(int i = 0; i < entries.length; i++ ) { |
483 |
if(!Maven2ClasspathContainer.isMaven2ClasspathContainer(entries[i].getPath())) { |
484 |
newEntries.add(entries[i]); |
485 |
} |
486 |
} |
487 |
javaProject.setRawClasspath((IClasspathEntry[]) newEntries.toArray(new IClasspathEntry[newEntries.size()]), |
488 |
null); |
489 |
} |
490 |
|
491 |
} catch(CoreException ex) { |
492 |
Maven2Plugin.getDefault().getConsole().logError("Can't disable nature " + ex.toString()); |
493 |
Maven2Plugin.log(ex); |
494 |
} |
495 |
} |
496 |
} |