use of org.eclipse.jdt.launching.IRuntimeClasspathEntry2 in project bndtools by bndtools.
the class BndContainerRuntimeClasspathEntryResolver method resolveRuntimeClasspathEntry.
@Override
public IRuntimeClasspathEntry[] resolveRuntimeClasspathEntry(IRuntimeClasspathEntry entryToResolve, IJavaProject entryProject) throws CoreException {
if (entryToResolve == null || entryProject == null) {
return new IRuntimeClasspathEntry[0];
}
final List<IRuntimeClasspathEntry> resolvedRuntimeClasspathEntries = new ArrayList<>();
final IClasspathContainer container = JavaCore.getClasspathContainer(entryToResolve.getPath(), entryProject);
if (container == null) {
throw new CoreException(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Could not resolve Bnd classpath container", null));
}
final IClasspathEntry[] classpathEntries = container.getClasspathEntries();
List<IJavaProject> projects = resolvingProjects.get();
Integer count = resolvingCount.get();
if (projects == null) {
projects = new ArrayList<>();
resolvingProjects.set(projects);
count = 0;
}
int intCount = count.intValue();
intCount++;
resolvingCount.set(intCount);
try {
for (IClasspathEntry classpathEntry : classpathEntries) {
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
final IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(classpathEntry.getPath().segment(0));
final IJavaProject javaProject = JavaCore.create(project);
if (!projects.contains(javaProject)) {
projects.add(javaProject);
final IRuntimeClasspathEntry2 defaultProjectClasspathEntry = (IRuntimeClasspathEntry2) JavaRuntime.newDefaultProjectClasspathEntry(javaProject);
final IRuntimeClasspathEntry[] projectRuntimeClasspathEntries = defaultProjectClasspathEntry.getRuntimeClasspathEntries(null);
for (IRuntimeClasspathEntry projectRuntimeClasspathEntry : projectRuntimeClasspathEntries) {
// instead of resolving all output locations we simply just return the project runtime classpath entry itself
if (projectRuntimeClasspathEntry.getType() == IRuntimeClasspathEntry.PROJECT) {
IResource resource = projectRuntimeClasspathEntry.getResource();
if (resource instanceof IProject) {
resolvedRuntimeClasspathEntries.add(projectRuntimeClasspathEntry);
}
} else {
IRuntimeClasspathEntry[] resolvedEntries = JavaRuntime.resolveRuntimeClasspathEntry(projectRuntimeClasspathEntry, javaProject);
for (IRuntimeClasspathEntry resolvedEntry : resolvedEntries) {
resolvedRuntimeClasspathEntries.add(resolvedEntry);
}
}
}
}
} else {
final IRuntimeClasspathEntry runtimeClasspathEntry = new RuntimeClasspathEntry(classpathEntry);
if (!resolvedRuntimeClasspathEntries.contains(runtimeClasspathEntry)) {
resolvedRuntimeClasspathEntries.add(runtimeClasspathEntry);
}
}
}
} finally {
intCount--;
if (intCount == 0) {
resolvingProjects.set(null);
resolvingCount.set(null);
} else {
resolvingCount.set(intCount);
}
}
for (IRuntimeClasspathEntry resolvedRuntimeClasspathEntry : resolvedRuntimeClasspathEntries) {
resolvedRuntimeClasspathEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES);
}
return resolvedRuntimeClasspathEntries.toArray(new IRuntimeClasspathEntry[0]);
}
Aggregations