Skip to content

Commit

Permalink
some code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
bmscomp authored and gsmet committed Jun 10, 2024
1 parent fcae2ab commit 791b933
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

public class AbstractDeploymentMojo extends BuildMojo {

Optional<String> deployer = Optional.empty();

@Parameter(property = "quarkus.deployment.dry-run")
boolean dryRun;

Expand All @@ -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();
}
Expand All @@ -58,13 +54,13 @@ protected List<Dependency> forcedDependencies(LaunchMode mode) {
List<Dependency> 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<ImageBuilder> projectBuilders = ImageBuilder.getProjectBuilder(project).stream().map(ImageBuilder::valueOf)
.collect(Collectors.toSet());
Optional<ImageBuilder> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -47,7 +45,7 @@ protected void doExecute() throws MojoExecutionException {
@Override
protected List<Dependency> forcedDependencies(LaunchMode mode) {
List<Dependency> dependencies = new ArrayList<>();
getBuilder().getExtensionArtifact(mavenProject()).ifPresent(d -> dependencies.add(d));
getBuilder().getExtensionArtifact(mavenProject()).ifPresent(dependencies::add);
return dependencies;
}
}
21 changes: 10 additions & 11 deletions devtools/maven/src/main/java/io/quarkus/maven/Deployer.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -64,22 +63,22 @@ public Optional<ArtifactDependency> 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<Deployer> 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<String> getProjecDeployer(MavenProject project) {
return getProjecDeployers(project.getDependencies());
public static Set<String> getProjectDeployer(MavenProject project) {
return getProjectDeployers(project.getDependencies());
}

/**
Expand All @@ -88,9 +87,9 @@ public static Set<String> getProjecDeployer(MavenProject project) {
* @param dependencies the dependencies for extensions
* @return A set with the discovered extenions.
*/
public static Set<String> getProjecDeployers(List<Dependency> dependencies) {
public static Set<String> getProjectDeployers(List<Dependency> dependencies) {
if (dependencies == null) {
return Collections.emptySet();
return Set.of();
}
return dependencies.stream()
.filter(d -> QUARKUS_GROUP_ID.equals(d.getGroupId()))
Expand All @@ -99,7 +98,7 @@ public static Set<String> getProjecDeployers(List<Dependency> dependencies) {
.collect(Collectors.toSet());
}

private static final String strip(String s) {
private static String strip(String s) {
return s.replaceAll("^" + Pattern.quote(QUARKUS_PREFIX), "");
}
}
7 changes: 0 additions & 7 deletions devtools/maven/src/main/java/io/quarkus/maven/UpdateMojo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions devtools/maven/src/test/java/io/quarkus/maven/DeployerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ public class DeployerTest {

@Test
void shouldNotFindDeployer() {
Set<String> deployers = Deployer.getProjecDeployers(List.of());
Set<String> 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<String> deployers = Deployer.getProjecDeployers(
Set<String> 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<String> deployers = Deployer.getProjecDeployers(
Set<String> deployers = Deployer.getProjectDeployers(
List.of(newDependency("quarkus-arc"), newDependency("quarkus-resteasy"), newDependency("quarkus-kubernetes"),
newDependency("quarkus-openshift")));
assertEquals(Set.of("kubernetes", "openshift"), deployers);
Expand Down

0 comments on commit 791b933

Please sign in to comment.