use of org.eclipse.jdt.launching.environments.IExecutionEnvironment in project bndtools by bndtools.
the class ImportBndWorkspaceWizard method addSystemLibraryContainer.
/**
* The Java-Nature doesn't add a JRE-Container, so we add one
*
* @param javaProject
* the Java project which should get enhanced with LibraryContainer
* @param javacTarget
* @param monitor
* current IProgressMonitor
* @throws JavaModelException
*/
private void addSystemLibraryContainer(final IJavaProject javaProject, final String javacTarget, final ImportSettings importSettings, IProgressMonitor monitor) throws JavaModelException {
List<IClasspathEntry> entries = new ArrayList<>(Arrays.asList(javaProject.getRawClasspath()));
// entries.addAll(newContainerEntries);
// only add JRE-Container if none available
boolean jreContainerAvailable = false;
Iterator<IClasspathEntry> it = entries.iterator();
while (it.hasNext()) {
IClasspathEntry entry = it.next();
if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER && entry.getPath() != null && entry.getPath().toString().startsWith(JavaRuntime.JRE_CONTAINER)) {
// remove existing entry if user want to infer EE
if (importSettings.inferExecutionEnvironment) {
it.remove();
} else {
jreContainerAvailable = true;
}
break;
}
}
if (!jreContainerAvailable) {
IClasspathEntry defaultJREContainerEntry = JavaRuntime.getDefaultJREContainerEntry();
if (importSettings.inferExecutionEnvironment) {
// fuzzy at the moment but better than nothing. We should find a way to handle CDC
IExecutionEnvironment environment = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("J2SE-" + javacTarget);
if (environment == null) {
environment = JavaRuntime.getExecutionEnvironmentsManager().getEnvironment("JavaSE-" + javacTarget);
}
if (environment != null) {
entries.add(JavaCore.newContainerEntry(JavaRuntime.newJREContainerPath(environment)));
} else {
Plugin.getDefault().getLog().log(new Status(IStatus.WARNING, Plugin.PLUGIN_ID, 0, String.format("Could not infer execution-environment in project '%s' for javac.target '%s'", javaProject.getElementName(), javacTarget), null));
entries.add(defaultJREContainerEntry);
}
} else {
entries.add(defaultJREContainerEntry);
}
javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), monitor);
}
}
Aggregations