Skip to content

Commit

Permalink
Managed scope of a dependency not displayed in mouse hover popup ecli…
Browse files Browse the repository at this point in the history
  • Loading branch information
vrubezhny committed Mar 9, 2023
1 parent 1140dc5 commit deca577
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ yield hoverForProject(request,
private static final String PomTextHover_managed_location = "The artifact is managed in {0}";
private static final String PomTextHover_managed_location_missing = "The managed definition location could not be determined, probably defined by \"import\" scoped dependencies.";
private static final String PomTextHover_property_location = "The property is defined in {0}";
private static final String PomTextHover_managed_scope = "The managed scope is: \"{0}\"";

private static String getActualVersionText(boolean supportsMarkdown, MavenProject project) {
if (project == null) {
Expand Down Expand Up @@ -252,12 +253,9 @@ private static String createVersionMessage(boolean supportsMarkdown, String vers
private static String createVersionMessage(boolean supportsMarkdown, String version, String sourceModelId, String uri) {
UnaryOperator<String> toBold = supportsMarkdown ? MarkdownUtils::toBold : UnaryOperator.identity();

String message = null;
if (version != null) {
message = toBold.apply(MessageFormat.format(PomTextHover_managed_version, version));
} else {
message = toBold.apply(PomTextHover_managed_version_missing);
}
String message = (version != null)
? toBold.apply(MessageFormat.format(PomTextHover_managed_version, version))
: toBold.apply(PomTextHover_managed_version_missing);

if (sourceModelId != null) {
message += ' ' + toBold.apply(MessageFormat.format(PomTextHover_managed_location,
Expand Down Expand Up @@ -340,6 +338,11 @@ private Hover collectArtifactDescription(IHoverRequest request) {
}
}

// Add dependency scope info
if (dependency.getScope() != null) {
message += lineBreak + toBold.apply(MessageFormat.format(PomTextHover_managed_scope, dependency.getScope()));
}

if (message.length() > 2) {
return new Hover(new MarkupContent(supportsMarkdown ? MarkupKind.MARKDOWN : MarkupKind.PLAINTEXT, message));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ void testManagedVersionHoverInDependencyChild() throws IOException, URISyntaxExc
assertTrue(value.contains("The artifact is managed in"));
assertTrue(value.contains("dependencyManagement:parent:0.0.1-SNAPSHOT"));
assertTrue(value.contains("pom-dependencyManagement-parent.xml"));
assertTrue(value.contains("The managed scope is: \"compile\""));
}

@Test
Expand All @@ -75,6 +76,7 @@ void testManagedVersionHoverInDependencyParent() throws IOException, URISyntaxEx
assertNotNull(value);
assertFalse(value.contains("The managed version is"));
assertFalse(value.contains("The artifact is managed in"));
assertFalse(value.contains("The managed scope is:"));
}

@Test
Expand All @@ -90,6 +92,7 @@ void testManagedVersionHoverInPluginChild() throws IOException, URISyntaxExcepti
assertTrue(value.contains("The artifact is managed in"));
assertTrue(value.contains("pluginManagement:parent:0.0.1-SNAPSHOT"));
assertTrue(value.contains("pom-pluginManagement-parent.xml"));
assertFalse(value.contains("The managed scope is:"));
}

@Test
Expand All @@ -102,6 +105,7 @@ void testManagedVersionHoverInPluginParent() throws IOException, URISyntaxExcept
assertNotNull(value);
assertFalse(value.contains("The managed version is"));
assertFalse(value.contains("The artifact is managed in"));
assertFalse(value.contains("The managed scope is:"));
}

@Test
Expand All @@ -117,6 +121,7 @@ void testManagedVersionHoverInDependencyGrandchild() throws IOException, URISynt
assertTrue(value.contains("The artifact is managed in"));
assertTrue(value.contains("com.zollum.demo:demo:0.0.1-SNAPSHOT"));
assertTrue(value.contains("hierarchy2/pom.xml"));
assertTrue(value.contains("The managed scope is: \"compile\""));
}

@Test
Expand Down Expand Up @@ -145,7 +150,9 @@ void testManagedVersionHoverForBomProvidedDependency() throws IOException, URISy
// Compare the links from definition and hover
assertTrue(definitions.stream().map(LocationLink::getTargetUri)
.anyMatch(uri -> value.replace('\\', '/').contains(uri.substring("file:/".length()))));
System.out.println("<<< testManagedVersionHoverForBomProvidedDependency");

assertTrue(value.contains("The managed scope is: \"provided\""));
System.out.println("<<< testManagedVersionHoverForBomProvidedDependency");
}

@Test
Expand All @@ -170,6 +177,7 @@ void testManagedVersionHoverForBomProvidedDependencyWithProperty() throws IOExce
assertTrue(value.contains("The artifact is managed in"));
assertTrue(value.contains("org.eclipse.test:bom-import-parent:1.0.0"));
assertTrue(value.contains("eclipse-bom-tester/parent/pom.xml"));
assertTrue(value.contains("The managed scope is: \"compile\""));
System.out.println("<<< testManagedVersionHoverForBomProvidedDependencyWithProperty");
}

Expand Down

0 comments on commit deca577

Please sign in to comment.