From d115f7a76cd72487ebabbba9ba5d4ae4b75544f2 Mon Sep 17 00:00:00 2001
From: "Andrzej J." <1554729+andrzejj0@users.noreply.github.com>
Date: Sat, 9 Nov 2024 09:57:32 +0100
Subject: [PATCH] Moved to modello-stax. Removed "versionDefinition" from
rule.mdo. (#1176)
---
versions-common/pom.xml | 5 +++--
.../versions/api/DefaultVersionsHelper.java | 18 +++++++++-------
.../versions/utils/CoreExtensionUtils.java | 11 +++++-----
.../mojo/versions/utils/RegexUtils.java | 11 +++++-----
.../utils/CoreExtensionUtilsTest.java | 7 ++++---
.../org/codehaus/mojo/versions/api/rules.xml | 4 +---
versions-maven-plugin/pom.xml | 4 ----
.../versions/DisplayExtensionUpdatesMojo.java | 3 +--
.../DependencyUpdatesXmlReportRenderer.java | 8 ++++---
.../xml/PluginUpdatesXmlReportRenderer.java | 8 ++++---
.../xml/PropertyUpdatesXmlReportRenderer.java | 8 ++++---
versions-model-report/pom.xml | 15 +++----------
versions-model/pom.xml | 21 ++++++++++---------
versions-model/src/main/mdo/rule.mdo | 3 ---
14 files changed, 59 insertions(+), 67 deletions(-)
diff --git a/versions-common/pom.xml b/versions-common/pom.xml
index 6de36a288d..d779e8e93d 100644
--- a/versions-common/pom.xml
+++ b/versions-common/pom.xml
@@ -144,12 +144,13 @@
src/main/mdo/core-extensions.mdo
1.1.0
+ false
generate-java-classes
- xpp3-reader
+ stax-reader
java
generate-sources
@@ -166,7 +167,7 @@
org.codehaus.mojo.versions.model,
- org.codehaus.mojo.versions.model.io.xpp3,
+ org.codehaus.mojo.versions.model.io.stax,
org.codehaus.mojo.versions.utils
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
index edb5309f0e..8f74bb7718 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java
@@ -19,9 +19,12 @@
* under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
@@ -75,7 +78,7 @@
import org.codehaus.mojo.versions.model.IgnoreVersion;
import org.codehaus.mojo.versions.model.Rule;
import org.codehaus.mojo.versions.model.RuleSet;
-import org.codehaus.mojo.versions.model.io.xpp3.RuleXpp3Reader;
+import org.codehaus.mojo.versions.model.io.stax.RuleStaxReader;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.codehaus.mojo.versions.ordering.VersionComparators;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
@@ -85,7 +88,6 @@
import org.codehaus.mojo.versions.utils.VersionsExpressionEvaluator;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.repository.AuthenticationContext;
import org.eclipse.aether.repository.RemoteRepository;
@@ -101,6 +103,7 @@
import static java.util.Optional.of;
import static java.util.Optional.ofNullable;
import static org.apache.maven.RepositoryUtils.toArtifact;
+;
/**
* Helper class that provides common functionality required by both the mojos and the reports.
@@ -740,10 +743,10 @@ private static RuleSet getRulesFromClasspath(String uri, Log logger) throws Mojo
}
try (BufferedInputStream bis = new BufferedInputStream(url.openStream())) {
- RuleSet result = new RuleXpp3Reader().read(bis);
+ RuleSet result = new RuleStaxReader().read(bis);
logger.debug("Loaded rules from \"" + uri + "\" successfully");
return result;
- } catch (IOException | XmlPullParserException e) {
+ } catch (IOException | XMLStreamException e) {
throw new MojoExecutionException("Could not load specified rules from " + uri, e);
}
}
@@ -905,8 +908,8 @@ private RuleSet getRulesUsingWagon() throws MojoExecutionException {
try {
Path tempFile = Files.createTempFile("rules-", ".xml");
wagon.get(uri.resource, tempFile.toFile());
- try (BufferedInputStream is = new BufferedInputStream(Files.newInputStream(tempFile))) {
- return new RuleXpp3Reader().read(is);
+ try (InputStream is = Files.newInputStream(tempFile)) {
+ return new RuleStaxReader().read(is);
} finally {
Files.deleteIfExists(tempFile);
}
@@ -915,8 +918,7 @@ private RuleSet getRulesUsingWagon() throws MojoExecutionException {
wagon.disconnect();
}
} catch (Exception e) {
- log.warn(e.getMessage());
- return null;
+ throw new RuntimeException(e);
}
})
.orElseThrow(() -> new MojoExecutionException("Could not load specified rules from " + rulesUri));
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
index 64564dfe56..8affa2a428 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java
@@ -16,6 +16,8 @@
* limitations under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -26,8 +28,7 @@
import org.apache.maven.model.Extension;
import org.apache.maven.project.MavenProject;
-import org.codehaus.mojo.versions.model.io.xpp3.CoreExtensionsXpp3Reader;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.codehaus.mojo.versions.model.io.stax.CoreExtensionsStaxReader;
/**
* Utilities for reading and handling core extensions.
@@ -43,17 +44,17 @@ public final class CoreExtensionUtils {
* @param project {@link MavenProject} instance
* @return stream of core extensions defined in the {@code ${project}/.mvn/extensions.xml} file
* @throws IOException thrown if a file I/O operation fails
- * @throws XmlPullParserException thrown if the file cannot be parsed
+ * @throws XMLStreamException thrown if the file cannot be parsed
* @since 2.15.0
*/
- public static Stream getCoreExtensions(MavenProject project) throws IOException, XmlPullParserException {
+ public static Stream getCoreExtensions(MavenProject project) throws IOException, XMLStreamException {
Path extensionsFile = project.getBasedir().toPath().resolve(".mvn/extensions.xml");
if (!Files.isRegularFile(extensionsFile)) {
return Stream.empty();
}
try (Reader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(extensionsFile)))) {
- return new CoreExtensionsXpp3Reader()
+ return new CoreExtensionsStaxReader()
.read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder()
.withGroupId(ex.getGroupId())
.withArtifactId(ex.getArtifactId())
diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/RegexUtils.java b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/RegexUtils.java
index b6f5081ead..014996ee69 100644
--- a/versions-common/src/main/java/org/codehaus/mojo/versions/utils/RegexUtils.java
+++ b/versions-common/src/main/java/org/codehaus/mojo/versions/utils/RegexUtils.java
@@ -19,6 +19,8 @@
* under the License.
*/
+import static java.util.Optional.ofNullable;
+
/**
* Utility methods to help with regex manipulation.
*
@@ -105,23 +107,21 @@ public static int getWildcardScore(String wildcardRule) {
/**
* Converts a wildcard rule to a regex rule.
*
- * @param wildcardRule the wildcard rule.
+ * @param wildcardRule the wildcard rule, may be {@code null}
* @param exactMatch true
results in an regex that will match the entire string, while
* false
will match the start of the string.
* @return The regex rule.
*/
public static String convertWildcardsToRegex(String wildcardRule, boolean exactMatch) {
StringBuilder regex = new StringBuilder();
- int index = 0;
- final int len = wildcardRule.length();
- while (index < len) {
+ final int wildcardLength = ofNullable(wildcardRule).map(String::length).orElse(0);
+ for (int index = 0, nextIndex = 0; index < wildcardLength; index = nextIndex + 1) {
final int nextQ = wildcardRule.indexOf('?', index);
final int nextS = wildcardRule.indexOf('*', index);
if (nextQ == -1 && nextS == -1) {
regex.append(quote(wildcardRule.substring(index)));
break;
}
- int nextIndex;
if (nextQ == -1) {
nextIndex = nextS;
} else if (nextS == -1) {
@@ -139,7 +139,6 @@ public static String convertWildcardsToRegex(String wildcardRule, boolean exactM
} else {
regex.append(".*");
}
- index = nextIndex + 1;
}
if (!exactMatch) {
regex.append(".*");
diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java
index 7af0c343c2..9507567e8f 100644
--- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java
+++ b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java
@@ -15,6 +15,8 @@
* limitations under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.File;
import java.io.IOException;
import java.util.Optional;
@@ -24,7 +26,6 @@
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Extension;
import org.apache.maven.project.MavenProject;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,7 +42,7 @@
class CoreExtensionUtilsTest {
@Test
- void testNoExtensions() throws XmlPullParserException, IOException {
+ void testNoExtensions() throws IOException, XMLStreamException {
MavenProject project = mock(MavenProject.class);
when(project.getBasedir())
.thenReturn(
@@ -52,7 +53,7 @@ void testNoExtensions() throws XmlPullParserException, IOException {
}
@Test
- void testExtensionsFound() throws XmlPullParserException, IOException {
+ void testExtensionsFound() throws IOException, XMLStreamException {
MavenProject project = mock(MavenProject.class);
when(project.getBasedir())
.thenReturn(new File("src/test/resources/org/codehaus/mojo/versions/utils/core-extensions"));
diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/api/rules.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/api/rules.xml
index 7efd3bff88..24ed244f73 100644
--- a/versions-common/src/test/resources/org/codehaus/mojo/versions/api/rules.xml
+++ b/versions-common/src/test/resources/org/codehaus/mojo/versions/api/rules.xml
@@ -1,6 +1,4 @@
-
+
.*-alpha
.*-beta
diff --git a/versions-maven-plugin/pom.xml b/versions-maven-plugin/pom.xml
index a780bb44dd..7aa9e13edd 100644
--- a/versions-maven-plugin/pom.xml
+++ b/versions-maven-plugin/pom.xml
@@ -160,10 +160,6 @@
org.codehaus.plexus
plexus-utils
-
- org.codehaus.plexus
- plexus-xml
-
javax.inject
javax.inject
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayExtensionUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayExtensionUpdatesMojo.java
index efdfe89660..503b04be78 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayExtensionUpdatesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayExtensionUpdatesMojo.java
@@ -57,7 +57,6 @@
import org.codehaus.mojo.versions.utils.ExtensionBuilder;
import org.codehaus.mojo.versions.utils.ModelNode;
import org.codehaus.mojo.versions.utils.SegmentUtils;
-import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.eclipse.aether.RepositorySystem;
import static java.util.Optional.of;
@@ -252,7 +251,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
.filter(includeFilter::matchersMatch)
.filter(excludeFilter::matchersDontMatch)
.collect(Collectors.toSet());
- } catch (IOException | XmlPullParserException e) {
+ } catch (IOException | XMLStreamException e) {
throw new MojoExecutionException(e.getMessage());
}
if (dependencies.isEmpty()) {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java
index 8cdec4a6ac..b9ba455cbe 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java
@@ -19,6 +19,8 @@
* under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -38,7 +40,7 @@
import org.codehaus.mojo.versions.reporting.model.DependencyReportSummary;
import org.codehaus.mojo.versions.reporting.model.DependencyUpdatesModel;
import org.codehaus.mojo.versions.reporting.model.DependencyUpdatesReport;
-import org.codehaus.mojo.versions.reporting.model.io.xpp3.DependencyUpdatesReportXpp3Writer;
+import org.codehaus.mojo.versions.reporting.model.io.stax.DependencyUpdatesReportStaxWriter;
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
import static java.util.Optional.empty;
@@ -91,7 +93,7 @@ public String getTitle() {
@Override
public void render() {
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
- new DependencyUpdatesReportXpp3Writer().write(writer, new DependencyUpdatesReport() {
+ new DependencyUpdatesReportStaxWriter().write(writer, new DependencyUpdatesReport() {
{
setSummary(new DependencyReportSummary() {
{
@@ -109,7 +111,7 @@ public void render() {
setDependencies(createDependencyInfo(model.getArtifactUpdates(), isAllowSnapshots()));
}
});
- } catch (IOException e) {
+ } catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java
index 7aac9e16a9..da549b72fc 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java
@@ -19,6 +19,8 @@
* under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -38,7 +40,7 @@
import org.codehaus.mojo.versions.reporting.model.PluginReportSummary;
import org.codehaus.mojo.versions.reporting.model.PluginUpdatesModel;
import org.codehaus.mojo.versions.reporting.model.PluginUpdatesReport;
-import org.codehaus.mojo.versions.reporting.model.io.xpp3.PluginUpdatesReportXpp3Writer;
+import org.codehaus.mojo.versions.reporting.model.io.stax.PluginUpdatesReportStaxWriter;
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
import static java.util.Optional.empty;
@@ -91,7 +93,7 @@ public boolean isAllowSnapshots() {
@Override
public void render() {
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
- new PluginUpdatesReportXpp3Writer().write(writer, new PluginUpdatesReport() {
+ new PluginUpdatesReportStaxWriter().write(writer, new PluginUpdatesReport() {
{
setSummary(new PluginReportSummary() {
{
@@ -109,7 +111,7 @@ public void render() {
setPlugins(createPluginInfo(model.getArtifactUpdates(), isAllowSnapshots()));
}
});
- } catch (IOException e) {
+ } catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java
index 710e2596f4..afca1e3d75 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java
@@ -19,6 +19,8 @@
* under the License.
*/
+import javax.xml.stream.XMLStreamException;
+
import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -40,7 +42,7 @@
import org.codehaus.mojo.versions.reporting.model.PropertyReportSummary;
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesModel;
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesReport;
-import org.codehaus.mojo.versions.reporting.model.io.xpp3.PropertyUpdatesReportXpp3Writer;
+import org.codehaus.mojo.versions.reporting.model.io.stax.PropertyUpdatesReportStaxWriter;
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
import static java.util.Optional.empty;
@@ -89,7 +91,7 @@ public String getTitle() {
@Override
public void render() {
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
- new PropertyUpdatesReportXpp3Writer().write(writer, new PropertyUpdatesReport() {
+ new PropertyUpdatesReportStaxWriter().write(writer, new PropertyUpdatesReport() {
{
setSummary(new PropertyReportSummary() {
{
@@ -105,7 +107,7 @@ public void render() {
setProperties(createPropertyInfo(model.getAllUpdates(), allowSnapshots));
}
});
- } catch (IOException e) {
+ } catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
diff --git a/versions-model-report/pom.xml b/versions-model-report/pom.xml
index f1ee87f448..a620d2ad7d 100644
--- a/versions-model-report/pom.xml
+++ b/versions-model-report/pom.xml
@@ -12,13 +12,6 @@
Versions Model Report
Modello models used in reports
-
-
- org.codehaus.plexus
- plexus-xml
-
-
-
@@ -31,16 +24,14 @@
src/main/mdo/property-updates-report.mdo
${modelloNamespaceReportVersion}
+ false
generate-rule
-
- xpp3-reader
-
- xpp3-writer
-
+ stax-reader
+ stax-writer
java
generate-sources
diff --git a/versions-model/pom.xml b/versions-model/pom.xml
index bd4dacb929..7f313f70af 100644
--- a/versions-model/pom.xml
+++ b/versions-model/pom.xml
@@ -12,14 +12,16 @@
Versions Model
Modello models used in plugin
-
-
- org.codehaus.plexus
- plexus-xml
-
-
-
+
+
+ true
+ ${project.basedir}/src/main/mdo
+
+ *.mdo
+
+
+
org.codehaus.modello
@@ -29,14 +31,13 @@
src/main/mdo/rule.mdo
${modelloNamespaceRuleVersion}
+ false
generate-rule
-
- xpp3-reader
-
+ stax-reader
java
generate-sources
diff --git a/versions-model/src/main/mdo/rule.mdo b/versions-model/src/main/mdo/rule.mdo
index eccd9fc518..93912c770b 100644
--- a/versions-model/src/main/mdo/rule.mdo
+++ b/versions-model/src/main/mdo/rule.mdo
@@ -34,9 +34,6 @@ under the License.
org.codehaus.mojo.versions.model
-
- namespace
-
Rule