From 7a4de6fdd0eb269503554ea4ae4a57edf699ae1d Mon Sep 17 00:00:00 2001 From: Ioannis Canellos Date: Tue, 17 Oct 2023 13:04:44 +0300 Subject: [PATCH] fix: deployer detection in mvn plugin --- .../main/java/io/quarkus/maven/Deployer.java | 20 ++++++- .../java/io/quarkus/maven/DeployerTest.java | 60 +++++++++++++++++++ 2 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java diff --git a/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java b/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java index 6cfd1d8073298..a33f312069b26 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java @@ -1,11 +1,14 @@ package io.quarkus.maven; import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.apache.maven.model.Dependency; import org.apache.maven.project.MavenProject; import io.quarkus.deployment.util.DeploymentUtil; @@ -76,10 +79,23 @@ public static Optional getDeployer(MavenProject project) { * @return A set with the discovered extenions. */ public static Set getProjecDeployer(MavenProject project) { - return project.getDependencies().stream() + return getProjecDeployers(project.getDependencies()); + } + + /** + * Get the deployer extensions found in the project. + * + * @param dependencies the dependencies for extensions + * @return A set with the discovered extenions. + */ + public static Set getProjecDeployers(List dependencies) { + if (dependencies == null) { + return Collections.emptySet(); + } + return dependencies.stream() .filter(d -> QUARKUS_GROUP_ID.equals(d.getGroupId())) .map(d -> strip(d.getArtifactId())) - .filter(n -> Arrays.stream(Deployer.values()).anyMatch(e -> e.equals(n))) + .filter(n -> Arrays.stream(Deployer.values()).anyMatch(e -> e.name().equals(n))) .collect(Collectors.toSet()); } diff --git a/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java b/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java new file mode 100644 index 0000000000000..94e200f95bb3d --- /dev/null +++ b/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java @@ -0,0 +1,60 @@ +package io.quarkus.maven; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; +import java.util.Set; + +import org.apache.maven.model.Dependency; +import org.junit.jupiter.api.Test; + +import io.quarkus.builder.Version; + +public class DeployerTest { + + @Test + void shouldNotFindDeployer() { + Set deployers = Deployer.getProjecDeployers(List.of()); + assertTrue(deployers.isEmpty()); + + deployers = Deployer.getProjecDeployers(List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"))); + assertTrue(deployers.isEmpty()); + } + + @Test + void shouldFindDeployer() { + Set deployers = Deployer.getProjecDeployers( + List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kubernetes"))); + assertEquals(Set.of("kubernetes"), deployers); + + deployers = Deployer.getProjecDeployers( + List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-openshift"))); + assertEquals(Set.of("openshift"), deployers); + + deployers = Deployer.getProjecDeployers( + List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kind"))); + assertEquals(Set.of("kind"), deployers); + + deployers = Deployer.getProjecDeployers( + List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-minikube"))); + assertEquals(Set.of("minikube"), deployers); + } + + @Test + void shouldFindMultipleDeployer() { + Set deployers = Deployer.getProjecDeployers( + List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kubernetes"), + newDependency("quarkus-openshift"))); + assertEquals(Set.of("kubernetes", "openshift"), deployers); + } + + private static Dependency newDependency(String artifactId) { + Dependency dependency = new Dependency(); + dependency.setGroupId("io.quarkus"); + dependency.setArtifactId(artifactId); + dependency.setVersion(Version.getVersion()); + dependency.setType("jar"); + return dependency; + } +}