diff --git a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java
index 7f67b15db7823f..c559521ba13642 100644
--- a/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java
+++ b/devtools/maven/src/main/java/io/quarkus/maven/CreateProjectMojo.java
@@ -331,8 +331,8 @@ public void execute() throws MojoExecutionException {
parent.setArtifactId(parentPomModel.getArtifactId());
parent.setVersion(parentPomModel.getVersion());
subModulePomModel.setParent(parent);
- MojoUtils.write(parentPomModel, pom);
- MojoUtils.write(subModulePomModel, subModulePomFile);
+ MojoUtils.writeFormatted(parentPomModel, pom);
+ MojoUtils.writeFormatted(subModulePomModel, subModulePomFile);
}
} catch (Exception e) {
throw new MojoExecutionException("Failed to generate Quarkus project", e);
diff --git a/docs/pom.xml b/docs/pom.xml
index 3994c55bdf11c0..715999890372b7 100644
--- a/docs/pom.xml
+++ b/docs/pom.xml
@@ -27,7 +27,7 @@
1.5.0-beta.8
WARN
2.26.0.Final
- 28
+ 33
11.1.0
6.9.0.202403050737-r
diff --git a/independent-projects/bootstrap/bom/pom.xml b/independent-projects/bootstrap/bom/pom.xml
index 5db6112b194ad2..10504e6d084e3f 100644
--- a/independent-projects/bootstrap/bom/pom.xml
+++ b/independent-projects/bootstrap/bom/pom.xml
@@ -481,6 +481,11 @@
+
+ io.fabric8
+ maven-model-helper
+ ${maven-model-helper.version}
+
io.smallrye.common
diff --git a/independent-projects/bootstrap/maven-resolver/pom.xml b/independent-projects/bootstrap/maven-resolver/pom.xml
index 97ce31340034ce..b6c21737f4c898 100644
--- a/independent-projects/bootstrap/maven-resolver/pom.xml
+++ b/independent-projects/bootstrap/maven-resolver/pom.xml
@@ -125,6 +125,10 @@
+
+ io.fabric8
+ maven-model-helper
+
org.junit.jupiter
junit-jupiter
diff --git a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtils.java b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtils.java
index 30459be661365b..9786fbb004fc0c 100644
--- a/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtils.java
+++ b/independent-projects/bootstrap/maven-resolver/src/main/java/io/quarkus/bootstrap/resolver/maven/workspace/ModelUtils.java
@@ -1,9 +1,9 @@
package io.quarkus.bootstrap.resolver.maven.workspace;
import java.io.BufferedReader;
-import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UncheckedIOException;
import java.nio.file.DirectoryStream;
import java.nio.file.FileSystem;
import java.nio.file.Files;
@@ -16,10 +16,9 @@
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import io.fabric8.maven.Maven;
+import io.fabric8.maven.XMLFormat;
import io.quarkus.bootstrap.util.PropertyUtils;
import io.quarkus.fs.util.ZipUtils;
import io.quarkus.maven.dependency.ArtifactCoords;
@@ -28,7 +27,6 @@
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
/**
- *
* @author Alexey Loubyansky
*/
public class ModelUtils {
@@ -182,7 +180,7 @@ public static String resolveVersion(String rawVersion, Model rawModel) {
putAll(props, System.getProperties());
Matcher matcher = getUnresolvedVersionPattern().matcher(rawVersion);
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
while (matcher.find()) {
final String resolved = props.get(matcher.group(1));
if (resolved == null) {
@@ -233,21 +231,30 @@ private static Properties loadPomProps(Path appJar, Path artifactIdPath) throws
}
public static Model readModel(final Path pomXml) throws IOException {
- return readModel(Files.newInputStream(pomXml));
+ try {
+ return Maven.readModel(pomXml);
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ } catch (RuntimeException e) {
+ throw new IOException("Failed to read model", e.getCause());
+ }
}
public static Model readModel(InputStream stream) throws IOException {
try (InputStream is = stream) {
- return new MavenXpp3Reader().read(stream);
- } catch (XmlPullParserException e) {
- throw new IOException("Failed to parse POM", e);
+ return Maven.readModel(is);
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ } catch (RuntimeException e) {
+ throw new IOException("Failed to read model", e.getCause());
}
}
public static void persistModel(Path pomFile, Model model) throws IOException {
- final MavenXpp3Writer xpp3Writer = new MavenXpp3Writer();
- try (BufferedWriter pomFileWriter = Files.newBufferedWriter(pomFile)) {
- xpp3Writer.write(pomFileWriter, model);
+ try {
+ Maven.writeModel(model, pomFile, XMLFormat.builder().indent(" ").insertLineBreakBetweenMajorSections().build());
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
}
}
}
diff --git a/independent-projects/bootstrap/pom.xml b/independent-projects/bootstrap/pom.xml
index 61ce4ff6a66a37..a629abaffd04d3 100644
--- a/independent-projects/bootstrap/pom.xml
+++ b/independent-projects/bootstrap/pom.xml
@@ -80,6 +80,7 @@
0.1.3
2.23.0
1.9.0
+ 33
bom
diff --git a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java
index 393e198361cbbc..b309cd3dbdafb2 100644
--- a/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java
+++ b/independent-projects/tools/codestarts/src/main/java/io/quarkus/devtools/codestarts/core/strategy/SmartPomMergeCodestartFileStrategyHandler.java
@@ -11,6 +11,7 @@
import org.apache.maven.model.Model;
import io.fabric8.maven.Maven;
+import io.fabric8.maven.XMLFormat;
import io.fabric8.maven.merge.SmartModelMerger;
import io.quarkus.devtools.codestarts.CodestartException;
import io.quarkus.devtools.codestarts.core.CodestartData;
@@ -41,6 +42,7 @@ public void process(Path targetDirectory, String relativePath, List
while (iterator.hasNext()) {
merger.merge(targetModel, Maven.readModel(new StringReader(iterator.next().getContent())), true, null);
}
- Maven.writeModel(targetModel, targetPath);
+ Maven.writeModel(targetModel, targetPath,
+ XMLFormat.builder().indent(" ").insertLineBreakBetweenMajorSections().build());
}
}
diff --git a/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml b/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml
index 77caeee071c278..283479a769639f 100644
--- a/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml
+++ b/independent-projects/tools/codestarts/src/test/resources/expected-pom-maven-merge.xml
@@ -1,22 +1,23 @@
-
-
- 4.0.0
- org.toto
- quarkus-project
- 1.2.3
-
- 123
- pineapple
- proppp
- prop-2-namespaced
- starts-with-z
-
-
-
- io.b
- b
- 0.1
-
-
+
+
+ 4.0.0
+ org.toto
+ quarkus-project
+ 1.2.3
+
+
+ 123
+ pineapple
+ proppp
+ prop-2-namespaced
+ starts-with-z
+
+
+
+
+ io.b
+ b
+ 0.1
+
+
diff --git a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java
index 089e63a1e45e51..e7a33a355a384a 100644
--- a/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java
+++ b/independent-projects/tools/devtools-common/src/main/java/io/quarkus/maven/utilities/MojoUtils.java
@@ -2,28 +2,33 @@
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.*;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+import java.util.Scanner;
import org.apache.maven.cli.transfer.QuietMavenTransferListener;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
-import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
-import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
+import org.codehaus.plexus.util.WriterFactory;
+import org.codehaus.plexus.util.xml.XmlStreamWriter;
import org.codehaus.plexus.util.xml.Xpp3Dom;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.RepositorySystemSession;
+import io.fabric8.maven.Maven;
+import io.fabric8.maven.XMLFormat;
+
/**
* @author kameshs
*/
@@ -161,14 +166,22 @@ public static Plugin plugin(String groupId, String artifactId, String version, L
}
public static Model readPom(final File pom) throws IOException {
- return readPom(new FileInputStream(pom));
+ try {
+ return Maven.readModel(pom.toPath());
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ } catch (RuntimeException e) {
+ throw new IOException("Failed to read model", e.getCause());
+ }
}
public static Model readPom(final InputStream resourceAsStream) throws IOException {
- try (InputStream stream = resourceAsStream) {
- return new MavenXpp3Reader().read(stream);
- } catch (XmlPullParserException e) {
- throw new IOException(e.getMessage(), e);
+ try (InputStream is = resourceAsStream) {
+ return Maven.readModel(is);
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ } catch (RuntimeException e) {
+ throw new IOException("Failed to read model", e.getCause());
}
}
@@ -178,8 +191,20 @@ public static String[] readGavFromPom(final InputStream resourceAsStream) throws
}
public static void write(Model model, File outputFile) throws IOException {
- FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
- write(model, fileOutputStream);
+ try {
+ Maven.writeModel(model, outputFile.toPath());
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ }
+ }
+
+ public static void writeFormatted(Model model, File outputFile) throws IOException {
+ try {
+ Maven.writeModel(model, outputFile.toPath(),
+ XMLFormat.builder().indent(" ").insertLineBreakBetweenMajorSections().build());
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
+ }
}
public static void write(Model model, OutputStream fileOutputStream) throws IOException {
@@ -190,8 +215,10 @@ public static void write(Model model, OutputStream fileOutputStream) throws IOEx
sorted.putAll(props);
model.setProperties(sorted);
}
- try (OutputStream stream = fileOutputStream) {
- new MavenXpp3Writer().write(stream, model);
+ try (XmlStreamWriter writer = WriterFactory.newXmlWriter(fileOutputStream)) {
+ Maven.writeModel(model, writer);
+ } catch (UncheckedIOException e) {
+ throw e.getCause();
}
}
diff --git a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java
index a27f7f059c483a..722ac60e605613 100644
--- a/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java
+++ b/independent-projects/tools/devtools-testing/src/test/java/io/quarkus/devtools/codestarts/quarkus/QuarkusCodestartGenerationTest.java
@@ -101,15 +101,15 @@ void generateMavenWithCustomDep(TestInfo testInfo) throws Throwable {
checkMaven(projectDir);
assertThatMatchSnapshot(testInfo, projectDir, "pom.xml")
.satisfies(checkContains("\n" +
- " commons-io\n" +
- " commons-io\n" +
- " 2.5\n" +
- " \n"))
+ " io.quarkus\n" +
+ " quarkus-resteasy\n" +
+ " 1.8\n" +
+ " "))
.satisfies(checkContains("\n" +
- " io.quarkus\n" +
- " quarkus-resteasy\n" +
- " 1.8\n" +
- " \n"));
+ " io.quarkus\n" +
+ " quarkus-resteasy\n" +
+ " 1.8\n" +
+ " "));
}
@Test
diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateDefault/pom.xml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateDefault/pom.xml
index 28937572322efc..2a1dabdf5f1547 100644
--- a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateDefault/pom.xml
+++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateDefault/pom.xml
@@ -1,112 +1,116 @@
-
-
- 4.0.0
- org.test
- test-codestart
- 1.0.0-codestart
-
- 3.8.1-MOCK
- 17
- UTF-8
- UTF-8
- quarkus-mock-bom
- io.quarkus
- 999-MOCK
- true
- 3.0.0-MOCK
-
-
+
+
+ 4.0.0
+ org.test
+ test-codestart
+ 1.0.0-codestart
+
+
+ 3.8.1-MOCK
+ 17
+ UTF-8
+ UTF-8
+ quarkus-mock-bom
+ io.quarkus
+ 999-MOCK
+ true
+ 3.0.0-MOCK
+
+
+
+
+
+ ${quarkus.platform.group-id}
+ ${quarkus.platform.artifact-id}
+ ${quarkus.platform.version}
+ pom
+ import
+
+
+
+
-
- ${quarkus.platform.group-id}
- ${quarkus.platform.artifact-id}
- ${quarkus.platform.version}
- pom
- import
-
+
+ io.quarkus
+ quarkus-arc
+
+
+ io.quarkus
+ quarkus-junit5
+ test
+
-
-
-
- io.quarkus
- quarkus-arc
-
-
- io.quarkus
- quarkus-junit5
- test
-
-
-
-
-
- ${quarkus.platform.group-id}
- quarkus-mock-maven-plugin
- ${quarkus.platform.version}
- true
-
-
-
- build
- generate-code
- generate-code-tests
-
-
-
-
-
- maven-compiler-plugin
- ${compiler-plugin.version}
-
-
- -parameters
-
-
-
-
- maven-surefire-plugin
- ${surefire-plugin.version}
-
-
- org.jboss.logmanager.LogManager
- ${maven.home}
-
-
-
-
- maven-failsafe-plugin
- ${surefire-plugin.version}
-
-
-
- integration-test
- verify
-
-
-
-
-
- ${project.build.directory}/${project.build.finalName}-runner
- org.jboss.logmanager.LogManager
- ${maven.home}
-
-
-
-
-
-
-
- native
-
-
- native
-
-
-
- false
- native
-
-
-
+
+
+
+
+ ${quarkus.platform.group-id}
+ quarkus-mock-maven-plugin
+ ${quarkus.platform.version}
+ true
+
+
+
+ build
+ generate-code
+ generate-code-tests
+
+
+
+
+
+ maven-compiler-plugin
+ ${compiler-plugin.version}
+
+
+ -parameters
+
+
+
+
+ maven-surefire-plugin
+ ${surefire-plugin.version}
+
+
+ org.jboss.logmanager.LogManager
+ ${maven.home}
+
+
+
+
+ maven-failsafe-plugin
+ ${surefire-plugin.version}
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+ ${project.build.directory}/${project.build.finalName}-runner
+ org.jboss.logmanager.LogManager
+ ${maven.home}
+
+
+
+
+
+
+
+
+ native
+
+
+ native
+
+
+
+ false
+ native
+
+
+
diff --git a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml
index 6abb5fb8568747..7878ba46f70f46 100644
--- a/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml
+++ b/independent-projects/tools/devtools-testing/src/test/resources/__snapshots__/QuarkusCodestartGenerationTest/generateMavenWithCustomDep/pom.xml
@@ -1,127 +1,131 @@
-
-
- 4.0.0
- org.test
- test-codestart
- 1.0.0-codestart
-
- 3.8.1-MOCK
- 17
- UTF-8
- UTF-8
- quarkus-mock-bom
- io.quarkus
- 999-MOCK
- true
- 3.0.0-MOCK
-
-
+
+
+ 4.0.0
+ org.test
+ test-codestart
+ 1.0.0-codestart
+
+
+ 3.8.1-MOCK
+ 17
+ UTF-8
+ UTF-8
+ quarkus-mock-bom
+ io.quarkus
+ 999-MOCK
+ true
+ 3.0.0-MOCK
+
+
+
+
+
+ ${quarkus.platform.group-id}
+ ${quarkus.platform.artifact-id}
+ ${quarkus.platform.version}
+ pom
+ import
+
+
+
+
-
- ${quarkus.platform.group-id}
- ${quarkus.platform.artifact-id}
- ${quarkus.platform.version}
- pom
- import
-
+
+ io.quarkus
+ quarkus-resteasy
+ 1.8
+
+
+ commons-io
+ commons-io
+ 2.5
+
+
+ io.quarkus
+ quarkus-arc
+
+
+ io.quarkus
+ quarkus-junit5
+ test
+
+
+ io.rest-assured
+ rest-assured
+ test
+
-
-
-
- io.quarkus
- quarkus-resteasy
- 1.8
-
-
- commons-io
- commons-io
- 2.5
-
-
- io.quarkus
- quarkus-arc
-
-
- io.quarkus
- quarkus-junit5
- test
-
-
- io.rest-assured
- rest-assured
- test
-
-
-
-
-
- ${quarkus.platform.group-id}
- quarkus-mock-maven-plugin
- ${quarkus.platform.version}
- true
-
-
-
- build
- generate-code
- generate-code-tests
-
-
-
-
-
- maven-compiler-plugin
- ${compiler-plugin.version}
-
-
- -parameters
-
-
-
-
- maven-surefire-plugin
- ${surefire-plugin.version}
-
-
- org.jboss.logmanager.LogManager
- ${maven.home}
-
-
-
-
- maven-failsafe-plugin
- ${surefire-plugin.version}
-
-
-
- integration-test
- verify
-
-
-
-
-
- ${project.build.directory}/${project.build.finalName}-runner
- org.jboss.logmanager.LogManager
- ${maven.home}
-
-
-
-
-
-
-
- native
-
-
- native
-
-
-
- false
- native
-
-
-
+
+
+
+
+ ${quarkus.platform.group-id}
+ quarkus-mock-maven-plugin
+ ${quarkus.platform.version}
+ true
+
+
+
+ build
+ generate-code
+ generate-code-tests
+
+
+
+
+
+ maven-compiler-plugin
+ ${compiler-plugin.version}
+
+
+ -parameters
+
+
+
+
+ maven-surefire-plugin
+ ${surefire-plugin.version}
+
+
+ org.jboss.logmanager.LogManager
+ ${maven.home}
+
+
+
+
+ maven-failsafe-plugin
+ ${surefire-plugin.version}
+
+
+
+ integration-test
+ verify
+
+
+
+
+
+ ${project.build.directory}/${project.build.finalName}-runner
+ org.jboss.logmanager.LogManager
+ ${maven.home}
+
+
+
+
+
+
+
+
+ native
+
+
+ native
+
+
+
+ false
+ native
+
+
+
diff --git a/independent-projects/tools/pom.xml b/independent-projects/tools/pom.xml
index 6691a639a1b1af..e2f4ab836aa643 100644
--- a/independent-projects/tools/pom.xml
+++ b/independent-projects/tools/pom.xml
@@ -58,7 +58,7 @@
3.2.1
3.2.5
${project.version}
- 28
+ 33
3.1.7
2.0.2
4.2.0