Skip to content

Commit

Permalink
Fix to #1: dependency scan was not including container deps (like Maven)
Browse files Browse the repository at this point in the history
  • Loading branch information
S1artie committed Aug 21, 2024
1 parent e05b700 commit ef861b4
Showing 1 changed file with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jdt.core.IClasspathContainer;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
Expand All @@ -35,6 +36,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

/**
* Resolves URIs.
Expand Down Expand Up @@ -97,27 +99,42 @@ private String resolveUriInternal(String importUri, URI declaringResourceUri, IP
if (project.isOpen() && JavaProject.hasJavaNature(project)) {
ArrayList<DirectoryPath> paths = new ArrayList<>();
try {
IJavaProject javaProject = JavaCore.create(project);
for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
if (classpathEntry.getPath().toOSString().toLowerCase().endsWith(".jar")) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath cpPath = classpathEntry.getPath();
IResource res = root.findMember(cpPath);
// If res is null, the path is absolute (it's an external jar)
String path;
if (res == null) {
path = cpPath.toOSString();
} else {
path = "${workspace_loc:" + res.getFullPath().toOSString() + "}";
}
paths.add(DirectoryPath.parse(path, project));
}
}
}
}
final Consumer<IClasspathEntry> cpeConsumer = new Consumer<IClasspathEntry>() {
@Override
public void accept(IClasspathEntry classpathEntry) {
if (classpathEntry.getPath().toOSString().toLowerCase().endsWith(".jar")) {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
IPath cpPath = classpathEntry.getPath();
IResource res = root.findMember(cpPath);
// If res is null, the path is absolute (it's an external jar)
String path;
if (res == null) {
path = cpPath.toOSString();
} else {
path = "${workspace_loc:" + res.getFullPath().toOSString() + "}";
}
paths.add(DirectoryPath.parse(path, project));
}
}
}
};


IJavaProject javaProject = JavaCore.create(project);
for (IClasspathEntry classpathEntry : javaProject.getRawClasspath()) {
if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
final IClasspathContainer container = JavaCore.getClasspathContainer(classpathEntry.getPath(), javaProject);
if(container.getKind() != IClasspathContainer.K_SYSTEM && container.getKind() != IClasspathContainer.K_DEFAULT_SYSTEM) {
for (IClasspathEntry containedClasspathEntry : container.getClasspathEntries()) {
cpeConsumer.accept(containedClasspathEntry);
}
}
} else if (classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY) {
cpeConsumer.accept(classpathEntry);
}
}
} catch(JavaModelException e) {
// ignored
}
Expand Down

0 comments on commit ef861b4

Please sign in to comment.