Skip to content

Commit

Permalink
fix: deployer detection in mvn plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
iocanel committed Oct 17, 2023
1 parent 36b5694 commit 6228a18
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
20 changes: 18 additions & 2 deletions devtools/maven/src/main/java/io/quarkus/maven/Deployer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -76,10 +79,23 @@ public static Optional<Deployer> getDeployer(MavenProject project) {
* @return A set with the discovered extenions.
*/
public static Set<String> 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<String> getProjecDeployers(List<Dependency> 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());
}

Expand Down
60 changes: 60 additions & 0 deletions devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> 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;
}
}

0 comments on commit 6228a18

Please sign in to comment.