Only add JREContainerEntry when not yet set [message #1756440] |
Thu, 16 March 2017 21:36 |
Marc Schlegel Messages: 69 Registered: July 2009 |
Member |
|
|
Hello everyone.
I am working on a importer for Bndtools and facing the problem that I dont want to add a JRE-Container if the Java-Project which has existing settings already has one.
List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(javaProject.getRawClasspath()));
entries.add(JavaRuntime.getDefaultJREContainerEntry());
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
Thats what I am doing now, but this way, I could easily end up with two Container within the project. For example the java-project which I create already defined a JRE-7 container, but in my environment JRE-8 is the default. Unfortunately, the ClasspathEntries provide no real information which I could use to check if this entry is a JRE-container.
So, how can I check if a Java project has a JRE-container?
Thanks
[Updated on: Thu, 16 March 2017 21:38] Report message to a moderator
|
|
|
|
Re: Only add JREContainerEntry when not yet set [message #1756500 is a reply to message #1756447] |
Fri, 17 March 2017 20:49 |
Marc Schlegel Messages: 69 Registered: July 2009 |
Member |
|
|
Thanks for the idea Ed.
edited:
The previous message was wrong because my workspace was already corrupted so that Classpath-entries were missing.
This is what I ended up with and seems to work for now
boolean jreContainerAvailable = false;
for (IClasspathEntry entry : entries) {
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath() != null && entry.getPath().toString().startsWith(JavaRuntime.JRE_CONTAINER)) {
jreContainerAvailable = true;
break;
}
}
if (!jreContainerAvailable) {
entries.add(JavaRuntime.getDefaultJREContainerEntry());
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
}
[Updated on: Tue, 21 March 2017 12:10] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03809 seconds