Merge branch 'master' of github.com:spring-projects/sts4

This commit is contained in:
Kris De Volder
2017-08-23 10:26:37 -07:00
20 changed files with 262 additions and 61 deletions

View File

@@ -27,7 +27,8 @@ export class JarLanguageClient extends AutoLanguageClient {
let childProcess;
return new Promise((resolve, reject) => {
PortFinder.getPort((err, port) => {
let basePort = Math.floor(Math.random() * 10000) + 40000;
PortFinder.getPort({port: basePort}, (err, port) => {
this.server = net.createServer(socket => {
this.socket = socket;
resolve(childProcess);

View File

@@ -1,6 +1,6 @@
{
"name": "pivotal-atom-languageclient-commons",
"version": "0.0.6",
"version": "0.0.7",
"description": "Atom language client commons for STS4 language servers",
"repository": "https://github.com/spring-projects/sts4",
"license": "MIT",

View File

@@ -8,7 +8,6 @@ title=Spring Boot IDE \n\
\n\
Version: @QUALIFIER@\n\
Build Id: @BUILD_ID@\n\
Platform: Eclipse @PLATFORM_VERSION@\n\
\n\
Copyright (c) 2007 - 2017 Pivotal Software, Inc.\n\
All rights reserved. Visit http://spring.io/tools/sts\n\

View File

@@ -6,7 +6,6 @@ productBlurb=Spring Boot IDE \n\
\n\
Version: @QUALIFIER@\n\
Build Id: @BUILD_ID@\n\
Platform: Eclipse @PLATFORM_VERSION@\n\
\n\
Copyright (c) 2007 - 2017 Pivotal Software, Inc.\n\
All rights reserved. Visit http://spring.io/tools/sts\n\

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>
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>
<parent>
<groupId>org.springframework.boot.ide</groupId>
@@ -11,13 +11,48 @@
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>org.springframework.boot.ide.branding</artifactId>
<packaging>eclipse-plugin</packaging>
<artifactId>org.springframework.boot.ide.branding</artifactId>
<packaging>eclipse-plugin</packaging>
<name>org.springframework.boot.ide.branding</name>
<name>org.springframework.boot.ide.branding</name>
<build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-version-details-about-dialog</id>
<phase>validate</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<if>
<equals arg1="${p2.replaceQualifier}" arg2="true" />
<then>
<propertyregex property="shortQualifier" input="${buildQualifier}" regexp="[0-9a-z.A-Z]*\-(.*)" select="\1" casesensitive="false" />
<propertyregex property="build.id" input="${buildQualifier}" regexp="([0-9a-z.A-Z]*)\-.*" select="\1" casesensitive="false" />
<property name="qualifier" value="${unqualifiedVersion}.${shortQualifier}" />
<replace file="about.properties" token="@QUALIFIER@" value="${qualifier}" summary="yes" />
<replace file="about.properties" token="@BUILD_ID@" value="${build.id}" summary="yes" />
<replace file="plugin.properties" token="@QUALIFIER@" value="${qualifier}" summary="yes" />
<replace file="plugin.properties" token="@BUILD_ID@" value="${build.id}" summary="yes" />
</then>
</if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-plugin</artifactId>
@@ -33,5 +68,5 @@
</executions>
</plugin>
</plugins>
</build>
</build>
</project>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.springframework.tooling.boot.java.ls.feature"
label="Spring Boot IDE Java Editing Language Server Feature"
label="Spring Boot Java Language Server Feature"
version="4.0.0.qualifier"
provider-name="Pivotal, Inc.">

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Spring Boot Java Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.boot.java.ls;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.springframework.tooling.bosh.ls.feature"
label="Spring Boot IDE Property Editing Language Server Feature"
label="BOSH Language Server Feature"
version="4.0.0.qualifier"
provider-name="Pivotal, Inc.">

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Servers
Bundle-Name: BOSH Manifest Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.bosh.ls;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.springframework.tooling.cloudfoundry.manifest.ls.integration.feature"
label="Spring Boot IDE Cloud Foundry Manifest Language Server Integration"
label="Cloud Foundry Manifest Language Server Generic Editor Integration Feature"
version="4.0.0.qualifier"
provider-name="Pivotal, Inc.">

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Server
Bundle-Name: Cloud Foundry Manifest Language Server Generic Editor Integration
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.cloudfoundry.manifest.ls.integration;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Server
Bundle-Name: Cloud Foundry Manifest Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.cloudfoundry.manifest.ls;singleton:=true
Bundle-Version: 0.0.9.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.springframework.tooling.concourse.ls.feature"
label="Spring Boot IDE Property Editing Language Server Feature"
label="Concourse Pipeline Language Server Feature"
version="4.0.0.qualifier"
provider-name="Pivotal, Inc.">

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Servers
Bundle-Name: Concourse Pipeline Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.concourse.ls;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feature
id="org.springframework.tooling.properties.ls.feature"
label="Spring Boot IDE Property Editing Language Server Feature"
label="Spring Boot Property Editing Language Server Feature"
version="4.0.0.qualifier"
provider-name="Pivotal, Inc.">

View File

@@ -1,6 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Servers
Bundle-Name: Spring Boot Properties Language Server
Bundle-Vendor: Pivotal, Inc.
Bundle-SymbolicName: org.springframework.tooling.properties.ls;singleton:=true
Bundle-Version: 4.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8

View File

@@ -62,6 +62,11 @@
<artifactId>commons-yaml</artifactId>
<version>${dependencies.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ide.vscode</groupId>
<artifactId>commons-boot-app-cli</artifactId>
<version>${dependencies.version}</version>
</dependency>
<!-- Eclipse JDT for parsing (at the moment) -->
<dependency>

View File

@@ -41,6 +41,13 @@ public class BootJavaHoverProvider implements HoverHandler {
private static final String SPRING_VALUE = "org.springframework.beans.factory.annotation.Value";
private static final String SPRING_REQUEST_MAPPING = "org.springframework.web.bind.annotation.RequestMapping";
private static final String SPRING_GET_MAPPING = "org.springframework.web.bind.annotation.GetMapping";
private static final String SPRING_POST_MAPPING = "org.springframework.web.bind.annotation.PostMapping";
private static final String SPRING_PUT_MAPPING = "org.springframework.web.bind.annotation.PutMapping";
private static final String SPRING_DELETE_MAPPING = "org.springframework.web.bind.annotation.DeleteMapping";
private static final String SPRING_PATCH_MAPPING = "org.springframework.web.bind.annotation.PatchMapping";
private JavaProjectFinder projectFinder;
private SimpleLanguageServer server;
@@ -123,6 +130,13 @@ public class BootJavaHoverProvider implements HoverHandler {
private CompletableFuture<Hover> provideHoverForSpringAnnotation(ASTNode node, Annotation annotation, ITypeBinding type, int offset, TextDocument doc) {
if (type.getQualifiedName().equals(SPRING_VALUE)) {
return new ValueHoverProvider().provideHoverForValueAnnotation(node, annotation, type, offset, doc);
} else if (type.getQualifiedName().equals(SPRING_REQUEST_MAPPING)
|| type.getQualifiedName().equals(SPRING_GET_MAPPING)
|| type.getQualifiedName().equals(SPRING_POST_MAPPING)
|| type.getQualifiedName().equals(SPRING_PUT_MAPPING)
|| type.getQualifiedName().equals(SPRING_DELETE_MAPPING)
|| type.getQualifiedName().equals(SPRING_PATCH_MAPPING)) {
return new RequestMappingHoverProvider().provideHoverForRequestMappingAnnotation(node, annotation, type, offset, doc);
}
return null;

View File

@@ -0,0 +1,136 @@
/*******************************************************************************
* Copyright (c) 2017 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.ide.vscode.boot.java.hover;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.Expression;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MemberValuePair;
import org.eclipse.jdt.core.dom.NormalAnnotation;
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.StringLiteral;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.json.JSONObject;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
* @author Martin Lippert
*/
public class RequestMappingHoverProvider {
public CompletableFuture<Hover> provideHoverForRequestMappingAnnotation(ASTNode node, Annotation annotation,
ITypeBinding type, int offset, TextDocument doc) {
return provideHover(annotation, doc);
}
private CompletableFuture<Hover> provideHover(Annotation annotation, TextDocument doc) {
try {
JSONObject[] mappings = getRequestMappingsFromProcesses();
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
for (int i = 0; i < mappings.length; i++) {
addHoverContent(mappings[i], hoverContent, annotation);
}
Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength());
Hover hover = new Hover();
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void addHoverContent(JSONObject jsonObject, List<Either<String, MarkedString>> hoverContent, Annotation annotation) {
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String key = keys.next();
if (doesMatch(annotation, key)) {
hoverContent.add(Either.forLeft(key));
hoverContent.add(Either.forLeft(jsonObject.get(key).toString()));
}
}
}
private boolean doesMatch(Annotation annotation, String key) {
String mappingPath = null;
if (annotation instanceof SingleMemberAnnotation) {
Expression valueContent = ((SingleMemberAnnotation) annotation).getValue();
if (valueContent instanceof StringLiteral) {
mappingPath = ((StringLiteral)valueContent).getLiteralValue();
}
}
else if (annotation instanceof NormalAnnotation) {
List<?> values = ((NormalAnnotation) annotation).values();
for (Object value : values) {
if (value instanceof MemberValuePair) {
String name = ((MemberValuePair)value).getName().toString();
if (name != null && name.equals("value")) {
Expression valueContent = ((MemberValuePair)value).getValue();
if (valueContent instanceof StringLiteral) {
mappingPath = ((StringLiteral)valueContent).getLiteralValue();
}
}
}
}
}
return mappingPath != null ? key.contains(mappingPath) : false;
}
public JSONObject[] getRequestMappingsFromProcesses() {
List<JSONObject> result = new ArrayList<>();
try {
Map<String, SpringBootApp> apps = SpringBootApp.getAllRunningJavaApps();
Iterator<SpringBootApp> appsIter = apps.values().iterator();
while (appsIter.hasNext()) {
SpringBootApp app = appsIter.next();
if (app.isSpringBootApp()) {
String mappings = app.getRequestMappings();
if (mappings != null) {
JSONObject requestMappings = new JSONObject(mappings);
if (requestMappings != null) {
result.add(requestMappings);
}
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return result.toArray(new JSONObject[result.size()]);
}
}

View File

@@ -10,15 +10,12 @@
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.hover;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import org.apache.commons.io.IOUtils;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Annotation;
import org.eclipse.jdt.core.dom.ITypeBinding;
@@ -29,7 +26,7 @@ import org.eclipse.lsp4j.MarkedString;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.json.JSONObject;
import org.json.JSONTokener;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.util.text.TextDocument;
/**
@@ -69,32 +66,37 @@ public class ValueHoverProvider {
if (range != null) {
String propertyKey = value.substring(range.getStart(), range.getEnd());
JSONObject properties = getPropertiesFromProcess();
if (propertyKey != null && properties != null) {
Iterator<?> keys = properties.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
JSONObject props = properties.getJSONObject(key);
if (propertyKey != null) {
JSONObject[] allProperties = getPropertiesFromProcesses();
if (props.has(propertyKey)) {
String propertyValue = props.getString(propertyKey);
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
Range hoverRange = doc.toRange(nodeStartOffset + range.getStart(), range.getEnd() - range.getStart());
for (int i = 0; i < allProperties.length; i++) {
Iterator<?> keys = allProperties[i].keys();
while (keys.hasNext()) {
String key = (String) keys.next();
if (allProperties[i].get(key) instanceof JSONObject) {
JSONObject props = allProperties[i].getJSONObject(key);
Hover hover = new Hover();
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
if (props.has(propertyKey)) {
String propertyValue = props.getString(propertyKey);
hoverContent.add(Either.forLeft("property value for " + propertyKey));
hoverContent.add(Either.forLeft(propertyValue));
hoverContent.add(Either.forLeft("coming from:"));
hoverContent.add(Either.forLeft(key));
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
hoverContent.add(Either.forLeft("property value for " + propertyKey));
hoverContent.add(Either.forLeft(propertyValue));
hoverContent.add(Either.forLeft("coming from:"));
hoverContent.add(Either.forLeft(key));
}
}
}
}
Range hoverRange = doc.toRange(nodeStartOffset + range.getStart(), range.getEnd() - range.getStart());
Hover hover = new Hover();
hover.setContents(hoverContent);
hover.setRange(hoverRange);
return CompletableFuture.completedFuture(hover);
}
}
}
@@ -105,26 +107,30 @@ public class ValueHoverProvider {
return null;
}
public JSONObject getPropertiesFromProcess() {
public JSONObject[] getPropertiesFromProcesses() {
List<JSONObject> result = new ArrayList<>();
try {
URL url = new URL("http://localhost:8080/env");
URLConnection con = url.openConnection();
InputStream in = con.getInputStream();
String encoding = con.getContentEncoding();
encoding = encoding == null ? "UTF-8" : encoding;
String body = IOUtils.toString(in, encoding);
JSONTokener tokener = new JSONTokener(body);
JSONObject jsonData = new JSONObject(tokener);
return jsonData;
Map<String, SpringBootApp> apps = SpringBootApp.getAllRunningJavaApps();
Iterator<SpringBootApp> appsIter = apps.values().iterator();
while (appsIter.hasNext()) {
SpringBootApp app = appsIter.next();
if (app.isSpringBootApp()) {
String environment = app.getEnvironment();
if (environment != null) {
JSONObject env = new JSONObject(environment);
if (env != null) {
result.add(env);
}
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
return result.toArray(new JSONObject[result.size()]);
}
public String getPropertyKey(String value, int offset) {