From 56408ec8dc420d6f80981bf24e1f5dcbceedd1af Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Sat, 11 Feb 2023 21:11:23 +0100 Subject: [PATCH] Use the effective Maven project build config when initializing sources and classes paths for dev mode --- .../io/quarkus/maven/QuarkusBootstrapProvider.java | 7 +++++-- .../resolver/maven/workspace/LocalProject.java | 2 +- .../resolver/maven/workspace/WorkspaceLoader.java | 10 +++++++--- .../src/test/java/io/quarkus/maven/it/DevMojoIT.java | 6 ++++++ .../test/resources-filtered/projects/classic/pom.xml | 6 ++++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java index 1821722bc8c1f..f645cbc37f0aa 100644 --- a/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java +++ b/devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java @@ -71,8 +71,11 @@ static Map getProjectMap(MavenSession session) { } final Map projectModels = new HashMap<>(allProjects.size()); for (MavenProject mp : allProjects) { - mp.getOriginalModel().setPomFile(mp.getFile()); - projectModels.put(mp.getBasedir().toPath(), mp.getOriginalModel()); + final Model model = mp.getOriginalModel(); + model.setPomFile(mp.getFile()); + // activated profiles or custom extensions may have overridden the build defaults + model.setBuild(mp.getModel().getBuild()); + projectModels.put(mp.getBasedir().toPath(), model); } return projectModels; } 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 c2fa020ce577d..9b8e77720bf36 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 @@ -380,7 +380,7 @@ public WorkspaceModule toWorkspaceModule(BootstrapMavenContext ctx) { DefaultArtifactSources src = null; if (e.getGoals().contains(ArtifactCoords.TYPE_JAR)) { src = processJarPluginExecutionConfig(e.getConfiguration(), false); - addDefaultSourceSet &= !e.getId().equals("default-jar"); + addDefaultSourceSet &= !(src != null && e.getId().equals("default-jar")); } else if (e.getGoals().contains("test-jar")) { src = processJarPluginExecutionConfig(e.getConfiguration(), true); } diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java index 9e2587ee65a3b..588b2766a00f9 100644 --- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java +++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/WorkspaceLoader.java @@ -153,12 +153,16 @@ private LocalProject loadAndCacheProject(Path pomFile) throws BootstrapMavenExce } private Model rawModel(Path pomFile) throws BootstrapMavenException { - Model rawModel = rawModelCache.getOrDefault(pomFile.getParent(), - modelProvider == null ? null : modelProvider.apply(pomFile.getParent())); + final Path moduleDir = pomFile.getParent(); + Model rawModel = rawModelCache.get(moduleDir); + if (rawModel != null) { + return rawModel; + } + rawModel = modelProvider == null ? null : modelProvider.apply(moduleDir); if (rawModel == null) { rawModel = readModel(pomFile); } - rawModelCache.put(pomFile.getParent(), rawModel); + rawModelCache.put(moduleDir, rawModel); return rawModel; } 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 80740086cf898..9bd6f0ca8d941 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 @@ -316,6 +316,12 @@ public void testThatTheApplicationIsReloadedOnJavaChange() throws MavenInvocatio .atMost(1, TimeUnit.MINUTES).until(() -> DevModeTestUtils.getHttpResponse("/app/hello").contains("carambar")); } + @Test + public void testCustomOutputDirSetInProfile() throws MavenInvocationException, IOException { + testDir = initProject("projects/classic", "projects/project-classic-custom-output-dir"); + runAndCheck("-PcustomOutputDir"); + } + @Test public void testThatNonExistentSrcDirCanBeAdded() throws MavenInvocationException, IOException { testDir = initProject("projects/classic", "projects/project-classic-run-java-change"); diff --git a/integration-tests/maven/src/test/resources-filtered/projects/classic/pom.xml b/integration-tests/maven/src/test/resources-filtered/projects/classic/pom.xml index c371b8c32cc24..858a9502a30f8 100644 --- a/integration-tests/maven/src/test/resources-filtered/projects/classic/pom.xml +++ b/integration-tests/maven/src/test/resources-filtered/projects/classic/pom.xml @@ -88,5 +88,11 @@ native + + customOutputDir + + target-other + +