Split jdt ls extension into two parts

One pugin to contain the bulk of the code, which is independent of jdt.ls, lsp4e and lsp4j.
Second plugin to contain the jdt.ls specific DelegateCommandHandler implementation.

This should allow us to somehow re-use the bulk of the code in STS4 eclipse, i.e. when
we have access to JDT from eclipse directly, and there is no jdt.ls process around.
This commit is contained in:
Kris De Volder
2018-04-16 14:24:42 -07:00
parent 704fdaa21d
commit 6f2b8be802
30 changed files with 206 additions and 153 deletions

View File

@@ -35,9 +35,6 @@ public interface STS4LanguageClient extends LanguageClient {
@JsonRequest("sts/moveCursor")
CompletableFuture<Object> moveCursor(CursorMovement cursorMovement);
@JsonRequest("sts/project")
CompletableFuture<ProjectResponse> project(String uri);
@JsonRequest("sts/addClasspathListener")
CompletableFuture<Object> addClasspathListener(ClasspathListenerParams params);

View File

@@ -294,11 +294,6 @@ public class LanguageServerHarness<S extends SimpleLanguageServerWrapper> {
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
}
@Override
public CompletableFuture<ProjectResponse> project(String uri) {
return CompletableFuture.completedFuture(null);
}
@Override
public CompletableFuture<Object> addClasspathListener(
ClasspathListenerParams params) {

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>jdt-ls-extension-parent</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.springframework.tooling.jdt.ls.commons</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,13 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Commons
Bundle-SymbolicName: org.springframework.tooling.jdt.ls.commons
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: org.springframework.tooling.jdt.ls.commons
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.jdt.ls.core,
org.eclipse.core.runtime,
org.eclipse.jdt.core,
org.eclipse.core.resources
Export-Package: org.springframework.tooling.jdt.ls.commons,
org.springframework.tooling.jdt.ls.commons.classpath

View File

@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.

View File

@@ -0,0 +1,18 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>eclipse-plugin</packaging>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>org.springframework.tooling.jdt.ls.commons</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>org.springframework.tooling.jdt.ls.commons</name>
<parent>
<groupId>org.springframework.tooling</groupId>
<artifactId>jdt-ls-extension-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>

View File

@@ -8,13 +8,17 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;
package org.springframework.tooling.jdt.ls.commons;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Date;
/**
* Poor man's logger which writes log output for jdt.ls extension into a predictable location.
*/
public class Logger {
private static PrintWriter printwriter;
@@ -24,7 +28,7 @@ public class Logger {
file = new File(file, "stsjdt.log");
try {
printwriter = new PrintWriter(new FileOutputStream(file), true);
log("=====================================");
log("======== "+new Date()+" =======");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;
package org.springframework.tooling.jdt.ls.commons.classpath;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -19,8 +19,9 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.springframework.tooling.jdt.ls.commons.Logger;
import static org.springframework.tooling.jdt.ls.extension.Logger.log;
import static org.springframework.tooling.jdt.ls.commons.Logger.*;
/**
* An instance of this class provides a means to register

View File

@@ -1,6 +1,18 @@
package org.springframework.tooling.jdt.ls.extension;
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.jdt.ls.commons.classpath;
import static org.springframework.tooling.jdt.ls.extension.Logger.log;
import static org.springframework.tooling.jdt.ls.commons.classpath.Classpath.ENTRY_KIND_BINARY;
import static org.springframework.tooling.jdt.ls.commons.classpath.Classpath.ENTRY_KIND_SOURCE;
import static org.springframework.tooling.jdt.ls.commons.Logger.*;
import java.util.ArrayList;
import java.util.List;
@@ -8,8 +20,7 @@ import java.util.List;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.springframework.tooling.jdt.ls.extension.Classpath.CPE;
import static org.springframework.tooling.jdt.ls.extension.Classpath.*;
import org.springframework.tooling.jdt.ls.commons.classpath.Classpath.CPE;
public class ClasspathUtil {

View File

@@ -8,9 +8,9 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;
package org.springframework.tooling.jdt.ls.commons.resources;
import static org.springframework.tooling.jdt.ls.extension.Logger.log;
import static org.springframework.tooling.jdt.ls.commons.Logger.*;
import java.io.File;
import java.net.URI;

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@@ -8,4 +8,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.jdt.ls.core,
org.eclipse.core.runtime,
org.eclipse.jdt.core,
org.eclipse.core.resources
org.eclipse.core.resources,
org.springframework.tooling.jdt.ls.commons

View File

@@ -1,11 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
<delegateCommandHandler class="org.springframework.tooling.jdt.ls.extension.ResolveProjectHandler">
<command id="sts.java.resolveProject"/>
</delegateCommandHandler>
</extension>
<extension point="org.eclipse.jdt.ls.core.delegateCommandHandler">
<delegateCommandHandler class="org.springframework.tooling.jdt.ls.extension.ClasspathListenerHandler">
<command id="sts.java.addClasspathListener"/>

View File

@@ -0,0 +1,18 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>eclipse-plugin</packaging>
<groupId>org.springframework.tooling</groupId>
<artifactId>org.springframework.tooling.jdt.ls.extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>org.springframework.tooling.jdt.ls.extension</name>
<parent>
<groupId>org.springframework.tooling</groupId>
<artifactId>jdt-ls-extension-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
</project>

View File

@@ -10,7 +10,7 @@
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;
import static org.springframework.tooling.jdt.ls.extension.Logger.log;
import static org.springframework.tooling.jdt.ls.commons.Logger.log;
import java.util.HashMap;
import java.util.List;
@@ -24,11 +24,19 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
import org.eclipse.jdt.ls.core.internal.JavaClientConnection;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
import org.springframework.tooling.jdt.ls.extension.ClasspathListenerManager.ClasspathListener;
import org.springframework.tooling.jdt.ls.commons.Logger;
import org.springframework.tooling.jdt.ls.commons.classpath.Classpath;
import org.springframework.tooling.jdt.ls.commons.classpath.ClasspathListenerManager;
import org.springframework.tooling.jdt.ls.commons.classpath.ClasspathListenerManager.ClasspathListener;
import org.springframework.tooling.jdt.ls.commons.classpath.ClasspathUtil;
@SuppressWarnings("restriction")
public class ClasspathListenerHandler implements IDelegateCommandHandler {
static {
Logger.log("THIS IS NEW!");
}
static final boolean isSupported = checkSupported();
private static boolean checkSupported() {
try {

View File

@@ -0,0 +1,45 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.tooling</groupId>
<artifactId>jdt-ls-extension-parent</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>jdt-ls-extension-parent</name>
<modules>
<module>org.springframework.tooling.jdt.ls.extension</module>
<module>org.springframework.tooling.jdt.ls.commons</module>
</modules>
<properties>
<tycho-version>1.1.0</tycho-version>
</properties>
<repositories>
<repository>
<id>eclipse-oxygen</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/oxygen</url>
</repository>
<repository>
<id>JDT.LS</id>
<layout>p2</layout>
<!-- <url>${jdt.ls.updatesite}</url> -->
<url>http://download.eclipse.org/jdtls/snapshots/repository/latest/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,36 +0,0 @@
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<packaging>eclipse-plugin</packaging>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>org.springframework.tooling.jdt.ls.extension</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>org.springframework.tooling.jdt.ls.extension</name>
<properties>
<tycho-version>1.1.0</tycho-version>
</properties>
<repositories>
<repository>
<id>eclipse-oxygen</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/oxygen</url>
</repository>
<repository>
<id>JDT.LS</id>
<layout>p2</layout>
<!-- <url>${jdt.ls.updatesite}</url> -->
<url>http://download.eclipse.org/jdtls/snapshots/repository/latest/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>

View File

@@ -1,81 +0,0 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.tooling.jdt.ls.extension;
import static org.springframework.tooling.jdt.ls.extension.Logger.log;
import java.net.URI;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.ls.core.internal.IDelegateCommandHandler;
@SuppressWarnings("restriction")
public class ResolveProjectHandler implements IDelegateCommandHandler {
@Override
public Object executeCommand(String commandId, List<Object> arguments, IProgressMonitor monitor) throws Exception {
log("ResolveProjectHandler=" + commandId);
try {
URI resourceUri = ResourceUtils.getResourceUri(arguments);
log("resourceUri=" + resourceUri);
IJavaProject javaProject = ResourceUtils.getJavaProject(resourceUri);
ProjectResponse projectResponse = new ProjectResponse(javaProject.getElementName(), javaProject.getProject().getLocationURI().toString());
log("projectResponse="+projectResponse);
return projectResponse;
} catch (Exception e) {
log(e);
throw e;
}
}
public class ProjectResponse {
private String name;
private String uri;
public ProjectResponse(String name, String uri) {
super();
this.name = name;
this.uri = uri;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
@Override
public String toString() {
return "ProjectResponse [name=" + name + ", uri=" + uri + "]";
}
}
}

View File

@@ -4,9 +4,9 @@ set -e -x
workdir=$(pwd)
# Build jdt.ls
cd ${HOME}/git/eclipse.jdt.ls
jdt_ls_repo=$(pwd)
./mvnw -Pserver-distro -Pupdate-site clean package
# cd ${HOME}/git/eclipse.jdt.ls
# jdt_ls_repo=$(pwd)
# ./mvnw -Pserver-distro -Pupdate-site clean package
# Section below disabled for now. So we can work on the 'fallbacks' with missing or old vscode-java
# Build vscode-java
@@ -21,10 +21,12 @@ jdt_ls_repo=$(pwd)
#code --uninstall-extension redhat.java || echo "Not installed redhat.java"
#code --install-extension *.vsix
code --install-extension redhat.java
# Build spring boot ls
cd $workdir
npm install
rm -fr *.vsix
npm run vsce-package
code --uninstall-extension Pivotal.vscode-spring-boot || echo "Not installed Pivotal.vscode-spring-boot"
rm -fr ${home}/.vscode/extensions/Pivotal.vscode-spring-boot-*
code --install-extension *.vsix

View File

@@ -32,6 +32,7 @@
],
"contributes": {
"javaExtensions": [
"./jars/jdt-ls-commons.jar",
"./jars/jdt-ls-extension.jar"
],
"languages": [
@@ -93,7 +94,7 @@
"vsce-package": "vsce package"
},
"dependencies": {
"@pivotal-tools/commons-vscode": "^0.2.0",
"@pivotal-tools/commons-vscode": "file:../commons-vscode/pivotal-tools-commons-vscode-0.2.1.tgz",
"vscode-languageclient": "^4.0.0"
},
"devDependencies": {

View File

@@ -16,10 +16,10 @@ rm -fr ${workdir}/jars
mkdir -p ${workdir}/jars
# Use maven to build jdt ls extension
cd ../../headless-services/org.springframework.tooling.jdt.ls.extension
../mvnw \
clean package
cp target/*.jar ${workdir}/jars/jdt-ls-extension.jar
cd ../../headless-services/jdt-ls-extension
../mvnw clean package
cp org.springframework.tooling.jdt.ls.extension/target/*.jar ${workdir}/jars/jdt-ls-extension.jar
cp org.springframework.tooling.jdt.ls.commons/target/*.jar ${workdir}/jars/jdt-ls-commons.jar
# Use maven to build fat jar of the language server
cd ../../headless-services/spring-boot-language-server