Skip to content

Commit 405455a

Browse files
committed
* Support configuring quarkus.bootstrap.effective-model-builder as a POM property;
* suport resolving JAR artifacts with classifiers from the classes dir; * support the JAR and Surefire plugin configurations in the pluginManagement when initializing artifact source sets.
1 parent 19ee291 commit 405455a

File tree

15 files changed

+304
-79
lines changed

15 files changed

+304
-79
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1375,7 +1375,8 @@ private QuarkusDevModeLauncher newLauncher(String actualDebugPort, String bootst
13751375
.setPreferPomsFromWorkspace(true)
13761376
// it's important to set the base directory instead of the POM
13771377
// which maybe manipulated by a plugin and stored outside the base directory
1378-
.setCurrentProject(project.getBasedir().toString());
1378+
.setCurrentProject(project.getBasedir().toString())
1379+
.setEffectiveModelBuilder(BootstrapMavenContextConfig.getEffectiveModelBuilderProperty(projectProperties));
13791380

13801381
// There are a couple of reasons we don't want to use the original Maven session:
13811382
// 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;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import io.quarkus.bootstrap.resolver.AppModelResolverException;
4141
import io.quarkus.bootstrap.resolver.BootstrapAppModelResolver;
4242
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContext;
43+
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenContextConfig;
4344
import io.quarkus.bootstrap.resolver.maven.BootstrapMavenException;
4445
import io.quarkus.bootstrap.resolver.maven.EffectiveModelResolver;
4546
import io.quarkus.bootstrap.resolver.maven.IncubatingApplicationModelResolver;
@@ -195,7 +196,9 @@ private MavenArtifactResolver artifactResolver(QuarkusBootstrapMojo mojo, Launch
195196
.setPreferPomsFromWorkspace(true)
196197
.setProjectModelProvider(getProjectMap(mojo.mavenSession())::get)
197198
// pass the repositories since Maven extensions could manipulate repository configs
198-
.setRemoteRepositories(mojo.remoteRepositories()));
199+
.setRemoteRepositories(mojo.remoteRepositories())
200+
.setEffectiveModelBuilder(BootstrapMavenContextConfig
201+
.getEffectiveModelBuilderProperty(mojo.mavenProject().getProperties())));
199202
}
200203
// PROD packaging mode with workspace discovery disabled
201204
return MavenArtifactResolver.builder()

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public class BootstrapMavenContext {
9797
private static final String SETTINGS_XML = "settings.xml";
9898
private static final String SETTINGS_SECURITY = "settings.security";
9999

100-
private static final String EFFECTIVE_MODEL_BUILDER_PROP = "quarkus.bootstrap.effective-model-builder";
100+
static final String EFFECTIVE_MODEL_BUILDER_PROP = "quarkus.bootstrap.effective-model-builder";
101101
private static final String WARN_ON_FAILING_WS_MODULES_PROP = "quarkus.bootstrap.warn-on-failing-workspace-modules";
102102

103103
private static final String MAVEN_RESOLVER_TRANSPORT_KEY = "maven.resolver.transport";
@@ -1080,8 +1080,7 @@ public boolean isPreferPomsFromWorkspace() {
10801080

10811081
public boolean isEffectiveModelBuilder() {
10821082
if (effectiveModelBuilder == null) {
1083-
final String s = PropertyUtils.getProperty(EFFECTIVE_MODEL_BUILDER_PROP);
1084-
effectiveModelBuilder = s == null ? false : Boolean.parseBoolean(s);
1083+
effectiveModelBuilder = Boolean.getBoolean(EFFECTIVE_MODEL_BUILDER_PROP);
10851084
}
10861085
return effectiveModelBuilder;
10871086
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.nio.file.Paths;
77
import java.util.ArrayList;
88
import java.util.List;
9+
import java.util.Properties;
910
import java.util.function.Function;
1011

1112
import org.apache.maven.model.Model;
@@ -20,6 +21,23 @@
2021

2122
public class BootstrapMavenContextConfig<T extends BootstrapMavenContextConfig<?>> {
2223

24+
/**
25+
* Resolves the effective value of the {@code effective-model-builder} option by looking for the
26+
* {@code quarkus.bootstrap.effective-model-builder} property among the system properties and,
27+
* if not set, in the properties argument.
28+
* <p>
29+
* If the property is found, the method will return the result of {@link java.lang.Boolean#parseBoolean}.
30+
* If the property is not set, the method will return false.
31+
*
32+
* @param props primary source of properties
33+
* @return whether effective model builder should be enabled
34+
*/
35+
public static boolean getEffectiveModelBuilderProperty(Properties props) {
36+
final String value = System.getProperty(BootstrapMavenContext.EFFECTIVE_MODEL_BUILDER_PROP);
37+
return value == null ? Boolean.parseBoolean(props.getProperty(BootstrapMavenContext.EFFECTIVE_MODEL_BUILDER_PROP))
38+
: Boolean.parseBoolean(value);
39+
}
40+
2341
protected String localRepo;
2442
protected String[] localRepoTail;
2543
protected Boolean localRepoTailIgnoreAvailability;

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

Lines changed: 77 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -366,71 +366,19 @@ public WorkspaceModule toWorkspaceModule(BootstrapMavenContext ctx) {
366366
.setBuildDir(getOutputDir());
367367

368368
final Model model = modelBuildingResult == null ? getRawModel() : modelBuildingResult.getEffectiveModel();
369-
if (!ArtifactCoords.TYPE_POM.equals(model.getPackaging())) {
370-
final Build build = model.getBuild();
371-
boolean addDefaultSourceSet = true;
372-
if (build != null && !build.getPlugins().isEmpty()) {
373-
for (Plugin plugin : build.getPlugins()) {
374-
if (plugin.getArtifactId().equals("maven-jar-plugin")) {
375-
if (plugin.getExecutions().isEmpty()) {
376-
final DefaultArtifactSources src = processJarPluginExecutionConfig(plugin.getConfiguration(),
377-
false);
378-
if (src != null) {
379-
addDefaultSourceSet = false;
380-
moduleBuilder.addArtifactSources(src);
381-
}
382-
} else {
383-
for (PluginExecution e : plugin.getExecutions()) {
384-
DefaultArtifactSources src = null;
385-
if (e.getGoals().contains(ArtifactCoords.TYPE_JAR)) {
386-
src = processJarPluginExecutionConfig(e.getConfiguration(), false);
387-
addDefaultSourceSet &= !(src != null && e.getId().equals("default-jar"));
388-
} else if (e.getGoals().contains("test-jar")) {
389-
src = processJarPluginExecutionConfig(e.getConfiguration(), true);
390-
}
391-
if (src != null) {
392-
moduleBuilder.addArtifactSources(src);
393-
}
394-
}
395-
}
396-
} else if (plugin.getArtifactId().equals("maven-surefire-plugin") && plugin.getConfiguration() != null) {
397-
Object config = plugin.getConfiguration();
398-
if (!(config instanceof Xpp3Dom)) {
399-
continue;
400-
}
401-
Xpp3Dom dom = (Xpp3Dom) config;
402-
final Xpp3Dom depExcludes = dom.getChild("classpathDependencyExcludes");
403-
if (depExcludes != null) {
404-
final Xpp3Dom[] excludes = depExcludes.getChildren("classpathDependencyExclude");
405-
if (excludes != null) {
406-
final List<String> list = new ArrayList<>(excludes.length);
407-
for (Xpp3Dom exclude : excludes) {
408-
list.add(exclude.getValue());
409-
}
410-
moduleBuilder.setTestClasspathDependencyExclusions(list);
411-
}
412-
}
413-
final Xpp3Dom additionalElements = dom.getChild("additionalClasspathElements");
414-
if (additionalElements != null) {
415-
final Xpp3Dom[] elements = additionalElements.getChildren("additionalClasspathElement");
416-
if (elements != null) {
417-
final List<String> list = new ArrayList<>(elements.length);
418-
for (Xpp3Dom element : elements) {
419-
for (String s : element.getValue().split(",")) {
420-
list.add(stripProjectBasedirPrefix(s, PROJECT_BASEDIR));
421-
}
422-
}
423-
moduleBuilder.setAdditionalTestClasspathElements(list);
424-
}
425-
}
426-
}
427-
}
428-
}
429-
369+
if (!ArtifactCoords.TYPE_POM.equals(getPackaging())) {
370+
final List<Plugin> plugins = model.getBuild() == null ? List.of() : model.getBuild().getPlugins();
371+
boolean addDefaultSourceSet = addSourceSetsFromPlugins(plugins, moduleBuilder);
430372
if (addDefaultSourceSet) {
431-
moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN,
432-
List.of(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir(), getGeneratedSourcesDir())),
433-
collectMainResources(null)));
373+
var pluginManagement = model.getBuild() == null ? null : model.getBuild().getPluginManagement();
374+
if (pluginManagement != null) {
375+
addDefaultSourceSet = addSourceSetsFromPlugins(pluginManagement.getPlugins(), moduleBuilder);
376+
}
377+
if (addDefaultSourceSet) {
378+
moduleBuilder.addArtifactSources(new DefaultArtifactSources(ArtifactSources.MAIN,
379+
List.of(new DefaultSourceDir(getSourcesSourcesDir(), getClassesDir(), getGeneratedSourcesDir())),
380+
collectMainResources(null)));
381+
}
434382
}
435383
if (!moduleBuilder.hasTestSources()) {
436384
// FIXME: do tests have generated sources?
@@ -454,6 +402,70 @@ public WorkspaceModule toWorkspaceModule(BootstrapMavenContext ctx) {
454402
return this.module = moduleBuilder.build();
455403
}
456404

405+
private boolean addSourceSetsFromPlugins(List<Plugin> plugins, WorkspaceModule.Mutable moduleBuilder) {
406+
boolean addDefaultSourceSet = true;
407+
int processedPlugins = 0;
408+
for (int i = 0; i < plugins.size() && processedPlugins < 2; ++i) {
409+
var plugin = plugins.get(i);
410+
if (plugin.getArtifactId().equals("maven-jar-plugin")) {
411+
++processedPlugins;
412+
if (plugin.getExecutions().isEmpty()) {
413+
final DefaultArtifactSources src = processJarPluginExecutionConfig(plugin.getConfiguration(),
414+
false);
415+
if (src != null) {
416+
addDefaultSourceSet = false;
417+
moduleBuilder.addArtifactSources(src);
418+
}
419+
} else {
420+
for (PluginExecution e : plugin.getExecutions()) {
421+
DefaultArtifactSources src = null;
422+
if (e.getGoals().contains(ArtifactCoords.TYPE_JAR)) {
423+
src = processJarPluginExecutionConfig(e.getConfiguration(), false);
424+
addDefaultSourceSet &= !(src != null && e.getId().equals("default-jar"));
425+
} else if (e.getGoals().contains("test-jar")) {
426+
src = processJarPluginExecutionConfig(e.getConfiguration(), true);
427+
}
428+
if (src != null) {
429+
moduleBuilder.addArtifactSources(src);
430+
}
431+
}
432+
}
433+
} else if (plugin.getArtifactId().equals("maven-surefire-plugin") && plugin.getConfiguration() != null) {
434+
++processedPlugins;
435+
Object config = plugin.getConfiguration();
436+
if (!(config instanceof Xpp3Dom)) {
437+
continue;
438+
}
439+
Xpp3Dom dom = (Xpp3Dom) config;
440+
final Xpp3Dom depExcludes = dom.getChild("classpathDependencyExcludes");
441+
if (depExcludes != null) {
442+
final Xpp3Dom[] excludes = depExcludes.getChildren("classpathDependencyExclude");
443+
if (excludes != null) {
444+
final List<String> list = new ArrayList<>(excludes.length);
445+
for (Xpp3Dom exclude : excludes) {
446+
list.add(exclude.getValue());
447+
}
448+
moduleBuilder.setTestClasspathDependencyExclusions(list);
449+
}
450+
}
451+
final Xpp3Dom additionalElements = dom.getChild("additionalClasspathElements");
452+
if (additionalElements != null) {
453+
final Xpp3Dom[] elements = additionalElements.getChildren("additionalClasspathElement");
454+
if (elements != null) {
455+
final List<String> list = new ArrayList<>(elements.length);
456+
for (Xpp3Dom element : elements) {
457+
for (String s : element.getValue().split(",")) {
458+
list.add(stripProjectBasedirPrefix(s, PROJECT_BASEDIR));
459+
}
460+
}
461+
moduleBuilder.setAdditionalTestClasspathElements(list);
462+
}
463+
}
464+
}
465+
}
466+
return addDefaultSourceSet;
467+
}
468+
457469
private List<io.quarkus.maven.dependency.Dependency> toArtifactDependencies(List<Dependency> rawModelDeps,
458470
BootstrapMavenContext ctx) {
459471
if (rawModelDeps.isEmpty()) {
@@ -509,7 +521,7 @@ private DefaultArtifactSources processJarPluginExecutionConfig(Object config, bo
509521
new DefaultSourceDir(new DirectoryPathTree(test ? getTestSourcesSourcesDir() : getSourcesSourcesDir()),
510522
new DirectoryPathTree(test ? getTestClassesDir() : getClassesDir(), filter),
511523
// FIXME: wrong for tests
512-
new DirectoryPathTree(test ? getGeneratedSourcesDir() : getGeneratedSourcesDir(), filter),
524+
new DirectoryPathTree(getGeneratedSourcesDir(), filter),
513525
Map.of()));
514526
final Collection<SourceDir> resources = test ? collectTestResources(filter) : collectMainResources(filter);
515527
return new DefaultArtifactSources(classifier, sources, resources);

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,12 @@ public File findArtifact(Artifact artifact) {
124124
return path.toFile();
125125
}
126126

127-
if (!artifact.getClassifier().isEmpty()) {
128-
if ("tests".equals(artifact.getClassifier())) {
129-
//special classifier used for test jars
130-
path = lp.getTestClassesDir();
131-
if (Files.exists(path)) {
132-
return path.toFile();
133-
}
127+
if ("tests".equals(artifact.getClassifier())) {
128+
//special classifier used for test jars
129+
path = lp.getTestClassesDir();
130+
if (Files.exists(path)) {
131+
return path.toFile();
134132
}
135-
// otherwise, this artifact hasn't been built yet
136-
return null;
137133
}
138134

139135
if (ArtifactCoords.TYPE_JAR.equals(artifact.getExtension())) {

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
@@ -1622,4 +1622,12 @@ public void testThatAptInAnnotationProcessorsWorks() throws MavenInvocationExcep
16221622
assertThat(entityMetamodelClassFile).exists();
16231623
assertThat(entityQueryClassFile).doesNotExist();
16241624
}
1625+
1626+
@Test
1627+
void testMultimoduleFilteredClassifier()
1628+
throws MavenInvocationException, IOException {
1629+
testDir = initProject("projects/multimodule-filtered-classifier");
1630+
run(true);
1631+
assertThat(devModeClient.getHttpResponse("/")).isEqualTo("Big");
1632+
}
16251633
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>acme-parent</artifactId>
7+
<groupId>org.acme</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>acme-app</artifactId>
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.acme</groupId>
16+
<version>\${project.version}</version>
17+
<artifactId>acme-lib</artifactId>
18+
<classifier>shared</classifier>
19+
</dependency>
20+
</dependencies>
21+
<build>
22+
<plugins>
23+
<plugin>
24+
<groupId>\${quarkus.platform.group-id}</groupId>
25+
<artifactId>quarkus-maven-plugin</artifactId>
26+
<executions>
27+
<execution>
28+
<goals>
29+
<goal>build</goal>
30+
</goals>
31+
</execution>
32+
</executions>
33+
</plugin>
34+
</plugins>
35+
</build>
36+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.acme;
2+
3+
import org.acme.shared.BigBean;
4+
5+
import jakarta.inject.Inject;
6+
import jakarta.ws.rs.GET;
7+
import jakarta.ws.rs.Path;
8+
9+
@Path("/")
10+
public class App {
11+
12+
@Inject
13+
BigBean bean;
14+
15+
@GET
16+
public String get() {
17+
return bean.getName();
18+
}
19+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>acme-parent</artifactId>
7+
<groupId>org.acme</groupId>
8+
<version>1.0.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>acme-lib</artifactId>
13+
14+
</project>

0 commit comments

Comments
 (0)