Merge branch 'master' of github.com:spring-projects/sts4
This commit is contained in:
@@ -96,9 +96,20 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
|
||||
private void addHoverContent(List<RunningAppConditional> conditions,
|
||||
List<Either<String, MarkedString>> hoverContent) throws Exception {
|
||||
for (RunningAppConditional condition : conditions) {
|
||||
for (int i = 0; i < conditions.size(); i++) {
|
||||
RunningAppConditional condition = conditions.get(i);
|
||||
hoverContent.add(Either.forLeft("Condition: " + condition.condition));
|
||||
hoverContent.add(Either.forLeft("Message: " + condition.message));
|
||||
|
||||
// If there is more than one instances show process information
|
||||
if (conditions.size() > 1) {
|
||||
hoverContent.add(Either.forLeft("Process ID: " + condition.app.getProcessID()));
|
||||
hoverContent.add(Either.forLeft("Process Name: " + condition.app.getProcessName()));
|
||||
}
|
||||
|
||||
if (i < conditions.size() - 1) {
|
||||
hoverContent.add(Either.forLeft("---"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,16 +128,21 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
public Optional<List<RunningAppConditional>> parse(Annotation annotation, SpringBootApp[] runningApps) {
|
||||
|
||||
try {
|
||||
List<RunningAppConditional> allConditionals = new ArrayList<>();
|
||||
for (SpringBootApp app : runningApps) {
|
||||
String autoConfigRecord = app.getAutoConfigReport();
|
||||
if (autoConfigRecord != null) {
|
||||
JSONObject autoConfigJson = new JSONObject(autoConfigRecord);
|
||||
List<RunningAppConditional> conditionalsFromPositiveMatches = getConditionals(annotation, autoConfigJson);
|
||||
if(!conditionalsFromPositiveMatches.isEmpty()) {
|
||||
return Optional.of(conditionalsFromPositiveMatches);
|
||||
List<RunningAppConditional> conditionalsFromPositiveMatches = getConditionals(app, annotation,
|
||||
autoConfigJson);
|
||||
if (!conditionalsFromPositiveMatches.isEmpty()) {
|
||||
allConditionals.addAll(conditionalsFromPositiveMatches);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!allConditionals.isEmpty()) {
|
||||
return Optional.of(allConditionals);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.log(e);
|
||||
}
|
||||
@@ -135,12 +151,13 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param app
|
||||
* @param annotation
|
||||
* @param autoConfigJson
|
||||
* @return non-null list of conditionals parsed from an autoconfig report. List
|
||||
* may be empty.
|
||||
*/
|
||||
private List<RunningAppConditional> getConditionals(Annotation annotation,
|
||||
private List<RunningAppConditional> getConditionals(SpringBootApp app, Annotation annotation,
|
||||
JSONObject autoConfigJson) {
|
||||
List<RunningAppConditional> conditions = new ArrayList<>();
|
||||
|
||||
@@ -152,7 +169,7 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
JSONArray matchList = (JSONArray) positiveMatches.get(positiveMatchKey);
|
||||
matchList.forEach((match) -> {
|
||||
if (match instanceof JSONObject) {
|
||||
getMatchedCondition((JSONObject) match, annotation)
|
||||
getMatchedCondition(app, (JSONObject) match, annotation)
|
||||
.ifPresent((condition) -> conditions.add(condition));
|
||||
}
|
||||
});
|
||||
@@ -203,13 +220,14 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Optional<RunningAppConditional> getMatchedCondition(JSONObject conditionJson, Annotation annotation) {
|
||||
protected Optional<RunningAppConditional> getMatchedCondition(SpringBootApp app, JSONObject conditionJson,
|
||||
Annotation annotation) {
|
||||
if (conditionJson != null) {
|
||||
String condition = (String) conditionJson.get("condition");
|
||||
String message = (String) conditionJson.get("message");
|
||||
String annotationName = annotation.resolveTypeBinding().getName();
|
||||
if (message.contains(annotationName)) {
|
||||
return Optional.of(new RunningAppConditional(condition, message));
|
||||
return Optional.of(new RunningAppConditional(app, condition, message));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
@@ -220,10 +238,12 @@ public class ConditionalsLiveHoverProvider implements HoverProvider {
|
||||
|
||||
public final String condition;
|
||||
public final String message;
|
||||
public final SpringBootApp app;
|
||||
|
||||
public RunningAppConditional(String condition, String message) {
|
||||
public RunningAppConditional(SpringBootApp app, String condition, String message) {
|
||||
this.condition = condition;
|
||||
this.message = message;
|
||||
this.app = app;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,9 +160,8 @@ public class RequestMappingHoverProvider implements HoverProvider {
|
||||
String host = method.app.getHost();
|
||||
String url = UrlUtil.createUrl(host, port, path);
|
||||
|
||||
builder.append("Path: ");
|
||||
builder.append("[");
|
||||
builder.append(path);
|
||||
builder.append(url);
|
||||
builder.append("]");
|
||||
builder.append("(");
|
||||
builder.append(url);
|
||||
|
||||
@@ -136,6 +136,66 @@ public class ConditionalsLiveHoverTest {
|
||||
+ "Message: @ConditionalOnExpression (#{true}) resulted in true");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testMultipleAppsLiveHover() throws Exception {
|
||||
|
||||
File directory = new File(
|
||||
ProjectsHarness.class.getResource("/test-projects/test-conditionals-live-hover/").toURI());
|
||||
String docUri = "file://" + directory.getAbsolutePath()
|
||||
+ "/src/main/java/example/ConditionalOnMissingBeanConfig.java";
|
||||
|
||||
// Build a mock running boot app
|
||||
mockAppProvider.builder().isSpringBootApp(true).port("1000").processId("70000").host("cfapps.io")
|
||||
.processName("test-conditionals-live-hover")
|
||||
.getAutoConfigReport(
|
||||
"{\"positiveMatches\":{\"ConditionalOnMissingBeanConfig#missing\":[{\"condition\":\"OnBeanCondition\",\"message\":\"@ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\"}]}}")
|
||||
.build();
|
||||
|
||||
mockAppProvider.builder().isSpringBootApp(true).port("1001").processId("80000").host("cfapps.io")
|
||||
.processName("test-conditionals-live-hover")
|
||||
.getAutoConfigReport(
|
||||
"{\"positiveMatches\":{\"ConditionalOnMissingBeanConfig#missing\":[{\"condition\":\"OnBeanCondition\",\"message\":\"@ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\"}]}}")
|
||||
.build();
|
||||
|
||||
mockAppProvider.builder().isSpringBootApp(true).port("1002").processId("90000").host("cfapps.io")
|
||||
.processName("test-conditionals-live-hover")
|
||||
.getAutoConfigReport(
|
||||
"{\"positiveMatches\":{\"ConditionalOnMissingBeanConfig#missing\":[{\"condition\":\"OnBeanCondition\",\"message\":\"@ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\"}]}}")
|
||||
.build();
|
||||
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
|
||||
|
||||
editor.assertHoverContains("@ConditionalOnMissingBean", "Condition: OnBeanCondition\n" + "\n"
|
||||
+ "Message: @ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\n" +
|
||||
"\n" +
|
||||
"Process ID: 70000\n" +
|
||||
"\n" +
|
||||
"Process Name: test-conditionals-live-hover\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"Condition: OnBeanCondition\n" + "\n"
|
||||
+ "Message: @ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\n" +
|
||||
"\n" +
|
||||
"Process ID: 80000\n" +
|
||||
"\n" +
|
||||
"Process Name: test-conditionals-live-hover\n" +
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"Condition: OnBeanCondition\n" + "\n"
|
||||
+ "Message: @ConditionalOnMissingBean (types: example.Hello; SearchStrategy: all) did not find any beans\n" +
|
||||
"\n" +
|
||||
"Process ID: 90000\n" +
|
||||
"\n" +
|
||||
"Process Name: test-conditionals-live-hover");
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void testMultipleLiveHoverHints() throws Exception {
|
||||
//
|
||||
|
||||
@@ -62,7 +62,7 @@ public class RequestMappingLiveHoverTest {
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello-world\")", "Path: [/hello-world](http://cfapps.io:1111/hello-world)\n" +
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello-world\")", "[http://cfapps.io:1111/hello-world](http://cfapps.io:1111/hello-world)\n" +
|
||||
"\n" +
|
||||
"Process ID: 22022\n" +
|
||||
"\n" +
|
||||
@@ -94,13 +94,13 @@ public class RequestMappingLiveHoverTest {
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello\")", "Path: [/hello](http://cfapps.io:999/hello)\n" +
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello\")", "[http://cfapps.io:999/hello](http://cfapps.io:999/hello)\n" +
|
||||
"\n" +
|
||||
"Process ID: 76543\n" +
|
||||
"\n" +
|
||||
"Process Name: test-request-mapping-live-hover");
|
||||
|
||||
editor.assertHoverContains("@RequestMapping(\"/goodbye\")", "Path: [/goodbye](http://cfapps.io:999/goodbye)\n" +
|
||||
editor.assertHoverContains("@RequestMapping(\"/goodbye\")", "[http://cfapps.io:999/goodbye](http://cfapps.io:999/goodbye)\n" +
|
||||
"\n" +
|
||||
"Process ID: 76543\n" +
|
||||
"\n" +
|
||||
@@ -179,7 +179,7 @@ public class RequestMappingLiveHoverTest {
|
||||
harness.intialize(directory);
|
||||
|
||||
Editor editor = harness.newEditorFromFileUri(docUri, LanguageId.JAVA);
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello\")", "Path: [/hello](http://cfapps.io:1000/hello)\n" +
|
||||
editor.assertHoverContains("@RequestMapping(\"/hello\")", "[http://cfapps.io:1000/hello](http://cfapps.io:1000/hello)\n" +
|
||||
"\n" +
|
||||
"Process ID: 70000\n" +
|
||||
"\n" +
|
||||
@@ -187,7 +187,7 @@ public class RequestMappingLiveHoverTest {
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"Path: [/hello](http://cfapps.io:1001/hello)\n" +
|
||||
"[http://cfapps.io:1001/hello](http://cfapps.io:1001/hello)\n" +
|
||||
"\n" +
|
||||
"Process ID: 80000\n" +
|
||||
"\n" +
|
||||
@@ -195,7 +195,7 @@ public class RequestMappingLiveHoverTest {
|
||||
"\n" +
|
||||
"---\n" +
|
||||
"\n" +
|
||||
"Path: [/hello](http://cfapps.io:1002/hello)\n" +
|
||||
"[http://cfapps.io:1002/hello](http://cfapps.io:1002/hello)\n" +
|
||||
"\n" +
|
||||
"Process ID: 90000\n" +
|
||||
"\n" +
|
||||
|
||||
Reference in New Issue
Block a user