diff --git a/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/IntegrationTestMojo.java b/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/IntegrationTestMojo.java index 91e9ff382..682bd1398 100644 --- a/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/IntegrationTestMojo.java +++ b/maven-plugins/helidon-archetype-maven-plugin/src/main/java/io/helidon/build/maven/archetype/IntegrationTestMojo.java @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -318,13 +317,12 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - Set artifactIds = new HashSet<>(); Map> variations = filterVariations(); for (Map.Entry> entry : variations.entrySet()) { index = entry.getKey(); Map variation = entry.getValue(); String artifactId = variation.getOrDefault("artifactId", "myproject"); - if (!artifactIds.add(artifactId)) { + if (index > 1) { variation.put("artifactId", artifactId + "-" + index); } processIntegrationTest(testName, variation, archetypeFile); @@ -332,7 +330,6 @@ public void execute() throws MojoExecutionException, MojoFailureException { } else { processIntegrationTest(testName, externalValues, archetypeFile); } - } catch (IOException e) { Log.error(e, "Integration test failed with error(s)"); throw new MojoExecutionException("Integration test failed with error(s)"); @@ -509,7 +506,8 @@ private void logVariations(String testName) { private void logTestDescription(String testName, Map externalValues) { String description = Bold.apply("Test: ") + BoldBlue.apply(testName); if (variations != null && index > 0) { - description += BoldBlue.apply(String.format(", progress: %s/%s", index, variations.size())); + int total = endIndex == -1 ? variations.size() : endIndex; + description += BoldBlue.apply(String.format(", progress: %s/%s", index, total)); } Log.info(""); Log.info("-------------------------------------"); @@ -693,7 +691,7 @@ private FileLogger setupBuildLogger(Path basedir) throws IOException { return logger; } - private static final class FileLogger implements InvocationOutputHandler, Closeable { + private final class FileLogger implements InvocationOutputHandler, Closeable { private final PrintStream printer; private final boolean streamLogs; @@ -709,7 +707,7 @@ public void consumeLine(String line) { printer.println(line); printer.flush(); if (streamLogs) { - Log.info(line); + getLog().info(line); } } diff --git a/maven-plugins/helidon-archetype-maven-plugin/src/test/java/io/helidon/build/maven/archetype/ProjectsTestIT.java b/maven-plugins/helidon-archetype-maven-plugin/src/test/java/io/helidon/build/maven/archetype/ProjectsTestIT.java index 708972ff0..7ff23aadd 100644 --- a/maven-plugins/helidon-archetype-maven-plugin/src/test/java/io/helidon/build/maven/archetype/ProjectsTestIT.java +++ b/maven-plugins/helidon-archetype-maven-plugin/src/test/java/io/helidon/build/maven/archetype/ProjectsTestIT.java @@ -20,6 +20,7 @@ import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import io.helidon.build.common.test.utils.BuildLog; @@ -29,10 +30,12 @@ import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import org.junit.jupiter.params.ParameterizedTest; +import static io.helidon.build.common.FileUtils.fileName; import static io.helidon.build.common.test.utils.BuildLog.assertDiffs; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.nullValue; /** * Integration test that verifies the projects under {@code src/it/projects}. @@ -135,31 +138,44 @@ private static Path projectsDir(String baseDir, String prefix) { return projectsDir; } - private static void assertProjectCount(Path projectsDir, int expectedCount) throws IOException { - int projectCount = 0; + private static List testProjects(Path projectsDir) throws IOException { + List projects = new ArrayList<>(); try (DirectoryStream paths = Files.newDirectoryStream(projectsDir)) { for (Path path : paths) { - if (path.getFileName().toString().endsWith("-project")) { - assertThat(Files.isDirectory(path), is(true)); - projectCount++; + if (fileName(path).matches(".*-project(-[0-9]+)?$")) { + projects.add(path); } } - assertThat(projectCount, is(expectedCount)); } + return projects; + } + + private static void assertProjectCount(Path projectsDir, int expectedCount) throws IOException { + int projectCount = 0; + for (Path path : testProjects(projectsDir)) { + assertThat(Files.isDirectory(path), is(true)); + projectCount++; + } + assertThat(projectCount, is(expectedCount)); } private static void assertProjectShape(Path projectsDir, String shape) throws IOException { // Check project directory - Path outputDir = projectsDir.resolve(shape + "-project"); + Path outputDir = testProjects(projectsDir).stream() + .filter(p -> fileName(p).contains(shape + "-project")) + .findFirst() + .orElse(null); + assertThat(outputDir, is(not(nullValue()))); assertThat(Files.exists(outputDir), is(true)); // Check pom file Path pomFile = outputDir.resolve("pom.xml"); + String fileName = fileName(outputDir); assertContains(pomFile, List.of( "io.helidon.build.maven.archetype.tests", - "" + shape + "-project", + "" + fileName + "", "0.1-SNAPSHOT", - "" + shape + "-project" + "" + fileName + "" )); // Check source file