Some steps towards mergin boot-java and boot-properties LS

- Refactor towards more composable LanguageServers
- disable fatjar support on boot-java and boot-properties
This commit is contained in:
Kris De Volder
2018-02-09 09:49:21 -08:00
parent 6f03e83e59
commit 5c19bdefe6
37 changed files with 137 additions and 139 deletions

View File

@@ -10,11 +10,13 @@
<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">

View File

@@ -101,7 +101,7 @@
<target>1.8</target>
</configuration>
</plugin>
<!-- Configure fat jar -->
<!-- Configure fat jar
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
@@ -111,9 +111,12 @@
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<finalName>${project.build.finalName}-fat</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugin> -->
<!-- Ignore test classes from test projects -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@@ -117,7 +117,7 @@ public abstract class CachingValueProvider implements ValueProviderStrategy {
// Log.log(e);
}
if (cached!=null) {
System.out.println("cached "+subquery+": "+cached);
// debug("cached "+subquery+": "+cached);
if (cached.isComplete) {
return cached.values
// .doOnNext((hint) -> debug("filter["+query+"]: "+hint.getValue()))

View File

@@ -28,11 +28,11 @@ import org.springframework.ide.vscode.commons.java.IClasspath;
import org.springframework.ide.vscode.commons.util.Log;
public class PropertiesLoader {
private static final String MAIN_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/spring-configuration-metadata.json";
public static final String ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON = "META-INF/additional-spring-configuration-metadata.json";
/**
* The default classpath location for config metadata loaded when scanning .jar files on the classpath.
*/
@@ -48,15 +48,15 @@ public class PropertiesLoader {
MAIN_SPRING_CONFIGURATION_METADATA_JSON,
ADDITIONAL_SPRING_CONFIGURATION_METADATA_JSON
};
private static final Logger LOG = Logger.getLogger(PropertiesLoader.class.getName());
private ConfigurationMetadataRepositoryJsonBuilder builder = ConfigurationMetadataRepositoryJsonBuilder.create();
public ConfigurationMetadataRepository load(IClasspath classPath) {
try {
classPath.getClasspathEntries().forEach(entry -> {
Log.info("Indexing "+entry);
//Log.info("Indexing "+entry);
File fileEntry = entry.toFile();
if (fileEntry.exists()) {
if (fileEntry.isDirectory()) {
@@ -72,7 +72,7 @@ public class PropertiesLoader {
ConfigurationMetadataRepository repository = builder.build();
return repository;
}
private void loadFromOutputFolder(Path outputFolderPath) {
if (outputFolderPath != null && Files.exists(outputFolderPath)) {
Arrays.stream(PROJECT_META_DATA_LOCATIONS).forEach(mdLoc -> {
@@ -100,7 +100,7 @@ public class PropertiesLoader {
}
}
}
private void loadFromJar(Path f) {
JarFile jarFile = null;
try {
@@ -145,5 +145,5 @@ public class PropertiesLoader {
private void loadFromInputStream(Object origin, InputStream is) throws IOException {
builder.withJsonResource(origin, is);
}
}

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot;
package org.springframework.ide.vscode.boot.properties;
import org.springframework.ide.vscode.boot.common.PropertyCompletionFactory;
import org.springframework.ide.vscode.boot.common.RelaxedNameConfig;
@@ -30,6 +30,7 @@ import org.springframework.ide.vscode.commons.languageserver.java.ProjectObserve
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
import org.springframework.ide.vscode.commons.languageserver.util.LSFactory;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServerWrapper;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
import org.springframework.ide.vscode.commons.util.FuzzyMap;
import org.springframework.ide.vscode.commons.util.text.IDocument;
@@ -53,7 +54,7 @@ import com.google.common.collect.ImmutableList;
* @author Alex Boyko
*
*/
public class BootPropertiesLanguageServer extends SimpleLanguageServer {
public class BootPropertiesLanguageServer implements SimpleLanguageServerWrapper {
private static final String YML = ".yml";
private static final String PROPERTIES = ".properties";
@@ -78,11 +79,11 @@ public class BootPropertiesLanguageServer extends SimpleLanguageServer {
private final YamlASTProvider parser = new YamlParser(yaml);
private final YamlStructureProvider yamlStructureProvider= YamlStructureProvider.DEFAULT;
private YamlAssistContextProvider yamlAssistContextProvider;
private final SimpleLanguageServer server;
public BootPropertiesLanguageServer(LSFactory<BootPropertiesLanguageServerParams> _params) {
super("vscode-boot-properties");
BootPropertiesLanguageServerParams serverParams = _params.create(this);
this.server = new SimpleLanguageServer("vscode-boot-properties");
BootPropertiesLanguageServerParams serverParams = _params.create(server);
this.indexProvider = serverParams.indexProvider;
this.typeUtilProvider = serverParams.typeUtilProvider;
@@ -99,22 +100,22 @@ public class BootPropertiesLanguageServer extends SimpleLanguageServer {
}
};
SimpleTextDocumentService documents = getTextDocumentService();
SimpleTextDocumentService documents = server.getTextDocumentService();
IReconcileEngine reconcileEngine = getReconcileEngine();
documents.onDidChangeContent(params -> {
TextDocument doc = params.getDocument();
validateWith(doc.getId(), reconcileEngine);
server.validateWith(doc.getId(), reconcileEngine);
});
ICompletionEngine propertiesCompletionEngine = getCompletionEngine();
completionEngine = createCompletionEngineAdapter(this, propertiesCompletionEngine);
completionEngine = server.createCompletionEngineAdapter(server, propertiesCompletionEngine);
completionEngine.setMaxCompletions(100);
documents.onCompletion(completionEngine::getCompletions);
documents.onCompletionResolve(completionEngine::resolveCompletion);
HoverInfoProvider hoverInfoProvider = getHoverProvider();
hoverEngine = new VscodeHoverEngineAdapter(this, hoverInfoProvider);
hoverEngine = new VscodeHoverEngineAdapter(server, hoverInfoProvider);
documents.onHover(hoverEngine::getHover);
}
@@ -187,4 +188,9 @@ public class BootPropertiesLanguageServer extends SimpleLanguageServer {
public SpringPropertyIndexProvider getPropertiesIndexProvider() {
return indexProvider;
}
@Override
public SimpleLanguageServer getServer() {
return this.server;
}
}

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot;
package org.springframework.ide.vscode.boot.properties;
import java.nio.file.Paths;
import java.util.Arrays;

View File

@@ -8,7 +8,7 @@
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot;
package org.springframework.ide.vscode.boot.properties;
import java.io.IOException;
@@ -17,18 +17,19 @@ import org.springframework.ide.vscode.commons.util.LogRedirect;
/**
* Starts up Language Server process
*
*
* @author Alex Boyko
* @author Kris De Volder
*
*/
public class Main {
public static void main(String[] args) throws IOException, InterruptedException {
String serverName = "boot-properties-language-server";
LogRedirect.redirectToFile(serverName);
LaunguageServerApp.start(serverName,
() -> new BootPropertiesLanguageServer(BootPropertiesLanguageServerParams.createDefault()));
() -> new BootPropertiesLanguageServer(BootPropertiesLanguageServerParams.createDefault()).getServer()
);
}
}

View File

@@ -24,12 +24,12 @@ import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.Diagnostic;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest;
import org.springframework.ide.vscode.boot.editor.harness.StyledStringMatcher;
import org.springframework.ide.vscode.boot.metadata.CachingValueProvider;
import org.springframework.ide.vscode.boot.metadata.PropertiesLoader;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.java.IType;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
@@ -1590,7 +1590,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
s -> new BootPropertiesLanguageServerParams(javaProjectFinder, null, md.getIndexProvider(),
typeUtilProvider));
server.setMaxCompletionsNumber(-1);
return server;
return server.getServer();
}
/**

View File

@@ -20,12 +20,12 @@ import org.eclipse.lsp4j.CompletionItem;
import org.eclipse.lsp4j.Diagnostic;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.boot.editor.harness.AbstractPropsEditorTest;
import org.springframework.ide.vscode.boot.editor.harness.StyledStringMatcher;
import org.springframework.ide.vscode.boot.metadata.CachingValueProvider;
import org.springframework.ide.vscode.boot.metadata.PropertyInfo;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.commons.util.StringUtil;
@@ -3710,7 +3710,7 @@ public class ApplicationYamlEditorTest extends AbstractPropsEditorTest {
s -> new BootPropertiesLanguageServerParams(javaProjectFinder, null, md.getIndexProvider(),
typeUtilProvider));
server.setMaxCompletionsNumber(-1);
return server;
return server.getServer();
}
@Override

View File

@@ -1,63 +0,0 @@
/*******************************************************************************
* Copyright (c) 2016 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.test;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.concurrent.Callable;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.TextDocumentSyncKind;
import org.junit.Test;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
import org.springframework.ide.vscode.languageserver.testharness.LanguageServerHarness;
/**
* Boot app properties file language server tests
*
* @author Alex Boyko
*
*/
public class BootPropertiesLanguageServerTest {
public static File getTestResource(String name) throws URISyntaxException {
return Paths.get(BootPropertiesLanguageServer.class.getResource(name).toURI()).toFile();
}
private LanguageServerHarness newHarness() throws Exception {
Callable<? extends SimpleLanguageServer> f = () -> new BootPropertiesLanguageServer(BootPropertiesLanguageServerParams.createTestDefault());
return new LanguageServerHarness(f);
}
@Test
public void createAndInitializeServerWithWorkspace() throws Exception {
LanguageServerHarness harness = newHarness();
File workspaceRoot = getTestResource("/workspace/");
assertExpectedInitResult(harness.intialize(workspaceRoot));
}
@Test
public void createAndInitializeServerWithoutWorkspace() throws Exception {
File workspaceRoot = null;
LanguageServerHarness harness = newHarness();
assertExpectedInitResult(harness.intialize(workspaceRoot));
}
private void assertExpectedInitResult(InitializeResult initResult) {
assertThat(initResult.getCapabilities().getTextDocumentSync().getLeft()).isEqualTo(TextDocumentSyncKind.Incremental);
}
}

View File

@@ -20,9 +20,9 @@ import java.io.File;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.boot.metadata.DefaultSpringPropertyIndexProvider;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServer;
import org.springframework.ide.vscode.boot.properties.BootPropertiesLanguageServerParams;
import org.springframework.ide.vscode.commons.languageserver.ProgressService;
import org.springframework.ide.vscode.commons.maven.MavenCore;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
@@ -32,12 +32,12 @@ import org.springframework.ide.vscode.project.harness.ProjectsHarness;
/**
* Tests for Boot properties index
*
*
* @author Alex Boyko
*
*/
public class SpringPropertiesIndexTest {
private LanguageServerHarness<BootPropertiesLanguageServer> harness;
private DefaultSpringPropertyIndexProvider propertyIndexProvider;
@@ -50,7 +50,7 @@ public class SpringPropertiesIndexTest {
@Test
public void testPropertiesIndexRefreshOnProjectChange() throws Exception {
harness.intialize(new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI()));
propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServer().getPropertiesIndexProvider();
propertyIndexProvider = (DefaultSpringPropertyIndexProvider) harness.getServerWrapper().getPropertiesIndexProvider();
File directory = new File(ProjectsHarness.class.getResource("/test-projects/boot-1.2.0-properties-live-metadta/").toURI());