Skip to content

Commit

Permalink
Moved to modello-stax. Removed "versionDefinition" from rule.mdo. (#1176
Browse files Browse the repository at this point in the history
)
  • Loading branch information
andrzejj0 authored Nov 9, 2024
1 parent 3841bb6 commit d115f7a
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 67 deletions.
5 changes: 3 additions & 2 deletions versions-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,13 @@
<model>src/main/mdo/core-extensions.mdo</model>
</models>
<version>1.1.0</version>
<domAsXpp3>false</domAsXpp3>
</configuration>
<executions>
<execution>
<id>generate-java-classes</id>
<goals>
<goal>xpp3-reader</goal>
<goal>stax-reader</goal>
<goal>java</goal>
</goals>
<phase>generate-sources</phase>
Expand All @@ -166,7 +167,7 @@
<configuration>
<!-- Exclude packages generated by Modello in JavaDocs -->
<excludePackageNames>org.codehaus.mojo.versions.model,
org.codehaus.mojo.versions.model.io.xpp3,
org.codehaus.mojo.versions.model.io.stax,
org.codehaus.mojo.versions.utils</excludePackageNames>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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<Extension> getCoreExtensions(MavenProject project) throws IOException, XmlPullParserException {
public static Stream<Extension> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* under the License.
*/

import static java.util.Optional.ofNullable;

/**
* Utility methods to help with regex manipulation.
*
Expand Down Expand Up @@ -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 <code>true</code> results in an regex that will match the entire string, while
* <code>false</code> 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) {
Expand All @@ -139,7 +139,6 @@ public static String convertWildcardsToRegex(String wildcardRule, boolean exactM
} else {
regex.append(".*");
}
index = nextIndex + 1;
}
if (!exactMatch) {
regex.append(".*");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<ruleset comparisonMethod="maven"
xmlns="http://mojo.codehaus.org/versions-maven-plugin/rule/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
<ruleset comparisonMethod="maven">
<ignoreVersions>
<ignoreVersion type="regex">.*-alpha</ignoreVersion>
<ignoreVersion type="regex">.*-beta</ignoreVersion>
Expand Down
4 changes: 0 additions & 4 deletions versions-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,6 @@
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
{
Expand All @@ -109,7 +111,7 @@ public void render() {
setDependencies(createDependencyInfo(model.getArtifactUpdates(), isAllowSnapshots()));
}
});
} catch (IOException e) {
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
{
Expand All @@ -109,7 +111,7 @@ public void render() {
setPlugins(createPluginInfo(model.getArtifactUpdates(), isAllowSnapshots()));
}
});
} catch (IOException e) {
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {
{
Expand All @@ -105,7 +107,7 @@ public void render() {
setProperties(createPropertyInfo(model.getAllUpdates(), allowSnapshots));
}
});
} catch (IOException e) {
} catch (IOException | XMLStreamException e) {
throw new RuntimeException(e);
}
}
Expand Down
15 changes: 3 additions & 12 deletions versions-model-report/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
<name>Versions Model Report</name>
<description>Modello models used in reports</description>

<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-xml</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
Expand All @@ -31,16 +24,14 @@
<model>src/main/mdo/property-updates-report.mdo</model>
</models>
<version>${modelloNamespaceReportVersion}</version>
<domAsXpp3>false</domAsXpp3>
</configuration>
<executions>
<execution>
<id>generate-rule</id>
<goals>
<!-- Generate the xpp3 reader code -->
<goal>xpp3-reader</goal>
<!-- Generate the xpp3 writer code -->
<goal>xpp3-writer</goal>
<!-- Generate the Java sources for the model itself -->
<goal>stax-reader</goal>
<goal>stax-writer</goal>
<goal>java</goal>
</goals>
<phase>generate-sources</phase>
Expand Down
Loading

0 comments on commit d115f7a

Please sign in to comment.