diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java index 2b289c1b86486..7e21238683369 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java @@ -800,31 +800,28 @@ private Path resolveCurrentPom() { if (alternatePom != null) { return pomXmlOrNull(basedir.resolve(alternatePom)); } - final Path pom = basedir.resolve("pom.xml"); + final Path pom = basedir.resolve(LocalProject.POM_XML); return Files.exists(pom) ? pom : null; } static Path getPomForDirOrNull(final Path basedir, Path alternatePom) { - // if the basedir matches the parent of the alternate pom, it's the alternate pom - if (alternatePom != null - && alternatePom.isAbsolute() - && alternatePom.getParent().equals(basedir)) { - return alternatePom; - } - // even if the alternate pom has been specified we try the default pom.xml first - // since unlike Maven CLI we don't know which project originated the build - Path pom = basedir.resolve("pom.xml"); - if (Files.exists(pom)) { - return pom; + if (alternatePom != null) { + if (alternatePom.getNameCount() == 1 || basedir.endsWith(alternatePom.getParent())) { + if (alternatePom.isAbsolute()) { + // if the basedir matches the parent of the alternate pom, it's the alternate pom + return alternatePom; + } + // if the basedir ends with the alternate POM parent relative path, we can try it as the base dir + final Path pom = basedir.resolve(alternatePom.getFileName()); + if (Files.exists(pom)) { + return pom; + } + } } - // if alternate pom path has a single element we can try it - // if it has more, it won't match the basedir - if (alternatePom != null && !alternatePom.isAbsolute() && alternatePom.getNameCount() == 1) { - pom = basedir.resolve(alternatePom); - if (Files.exists(pom)) { - return pom; - } + final Path pom = basedir.resolve(LocalProject.POM_XML); + if (Files.exists(pom)) { + return pom; } // give up @@ -833,7 +830,7 @@ static Path getPomForDirOrNull(final Path basedir, Path alternatePom) { private static Path pomXmlOrNull(Path path) { if (Files.isDirectory(path)) { - path = path.resolve("pom.xml"); + path = path.resolve(LocalProject.POM_XML); } return Files.exists(path) ? path : null; } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java index 30b2048e3856b..15c1557db6863 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/LocalProject.java @@ -32,7 +32,7 @@ public class LocalProject { private static final String PROJECT_BASEDIR = "${project.basedir}"; private static final String PROJECT_BUILD_DIR = "${project.build.directory}"; - static final String POM_XML = "pom.xml"; + public static final String POM_XML = "pom.xml"; public static LocalProject load(Path path) throws BootstrapMavenException { return load(path, true); diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/AddExtensionIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/AddExtensionIT.java index 645b1139591e6..bc1739be9ad1f 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/AddExtensionIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/AddExtensionIT.java @@ -30,7 +30,7 @@ class AddExtensionIT extends QuarkusPlatformAwareMojoTestBase { private static final String QUARKUS_GROUPID = "io.quarkus"; private static final String BOM_ARTIFACT_ID = "quarkus-bom"; private static final String VERTX_ARTIFACT_ID = "quarkus-vertx"; - private static final String COMMONS_IO = "commons-io"; + private static final String COMMONS_CODEC = "commons-codec"; private static final String PROJECT_SOURCE_DIR = "projects/classic"; private File testDir; private Invoker invoker; @@ -69,16 +69,16 @@ void testAddExtensionWithASingleExtensionToSubmodule() throws MavenInvocationExc void testAddExtensionWithMultipleExtension() throws MavenInvocationException, IOException { testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithMultipleExtension"); invoker = initInvoker(testDir); - addExtension(false, "quarkus-vertx, commons-io:commons-io:2.6"); + addExtension(false, "quarkus-vertx, commons-codec:commons-codec:1.15"); Model model = loadPom(testDir); Dependency expected1 = new Dependency(); expected1.setGroupId(QUARKUS_GROUPID); expected1.setArtifactId(VERTX_ARTIFACT_ID); Dependency expected2 = new Dependency(); - expected2.setGroupId(COMMONS_IO); - expected2.setArtifactId(COMMONS_IO); - expected2.setVersion("2.6"); + expected2.setGroupId(COMMONS_CODEC); + expected2.setArtifactId(COMMONS_CODEC); + expected2.setVersion("1.15"); assertThat(contains(model.getDependencies(), expected1)).isTrue(); assertThat(contains(model.getDependencies(), expected2)).isTrue(); } @@ -102,16 +102,16 @@ void testAddExtensionWithMultipleExtensionsAndPluralForm() throws MavenInvocatio testDir = initProject(PROJECT_SOURCE_DIR, "projects/testAddExtensionWithMultipleExtensionAndPluralForm"); invoker = initInvoker(testDir); - addExtension(true, "quarkus-vertx, commons-io:commons-io:2.6"); + addExtension(true, "quarkus-vertx, commons-codec:commons-codec:1.15"); Model model = loadPom(testDir); Dependency expected1 = new Dependency(); expected1.setGroupId(QUARKUS_GROUPID); expected1.setArtifactId(VERTX_ARTIFACT_ID); Dependency expected2 = new Dependency(); - expected2.setGroupId(COMMONS_IO); - expected2.setArtifactId(COMMONS_IO); - expected2.setVersion("2.6"); + expected2.setGroupId(COMMONS_CODEC); + expected2.setArtifactId(COMMONS_CODEC); + expected2.setVersion("1.15"); assertThat(contains(model.getDependencies(), expected1)).isTrue(); assertThat(contains(model.getDependencies(), expected2)).isTrue(); } @@ -119,7 +119,7 @@ void testAddExtensionWithMultipleExtensionsAndPluralForm() throws MavenInvocatio private boolean contains(List dependencies, Dependency expected) { return dependencies.stream().anyMatch(dep -> dep.getGroupId().equals(expected.getGroupId()) && dep.getArtifactId().equals(expected.getArtifactId()) - && (dep.getVersion() == null && expected.getVersion() == null || dep.getVersion().equals(expected.getVersion())) + && (expected.getVersion() == null ? dep.getVersion() == null : expected.getVersion().equals(dep.getVersion())) && (dep.getScope() == null || dep.getScope().equals(expected.getScope())) && dep.isOptional() == expected.isOptional() && dep.getType().equals(expected.getType())); diff --git a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java index 0358e34ea3f5f..475a22423adb3 100644 --- a/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java +++ b/integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java @@ -409,21 +409,7 @@ public void testAlternatePom() throws Exception { if (alternatePom.exists()) { alternatePom.delete(); } - pom.renameTo(alternatePom); - if (pom.exists()) { - throw new IllegalStateException(pom + " was expected to be renamed to " + alternatePom); - } - runAndCheck("-f", alternatePomName); - - // Edit a Java file too - final File javaSource = new File(testDir, "src/main/java/org/acme/HelloResource.java"); - final String uuid = UUID.randomUUID().toString(); - filter(javaSource, Collections.singletonMap("return \"hello\";", "return \"hello " + uuid + "\";")); - - // edit the application.properties too - final File applicationProps = new File(testDir, "src/main/resources/application.properties"); - filter(applicationProps, Collections.singletonMap("greeting=bonjour", "greeting=" + uuid + "")); - + Files.copy(pom.toPath(), alternatePom.toPath()); // Now edit the pom.xml to trigger the dev mode restart filter(alternatePom, Collections.singletonMap("", " \n" + @@ -431,17 +417,12 @@ public void testAlternatePom() throws Exception { " quarkus-smallrye-openapi\n" + " ")); - // Wait until we get the updated responses - await() - .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES) - .until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("hello " + uuid)); - - await() - .pollDelay(100, TimeUnit.MILLISECONDS) - .atMost(1, TimeUnit.MINUTES) - .until(() -> DevModeTestUtils.getHttpResponse("/app/hello/greeting").contains(uuid)); + runAndCheck(); + assertThat(DevModeTestUtils.getHttpResponse("/q/openapi", true)).contains("Resource not found"); + shutdownTheApp(); + runAndCheck("-f", alternatePomName); + DevModeTestUtils.getHttpResponse("/q/openapi").contains("hello"); } @Test diff --git a/integration-tests/maven/src/test/resources/projects/classic/pom.xml b/integration-tests/maven/src/test/resources/projects/classic/pom.xml index 9c61e559f4160..c5de77f219f15 100644 --- a/integration-tests/maven/src/test/resources/projects/classic/pom.xml +++ b/integration-tests/maven/src/test/resources/projects/classic/pom.xml @@ -48,7 +48,6 @@ commons-io commons-io - 2.6 io.quarkus diff --git a/test-framework/maven/src/main/java/io/quarkus/maven/it/RunAndCheckMojoTestBase.java b/test-framework/maven/src/main/java/io/quarkus/maven/it/RunAndCheckMojoTestBase.java index cf04ad4ee14f1..0c78707912fa8 100644 --- a/test-framework/maven/src/main/java/io/quarkus/maven/it/RunAndCheckMojoTestBase.java +++ b/test-framework/maven/src/main/java/io/quarkus/maven/it/RunAndCheckMojoTestBase.java @@ -25,6 +25,10 @@ public class RunAndCheckMojoTestBase extends MojoTestBase { @AfterEach public void cleanup() throws IOException { + shutdownTheApp(); + } + + public void shutdownTheApp() { if (running != null) { running.stop(); }