Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issue #402 missing runtime scope classpath entry (#219)
* fix issue #402 missing runtime scope classpath entry, eg:
maven.pomderived=true
test=true
maven.groupId=org.yaml
maven.artifactId=snakeyaml
maven.version=1.19
maven.scope=runtime
  • Loading branch information
andxu authored Sep 6, 2018
commit 81a3b3bc05097e0f2f38f8e37d6da531323d4fc0
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
Expand All @@ -36,6 +38,7 @@

public class ResolveClasspathsHandler {
private static final Logger logger = Logger.getLogger(Configuration.LOGGER_NAME);
private static final String SCOPE_ATTRIBUTE = "maven.scope";

/**
* Resolves class path for a java project.
Expand Down Expand Up @@ -178,10 +181,10 @@ private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) th
for (int i = 0; i < unresolved.length; i++) {
IRuntimeClasspathEntry entry = unresolved[i];
if (entry.getClasspathProperty() == IRuntimeClasspathEntry.USER_CLASSES) {
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject);
IRuntimeClasspathEntry[] entries = JavaRuntime.resolveRuntimeClasspathEntry(entry, jproject, true);
for (int j = 0; j < entries.length; j++) {

if (entries[j].getClasspathEntry().isTest()) {
if (entries[j].getClasspathEntry().isTest() && !isRuntime(entries[j].getClasspathEntry())) {
continue;
}
String location = entries[j].getLocation();
Expand All @@ -193,4 +196,13 @@ private static String[] computeDefaultRuntimeClassPath(IJavaProject jproject) th
}
return resolved.toArray(new String[resolved.size()]);
}

private static boolean isRuntime(final IClasspathEntry classpathEntry) {
for (IClasspathAttribute attribute : classpathEntry.getExtraAttributes()) {
if (SCOPE_ATTRIBUTE.equals(attribute.getName()) && "runtime".equals(attribute.getValue())) {
return true;
}
}
return false;
}
}