Skip to content

Commit

Permalink
[test] Provided dependencies from imported BOM are not correctly calc…
Browse files Browse the repository at this point in the history
…ulated on hover #347
  • Loading branch information
vrubezhny committed Feb 1, 2023
1 parent fd345f3 commit dd3fe65
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ public static PluginDescriptor getContainingPluginDescriptor(DOMNode node,

PluginDescriptor pluginDescriptor = null;
try {
// Fix plugin version in case its value is 'null', to initiate search for an actual version
if (plugin.getVersion() == null) {
plugin.setVersion("0.0.1-SNAPSHOT");
}

pluginDescriptor = lemminxMavenPlugin.getMavenPluginManager().getPluginDescriptor(plugin,
project.getRemotePluginRepositories().stream().collect(Collectors.toList()),
lemminxMavenPlugin.getMavenSession().getRepositorySession());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public static Dependency resolveDependency (MavenProject project, Dependency dep
} catch (PluginResolutionException | PluginDescriptorParsingException
| InvalidPluginDescriptorException e) {
// Ignore
} catch (Exception e) {
LOGGER.log(Level.SEVERE, e.getMessage(), e);
}
} else if (isDependency(element)) {
if (dependency.getGroupId() == null || dependency.getVersion() == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019-2022 Red Hat Inc. and others.
* Copyright (c) 2019-2023 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand Down Expand Up @@ -32,6 +32,7 @@
import org.eclipse.lsp4j.Diagnostic;
import org.eclipse.lsp4j.DiagnosticSeverity;
import org.eclipse.lsp4j.HoverCapabilities;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
Expand Down Expand Up @@ -225,6 +226,16 @@ public void testPluginArtifactHover() throws IOException, InterruptedException,
new Position(14, 18), new SharedSettings()).getContents().getRight().getValue().contains("Maven Surefire MOJO in maven-surefire-plugin"));
}

// Definition related tests

@Test
public void testPluginArtifactDefinition() throws IOException, InterruptedException, ExecutionException, URISyntaxException, TimeoutException {
// Find Definition links
List<? extends LocationLink> definitions = languageService.findDefinition(createDOMDocument("/pom-plugin-artifact-hover.xml", languageService), new Position(14, 18), ()->{});
definitions.stream().map(LocationLink::getTargetUri).forEach(u -> System.out.println("Definition Link: " + u));
assertTrue(definitions.stream().map(LocationLink::getTargetUri).anyMatch(uri -> uri.endsWith(".pom") && uri.contains("maven-surefire-plugin")));
}

// Diagnostic related tests

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat Inc. and others.
* Copyright (c) 2022, 2023 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -16,6 +16,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ExecutionException;

import org.eclipse.lemminx.dom.DOMDocument;
Expand All @@ -24,6 +25,7 @@
import org.eclipse.lemminx.settings.SharedSettings;
import org.eclipse.lsp4j.Hover;
import org.eclipse.lsp4j.HoverCapabilities;
import org.eclipse.lsp4j.LocationLink;
import org.eclipse.lsp4j.MarkupKind;
import org.eclipse.lsp4j.Position;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -117,6 +119,34 @@ void testManagedVersionHoverInDependencyGrandchild() throws IOException, URISynt
assertTrue(value.contains("hierarchy2/pom.xml"));
}

@Test
@Timeout(90000)
void testManagedVersionHoverForBomProvidedDependency() throws IOException, URISyntaxException {
System.out.println(">>> testManagedVersionHoverForBomProvidedDependency");
DOMDocument document = createDOMDocument("/pom-bom-defined-dependency-version.xml", languageService);
Position position = new Position(25, 20);

// Find Definition links
List<? extends LocationLink> definitions = languageService.findDefinition(document, position, ()->{});
definitions.stream().map(LocationLink::getTargetUri).forEach(u -> System.out.println("Definition Link: " + u));
assertTrue(definitions.stream().map(LocationLink::getTargetUri).anyMatch(uri -> uri.endsWith("jakarta.jakartaee-api-8.0.0.pom")));

// Find Hover with managed version
Hover hover = languageService.doHover(document, position, createSharedSettings());
final String value = hover.getContents().getRight().getValue();
System.out.println("Hover Text: [" + value + "]");
assertNotNull(value);
assertTrue(value.contains("The managed version is"));
assertTrue(value.contains("8.0.0"));
assertTrue(value.contains("The artifact is managed in"));
assertTrue(value.contains("jakarta.platform:jakarta.jakartaee-api:8.0.0"));

// 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");
}

// Enable MARKDOWN format
private static SharedSettings createSharedSettings() {
HoverCapabilities hoverCapabilities = new HoverCapabilities();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.org.eclipse.lemminx.lemminx-maven.test</groupId>
<artifactId>bom.defined.version.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<!-- Payara version -->
<payara-version>5.2022.3</payara-version>
</properties>
<dependencyManagement>
<dependencies>
<!-- All of our provided dependencies actually come from the application server, this solves it all -->
<dependency>
<groupId>fish.payara.api</groupId>
<artifactId>payara-bom</artifactId>
<version>${payara-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- Platform dependencies -->
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,29 @@
<artifactId>target-platform-configuration</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<!--
Do not remove '.' (dot)-character in <groupId/> element -
this hack allows to make maven to download and save to local repository
two different versions of the same artifact
-->
<groupId>jakarta.platform.</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>10.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>fish.payara.api</groupId>
<artifactId>payara-bom</artifactId>
<version>5.2022.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</project>

0 comments on commit dd3fe65

Please sign in to comment.