Skip to content

Commit d115f7a

Browse files
authored
Moved to modello-stax. Removed "versionDefinition" from rule.mdo. (#1176)
1 parent 3841bb6 commit d115f7a

File tree

14 files changed

+59
-67
lines changed

14 files changed

+59
-67
lines changed

versions-common/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,13 @@
144144
<model>src/main/mdo/core-extensions.mdo</model>
145145
</models>
146146
<version>1.1.0</version>
147+
<domAsXpp3>false</domAsXpp3>
147148
</configuration>
148149
<executions>
149150
<execution>
150151
<id>generate-java-classes</id>
151152
<goals>
152-
<goal>xpp3-reader</goal>
153+
<goal>stax-reader</goal>
153154
<goal>java</goal>
154155
</goals>
155156
<phase>generate-sources</phase>
@@ -166,7 +167,7 @@
166167
<configuration>
167168
<!-- Exclude packages generated by Modello in JavaDocs -->
168169
<excludePackageNames>org.codehaus.mojo.versions.model,
169-
org.codehaus.mojo.versions.model.io.xpp3,
170+
org.codehaus.mojo.versions.model.io.stax,
170171
org.codehaus.mojo.versions.utils</excludePackageNames>
171172
</configuration>
172173
</plugin>

versions-common/src/main/java/org/codehaus/mojo/versions/api/DefaultVersionsHelper.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
* under the License.
2020
*/
2121

22+
import javax.xml.stream.XMLStreamException;
23+
2224
import java.io.BufferedInputStream;
2325
import java.io.File;
2426
import java.io.IOException;
27+
import java.io.InputStream;
2528
import java.net.URISyntaxException;
2629
import java.net.URL;
2730
import java.nio.file.Files;
@@ -75,7 +78,7 @@
7578
import org.codehaus.mojo.versions.model.IgnoreVersion;
7679
import org.codehaus.mojo.versions.model.Rule;
7780
import org.codehaus.mojo.versions.model.RuleSet;
78-
import org.codehaus.mojo.versions.model.io.xpp3.RuleXpp3Reader;
81+
import org.codehaus.mojo.versions.model.io.stax.RuleStaxReader;
7982
import org.codehaus.mojo.versions.ordering.VersionComparator;
8083
import org.codehaus.mojo.versions.ordering.VersionComparators;
8184
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
@@ -85,7 +88,6 @@
8588
import org.codehaus.mojo.versions.utils.VersionsExpressionEvaluator;
8689
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
8790
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
88-
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
8991
import org.eclipse.aether.RepositorySystem;
9092
import org.eclipse.aether.repository.AuthenticationContext;
9193
import org.eclipse.aether.repository.RemoteRepository;
@@ -101,6 +103,7 @@
101103
import static java.util.Optional.of;
102104
import static java.util.Optional.ofNullable;
103105
import static org.apache.maven.RepositoryUtils.toArtifact;
106+
;
104107

105108
/**
106109
* 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
740743
}
741744

742745
try (BufferedInputStream bis = new BufferedInputStream(url.openStream())) {
743-
RuleSet result = new RuleXpp3Reader().read(bis);
746+
RuleSet result = new RuleStaxReader().read(bis);
744747
logger.debug("Loaded rules from \"" + uri + "\" successfully");
745748
return result;
746-
} catch (IOException | XmlPullParserException e) {
749+
} catch (IOException | XMLStreamException e) {
747750
throw new MojoExecutionException("Could not load specified rules from " + uri, e);
748751
}
749752
}
@@ -905,8 +908,8 @@ private RuleSet getRulesUsingWagon() throws MojoExecutionException {
905908
try {
906909
Path tempFile = Files.createTempFile("rules-", ".xml");
907910
wagon.get(uri.resource, tempFile.toFile());
908-
try (BufferedInputStream is = new BufferedInputStream(Files.newInputStream(tempFile))) {
909-
return new RuleXpp3Reader().read(is);
911+
try (InputStream is = Files.newInputStream(tempFile)) {
912+
return new RuleStaxReader().read(is);
910913
} finally {
911914
Files.deleteIfExists(tempFile);
912915
}
@@ -915,8 +918,7 @@ private RuleSet getRulesUsingWagon() throws MojoExecutionException {
915918
wagon.disconnect();
916919
}
917920
} catch (Exception e) {
918-
log.warn(e.getMessage());
919-
return null;
921+
throw new RuntimeException(e);
920922
}
921923
})
922924
.orElseThrow(() -> new MojoExecutionException("Could not load specified rules from " + rulesUri));

versions-common/src/main/java/org/codehaus/mojo/versions/utils/CoreExtensionUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
* limitations under the License.
1717
*/
1818

19+
import javax.xml.stream.XMLStreamException;
20+
1921
import java.io.BufferedReader;
2022
import java.io.IOException;
2123
import java.io.InputStreamReader;
@@ -26,8 +28,7 @@
2628

2729
import org.apache.maven.model.Extension;
2830
import org.apache.maven.project.MavenProject;
29-
import org.codehaus.mojo.versions.model.io.xpp3.CoreExtensionsXpp3Reader;
30-
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
31+
import org.codehaus.mojo.versions.model.io.stax.CoreExtensionsStaxReader;
3132

3233
/**
3334
* Utilities for reading and handling core extensions.
@@ -43,17 +44,17 @@ public final class CoreExtensionUtils {
4344
* @param project {@link MavenProject} instance
4445
* @return stream of core extensions defined in the {@code ${project}/.mvn/extensions.xml} file
4546
* @throws IOException thrown if a file I/O operation fails
46-
* @throws XmlPullParserException thrown if the file cannot be parsed
47+
* @throws XMLStreamException thrown if the file cannot be parsed
4748
* @since 2.15.0
4849
*/
49-
public static Stream<Extension> getCoreExtensions(MavenProject project) throws IOException, XmlPullParserException {
50+
public static Stream<Extension> getCoreExtensions(MavenProject project) throws IOException, XMLStreamException {
5051
Path extensionsFile = project.getBasedir().toPath().resolve(".mvn/extensions.xml");
5152
if (!Files.isRegularFile(extensionsFile)) {
5253
return Stream.empty();
5354
}
5455

5556
try (Reader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(extensionsFile)))) {
56-
return new CoreExtensionsXpp3Reader()
57+
return new CoreExtensionsStaxReader()
5758
.read(reader).getExtensions().stream().map(ex -> ExtensionBuilder.newBuilder()
5859
.withGroupId(ex.getGroupId())
5960
.withArtifactId(ex.getArtifactId())

versions-common/src/main/java/org/codehaus/mojo/versions/utils/RegexUtils.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* under the License.
2020
*/
2121

22+
import static java.util.Optional.ofNullable;
23+
2224
/**
2325
* Utility methods to help with regex manipulation.
2426
*
@@ -105,23 +107,21 @@ public static int getWildcardScore(String wildcardRule) {
105107
/**
106108
* Converts a wildcard rule to a regex rule.
107109
*
108-
* @param wildcardRule the wildcard rule.
110+
* @param wildcardRule the wildcard rule, may be {@code null}
109111
* @param exactMatch <code>true</code> results in an regex that will match the entire string, while
110112
* <code>false</code> will match the start of the string.
111113
* @return The regex rule.
112114
*/
113115
public static String convertWildcardsToRegex(String wildcardRule, boolean exactMatch) {
114116
StringBuilder regex = new StringBuilder();
115-
int index = 0;
116-
final int len = wildcardRule.length();
117-
while (index < len) {
117+
final int wildcardLength = ofNullable(wildcardRule).map(String::length).orElse(0);
118+
for (int index = 0, nextIndex = 0; index < wildcardLength; index = nextIndex + 1) {
118119
final int nextQ = wildcardRule.indexOf('?', index);
119120
final int nextS = wildcardRule.indexOf('*', index);
120121
if (nextQ == -1 && nextS == -1) {
121122
regex.append(quote(wildcardRule.substring(index)));
122123
break;
123124
}
124-
int nextIndex;
125125
if (nextQ == -1) {
126126
nextIndex = nextS;
127127
} else if (nextS == -1) {
@@ -139,7 +139,6 @@ public static String convertWildcardsToRegex(String wildcardRule, boolean exactM
139139
} else {
140140
regex.append(".*");
141141
}
142-
index = nextIndex + 1;
143142
}
144143
if (!exactMatch) {
145144
regex.append(".*");

versions-common/src/test/java/org/codehaus/mojo/versions/utils/CoreExtensionUtilsTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
* limitations under the License.
1616
*/
1717

18+
import javax.xml.stream.XMLStreamException;
19+
1820
import java.io.File;
1921
import java.io.IOException;
2022
import java.util.Optional;
@@ -24,7 +26,6 @@
2426
import org.apache.maven.execution.MavenSession;
2527
import org.apache.maven.model.Extension;
2628
import org.apache.maven.project.MavenProject;
27-
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
2829
import org.junit.jupiter.api.Test;
2930

3031
import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,7 +42,7 @@
4142
class CoreExtensionUtilsTest {
4243

4344
@Test
44-
void testNoExtensions() throws XmlPullParserException, IOException {
45+
void testNoExtensions() throws IOException, XMLStreamException {
4546
MavenProject project = mock(MavenProject.class);
4647
when(project.getBasedir())
4748
.thenReturn(
@@ -52,7 +53,7 @@ void testNoExtensions() throws XmlPullParserException, IOException {
5253
}
5354

5455
@Test
55-
void testExtensionsFound() throws XmlPullParserException, IOException {
56+
void testExtensionsFound() throws IOException, XMLStreamException {
5657
MavenProject project = mock(MavenProject.class);
5758
when(project.getBasedir())
5859
.thenReturn(new File("src/test/resources/org/codehaus/mojo/versions/utils/core-extensions"));

versions-common/src/test/resources/org/codehaus/mojo/versions/api/rules.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
<ruleset comparisonMethod="maven"
2-
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0 https://www.mojohaus.org/versions-maven-plugin/xsd/rule-2.0.0.xsd">
1+
<ruleset comparisonMethod="maven">
42
<ignoreVersions>
53
<ignoreVersion type="regex">.*-alpha</ignoreVersion>
64
<ignoreVersion type="regex">.*-beta</ignoreVersion>

versions-maven-plugin/pom.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,6 @@
160160
<groupId>org.codehaus.plexus</groupId>
161161
<artifactId>plexus-utils</artifactId>
162162
</dependency>
163-
<dependency>
164-
<groupId>org.codehaus.plexus</groupId>
165-
<artifactId>plexus-xml</artifactId>
166-
</dependency>
167163
<dependency>
168164
<groupId>javax.inject</groupId>
169165
<artifactId>javax.inject</artifactId>

versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayExtensionUpdatesMojo.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
import org.codehaus.mojo.versions.utils.ExtensionBuilder;
5858
import org.codehaus.mojo.versions.utils.ModelNode;
5959
import org.codehaus.mojo.versions.utils.SegmentUtils;
60-
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
6160
import org.eclipse.aether.RepositorySystem;
6261

6362
import static java.util.Optional.of;
@@ -252,7 +251,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
252251
.filter(includeFilter::matchersMatch)
253252
.filter(excludeFilter::matchersDontMatch)
254253
.collect(Collectors.toSet());
255-
} catch (IOException | XmlPullParserException e) {
254+
} catch (IOException | XMLStreamException e) {
256255
throw new MojoExecutionException(e.getMessage());
257256
}
258257
if (dependencies.isEmpty()) {

versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/DependencyUpdatesXmlReportRenderer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* under the License.
2020
*/
2121

22+
import javax.xml.stream.XMLStreamException;
23+
2224
import java.io.BufferedWriter;
2325
import java.io.IOException;
2426
import java.nio.charset.StandardCharsets;
@@ -38,7 +40,7 @@
3840
import org.codehaus.mojo.versions.reporting.model.DependencyReportSummary;
3941
import org.codehaus.mojo.versions.reporting.model.DependencyUpdatesModel;
4042
import org.codehaus.mojo.versions.reporting.model.DependencyUpdatesReport;
41-
import org.codehaus.mojo.versions.reporting.model.io.xpp3.DependencyUpdatesReportXpp3Writer;
43+
import org.codehaus.mojo.versions.reporting.model.io.stax.DependencyUpdatesReportStaxWriter;
4244
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
4345

4446
import static java.util.Optional.empty;
@@ -91,7 +93,7 @@ public String getTitle() {
9193
@Override
9294
public void render() {
9395
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
94-
new DependencyUpdatesReportXpp3Writer().write(writer, new DependencyUpdatesReport() {
96+
new DependencyUpdatesReportStaxWriter().write(writer, new DependencyUpdatesReport() {
9597
{
9698
setSummary(new DependencyReportSummary() {
9799
{
@@ -109,7 +111,7 @@ public void render() {
109111
setDependencies(createDependencyInfo(model.getArtifactUpdates(), isAllowSnapshots()));
110112
}
111113
});
112-
} catch (IOException e) {
114+
} catch (IOException | XMLStreamException e) {
113115
throw new RuntimeException(e);
114116
}
115117
}

versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PluginUpdatesXmlReportRenderer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* under the License.
2020
*/
2121

22+
import javax.xml.stream.XMLStreamException;
23+
2224
import java.io.BufferedWriter;
2325
import java.io.IOException;
2426
import java.nio.charset.StandardCharsets;
@@ -38,7 +40,7 @@
3840
import org.codehaus.mojo.versions.reporting.model.PluginReportSummary;
3941
import org.codehaus.mojo.versions.reporting.model.PluginUpdatesModel;
4042
import org.codehaus.mojo.versions.reporting.model.PluginUpdatesReport;
41-
import org.codehaus.mojo.versions.reporting.model.io.xpp3.PluginUpdatesReportXpp3Writer;
43+
import org.codehaus.mojo.versions.reporting.model.io.stax.PluginUpdatesReportStaxWriter;
4244
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
4345

4446
import static java.util.Optional.empty;
@@ -91,7 +93,7 @@ public boolean isAllowSnapshots() {
9193
@Override
9294
public void render() {
9395
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
94-
new PluginUpdatesReportXpp3Writer().write(writer, new PluginUpdatesReport() {
96+
new PluginUpdatesReportStaxWriter().write(writer, new PluginUpdatesReport() {
9597
{
9698
setSummary(new PluginReportSummary() {
9799
{
@@ -109,7 +111,7 @@ public void render() {
109111
setPlugins(createPluginInfo(model.getArtifactUpdates(), isAllowSnapshots()));
110112
}
111113
});
112-
} catch (IOException e) {
114+
} catch (IOException | XMLStreamException e) {
113115
throw new RuntimeException(e);
114116
}
115117
}

versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/xml/PropertyUpdatesXmlReportRenderer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* under the License.
2020
*/
2121

22+
import javax.xml.stream.XMLStreamException;
23+
2224
import java.io.BufferedWriter;
2325
import java.io.IOException;
2426
import java.nio.charset.StandardCharsets;
@@ -40,7 +42,7 @@
4042
import org.codehaus.mojo.versions.reporting.model.PropertyReportSummary;
4143
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesModel;
4244
import org.codehaus.mojo.versions.reporting.model.PropertyUpdatesReport;
43-
import org.codehaus.mojo.versions.reporting.model.io.xpp3.PropertyUpdatesReportXpp3Writer;
45+
import org.codehaus.mojo.versions.reporting.model.io.stax.PropertyUpdatesReportStaxWriter;
4446
import org.codehaus.mojo.versions.reporting.util.ReportRenderer;
4547

4648
import static java.util.Optional.empty;
@@ -89,7 +91,7 @@ public String getTitle() {
8991
@Override
9092
public void render() {
9193
try (BufferedWriter writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
92-
new PropertyUpdatesReportXpp3Writer().write(writer, new PropertyUpdatesReport() {
94+
new PropertyUpdatesReportStaxWriter().write(writer, new PropertyUpdatesReport() {
9395
{
9496
setSummary(new PropertyReportSummary() {
9597
{
@@ -105,7 +107,7 @@ public void render() {
105107
setProperties(createPropertyInfo(model.getAllUpdates(), allowSnapshots));
106108
}
107109
});
108-
} catch (IOException e) {
110+
} catch (IOException | XMLStreamException e) {
109111
throw new RuntimeException(e);
110112
}
111113
}

versions-model-report/pom.xml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@
1212
<name>Versions Model Report</name>
1313
<description>Modello models used in reports</description>
1414

15-
<dependencies>
16-
<dependency>
17-
<groupId>org.codehaus.plexus</groupId>
18-
<artifactId>plexus-xml</artifactId>
19-
</dependency>
20-
</dependencies>
21-
2215
<build>
2316
<plugins>
2417
<plugin>
@@ -31,16 +24,14 @@
3124
<model>src/main/mdo/property-updates-report.mdo</model>
3225
</models>
3326
<version>${modelloNamespaceReportVersion}</version>
27+
<domAsXpp3>false</domAsXpp3>
3428
</configuration>
3529
<executions>
3630
<execution>
3731
<id>generate-rule</id>
3832
<goals>
39-
<!-- Generate the xpp3 reader code -->
40-
<goal>xpp3-reader</goal>
41-
<!-- Generate the xpp3 writer code -->
42-
<goal>xpp3-writer</goal>
43-
<!-- Generate the Java sources for the model itself -->
33+
<goal>stax-reader</goal>
34+
<goal>stax-writer</goal>
4435
<goal>java</goal>
4536
</goals>
4637
<phase>generate-sources</phase>

0 commit comments

Comments
 (0)