Skip to content

Commit

Permalink
Merge pull request #34774 from aloubyansky/pom-outside-project-dir
Browse files Browse the repository at this point in the history
Fixed workspace loading in dev mode when POM manipulaing plugins store POM files outside project directories
  • Loading branch information
aloubyansky authored Jul 16, 2023
2 parents 35b1b74 + 2ea45da commit adf7895
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 2 deletions.
4 changes: 3 additions & 1 deletion devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -1139,7 +1139,9 @@ private QuarkusDevModeLauncher newLauncher(Boolean debugPortOk, String bootstrap
.setRemoteRepositories(repos)
.setWorkspaceDiscovery(true)
.setPreferPomsFromWorkspace(true)
.setCurrentProject(project.getFile().toString());
// it's important to set the base directory instead of the POM
// which maybe manipulated by a plugin and stored outside the base directory
.setCurrentProject(project.getBasedir().toString());

// There are a couple of reasons we don't want to use the original Maven session:
// 1) a reload could be triggered by a change in a pom.xml, in which case the Maven session might not be in sync any more with the effective POM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ static Map<Path, Model> getProjectMap(MavenSession session) {
// activated profiles or custom extensions may have overridden the build defaults
model.setBuild(mp.getModel().getBuild());
projectModels.put(mp.getBasedir().toPath(), model);
// The Maven Model API determines the project directory as the directory containing the POM file.
// However, in case when plugins manipulating POMs store their results elsewhere
// (such as the flatten plugin storing the flattened POM under the target directory),
// both the base directory and the directory containing the POM file should be added to the map.
var pomDir = mp.getFile().getParentFile();
if (!pomDir.equals(mp.getBasedir())) {
projectModels.put(pomDir.toPath(), model);
}
}
return projectModels;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,16 @@ protected ContinuousTestingMavenTestUtils getTestingTestUtils() {
return new ContinuousTestingMavenTestUtils();
}

@Test
public void testFlattenedPomInTargetDir() throws MavenInvocationException, IOException {
testDir = initProject("projects/pom-in-target-dir");
run(true);
assertThat(DevModeTestUtils.getHttpResponse("/hello")).isEqualTo("Hello from RESTEasy Reactive");
}

@Test
public void testConfigFactoryInAppModuleBannedInCodeGen() throws MavenInvocationException, IOException {
testDir = initProject("projects/codegen-config-factory", "project/codegen-config-factory-banned");
testDir = initProject("projects/codegen-config-factory", "projects/codegen-config-factory-banned");
run(true);
assertThat(DevModeTestUtils.getHttpResponse("/codegen-config/acme-config-factory")).isEqualTo("n/a");
assertThat(DevModeTestUtils.getHttpResponse("/codegen-config/acme-config-provider")).isEqualTo("n/a");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.acme</groupId>
<artifactId>code-with-quarkus</artifactId>
<version>1.0.0-SNAPSHOT</version>
<properties>
<compiler-plugin.version>${compiler-plugin.version}</compiler-plugin.version>
<maven.compiler.release>11</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>${project.version}</quarkus.platform.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>\${quarkus.platform.group-id}</groupId>
<artifactId>\${quarkus.platform.artifact-id}</artifactId>
<version>\${quarkus.platform.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>1.5.0</version>
<configuration>
<outputDirectory>target</outputDirectory>
<pomElements>
<build>keep</build>
<dependencyManagement>keep</dependencyManagement>
<properties>keep</properties>
</pomElements>
</configuration>
<executions>
<execution>
<id>flatten</id>
<phase>process-resources</phase>
<goals>
<goal>flatten</goal>
</goals>
</execution>
<execution>
<id>flatten.clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>\${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>\${quarkus.platform.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>\${compiler-plugin.version}</version>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme;

import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/hello")
public class GreetingResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "Hello from RESTEasy Reactive";
}
}

0 comments on commit adf7895

Please sign in to comment.