Skip to content

Commit 9572200

Browse files
committed
Fix bootstrap when module is pointing to POM file directly
Also make sure the Map cache in WorkspaceLoader is consistently referencing the POM files. Note that I stumbled upon another limitation: the app artifact requires a strict pom.xml as assumptions are hardcoded in LocalProject#locateCurrentProjectPom(). I haven't fixed that one as it probably requires a lot more changes. I added a test to make sure we don't regress on this. Fixes #50571
1 parent 87ca3ec commit 9572200

File tree

16 files changed

+544
-13
lines changed

16 files changed

+544
-13
lines changed

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ private static Path locateCurrentProjectPom(Path path) throws BootstrapMavenExce
7777
}
7878

7979
private final Deque<WorkspaceModulePom> moduleQueue = new ConcurrentLinkedDeque<>();
80+
// Map key is the normalized absolute Path to the POM file
8081
private final Map<Path, Model> loadedPoms = new ConcurrentHashMap<>();
8182
private final Map<GAV, Model> loadedModules = new ConcurrentHashMap<>();
8283
private final Consumer<WorkspaceModulePom> modelProcessor;
@@ -194,19 +195,23 @@ private Consumer<WorkspaceModulePom> getModelProcessor(BootstrapMavenContext ctx
194195
currentProject = project;
195196
}
196197
for (var module : project.getEffectiveModel().getModules()) {
197-
addModulePom(project.getDir().resolve(module).resolve(POM_XML));
198+
Path modulePath = project.getDir().resolve(module);
199+
if (Files.isDirectory(modulePath)) {
200+
addModulePom(modulePath.resolve(POM_XML));
201+
} else {
202+
addModulePom(modulePath);
203+
}
198204
}
199205
};
200206
}
201207

202208
private void loadModule(WorkspaceModulePom rawModule, Collection<WorkspaceModulePom> newModules) {
203-
final Path moduleDir = rawModule.getModuleDir();
204-
if (loadedPoms.containsKey(moduleDir)) {
209+
if (loadedPoms.containsKey(rawModule.getPom())) {
205210
return;
206211
}
207212

208213
final Model model = rawModule.getModel();
209-
loadedPoms.put(moduleDir, model);
214+
loadedPoms.put(rawModule.getPom(), model);
210215
if (model == MISSING_MODEL) {
211216
return;
212217
}
@@ -238,21 +243,22 @@ private void loadModule(WorkspaceModulePom rawModule, Collection<WorkspaceModule
238243
if (rawModule.parent == null) {
239244
final Path parentPom = rawModule.getParentPom();
240245
if (parentPom != null) {
241-
var parentDir = parentPom.getParent();
242-
if (parentDir == null) {
243-
parentDir = getFsRootDir();
244-
}
245-
if (!loadedPoms.containsKey(parentDir)) {
246+
if (!loadedPoms.containsKey(parentPom)) {
246247
rawModule.parent = new WorkspaceModulePom(parentPom);
247248
moduleQueue.push(rawModule.parent);
248249
}
249250
}
250251
}
251252
}
252253

253-
private void queueModule(Path dir) {
254-
if (!loadedPoms.containsKey(dir)) {
255-
moduleQueue.push(new WorkspaceModulePom(dir.resolve(POM_XML)));
254+
private void queueModule(Path module) {
255+
Path pom = module.normalize().toAbsolutePath();
256+
if (Files.isDirectory(pom)) {
257+
pom = pom.resolve(POM_XML);
258+
}
259+
260+
if (!loadedPoms.containsKey(pom)) {
261+
moduleQueue.push(new WorkspaceModulePom(pom));
256262
}
257263
}
258264

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ public WorkspaceModulePom(Path pom, Model model, Model effectiveModel) {
2424
this.effectiveModel = effectiveModel;
2525
}
2626

27+
Path getPom() {
28+
return pom;
29+
}
30+
2731
Path getModuleDir() {
2832
var moduleDir = pom.getParent();
2933
return moduleDir == null ? WorkspaceLoader.getFsRootDir() : moduleDir;
@@ -50,7 +54,7 @@ Path getParentPom() {
5054
parentPom = parentDir.resolve(WorkspaceLoader.POM_XML);
5155
}
5256
}
53-
return parentPom != null && Files.exists(parentPom) ? parentPom : null;
57+
return parentPom != null && Files.exists(parentPom) ? parentPom.normalize().toAbsolutePath() : null;
5458
}
5559

5660
void process(Consumer<WorkspaceModulePom> consumer) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ void testFlattenMavenPlugin()
249249
build();
250250
}
251251

252+
@Test
253+
void testPomReference() throws Exception {
254+
testDir = initProject("projects/multimodule-pom-reference", "projects/project-with-pom-reference");
255+
running = new RunningInvoker(testDir, false);
256+
MavenProcessInvocationResult result = running
257+
.execute(List.of("clean", "package", "-Dquarkus.analytics.disabled=true"), Map.of());
258+
assertThat(result.getProcess().waitFor()).isZero();
259+
}
260+
252261
private void launch() throws IOException {
253262
launch(TestContext.FAST_NO_PREFIX, "", "hello, from foo");
254263
}
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>
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.acme</groupId>
7+
<artifactId>quarkus-quickstart-multimodule-parent</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<groupId>org.acme</groupId>
11+
<artifactId>quarkus-quickstart-multimodule-dependency</artifactId>
12+
<version>1.0-SNAPSHOT</version>
13+
14+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project>
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.acme</groupId>
7+
<artifactId>quarkus-quickstart-multimodule-parent</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
11+
<groupId>org.acme</groupId>
12+
<artifactId>quarkus-quickstart-multimodule-html</artifactId>
13+
<version>1.0-SNAPSHOT</version>
14+
<dependencies>
15+
<dependency>
16+
<groupId>org.junit.jupiter</groupId>
17+
<artifactId>junit-jupiter</artifactId>
18+
<version>5.8.2</version>
19+
</dependency>
20+
</dependencies>
21+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sadfasdfasdfas
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>getting-started - 1.0-SNAPSHOT</title>
6+
<style>
7+
h1, h2, h3, h4, h5, h6 {
8+
margin-bottom: 0.5rem;
9+
font-weight: 400;
10+
line-height: 1.5;
11+
}
12+
13+
h1 {
14+
font-size: 2.5rem;
15+
}
16+
17+
h2 {
18+
font-size: 2rem
19+
}
20+
21+
h3 {
22+
font-size: 1.75rem
23+
}
24+
25+
h4 {
26+
font-size: 1.5rem
27+
}
28+
29+
h5 {
30+
font-size: 1.25rem
31+
}
32+
33+
h6 {
34+
font-size: 1rem
35+
}
36+
37+
.lead {
38+
font-weight: 300;
39+
font-size: 2rem;
40+
}
41+
42+
.banner {
43+
font-size: 2.7rem;
44+
margin: 0;
45+
padding: 2rem 1rem;
46+
background-color: #00A1E2;
47+
color: white;
48+
}
49+
50+
body {
51+
margin: 0;
52+
font-family: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
53+
}
54+
55+
code {
56+
font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
57+
font-size: 87.5%;
58+
color: #e83e8c;
59+
word-break: break-word;
60+
}
61+
62+
.left-column {
63+
padding: .75rem;
64+
max-width: 75%;
65+
min-width: 55%;
66+
}
67+
68+
.right-column {
69+
padding: .75rem;
70+
max-width: 25%;
71+
}
72+
73+
.container {
74+
display: flex;
75+
width: 100%;
76+
}
77+
78+
li {
79+
margin: 0.75rem;
80+
}
81+
82+
.right-section {
83+
margin-left: 1rem;
84+
padding-left: 0.5rem;
85+
}
86+
87+
.right-section h3 {
88+
padding-top: 0;
89+
font-weight: 200;
90+
}
91+
92+
.right-section ul {
93+
border-left: 0.3rem solid #00A1E2;
94+
list-style-type: none;
95+
padding-left: 0;
96+
}
97+
98+
</style>
99+
</head>
100+
<body>
101+
102+
<div class="banner lead">
103+
Your new Cloud-Native a is ready!
104+
</div>
105+
106+
<div class="container">
107+
<div class="left-column">
108+
<p class="lead"> Congratulations, you have created a new Quarkus application.</p>
109+
110+
<h2>Why do you see this?</h2>
111+
112+
<p>This page is served by Quarkus. The source is in
113+
<code>src/main/resources/META-INF/resources/index.html</code>.</p>
114+
115+
<h2>What can I do from here?</h2>
116+
117+
<p>If not already done, run the application in <em>dev mode</em> using: <code>mvn quarkus:dev</code>.
118+
</p>
119+
<ul>
120+
<li>Add REST resources, Servlets, functions and other services in <code>src/main/java</code>.</li>
121+
<li>Your static assets are located in <code>src/main/resources/META-INF/resources</code>.</li>
122+
<li>Configure your application in <code>src/main/resources/META-INF/microprofile-config.properties</code>.
123+
</li>
124+
</ul>
125+
126+
<h2>Do you like Quarkus?</h2>
127+
<p>Go give it a star on <a href="https://github.com/quarkusio/quarkus">GitHub</a>.</p>
128+
129+
<h2>How do I get rid of this page?</h2>
130+
<p>Just delete the <code>src/main/resources/META-INF/resources/index.html</code> file.</p>
131+
</div>
132+
<div class="right-column">
133+
<div class="right-section">
134+
<h3>Application</h3>
135+
<ul>
136+
<li>GroupId: org.acme</li>
137+
<li>ArtifactId: getting-started</li>
138+
<li>Version: 1.0-SNAPSHOT</li>
139+
<li>Quarkus Version: 0.11.0</li>
140+
</ul>
141+
</div>
142+
<div class="right-section">
143+
<h3>Next steps</h3>
144+
<ul>
145+
<li><a href="https://quarkus.io/guides/maven-tooling">Setup your IDE</a></li>
146+
<li><a href="https://quarkus.io/guides/getting-started">Getting started</a></li>
147+
<li><a href="https://quarkus.io">Quarkus Web Site</a></li>
148+
</ul>
149+
</div>
150+
</div>
151+
</div>
152+
153+
154+
</body>
155+
</html>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0"?>
2+
<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"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>org.acme</groupId>
7+
<artifactId>quarkus-quickstart-multimodule-parent</artifactId>
8+
<version>1.0-SNAPSHOT</version>
9+
<packaging>pom</packaging>
10+
11+
<properties>
12+
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
13+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
14+
<quarkus.platform.version>@project.version@</quarkus.platform.version>
15+
<quarkus-plugin.version>@project.version@</quarkus-plugin.version>
16+
<compiler-plugin.version>${compiler-plugin.version}</compiler-plugin.version>
17+
<surefire-plugin.version>${version.surefire.plugin}</surefire-plugin.version>
18+
<maven.compiler.source>${maven.compiler.source}</maven.compiler.source>
19+
<maven.compiler.target>${maven.compiler.target}</maven.compiler.target>
20+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
21+
</properties>
22+
<modules>
23+
<module>dependency/specific-pom.xml</module>
24+
<module>rest</module>
25+
<module>html</module>
26+
<module>runner</module>
27+
</modules>
28+
29+
<build>
30+
<pluginManagement>
31+
<plugins>
32+
<plugin>
33+
<artifactId>maven-compiler-plugin</artifactId>
34+
<version>\${compiler-plugin.version}</version>
35+
<configuration>
36+
<parameters>true</parameters>
37+
</configuration>
38+
</plugin>
39+
<plugin>
40+
<groupId>io.quarkus</groupId>
41+
<artifactId>quarkus-maven-plugin</artifactId>
42+
<version>\${quarkus-plugin.version}</version>
43+
</plugin>
44+
</plugins>
45+
</pluginManagement>
46+
</build>
47+
48+
<dependencyManagement>
49+
<dependencies>
50+
<dependency>
51+
<groupId>\${quarkus.platform.group-id}</groupId>
52+
<artifactId>\${quarkus.platform.artifact-id}</artifactId>
53+
<version>\${quarkus.platform.version}</version>
54+
<type>pom</type>
55+
<scope>import</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>org.acme</groupId>
59+
<artifactId>quarkus-quickstart-multimodule-html</artifactId>
60+
<version>1.0-SNAPSHOT</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.acme</groupId>
64+
<artifactId>quarkus-quickstart-multimodule-rest</artifactId>
65+
<version>1.0-SNAPSHOT</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.acme</groupId>
69+
<artifactId>quarkus-quickstart-multimodule-dependency</artifactId>
70+
<version>1.0-SNAPSHOT</version>
71+
</dependency>
72+
</dependencies>
73+
</dependencyManagement>
74+
75+
</project>

0 commit comments

Comments
 (0)