Skip to content

Commit 841f37c

Browse files
authored
Merge pull request #46145 from Ladicek/enable-maven-top-level-basedir-in-quarkus-dev
Maven: enable configuring `maven.top-level-basedir` in `quarkus:dev`
2 parents 1bdd69f + 9f4118b commit 841f37c

File tree

10 files changed

+199
-6
lines changed

10 files changed

+199
-6
lines changed

devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import org.apache.maven.plugin.MojoExecution;
6060
import org.apache.maven.plugin.MojoExecutionException;
6161
import org.apache.maven.plugin.MojoFailureException;
62+
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
6263
import org.apache.maven.plugin.descriptor.MojoDescriptor;
6364
import org.apache.maven.plugin.descriptor.PluginDescriptor;
6465
import org.apache.maven.plugin.logging.Log;
@@ -71,6 +72,8 @@
7172
import org.apache.maven.shared.utils.cli.CommandLineUtils;
7273
import org.apache.maven.toolchain.Toolchain;
7374
import org.apache.maven.toolchain.ToolchainManager;
75+
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
76+
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
7477
import org.codehaus.plexus.util.xml.Xpp3Dom;
7578
import org.eclipse.aether.RepositorySystem;
7679
import org.eclipse.aether.RepositorySystemSession;
@@ -97,6 +100,7 @@
97100
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
98101
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
99102
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
103+
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
100104
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
101105
import io.quarkus.bootstrap.util.BootstrapUtils;
102106
import io.quarkus.bootstrap.workspace.ArtifactSources;
@@ -1405,6 +1409,18 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
14051409
if (appModel != null) {
14061410
bootstrapProvider.close();
14071411
} else {
1412+
Path rootProjectDir = null;
1413+
String topLevelBaseDirStr = systemProperties.get(BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR);
1414+
if (topLevelBaseDirStr != null) {
1415+
final Path tmp = Path.of(topLevelBaseDirStr);
1416+
if (!Files.exists(tmp)) {
1417+
throw new BootstrapMavenException("Top-level project base directory " + topLevelBaseDirStr
1418+
+ " specified with system property " + BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR
1419+
+ " does not exist");
1420+
}
1421+
rootProjectDir = tmp;
1422+
}
1423+
14081424
final BootstrapMavenContextConfig<?> mvnConfig = BootstrapMavenContext.config()
14091425
.setUserSettings(session.getRequest().getUserSettingsFile())
14101426
.setRemoteRepositories(repos)
@@ -1413,7 +1429,8 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
14131429
// it's important to set the base directory instead of the POM
14141430
// which maybe manipulated by a plugin and stored outside the base directory
14151431
.setCurrentProject(project.getBasedir().toString())
1416-
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties));
1432+
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties))
1433+
.setRootProjectDir(rootProjectDir);
14171434

14181435
// There are a couple of reasons we don't want to use the original Maven session:
14191436
// 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;
@@ -1521,22 +1538,30 @@ private void copySurefireVariables() {
15211538
return;
15221539
}
15231540

1541+
ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
15241542
Xpp3Dom config = (Xpp3Dom) surefireMavenPlugin.getConfiguration();
15251543
if (config != null) {
15261544
// we copy the maps because they can be unmodifiable
15271545
environmentVariables = new HashMap<>(environmentVariables);
1528-
copyConfiguration(config.getChild("environmentVariables"), environmentVariables);
1546+
copyConfiguration(config.getChild("environmentVariables"), environmentVariables, evaluator);
15291547
systemProperties = new HashMap<>(systemProperties);
1530-
copyConfiguration(config.getChild("systemPropertyVariables"), systemProperties);
1548+
copyConfiguration(config.getChild("systemPropertyVariables"), systemProperties, evaluator);
15311549
}
15321550
}
15331551

1534-
private void copyConfiguration(Xpp3Dom config, Map<String, String> targetMap) {
1552+
private void copyConfiguration(Xpp3Dom config, Map<String, String> targetMap, ExpressionEvaluator evaluator) {
15351553
if (config == null) {
15361554
return;
15371555
}
15381556
for (Xpp3Dom child : config.getChildren()) {
1539-
targetMap.putIfAbsent(child.getName(), child.getValue());
1557+
targetMap.computeIfAbsent(child.getName(), ignored -> {
1558+
try {
1559+
Object value = evaluator.evaluate(child.getValue());
1560+
return value == null ? null : value.toString();
1561+
} catch (ExpressionEvaluationException e) {
1562+
throw new RuntimeException(e);
1563+
}
1564+
});
15401565
}
15411566
}
15421567

independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/BootstrapMavenContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public class BootstrapMavenContext {
9292
private static final String MAVEN_DOT_HOME = "maven.home";
9393
private static final String MAVEN_HOME = "MAVEN_HOME";
9494
private static final String MAVEN_SETTINGS = "maven.settings";
95-
private static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
95+
public static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
9696
private static final String SETTINGS_XML = "settings.xml";
9797
private static final String SETTINGS_SECURITY = "settings.security";
9898

integration-tests/maven/src/test/java/io/quarkus/maven/it/DevMojoIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,4 +1666,12 @@ void testMultimoduleFilteredClassifier()
16661666
run(true);
16671667
assertThat(devModeClient.getHttpResponse("/")).isEqualTo("Big");
16681668
}
1669+
1670+
@Test
1671+
public void testNonParentAggregator() throws MavenInvocationException, IOException {
1672+
testDir = initProject("projects/non-parent-aggregator");
1673+
run(true, "-f", "aggregator");
1674+
assertThat(devModeClient.getHttpResponse("/model")).isEqualTo("Hello model");
1675+
assertThat(devModeClient.getHttpResponse("/service")).isEqualTo("Hello service");
1676+
}
16691677
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>aggregator</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<modules>
12+
<module>../model</module>
13+
<module>../service</module>
14+
</modules>
15+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>model</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
14+
<maven.compiler.source>17</maven.compiler.source>
15+
<maven.compiler.target>17</maven.compiler.target>
16+
<maven.compiler.release>17</maven.compiler.release>
17+
<maven.compiler.parameters>true</maven.compiler.parameters>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.quarkus</groupId>
24+
<artifactId>quarkus-bom</artifactId>
25+
<version>@project.version@</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-rest</artifactId>
36+
</dependency>
37+
</dependencies>
38+
39+
<build>
40+
<plugins>
41+
<plugin>
42+
<!-- only exists to not fail the build; we don't want quarkus:dev to do anything in this project -->
43+
<groupId>io.quarkus</groupId>
44+
<artifactId>quarkus-maven-plugin</artifactId>
45+
<version>@project.version@</version>
46+
<configuration>
47+
<warnIfBuildGoalMissing>false</warnIfBuildGoalMissing>
48+
</configuration>
49+
</plugin>
50+
</plugins>
51+
</build>
52+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.model;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
7+
@Path("/model")
8+
@ApplicationScoped
9+
public class ModelResource {
10+
@GET
11+
public String hello() {
12+
return "Hello model";
13+
}
14+
}

integration-tests/maven/src/test/resources-filtered/projects/non-parent-aggregator/model/src/main/resources/META-INF/beans.xml

Whitespace-only changes.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.example</groupId>
7+
<artifactId>service</artifactId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
10+
<properties>
11+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
13+
14+
<maven.compiler.source>17</maven.compiler.source>
15+
<maven.compiler.target>17</maven.compiler.target>
16+
<maven.compiler.release>17</maven.compiler.release>
17+
<maven.compiler.parameters>17</maven.compiler.parameters>
18+
</properties>
19+
20+
<dependencyManagement>
21+
<dependencies>
22+
<dependency>
23+
<groupId>io.quarkus</groupId>
24+
<artifactId>quarkus-bom</artifactId>
25+
<version>@project.version@</version>
26+
<type>pom</type>
27+
<scope>import</scope>
28+
</dependency>
29+
</dependencies>
30+
</dependencyManagement>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>io.quarkus</groupId>
35+
<artifactId>quarkus-rest</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>com.example</groupId>
39+
<artifactId>model</artifactId>
40+
<version>\${project.version}</version>
41+
</dependency>
42+
</dependencies>
43+
44+
<build>
45+
<plugins>
46+
<plugin>
47+
<groupId>io.quarkus</groupId>
48+
<artifactId>quarkus-maven-plugin</artifactId>
49+
<version>@project.version@</version>
50+
<configuration>
51+
<systemProperties>
52+
<maven.top-level-basedir>\${session.topLevelProject.basedir.absolutePath}</maven.top-level-basedir>
53+
</systemProperties>
54+
</configuration>
55+
<executions>
56+
<execution>
57+
<goals>
58+
<goal>build</goal>
59+
</goals>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
65+
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.example.service;
2+
3+
import jakarta.enterprise.context.ApplicationScoped;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.Path;
6+
7+
@Path("/service")
8+
@ApplicationScoped
9+
public class ServiceResource {
10+
@GET
11+
public String hello() {
12+
return "Hello service";
13+
}
14+
}

integration-tests/maven/src/test/resources-filtered/projects/non-parent-aggregator/service/src/main/resources/META-INF/beans.xml

Whitespace-only changes.

0 commit comments

Comments
 (0)