Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions devtools/maven/src/main/java/io/quarkus/maven/DevMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.PluginParameterExpressionEvaluator;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugin.logging.Log;
Expand All @@ -71,6 +72,8 @@
import org.apache.maven.shared.utils.cli.CommandLineUtils;
import org.apache.maven.toolchain.Toolchain;
import org.apache.maven.toolchain.ToolchainManager;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
Expand All @@ -97,6 +100,7 @@
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
import io.quarkus.bootstrap.resolver.maven.MavenArtifactResolver;
import io.quarkus.bootstrap.util.BootstrapUtils;
import io.quarkus.bootstrap.workspace.ArtifactSources;
Expand Down Expand Up @@ -1405,6 +1409,18 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
if (appModel != null) {
bootstrapProvider.close();
} else {
Path rootProjectDir = null;
String topLevelBaseDirStr = systemProperties.get(BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR);
if (topLevelBaseDirStr != null) {
final Path tmp = Path.of(topLevelBaseDirStr);
if (!Files.exists(tmp)) {
throw new BootstrapMavenException("Top-level project base directory " + topLevelBaseDirStr
+ " specified with system property " + BootstrapMavenContext.MAVEN_TOP_LEVEL_PROJECT_BASEDIR
+ " does not exist");
}
rootProjectDir = tmp;
}

final BootstrapMavenContextConfig<?> mvnConfig = BootstrapMavenContext.config()
.setUserSettings(session.getRequest().getUserSettingsFile())
.setRemoteRepositories(repos)
Expand All @@ -1413,7 +1429,8 @@ private DevModeCommandLine newLauncher(String actualDebugPort, String bootstrapI
// 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())
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties));
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties))
.setRootProjectDir(rootProjectDir);

// 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 Expand Up @@ -1521,22 +1538,30 @@ private void copySurefireVariables() {
return;
}

ExpressionEvaluator evaluator = new PluginParameterExpressionEvaluator(session, mojoExecution);
Xpp3Dom config = (Xpp3Dom) surefireMavenPlugin.getConfiguration();
if (config != null) {
// we copy the maps because they can be unmodifiable
environmentVariables = new HashMap<>(environmentVariables);
copyConfiguration(config.getChild("environmentVariables"), environmentVariables);
copyConfiguration(config.getChild("environmentVariables"), environmentVariables, evaluator);
systemProperties = new HashMap<>(systemProperties);
copyConfiguration(config.getChild("systemPropertyVariables"), systemProperties);
copyConfiguration(config.getChild("systemPropertyVariables"), systemProperties, evaluator);
}
}

private void copyConfiguration(Xpp3Dom config, Map<String, String> targetMap) {
private void copyConfiguration(Xpp3Dom config, Map<String, String> targetMap, ExpressionEvaluator evaluator) {
if (config == null) {
return;
}
for (Xpp3Dom child : config.getChildren()) {
targetMap.putIfAbsent(child.getName(), child.getValue());
targetMap.computeIfAbsent(child.getName(), ignored -> {
try {
Object value = evaluator.evaluate(child.getValue());
return value == null ? null : value.toString();
} catch (ExpressionEvaluationException e) {
throw new RuntimeException(e);
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class BootstrapMavenContext {
private static final String MAVEN_DOT_HOME = "maven.home";
private static final String MAVEN_HOME = "MAVEN_HOME";
private static final String MAVEN_SETTINGS = "maven.settings";
private static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
public static final String MAVEN_TOP_LEVEL_PROJECT_BASEDIR = "maven.top-level-basedir";
private static final String SETTINGS_XML = "settings.xml";
private static final String SETTINGS_SECURITY = "settings.security";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1666,4 +1666,12 @@ void testMultimoduleFilteredClassifier()
run(true);
assertThat(devModeClient.getHttpResponse("/")).isEqualTo("Big");
}

@Test
public void testNonParentAggregator() throws MavenInvocationException, IOException {
testDir = initProject("projects/non-parent-aggregator");
run(true, "-f", "aggregator");
assertThat(devModeClient.getHttpResponse("/model")).isEqualTo("Hello model");
assertThat(devModeClient.getHttpResponse("/service")).isEqualTo("Hello service");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>aggregator</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>../model</module>
<module>../service</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>model</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.parameters>true</maven.compiler.parameters>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>@project.version@</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<!-- only exists to not fail the build; we don't want quarkus:dev to do anything in this project -->
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<warnIfBuildGoalMissing>false</warnIfBuildGoalMissing>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.model;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/model")
@ApplicationScoped
public class ModelResource {
@GET
public String hello() {
return "Hello model";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.example</groupId>
<artifactId>service</artifactId>
<version>1.0.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.parameters>17</maven.compiler.parameters>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bom</artifactId>
<version>@project.version@</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>model</artifactId>
<version>\${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<systemProperties>
<maven.top-level-basedir>\${session.topLevelProject.basedir.absolutePath}</maven.top-level-basedir>
</systemProperties>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.service;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/service")
@ApplicationScoped
public class ServiceResource {
@GET
public String hello() {
return "Hello service";
}
}
Loading