From 791b933fabb4151b6dcfc5f02894f6cbffdc93ab Mon Sep 17 00:00:00 2001 From: Said BOUDJELDA Date: Thu, 5 Oct 2023 23:33:51 +0200 Subject: [PATCH] some code cleanups --- .../quarkus/maven/AbstractDeploymentMojo.java | 10 +++------ .../io/quarkus/maven/AbstractImageMojo.java | 6 ++---- .../main/java/io/quarkus/maven/Deployer.java | 21 +++++++++---------- .../java/io/quarkus/maven/UpdateMojo.java | 7 ------- .../java/io/quarkus/maven/DeployerTest.java | 14 ++++++------- 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/AbstractDeploymentMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/AbstractDeploymentMojo.java index 2979e1d1544bf..66e2e09224469 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/AbstractDeploymentMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/AbstractDeploymentMojo.java @@ -15,8 +15,6 @@ public class AbstractDeploymentMojo extends BuildMojo { - Optional deployer = Optional.empty(); - @Parameter(property = "quarkus.deployment.dry-run") boolean dryRun; @@ -34,9 +32,7 @@ protected void doExecute() throws MojoExecutionException { getLog().info("Deployment configuration:"); systemProperties.entrySet().stream() .filter(e -> e.getKey().contains("quarkus.deployment")) - .forEach(e -> { - getLog().info(" - " + e.getKey() + ": " + e.getValue()); - }); + .forEach(e -> getLog().info(" - " + e.getKey() + ": " + e.getValue())); } else { super.doExecute(); } @@ -58,13 +54,13 @@ protected List forcedDependencies(LaunchMode mode) { List dependencies = new ArrayList<>(); MavenProject project = mavenProject(); Deployer deployer = getDeployer(); - deployer.getExtensionArtifact(project).ifPresent(d -> dependencies.add(d)); + deployer.getExtensionArtifact(project).ifPresent(dependencies::add); if (this.imageBuild || this.imageBuilder != null) { Set projectBuilders = ImageBuilder.getProjectBuilder(project).stream().map(ImageBuilder::valueOf) .collect(Collectors.toSet()); Optional imageBuilder = ImageBuilder.getBuilder(this.imageBuilder, projectBuilders); imageBuilder.filter(b -> !projectBuilders.contains(b)).flatMap(b -> b.getExtensionArtifact(project)) - .ifPresent(d -> dependencies.add(d)); + .ifPresent(dependencies::add); } return dependencies; } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/AbstractImageMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/AbstractImageMojo.java index 702501d0cf67e..e4521b288d030 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/AbstractImageMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/AbstractImageMojo.java @@ -36,9 +36,7 @@ protected void doExecute() throws MojoExecutionException { getLog().info("Container image configuration:"); systemProperties.entrySet().stream() .filter(e -> e.getKey().contains("quarkus.container-image")) - .forEach(e -> { - getLog().info(" - " + e.getKey() + ": " + e.getValue()); - }); + .forEach(e -> getLog().info(" - " + e.getKey() + ": " + e.getValue())); } else { super.doExecute(); } @@ -47,7 +45,7 @@ protected void doExecute() throws MojoExecutionException { @Override protected List forcedDependencies(LaunchMode mode) { List dependencies = new ArrayList<>(); - getBuilder().getExtensionArtifact(mavenProject()).ifPresent(d -> dependencies.add(d)); + getBuilder().getExtensionArtifact(mavenProject()).ifPresent(dependencies::add); return dependencies; } } 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 a33f312069b26..bcd2dc6fbb4c2 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/Deployer.java @@ -1,7 +1,6 @@ package io.quarkus.maven; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.Set; @@ -64,22 +63,22 @@ public Optional getExtensionArtifact(MavenProject project) { /** * Get the deployer by name or the first one found in the project. * - * @project the project to search for deployer extensions + * @param project the project to search for deployer extensions * @return the {@link Optional} builder matching the name, project. */ public static Optional getDeployer(MavenProject project) { return DeploymentUtil.getEnabledDeployer() - .or(() -> getProjecDeployer(project).stream().findFirst()).map(Deployer::valueOf); + .or(() -> getProjectDeployer(project).stream().findFirst()).map(Deployer::valueOf); } /** - * Get teh deployer extensions found in the project. + * Get the deployer extensions found in the project. * - * @param the project to search for extensions - * @return A set with the discovered extenions. + * @param project The project to search for extensions + * @return A set with the discovered extensions. */ - public static Set getProjecDeployer(MavenProject project) { - return getProjecDeployers(project.getDependencies()); + public static Set getProjectDeployer(MavenProject project) { + return getProjectDeployers(project.getDependencies()); } /** @@ -88,9 +87,9 @@ public static Set getProjecDeployer(MavenProject project) { * @param dependencies the dependencies for extensions * @return A set with the discovered extenions. */ - public static Set getProjecDeployers(List dependencies) { + public static Set getProjectDeployers(List dependencies) { if (dependencies == null) { - return Collections.emptySet(); + return Set.of(); } return dependencies.stream() .filter(d -> QUARKUS_GROUP_ID.equals(d.getGroupId())) @@ -99,7 +98,7 @@ public static Set getProjecDeployers(List dependencies) { .collect(Collectors.toSet()); } - private static final String strip(String s) { + private static String strip(String s) { return s.replaceAll("^" + Pattern.quote(QUARKUS_PREFIX), ""); } } diff --git a/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java index 2812fc1be4db7..3c6a9d1048cdb 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java @@ -1,7 +1,5 @@ package io.quarkus.maven; -import static org.twdata.maven.mojoexecutor.MojoExecutor.*; - import java.util.List; import org.apache.maven.execution.MavenSession; @@ -35,11 +33,6 @@ public class UpdateMojo extends QuarkusProjectStateMojoBase { @Parameter(property = "perModule") boolean perModule; - /** - * If true, instead of checking and recommending the latest available Quarkus platform version, - * recommendations to properly align the current project configuration will be logged (if any) - */ - /** * Version of the target platform (e.g: 2.0.0.Final) * You may instead use stream to target the latest version of a specific platform stream. diff --git a/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java b/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java index 94e200f95bb3d..34687e881af08 100644 --- a/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java +++ b/devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java @@ -15,35 +15,35 @@ public class DeployerTest { @Test void shouldNotFindDeployer() { - Set deployers = Deployer.getProjecDeployers(List.of()); + Set deployers = Deployer.getProjectDeployers(List.of()); assertTrue(deployers.isEmpty()); - deployers = Deployer.getProjecDeployers(List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"))); + deployers = Deployer.getProjectDeployers(List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"))); assertTrue(deployers.isEmpty()); } @Test void shouldFindDeployer() { - Set deployers = Deployer.getProjecDeployers( + Set deployers = Deployer.getProjectDeployers( List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kubernetes"))); assertEquals(Set.of("kubernetes"), deployers); - deployers = Deployer.getProjecDeployers( + deployers = Deployer.getProjectDeployers( List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-openshift"))); assertEquals(Set.of("openshift"), deployers); - deployers = Deployer.getProjecDeployers( + deployers = Deployer.getProjectDeployers( List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kind"))); assertEquals(Set.of("kind"), deployers); - deployers = Deployer.getProjecDeployers( + deployers = Deployer.getProjectDeployers( List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-minikube"))); assertEquals(Set.of("minikube"), deployers); } @Test void shouldFindMultipleDeployer() { - Set deployers = Deployer.getProjecDeployers( + Set deployers = Deployer.getProjectDeployers( List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kubernetes"), newDependency("quarkus-openshift"))); assertEquals(Set.of("kubernetes", "openshift"), deployers);