Add support for source-jars in JdtLs classpath service
This commit is contained in:
@@ -39,6 +39,11 @@
|
||||
<id>org.eclipse.rcp</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
<requirement>
|
||||
<type>eclipse-feature</type>
|
||||
<id>org.eclipse.m2e.feature</id>
|
||||
<versionRange>0.0.0</versionRange>
|
||||
</requirement>
|
||||
</extraRequirements>
|
||||
</dependency-resolution>
|
||||
</configuration>
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>maven-with-jar-dependency</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -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
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,22 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>maven-with-jar-dependency</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>maven-with-jar-dependency</name>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<CPE> 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<IJavaProject> find(TextDocumentIdentifier doc) {
|
||||
String uri = UriUtil.normalize(doc.getUri());
|
||||
|
||||
Reference in New Issue
Block a user