Refactoring: introduce abstract 'SpringBootApp'

In preparation for supporting both local and
remote SpringBootApp as sources for live
information via jmx connection.
This commit is contained in:
Kris De Volder
2018-07-10 11:29:23 -07:00
parent 1383fff41d
commit e1c0953f4f
12 changed files with 670 additions and 600 deletions

View File

@@ -28,6 +28,7 @@ import org.eclipse.lsp4j.jsonrpc.messages.Either;
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
import org.springframework.ide.vscode.boot.java.livehover.LiveHoverUtils;
import org.springframework.ide.vscode.commons.boot.app.cli.LiveConditional;
import org.springframework.ide.vscode.commons.boot.app.cli.LocalSpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.java.IJavaProject;
import org.springframework.ide.vscode.commons.util.Log;

View File

@@ -12,13 +12,16 @@ package org.springframework.ide.vscode.boot.java.handlers;
import java.util.Collection;
import org.springframework.ide.vscode.commons.boot.app.cli.LocalSpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import com.google.common.collect.ImmutableList;
public interface RunningAppProvider {
public static final RunningAppProvider DEFAULT = SpringBootApp::getAllRunningSpringApps;
public static final RunningAppProvider LOCAL_APPS = LocalSpringBootApp::getAllRunningSpringApps;
public static final RunningAppProvider DEFAULT = LocalSpringBootApp::getAllRunningSpringApps;
public static final RunningAppProvider NULL = () -> ImmutableList.of();
Collection<SpringBootApp> getAllRunningSpringApps() throws Exception;

View File

@@ -36,9 +36,9 @@ import org.springframework.ide.vscode.commons.util.text.TextDocument;
import com.google.common.collect.ImmutableList;
public abstract class AbstractInjectedIntoHoverProvider implements HoverProvider {
protected BootJavaLanguageServerComponents server;
public AbstractInjectedIntoHoverProvider(BootJavaLanguageServerComponents server) {
this.server = server;
}

View File

@@ -57,13 +57,13 @@ public class ActiveProfilesProvider implements HoverProvider {
for (SpringBootApp app : runningApps) {
List<String> profiles = app.getActiveProfiles();
if (profiles==null) {
markdown.append(niceAppName(app)+" : _Unknown_\n\n");
markdown.append(LiveHoverUtils.niceAppName(app)+" : _Unknown_\n\n");
} else {
hasInterestingApp = true;
if (profiles.isEmpty()) {
markdown.append(niceAppName(app)+" : _None_\n\n");
markdown.append(LiveHoverUtils.niceAppName(app)+" : _None_\n\n");
} else {
markdown.append(niceAppName(app)+" :\n");
markdown.append(LiveHoverUtils.niceAppName(app)+" :\n");
for (String profile : profiles) {
markdown.append("- "+profile+"\n");
}
@@ -80,10 +80,6 @@ public class ActiveProfilesProvider implements HoverProvider {
return null;
}
private String niceAppName(SpringBootApp app) {
return "Process [PID="+app.getProcessID()+", name=`"+app.getProcessName()+"`]";
}
@Override
public Collection<Range> getLiveHoverHints(Annotation annotation, TextDocument doc, SpringBootApp[] runningApps) {
if (runningApps.length > 0) {

View File

@@ -26,7 +26,7 @@ import org.springframework.ide.vscode.commons.util.Renderables;
import org.springframework.ide.vscode.commons.util.StringUtil;
public class LiveHoverUtils {
public static String showBean(LiveBean bean) {
StringBuilder buf = new StringBuilder("Bean [id: " + bean.getId());
String type = bean.getType(true);
@@ -69,14 +69,6 @@ public class LiveHoverUtils {
return new SpringResource(sourceLinks, resource, project).toMarkdown();
}
public static String niceAppName(SpringBootApp app) {
return niceAppName(app.getProcessID() ,app.getProcessName());
}
public static String niceAppName(String processId, String processName) {
return "Process [PID=" + processId + ", name=`" + processName + "`]";
}
public static boolean hasRelevantBeans(SpringBootApp app, LiveBean definedBean) {
return findRelevantBeans(app, definedBean).findAny().isPresent();
}
@@ -94,4 +86,13 @@ public class LiveHoverUtils {
return Stream.empty();
}
public static String niceAppName(SpringBootApp app) {
return niceAppName(app.getProcessID(), app.getProcessName());
}
public static String niceAppName(String processId, String processName) {
return "Process [PID="+processId+", name=`"+processName+"`]";
}
}

View File

@@ -12,6 +12,7 @@ package org.springframework.ide.vscode.boot.java.requestmapping;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
@@ -22,6 +23,7 @@ import org.eclipse.lsp4j.SymbolInformation;
import org.eclipse.lsp4j.SymbolKind;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
import org.springframework.ide.vscode.commons.util.Log;
/**

View File

@@ -18,6 +18,7 @@ import java.util.Collection;
import org.mockito.Mockito;
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
import org.springframework.ide.vscode.commons.boot.app.cli.LocalSpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
@@ -106,13 +107,13 @@ public class MockRunningAppProvider {
}
public MockAppBuilder requestMappings(String mappings) throws Exception {
Collection<RequestMapping> requestMappings = SpringBootApp.parseRequestMappingsJson(mappings, "1.x");
Collection<RequestMapping> requestMappings = LocalSpringBootApp.parseRequestMappingsJson(mappings, "1.x");
when(app.getRequestMappings()).thenReturn(requestMappings);
return this;
}
public MockAppBuilder liveConditionalsJson(String rawJson) throws Exception{
when(app.getLiveConditionals()).thenReturn(SpringBootApp.getLiveConditionals(rawJson, processId, processName));
when(app.getLiveConditionals()).thenReturn(LocalSpringBootApp.getLiveConditionals(rawJson, processId, processName));
return this;
}