From cd73747a0e200c37f0bf7b1f734baa4296f7a7f1 Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Oct 2017 15:13:16 -0700 Subject: [PATCH 1/2] Multiple running app support for conditional live hovers --- .../ConditionalsLiveHoverProvider.java | 38 +++++++++--- .../test/ConditionalsLiveHoverTest.java | 60 +++++++++++++++++++ 2 files changed, 89 insertions(+), 9 deletions(-) diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalsLiveHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalsLiveHoverProvider.java index 83a256ba8..a5a1b1c45 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalsLiveHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/conditionals/ConditionalsLiveHoverProvider.java @@ -96,9 +96,20 @@ public class ConditionalsLiveHoverProvider implements HoverProvider { private void addHoverContent(List conditions, List> 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> parse(Annotation annotation, SpringBootApp[] runningApps) { try { + List allConditionals = new ArrayList<>(); for (SpringBootApp app : runningApps) { String autoConfigRecord = app.getAutoConfigReport(); if (autoConfigRecord != null) { JSONObject autoConfigJson = new JSONObject(autoConfigRecord); - List conditionalsFromPositiveMatches = getConditionals(annotation, autoConfigJson); - if(!conditionalsFromPositiveMatches.isEmpty()) { - return Optional.of(conditionalsFromPositiveMatches); + List 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 getConditionals(Annotation annotation, + private List getConditionals(SpringBootApp app, Annotation annotation, JSONObject autoConfigJson) { List 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 getMatchedCondition(JSONObject conditionJson, Annotation annotation) { + protected Optional 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; } } } diff --git a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/conditionals/test/ConditionalsLiveHoverTest.java b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/conditionals/test/ConditionalsLiveHoverTest.java index 5eaa0c273..cb887f67c 100644 --- a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/conditionals/test/ConditionalsLiveHoverTest.java +++ b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/conditionals/test/ConditionalsLiveHoverTest.java @@ -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 { // From 462e1d71b6ce2094f5d828560b172462c58e217f Mon Sep 17 00:00:00 2001 From: nsingh Date: Wed, 25 Oct 2017 16:33:09 -0700 Subject: [PATCH 2/2] Show full URL in request mapping live hover --- .../requestmapping/RequestMappingHoverProvider.java | 3 +-- .../test/RequestMappingLiveHoverTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java index bd092c22a..76af42453 100644 --- a/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java +++ b/headless-services/boot-java-language-server/src/main/java/org/springframework/ide/vscode/boot/java/requestmapping/RequestMappingHoverProvider.java @@ -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); diff --git a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/RequestMappingLiveHoverTest.java b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/RequestMappingLiveHoverTest.java index c5012cf58..0ad9bd216 100644 --- a/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/RequestMappingLiveHoverTest.java +++ b/headless-services/boot-java-language-server/src/test/java/org/springframework/ide/vscode/boot/java/requestmapping/test/RequestMappingLiveHoverTest.java @@ -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" +