diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/pom.xml b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/pom.xml index 4bbe46059..3b6c387eb 100644 --- a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/pom.xml +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/pom.xml @@ -39,6 +39,11 @@ org.eclipse.rcp 0.0.0 + + eclipse-feature + org.eclipse.m2e.feature + 0.0.0 + diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/src/org/springframework/tooling/jdt/ls/commons/test/ClasspathListenerHandlerTest.java b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/src/org/springframework/tooling/jdt/ls/commons/test/ClasspathListenerHandlerTest.java index d58f71e5a..5b40823dc 100644 --- a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/src/org/springframework/tooling/jdt/ls/commons/test/ClasspathListenerHandlerTest.java +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/src/org/springframework/tooling/jdt/ls/commons/test/ClasspathListenerHandlerTest.java @@ -116,6 +116,24 @@ public class ClasspathListenerHandlerTest { }); } + @Test public void sourceJar() throws Exception { + String projectName = "maven-with-jar-dependency"; + IProject project = createTestProject(projectName); + File loc = project.getLocation().toFile(); + + service.addClasspathListener(classpaths.commandId); + ACondition.waitFor("Project with classpath to appear", Duration.ofSeconds(50), () -> { + Classpath cp = classpaths.getFor(loc).classpath; + assertClasspath(cp, cp.getEntries().stream().filter(cpe -> Classpath.isSource(cpe)).count()>=1); //has source entries + CPE dependency = cp.getEntries().stream() + .filter(Classpath::isBinary) + .filter(cpe -> new File(cpe.getPath()).getName().startsWith("commons-io")) + .findFirst().get(); + assertClasspath(cp, dependency!=null); + assertTrue(new File(dependency.getSourceContainerUrl().toURI()).exists()); + }); + } + ///////////// harness stuff below /////////////////////////////////////////////// @Rule public TemporaryFolder tmp = new TemporaryFolder(); diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.classpath b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.classpath new file mode 100644 index 000000000..002ad570e --- /dev/null +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.classpath @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.project b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.project new file mode 100644 index 000000000..1afc5a78b --- /dev/null +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.project @@ -0,0 +1,23 @@ + + + maven-with-jar-dependency + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.jdt.core.prefs b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..714351aec --- /dev/null +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.m2e.core.prefs b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 000000000..f897a7f1c --- /dev/null +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/pom.xml b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/pom.xml new file mode 100644 index 000000000..a9755817b --- /dev/null +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons.test/test-projects/maven-with-jar-dependency/pom.xml @@ -0,0 +1,22 @@ + + 4.0.0 + com.example + maven-with-jar-dependency + 0.0.1-SNAPSHOT + maven-with-jar-dependency + + + 1.8 + 1.8 + + + + + org.apache.commons + commons-io + 1.3.2 + + + \ No newline at end of file diff --git a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons/src/org/springframework/tooling/jdt/ls/commons/classpath/ClasspathUtil.java b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons/src/org/springframework/tooling/jdt/ls/commons/classpath/ClasspathUtil.java index f6431d42d..02b3d2d5e 100644 --- a/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons/src/org/springframework/tooling/jdt/ls/commons/classpath/ClasspathUtil.java +++ b/headless-services/jdt-ls-extension/org.springframework.tooling.jdt.ls.commons/src/org/springframework/tooling/jdt/ls/commons/classpath/ClasspathUtil.java @@ -79,6 +79,15 @@ public class ClasspathUtil { if (systemLibs.contains(path)) { cpe.setSystem(true); } + IPath sp = entry.getSourceAttachmentPath(); + if (sp!=null) { + cpe.setSourceContainerUrl(sp.toFile().toURI().toURL()); + //TODO: +// IPath srp = entry.getSourceAttachmentRootPath(); +// if (srp!=null) { +// +// } + } cpEntries.add(cpe); break; } diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JdtLsProjectCache.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JdtLsProjectCache.java index 5d08d005d..79bd30132 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JdtLsProjectCache.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JdtLsProjectCache.java @@ -10,8 +10,12 @@ *******************************************************************************/ package org.springframework.ide.vscode.boot.jdt.ls; +import java.io.File; import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,6 +29,7 @@ import org.slf4j.LoggerFactory; import org.springframework.ide.vscode.commons.java.ClasspathData; import org.springframework.ide.vscode.commons.java.IJavaProject; import org.springframework.ide.vscode.commons.java.JavaProject; +import org.springframework.ide.vscode.commons.languageserver.jdt.ls.Classpath.CPE; import org.springframework.ide.vscode.commons.languageserver.jdt.ls.ClasspathListener; import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer; import org.springframework.ide.vscode.commons.util.Assert; @@ -180,11 +185,28 @@ public class JdtLsProjectCache implements JavaProjectsService { private void logEvent(String type, JavaProject project) { try { log.info("Project "+type+": " + project.getLocationUri()); - log.info("Classpath has "+project.getClasspath().getClasspathEntries().size()+" entries"); + log.info("Classpath has "+project.getClasspath().getClasspathEntries().size()+" entries " + +countSourceAttachments(project.getClasspath().getClasspathEntries()) + " source attachements"); } catch (Exception e) { } } + private static int countSourceAttachments(Collection classpathEntries) { + int count = 0; + for (CPE cpe : classpathEntries) { + URL sourceJar = cpe.getSourceContainerUrl(); + if (sourceJar!=null) { + try { + if (new File(sourceJar.toURI()).exists()) { + count++; + } + } catch (URISyntaxException e) { + } + } + } + return count; + } + @Override public Optional find(TextDocumentIdentifier doc) { String uri = UriUtil.normalize(doc.getUri());