+ assertThat(goToStartElement(reader, "api"), is(true));
+ reader.mark("");
+ reader.next();
+ assertThat(reader.isCharacters(), is(true));
+ reader.mark("api");
+ assertThat(goToEndElement(reader, "api"), is(true));
+ reader.mark("");
+
+ assertThat(reader.getBetween("", ""), is("1.0"));
+ assertThat(reader.getBetween("", ""), is("2.0"));
+
+ reader.replaceMark("version", "1.0.1-SNAPSHOT");
+ assertThat(reader.getBetween("", ""), is("1.0.1-SNAPSHOT"));
+ assertThat(reader.getBetween("", ""), is("2.0"));
+
+ reader.replaceMark("version", "2");
+ assertThat(reader.getBetween("", ""), is("2"));
+ assertThat(reader.getBetween("", ""), is("2.0"));
+ }
+}
diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/ModifiedPomXMLEventReaderUtils.java b/versions-common/src/test/java/org/codehaus/mojo/versions/utils/ModifiedPomXMLEventReaderUtils.java
deleted file mode 100644
index 01143daa4f..0000000000
--- a/versions-common/src/test/java/org/codehaus/mojo/versions/utils/ModifiedPomXMLEventReaderUtils.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.codehaus.mojo.versions.utils;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
-import org.hamcrest.Description;
-import org.hamcrest.Matcher;
-import org.hamcrest.TypeSafeMatcher;
-
-/**
- * Utilities for the {@link ModifiedPomXMLEventReader} class
- *
- * @author Andrzej Jarmoniuk
- */
-public class ModifiedPomXMLEventReaderUtils {
- public static Matcher
matches(String pattern) {
- return new TypeSafeMatcher
() {
- @Override
- public void describeTo(Description description) {
- description.appendText(pattern);
- }
-
- @Override
- protected void describeMismatchSafely(P pom, Description description) {
- description.appendText(asString(pom));
- }
-
- @Override
- protected boolean matchesSafely(P pom) {
- return pattern.matches(asString(pom));
- }
-
- private String asString(P pom) {
- return pom.asStringBuilder().toString().replaceAll("\\s", "");
- }
- };
- }
-}
diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.utf16.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.utf16.xml
new file mode 100644
index 0000000000..e654cff84c
Binary files /dev/null and b/versions-common/src/test/resources/org/codehaus/mojo/versions/api/PomHelperTest.utf16.xml differ
diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/iso-8859-2.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/iso-8859-2.xml
new file mode 100644
index 0000000000..6393a480d6
--- /dev/null
+++ b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/iso-8859-2.xml
@@ -0,0 +1,47 @@
+
+
+
+
+ 4.0.0
+
+ localhost
+ it-update-properties-016
+ 1.0
+ pom
+
+ iso-8859-2
+ a test file in iso-8859-2 with some special characters: ±ê󶳼æñ¡¯ÊÆ
+
+
+ 2.0
+ 1.0
+
+
+
+
+ localhost
+ dummy-api
+ ${api}
+
+
+ localhost
+ dummy-impl
+ ${impl}
+
+
+
+
diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-16.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-16.xml
new file mode 100644
index 0000000000..f85f8a0014
Binary files /dev/null and b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-16.xml differ
diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-8.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-8.xml
new file mode 100644
index 0000000000..fdc34c6ec4
--- /dev/null
+++ b/versions-common/src/test/resources/org/codehaus/mojo/versions/rewriting/utf-8.xml
@@ -0,0 +1,47 @@
+
+
+
+
+ 4.0.0
+
+ localhost
+ it-update-properties-016
+ 1.0
+ pom
+
+ utf-8
+ test file using the utf-8 encoding with some special characters: ąęóśłźćńĄŻĘĆ
+
+
+ 2.0
+ 1.0
+
+
+
+
+ localhost
+ dummy-api
+ ${api}
+
+
+ localhost
+ dummy-impl
+ ${impl}
+
+
+
+
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
index 0994cd94b8..a7d794b87d 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java
@@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.eclipse.aether.RepositorySystem;
@@ -285,7 +285,7 @@ protected String toString(MavenProject project) {
buf.append(':');
buf.append(project.getArtifactId());
- if (project.getVersion() != null && project.getVersion().length() > 0) {
+ if (project.getVersion() != null && !project.getVersion().isEmpty()) {
buf.append(":");
buf.append(project.getVersion());
}
@@ -298,17 +298,17 @@ protected String toString(Dependency d) {
buf.append(d.getGroupId());
buf.append(':');
buf.append(d.getArtifactId());
- if (d.getType() != null && d.getType().length() > 0) {
+ if (d.getType() != null && !d.getType().isEmpty()) {
buf.append(':');
buf.append(d.getType());
} else {
buf.append(":jar");
}
- if (d.getClassifier() != null && d.getClassifier().length() > 0) {
+ if (d.getClassifier() != null && !d.getClassifier().isEmpty()) {
buf.append(':');
buf.append(d.getClassifier());
}
- if (d.getVersion() != null && d.getVersion().length() > 0) {
+ if (d.getVersion() != null && !d.getVersion().isEmpty()) {
buf.append(":");
buf.append(d.getVersion());
}
@@ -405,7 +405,7 @@ private ArtifactFilter getIncludesArtifactFilter() {
List patterns = new ArrayList<>();
if (this.includesList != null) {
patterns.addAll(separatePatterns(includesList));
- } else if (includes != null) {
+ } else {
patterns.addAll(Arrays.asList(includes));
}
includesFilter = new PatternIncludesArtifactFilter(patterns);
@@ -418,7 +418,7 @@ private ArtifactFilter getExcludesArtifactFilter() {
List patterns = new ArrayList<>();
if (excludesList != null) {
patterns.addAll(separatePatterns(excludesList));
- } else if (excludes != null) {
+ } else {
patterns.addAll(Arrays.asList(excludes));
}
excludesFilter = new PatternExcludesArtifactFilter(patterns);
@@ -494,7 +494,7 @@ private int findFirstChar(final String includeString, final String chars) {
* Attempts to update the dependency {@code dep} to the given {@code newVersion}. The dependency can either
* be the parent project or any given dependency.
*
- * @param pom {@link ModifiedPomXMLEventReader} instance to update the POM XML document
+ * @param pom {@link MutableXMLStreamReader} instance to update the POM XML document
* @param dep dependency to be updated (can also be a dependency made from the parent)
* @param newVersion new version to update the dependency to
* @param changeKind title for the {@link ChangeRecorder} log
@@ -502,10 +502,7 @@ private int findFirstChar(final String includeString, final String chars) {
* @throws XMLStreamException thrown if updating the XML doesn't succeed
*/
protected boolean updateDependencyVersion(
- ModifiedPomXMLEventReader pom,
- Dependency dep,
- String newVersion,
- DependencyChangeRecord.ChangeKind changeKind)
+ MutableXMLStreamReader pom, Dependency dep, String newVersion, DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException {
boolean updated = false;
if (isProcessingParent()
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
index d0bbdb4c53..f394adcb01 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsUpdaterMojo.java
@@ -20,12 +20,13 @@
*/
import javax.inject.Inject;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.TransformerException;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.util.List;
import java.util.Map;
@@ -57,13 +58,11 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.model.RuleSet;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.WriterFactory;
-import org.codehaus.stax2.XMLInputFactory2;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static java.util.Optional.ofNullable;
/**
* Abstract base class for Versions Mojos.
@@ -313,8 +312,7 @@ protected ArtifactVersion findLatestVersion(
*/
protected void process(File outFile) throws MojoExecutionException, MojoFailureException {
try {
- StringBuilder input = PomHelper.readXmlFile(outFile);
- ModifiedPomXMLEventReader newPom = newModifiedPomXER(input, outFile.getAbsolutePath());
+ MutableXMLStreamReader newPom = new MutableXMLStreamReader(outFile.toPath());
update(newPom);
@@ -330,50 +328,20 @@ protected void process(File outFile) throws MojoExecutionException, MojoFailureE
} else {
getLog().debug("Skipping generation of backup file");
}
- writeFile(outFile, input);
+ try (Writer writer = Files.newBufferedWriter(
+ outFile.toPath(),
+ ofNullable(newPom.getEncoding()).map(Charset::forName).orElse(Charset.defaultCharset()))) {
+ writer.write(newPom.getSource());
+ }
}
-
saveChangeRecorderResults();
- } catch (IOException | XMLStreamException e) {
+ } catch (IOException e) {
getLog().error(e);
- } catch (VersionRetrievalException e) {
+ } catch (VersionRetrievalException | XMLStreamException | TransformerException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
- /**
- * Creates a {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader} from a StringBuilder.
- *
- * @param input The XML to read and modify.
- * @param path Path pointing to the source of the XML
- * @return The {@link org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader}.
- */
- protected final ModifiedPomXMLEventReader newModifiedPomXER(StringBuilder input, String path) {
- ModifiedPomXMLEventReader newPom = null;
- try {
- XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
- inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE);
- newPom = new ModifiedPomXMLEventReader(input, inputFactory, path);
- } catch (XMLStreamException e) {
- getLog().error(e);
- }
- return newPom;
- }
-
- /**
- * Writes a StringBuilder into a file.
- *
- * @param outFile The file to read.
- * @param input The contents of the file.
- * @throws IOException when things go wrong.
- */
- protected final void writeFile(File outFile, StringBuilder input) throws IOException {
-
- try (Writer writer = WriterFactory.newXmlWriter(outFile)) {
- IOUtil.copy(input.toString(), writer);
- }
- }
-
/**
* Updates the pom.
*
@@ -384,7 +352,7 @@ protected final void writeFile(File outFile, StringBuilder input) throws IOExcep
* @throws VersionRetrievalException if version retrieval goes wrong
* @since 1.0-alpha-1
*/
- protected abstract void update(ModifiedPomXMLEventReader pom)
+ protected abstract void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException;
/**
@@ -452,13 +420,13 @@ protected boolean shouldApplyUpdate(
* @param allowDowngrade if downgrades should be allowed if snapshots are not allowed
* @param unchangedSegment most major segment not to be changed
* @return new version of the artifact, if the property was updated; {@code null} if there was no update
- * @throws XMLStreamException thrown from {@link ModifiedPomXMLEventReader} if the update doesn't succeed
+ * @throws XMLStreamException thrown from {@link MutableXMLStreamReader} if the update doesn't succeed
* @throws InvalidVersionSpecificationException thrown if {@code unchangedSegment} doesn't match the version
* @throws InvalidSegmentException thrown if {@code unchangedSegment} is invalid
* @throws MojoExecutionException thrown if any other error occurs
*/
protected ArtifactVersion updatePropertyToNewestVersion(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Property property,
PropertyVersions version,
String currentVersion,
@@ -510,8 +478,7 @@ protected void saveChangeRecorderResults() throws IOException, MojoExecutionExce
this.getLog().debug("writing change record to " + this.changeRecorderOutputFile);
getChangeRecorder()
- .writeReport(Optional.ofNullable(changeRecorderOutputFile)
- .map(File::toPath)
- .orElse(null));
+ .writeReport(
+ ofNullable(changeRecorderOutputFile).map(File::toPath).orElse(null));
}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java
index d0ed14303e..43b5c171c3 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/CompareDependenciesMojo.java
@@ -47,7 +47,7 @@
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.eclipse.aether.RepositorySystem;
@@ -139,9 +139,9 @@ public CompareDependenciesMojo(
* @throws org.apache.maven.plugin.MojoExecutionException Something wrong with the plugin itself
* @throws org.apache.maven.plugin.MojoFailureException The plugin detected an error in the build
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
if (this.ignoreRemoteDependencies && this.ignoreRemoteDependencyManagement) {
throw new MojoFailureException(" ignoreRemoteDependencies and ignoreRemoteDependencyManagement "
@@ -219,7 +219,7 @@ protected void update(ModifiedPomXMLEventReader pom)
if (reportMode) {
getLog().info("The following differences were found:");
- if (totalDiffs.size() == 0) {
+ if (totalDiffs.isEmpty()) {
getLog().info(" none");
} else {
for (String totalDiff : totalDiffs) {
@@ -227,7 +227,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
}
getLog().info("The following property differences were found:");
- if (propertyDiffs.size() == 0) {
+ if (propertyDiffs.isEmpty()) {
getLog().info(" none");
} else {
for (String propertyDiff : propertyDiffs) {
@@ -281,7 +281,7 @@ private MavenProject getRemoteMavenProject(String groupId, String artifactId, St
* @throws MojoExecutionException
*/
private List compareVersions(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
List dependencies,
Map remoteDependencies,
DependencyChangeRecord.ChangeKind changeKind)
@@ -313,7 +313,7 @@ private List compareVersions(
* Updates the properties holding a version if necessary.
*/
private List updatePropertyVersions(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Map versionProperties,
Map remoteDependencies)
throws XMLStreamException {
@@ -383,7 +383,7 @@ private void writeReportFile(List dependenciesUpdate, List prope
PrintWriter pw = new PrintWriter(fw)) {
pw.println("The following differences were found:");
pw.println();
- if (dependenciesUpdate.size() == 0) {
+ if (dependenciesUpdate.isEmpty()) {
pw.println(" none");
} else {
for (String dependencyUpdate : dependenciesUpdate) {
@@ -393,7 +393,7 @@ private void writeReportFile(List dependenciesUpdate, List prope
pw.println();
pw.println("The following property differences were found:");
pw.println();
- if (propertiesUpdate.size() == 0) {
+ if (propertiesUpdate.isEmpty()) {
pw.println(" none");
} else {
for (String propertyUpdate : propertiesUpdate) {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
index ab8deb889b..f256b28de5 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojo.java
@@ -46,7 +46,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.filtering.WildcardMatcher;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.mojo.versions.utils.SegmentUtils;
import org.eclipse.aether.RepositorySystem;
@@ -582,11 +582,11 @@ private void logUpdates(Map updates, String sectio
/**
* @param pom the pom to update.
- * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
@Override
- protected void update(ModifiedPomXMLEventReader pom) {
+ protected void update(MutableXMLStreamReader pom) {
// do nothing
}
}
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 bd3e057d14..efdfe89660 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
@@ -16,9 +16,10 @@
*/
import javax.inject.Inject;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.TransformerException;
import java.io.IOException;
-import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -50,7 +51,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.filtering.DependencyFilter;
import org.codehaus.mojo.versions.filtering.WildcardMatcher;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.CoreExtensionUtils;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.ExtensionBuilder;
@@ -269,13 +270,12 @@ public void execute() throws MojoExecutionException, MojoFailureException {
private List getRawModels() throws MojoFailureException {
List rawModels;
try {
- ModifiedPomXMLEventReader pomReader = newModifiedPomXER(
- new StringBuilder(
- new String(Files.readAllBytes(getProject().getFile().toPath()))),
- getProject().getFile().toPath().toString());
- ModelNode rootNode = new ModelNode(PomHelper.getRawModel(pomReader), pomReader);
+ MutableXMLStreamReader pomReader =
+ new MutableXMLStreamReader(getProject().getFile().toPath());
+ ModelNode rootNode = new ModelNode(
+ PomHelper.getRawModel(pomReader.getSource(), getProject().getFile()), pomReader);
rawModels = PomHelper.getRawModelTree(rootNode, getLog());
- } catch (IOException e) {
+ } catch (IOException | XMLStreamException | TransformerException e) {
throw new MojoFailureException(e.getMessage(), e);
}
return rawModels;
@@ -354,11 +354,11 @@ private void logUpdates(Map updates) {
/**
* @param pom the pom to update.
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
@Override
- protected void update(ModifiedPomXMLEventReader pom) {
+ protected void update(MutableXMLStreamReader pom) {
// do nothing
}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java
index b8ca91b1c0..fa7f1b9787 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayParentUpdatesMojo.java
@@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.SegmentUtils;
@@ -258,5 +258,5 @@ private static Iterable reverse(T[] array) {
}
@Override
- protected void update(ModifiedPomXMLEventReader pom) {}
+ protected void update(MutableXMLStreamReader pom) {}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java
index 1380747131..f48a72362e 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPluginUpdatesMojo.java
@@ -21,13 +21,14 @@
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.events.XMLEvent;
+import javax.xml.transform.TransformerException;
+import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
-import java.io.Reader;
+import java.io.InputStream;
import java.io.StringWriter;
-import java.net.URL;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -81,17 +82,16 @@
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.ordering.MavenVersionComparator;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.PluginComparator;
-import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.util.ReaderFactory;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.emptyMap;
import static java.util.Optional.ofNullable;
import static java.util.stream.Collectors.toMap;
+import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT;
/**
* Displays all plugins that have newer versions available, taking care of Maven version prerequisites.
@@ -127,6 +127,7 @@ public class DisplayPluginUpdatesMojo extends AbstractVersionsDisplayMojo {
public static final Pattern PATTERN_PROJECT_PLUGIN = Pattern.compile(
"/project(/profiles/profile)?" + "((/build(/pluginManagement)?)|(/reporting))" + "/plugins/plugin");
+ public static final String SUPERPOM_PATH = "org/apache/maven/model/pom-4.0.0.xml";
/**
* @since 1.0-alpha-1
@@ -197,65 +198,57 @@ private Map getSuperPomPluginManagement() {
.stream()
.collect(LinkedHashMap::new, (m, p) -> m.put(p.getKey(), p.getVersion()), Map::putAll);
- URL superPom = getClass().getClassLoader().getResource("org/apache/maven/model/pom-4.0.0.xml");
- if (superPom != null) {
- try {
- try (Reader reader = ReaderFactory.newXmlReader(superPom)) {
- StringBuilder buf = new StringBuilder(IOUtil.toString(reader));
- ModifiedPomXMLEventReader pom = newModifiedPomXER(buf, superPom.toString());
-
- Stack pathStack = new Stack<>();
- StackState curState = null;
- while (pom.hasNext()) {
- XMLEvent event = pom.nextEvent();
- if (event.isStartDocument()) {
- curState = new StackState("");
- pathStack.clear();
- } else if (event.isStartElement()) {
- if (curState != null) {
- String elementName =
- event.asStartElement().getName().getLocalPart();
- if (PATTERN_PROJECT_PLUGIN
- .matcher(curState.path)
- .matches()) {
- if ("groupId".equals(elementName)) {
- curState.groupId = pom.getElementText().trim();
- continue;
- } else if ("artifactId".equals(elementName)) {
- curState.artifactId =
- pom.getElementText().trim();
- continue;
-
- } else if ("version".equals(elementName)) {
- curState.version = pom.getElementText().trim();
- continue;
- }
- }
-
- pathStack.push(curState);
- curState = new StackState(curState.path + "/" + elementName);
- }
- } else if (event.isEndElement()) {
- if (curState != null
- && curState.artifactId != null
- && PATTERN_PROJECT_PLUGIN
- .matcher(curState.path)
- .matches()) {
- result.putIfAbsent(
- Plugin.constructKey(
- curState.groupId == null
- ? PomHelper.APACHE_MAVEN_PLUGINS_GROUPID
- : curState.groupId,
- curState.artifactId),
- curState.version);
+ try (InputStream superPomIs = getClass().getClassLoader().getResourceAsStream(SUPERPOM_PATH)) {
+ Objects.requireNonNull(superPomIs);
+ MutableXMLStreamReader pomReader = new MutableXMLStreamReader(superPomIs, Paths.get(SUPERPOM_PATH));
+
+ Stack pathStack = new Stack<>();
+ StackState curState = new StackState("");
+
+ for (int event = pomReader.getEventType();
+ event != END_DOCUMENT && pomReader.hasNext();
+ event = pomReader.next()) {
+ if (pomReader.isStartElement()) {
+ if (curState != null) {
+ String elementName = pomReader.getLocalName();
+ if (PATTERN_PROJECT_PLUGIN.matcher(curState.path).matches()) {
+ switch (elementName) {
+ case "groupId":
+ curState.groupId =
+ pomReader.getElementText().trim();
+ break;
+ case "artifactId":
+ curState.artifactId =
+ pomReader.getElementText().trim();
+ break;
+ case "version":
+ curState.version =
+ pomReader.getElementText().trim();
+ break;
+ default:
+ break;
}
- curState = pathStack.pop();
}
+ pathStack.push(curState);
+ curState = new StackState(curState.path + "/" + elementName);
+ }
+ } else if (pomReader.isEndElement()) {
+ if (curState != null
+ && curState.artifactId != null
+ && PATTERN_PROJECT_PLUGIN.matcher(curState.path).matches()) {
+ result.putIfAbsent(
+ Plugin.constructKey(
+ curState.groupId == null
+ ? PomHelper.APACHE_MAVEN_PLUGINS_GROUPID
+ : curState.groupId,
+ curState.artifactId),
+ curState.version);
}
+ curState = pathStack.pop();
}
- } catch (IOException | XMLStreamException e) {
- // ignore
}
+ } catch (IOException | XMLStreamException | TransformerException e) {
+ // ignore
}
return result;
@@ -318,11 +311,10 @@ private Map getPluginManagement(Model model) {
public void execute() throws MojoExecutionException, MojoFailureException {
logInit();
Set pluginsWithVersionsSpecified;
- try {
- MavenProject project1 = getProject();
- pluginsWithVersionsSpecified = findPluginsWithVersionsSpecified(
- PomHelper.readXmlFile(project1.getFile()), getSafeProjectPathInfo(project1));
- } catch (XMLStreamException | IOException e) {
+ try (MutableXMLStreamReader pomReader =
+ new MutableXMLStreamReader(getProject().getFile().toPath())) {
+ pluginsWithVersionsSpecified = findPluginsWithVersionsSpecified(pomReader);
+ } catch (XMLStreamException | IOException | TransformerException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
@@ -685,22 +677,28 @@ private Map getParentsPlugins(List parents) throws
interpolatedModel = modelInterpolator.interpolateModel(
originalModel, null, modelBuildingRequest, new IgnoringModelProblemCollector());
if (havePom) {
- try {
- Set withVersionSpecified = findPluginsWithVersionsSpecified(
- new StringBuilder(writer.toString()), getSafeProjectPathInfo(parentProject));
-
- Map map = getPluginManagement(interpolatedModel);
- map.keySet().retainAll(withVersionSpecified);
- parentPlugins.putAll(map);
-
- map = getBuildPlugins(interpolatedModel, true);
- map.keySet().retainAll(withVersionSpecified);
- parentPlugins.putAll(map);
-
- map = getReportPlugins(interpolatedModel, true);
- map.keySet().retainAll(withVersionSpecified);
- parentPlugins.putAll(map);
- } catch (XMLStreamException e) {
+ try (ByteArrayInputStream bais =
+ new ByteArrayInputStream(writer.toString().getBytes())) {
+ try (MutableXMLStreamReader pomReader = new MutableXMLStreamReader(
+ bais,
+ ofNullable(parentProject.getFile())
+ .map(File::toPath)
+ .orElse(null))) {
+ Set withVersionSpecified = findPluginsWithVersionsSpecified(pomReader);
+
+ Map map = getPluginManagement(interpolatedModel);
+ map.keySet().retainAll(withVersionSpecified);
+ parentPlugins.putAll(map);
+
+ map = getBuildPlugins(interpolatedModel, true);
+ map.keySet().retainAll(withVersionSpecified);
+ parentPlugins.putAll(map);
+
+ map = getReportPlugins(interpolatedModel, true);
+ map.keySet().retainAll(withVersionSpecified);
+ parentPlugins.putAll(map);
+ }
+ } catch (XMLStreamException | TransformerException | IOException e) {
throw new MojoExecutionException(e.getMessage(), e);
}
} else {
@@ -712,14 +710,6 @@ private Map getParentsPlugins(List parents) throws
return parentPlugins;
}
- private String getSafeProjectPathInfo(MavenProject project) {
- return ofNullable(project.getFile())
- .map(File::getAbsolutePath)
- // path is used only as information in error message,
- // we can fallback to project artifact info here
- .orElse(project.toString());
- }
-
private boolean isMavenPluginProject() {
return "maven-plugin".equals(getProject().getPackaging());
}
@@ -752,34 +742,28 @@ public String toString() {
/**
* Returns a set of Strings which correspond to the plugin coordinates where there is a version specified.
*
- * @param pomContents The project to get the plugins with versions specified.
- * @param path Path that points to the source of the XML
+ * @param pom a {@link MutableXMLStreamReader} instance for the pom project to get the plugins with versions specified.
* @return a set of Strings which correspond to the plugin coordinates where there is a version specified.
*/
- private Set findPluginsWithVersionsSpecified(StringBuilder pomContents, String path)
- throws XMLStreamException {
+ private Set findPluginsWithVersionsSpecified(MutableXMLStreamReader pom)
+ throws XMLStreamException, IOException, TransformerException {
Set result = new HashSet<>();
- ModifiedPomXMLEventReader pom = newModifiedPomXER(pomContents, path);
-
Stack pathStack = new Stack<>();
- StackState curState = null;
+ StackState curState = new StackState("");
+
while (pom.hasNext()) {
- XMLEvent event = pom.nextEvent();
- if (event.isStartDocument()) {
- curState = new StackState("");
- pathStack.clear();
- } else if (event.isStartElement()) {
- String elementName = event.asStartElement().getName().getLocalPart();
+ pom.next();
+ if (pom.isStartElement()) {
if (curState != null
&& PATTERN_PROJECT_PLUGIN.matcher(curState.path).matches()) {
- if ("groupId".equals(elementName)) {
+ if ("groupId".equals(pom.getLocalName())) {
curState.groupId = pom.getElementText().trim();
continue;
- } else if ("artifactId".equals(elementName)) {
+ } else if ("artifactId".equals(pom.getLocalName())) {
curState.artifactId = pom.getElementText().trim();
continue;
- } else if ("version".equals(elementName)) {
+ } else if ("version".equals(pom.getLocalName())) {
curState.version = pom.getElementText().trim();
continue;
}
@@ -787,8 +771,10 @@ private Set findPluginsWithVersionsSpecified(StringBuilder pomContents,
assert curState != null;
pathStack.push(curState);
- curState = new StackState(curState.path + "/" + elementName);
- } else if (event.isEndElement()) {
+ curState = new StackState(curState.path + "/" + pom.getLocalName());
+ }
+ // for empty elements, pom can be both start- and end element
+ if (pom.isEndElement()) {
if (curState != null
&& PATTERN_PROJECT_PLUGIN.matcher(curState.path).matches()) {
if (curState.artifactId != null && curState.version != null) {
@@ -810,10 +796,10 @@ private Set findPluginsWithVersionsSpecified(StringBuilder pomContents,
/**
* Get the minimum required Maven version of the given plugin
* Same logic as in
- * @see PluginReport
*
* @param pluginProject the plugin for which to retrieve the minimum Maven version which is required
* @return The minimally required Maven version (never {@code null})
+ * @see PluginReport
*/
private ArtifactVersion getPrerequisitesMavenVersion(MavenProject pluginProject) {
return ofNullable(pluginProject.getPrerequisites())
@@ -875,7 +861,7 @@ private static boolean getPluginInherited(Object plugin) {
* Gets the plugins that are bound to the defined phases. This does not find plugins bound in the pom to a phase
* later than the plugin is executing.
*
- * @param project the project
+ * @param project the project
* @return the bound plugins
*/
// pilfered this from enforcer-rules
@@ -1154,10 +1140,10 @@ private Map getReportPlugins(Model model, boolean onlyIncludeInh
/**
* @param pom the pom to update.
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
- protected void update(ModifiedPomXMLEventReader pom) {
+ protected void update(MutableXMLStreamReader pom) {
// do nothing
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java
index 4dd1c8617b..28663868cd 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/DisplayPropertyUpdatesMojo.java
@@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Optional.empty;
@@ -267,5 +267,5 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
@Override
- protected void update(ModifiedPomXMLEventReader pom) {}
+ protected void update(MutableXMLStreamReader pom) {}
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java
index a9d5c0a4a2..5474d349c8 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ForceReleasesMojo.java
@@ -39,7 +39,7 @@
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -76,9 +76,9 @@ public ForceReleasesMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -103,7 +103,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useReleases(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java
index 1351b110d0..474a688f6c 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/LockSnapshotsMojo.java
@@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.resolution.VersionRequest;
import org.eclipse.aether.resolution.VersionResolutionException;
@@ -83,9 +83,9 @@ public LockSnapshotsMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
try {
if (isProcessingDependencyManagement()) {
@@ -106,7 +106,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
}
- protected void lockSnapshots(ModifiedPomXMLEventReader pom, Collection dependencies)
+ protected void lockSnapshots(MutableXMLStreamReader pom, Collection dependencies)
throws XMLStreamException, MojoExecutionException, VersionResolutionException {
for (Dependency dep : dependencies) {
if (isExcludeReactor() && isProducedByReactor(dep)) {
@@ -145,7 +145,7 @@ protected void lockSnapshots(ModifiedPomXMLEventReader pom, Collection dependencies)
+ private void resolveRanges(MutableXMLStreamReader pom, Collection dependencies)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
for (Dependency dep : dependencies) {
@@ -277,13 +276,11 @@ private void resolveRanges(ModifiedPomXMLEventReader pom, Collection
}
}
- private void resolvePropertyRanges(ModifiedPomXMLEventReader pom)
- throws XMLStreamException, MojoExecutionException {
+ private void resolvePropertyRanges(MutableXMLStreamReader pom) throws XMLStreamException, MojoExecutionException {
if (includeProperties == null) {
Properties originalProperties = getProject().getOriginalModel().getProperties();
- includeProperties =
- originalProperties.stringPropertyNames().stream().collect(Collectors.joining(","));
+ includeProperties = String.join(",", originalProperties.stringPropertyNames());
}
Map propertyVersions = this.getHelper()
.getVersionPropertiesMap(VersionsHelper.VersionPropertiesMapRequest.builder()
@@ -323,10 +320,9 @@ private void resolvePropertyRanges(ModifiedPomXMLEventReader pom)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
// TODO: Check if we could add allowDowngrade ?
try {
- updatePropertyToNewestVersion(pom, property, version, currentVersion, false, unchangedSegment);
+ updatePropertyToNewestVersion(pom, property, version, currentVersion, false, unchangedSegment1);
} catch (InvalidSegmentException | InvalidVersionSpecificationException e) {
getLog().warn(String.format(
"Skipping the processing of %s:%s due to: %s",
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java
index b1b9fef939..baa70fcf92 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java
@@ -54,7 +54,7 @@
import org.codehaus.mojo.versions.change.VersionChanger;
import org.codehaus.mojo.versions.change.VersionChangerFactory;
import org.codehaus.mojo.versions.ordering.ReactorDepthComparator;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.ContextualLog;
import org.codehaus.mojo.versions.utils.DelegatingContextualLog;
import org.codehaus.mojo.versions.utils.RegexUtils;
@@ -542,11 +542,12 @@ private void applyChange(
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong.
* @throws javax.xml.stream.XMLStreamException when things go wrong.
*/
- protected synchronized void update(ModifiedPomXMLEventReader pom)
+ protected synchronized void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
ContextualLog log = new DelegatingContextualLog(getLog());
try {
- Model model = PomHelper.getRawModel(pom);
+ Model model =
+ PomHelper.getRawModel(pom.getSource(), pom.getFileName().toFile());
log.setContext("Processing " + PomHelper.getGroupId(model) + ":" + PomHelper.getArtifactId(model));
VersionChangerFactory versionChangerFactory = new VersionChangerFactory();
@@ -573,7 +574,7 @@ protected synchronized void update(ModifiedPomXMLEventReader pom)
log.clearContext();
}
- private void updateBuildOutputTimestamp(ModifiedPomXMLEventReader pom, Model model) throws XMLStreamException {
+ private void updateBuildOutputTimestamp(MutableXMLStreamReader pom, Model model) throws XMLStreamException {
String buildOutputTimestamp = model.getProperties().getProperty("project.build.outputTimestamp");
if (buildOutputTimestamp == null || isEmpty(buildOutputTimestamp)) {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
index fecc9716e8..ddf5d9ecca 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetPropertyMojo.java
@@ -37,7 +37,7 @@
import org.codehaus.mojo.versions.api.PropertyVersions;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.PropertiesVersionsFileReader;
import org.eclipse.aether.RepositorySystem;
@@ -108,9 +108,9 @@ public SetPropertyMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
Property[] propertiesConfig;
String properties;
@@ -144,7 +144,7 @@ protected void update(ModifiedPomXMLEventReader pom)
update(pom, propertiesConfig, properties);
}
- private void update(ModifiedPomXMLEventReader pom, Property[] propertiesConfig, String properties)
+ private void update(MutableXMLStreamReader pom, Property[] propertiesConfig, String properties)
throws MojoExecutionException, XMLStreamException {
Map propertyVersions = this.getHelper()
.getVersionPropertiesMap(VersionsHelper.VersionPropertiesMapRequest.builder()
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java
index 5d8fa051aa..e9e51338bf 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetScmTagMojo.java
@@ -17,7 +17,7 @@
import org.apache.maven.wagon.Wagon;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static org.apache.commons.lang3.StringUtils.isAllBlank;
@@ -90,10 +90,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}
@Override
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
try {
- Scm scm = PomHelper.getRawModel(pom).getScm();
+ Scm scm = PomHelper.getRawModel(pom.getSource(), pom.getFileName().toFile())
+ .getScm();
if (scm == null) {
throw new MojoFailureException("No was present");
}
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java
index 979cff0703..259215fdae 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UnlockSnapshotsMojo.java
@@ -37,7 +37,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
/**
@@ -75,9 +75,9 @@ public UnlockSnapshotsMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
try {
if (isProcessingDependencyManagement()) {
@@ -102,7 +102,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void unlockSnapshots(
- ModifiedPomXMLEventReader pom, List dependencies, DependencyChangeRecord.ChangeKind changeKind)
+ MutableXMLStreamReader pom, List dependencies, DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException {
for (Dependency dep : dependencies) {
if (isExcludeReactor() && isProducedByReactor(dep)) {
@@ -144,7 +144,7 @@ private void unlockSnapshots(
}
}
- private void unlockParentSnapshot(ModifiedPomXMLEventReader pom, MavenProject parent)
+ private void unlockParentSnapshot(MutableXMLStreamReader pom, MavenProject parent)
throws XMLStreamException, MojoExecutionException {
if (parent == null) {
getLog().info("Project does not have a parent");
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java
index d8c0a6ae46..4aa331ed1e 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateChildModulesMojo.java
@@ -38,7 +38,7 @@
import org.apache.maven.wagon.Wagon;
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
/**
@@ -172,7 +172,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* @throws MojoFailureException when things go wrong.
* @throws XMLStreamException when things go wrong.
*/
- protected synchronized void update(ModifiedPomXMLEventReader pom)
+ protected synchronized void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
getLog().debug("Updating parent to " + sourceVersion);
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
index 8f37aa8393..b992255a55 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdateParentMojo.java
@@ -42,7 +42,7 @@
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.SegmentUtils;
@@ -145,10 +145,10 @@ public UpdateParentMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
if (getProject().getParent() == null) {
getLog().info("Project does not have a parent");
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
index 188eeb6dd9..a0adb196ca 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojo.java
@@ -33,7 +33,7 @@
import org.codehaus.mojo.versions.api.Property;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
/**
@@ -82,10 +82,10 @@ public UpdatePropertiesMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
update(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java
index bd635fe28a..b567ecebb4 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java
@@ -36,7 +36,7 @@
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord;
import org.codehaus.mojo.versions.recording.DefaultPropertyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Optional.empty;
@@ -115,7 +115,7 @@ public UpdatePropertiesMojoBase(
super(artifactHandlerManager, repositorySystem, wagonMap, changeRecorders);
}
- protected void update(ModifiedPomXMLEventReader pom, Map propertyVersions)
+ protected void update(MutableXMLStreamReader pom, Map propertyVersions)
throws XMLStreamException {
for (Map.Entry entry : propertyVersions.entrySet()) {
Property property = entry.getKey();
@@ -148,18 +148,17 @@ protected void update(ModifiedPomXMLEventReader pom, Map unchangedSegment1 = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
+ Optional unchangedSegment = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
? empty()
: allowMinorUpdates && allowIncrementalUpdates
? of(MAJOR)
: allowIncrementalUpdates ? of(MINOR) : of(INCREMENTAL);
if (log != null && log.isDebugEnabled()) {
- log.debug(unchangedSegment1
+ log.debug(unchangedSegment
.map(Segment::minorTo)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
try {
ArtifactVersion targetVersion = updatePropertyToNewestVersion(
pom, property, version, currentVersion, allowDowngrade, unchangedSegment);
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
index 02088666e4..e03a6e0ad1 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertyMojo.java
@@ -33,7 +33,7 @@
import org.codehaus.mojo.versions.api.Property;
import org.codehaus.mojo.versions.api.VersionsHelper;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
/**
@@ -85,10 +85,10 @@ public UpdatePropertyMojo(
* @throws MojoExecutionException when things go wrong
* @throws MojoFailureException when things go wrong in a very bad way
* @throws XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
* @since 1.0-alpha-1
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException {
update(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java
index 6d5b75ed05..f195da38b7 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseDepVersionMojo.java
@@ -17,8 +17,11 @@
import javax.inject.Inject;
import javax.xml.stream.XMLStreamException;
+import javax.xml.transform.TransformerException;
import java.io.IOException;
+import java.io.Writer;
+import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -35,6 +38,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
@@ -52,7 +56,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord.ChangeKind;
import org.codehaus.mojo.versions.recording.DefaultPropertyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DependencyComparator;
import org.codehaus.mojo.versions.utils.ModelNode;
import org.eclipse.aether.RepositorySystem;
@@ -114,7 +118,7 @@ public UseDepVersionMojo(
@Override
protected void validateInput() throws MojoExecutionException {
super.validateInput();
- if (depVersion == null || depVersion.equals("")) {
+ if (StringUtils.isBlank(depVersion)) {
throw new IllegalArgumentException(
"depVersion must be supplied with use-specific-version, and cannot be blank.");
}
@@ -128,7 +132,7 @@ protected void validateInput() throws MojoExecutionException {
}
@Override
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
// not used
}
@@ -139,26 +143,28 @@ public void execute() throws MojoExecutionException, MojoFailureException {
List rawModels;
try {
- ModifiedPomXMLEventReader pomReader = newModifiedPomXER(
- PomHelper.readXmlFile(getProject().getFile()),
- getProject().getFile().toPath().toString());
- ModelNode rootNode = new ModelNode(PomHelper.getRawModel(pomReader), pomReader);
+ MutableXMLStreamReader pomReader =
+ new MutableXMLStreamReader(getProject().getFile().toPath());
+ ModelNode rootNode = new ModelNode(
+ PomHelper.getRawModel(pomReader.getSource(), getProject().getFile()), pomReader);
rawModels = PomHelper.getRawModelTree(rootNode, getLog());
// reversing to process depth-first
Collections.reverse(rawModels);
- } catch (IOException e) {
- throw new MojoFailureException(e.getMessage(), e);
- }
- try {
Set propertyBacklog = new HashSet<>();
Map> propertyConflicts = new HashMap<>();
for (ModelNode node : rawModels) {
- processModel(node, propertyBacklog, propertyConflicts);
+ processModel(
+ node,
+ propertyBacklog,
+ propertyConflicts,
+ ofNullable(pomReader.getEncoding())
+ .map(Charset::forName)
+ .orElse(Charset.defaultCharset()));
}
- propertyBacklog.forEach(p -> {
- getLog().warn("Not updating property ${" + p + "}: defined in parent");
- });
+ propertyBacklog.forEach(p -> getLog().warn("Not updating property ${" + p + "}: defined in parent"));
+ } catch (IOException | XMLStreamException | TransformerException e) {
+ throw new MojoFailureException(e.getMessage(), e);
} catch (RuntimeException e) {
if (e.getCause() instanceof MojoFailureException) {
throw (MojoFailureException) e.getCause();
@@ -179,10 +185,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* which are associated with dependencies which do not fit the filter and thus may not
* be changed. This is then used for conflict detection if a dependency to be changed
* used one of these properties. Such a change is not allowed and must be reported instead.
+ * @param charset charset for file writing
* @return {@code true} if the file has been changed
*/
protected boolean processModel(
- ModelNode node, Set propertyBacklog, Map> propertyConflicts)
+ ModelNode node,
+ Set propertyBacklog,
+ Map> propertyConflicts,
+ Charset charset)
throws MojoFailureException, MojoExecutionException {
// 1) process the properties carried over from children
propertyBacklog.removeIf(p -> updatePropertyValue(node, p));
@@ -225,7 +235,7 @@ protected boolean processModel(
e);
}
- if (node.getModifiedPomXMLEventReader().isModified()) {
+ if (node.getMutableXMLStreamReader().isModified()) {
if (generateBackupPoms) {
Objects.requireNonNull(node.getModel().getPomFile());
Objects.requireNonNull(node.getModel().getPomFile().toPath().getParent());
@@ -252,10 +262,9 @@ protected boolean processModel(
} else {
getLog().debug("Skipping the generation of a backup file");
}
- try {
- writeFile(
- node.getModel().getPomFile(),
- node.getModifiedPomXMLEventReader().asStringBuilder());
+ try (Writer writer =
+ Files.newBufferedWriter(node.getModel().getPomFile().toPath(), charset)) {
+ writer.write(node.getMutableXMLStreamReader().getSource());
} catch (IOException e) {
throw new MojoFailureException(
"Unable to write the changed file " + node.getModel().getPomFile(), e);
@@ -271,7 +280,7 @@ protected boolean processModel(
e);
}
- return node.getModifiedPomXMLEventReader().isModified();
+ return node.getMutableXMLStreamReader().isModified();
}
private static List getDependencies(Model model) {
@@ -288,7 +297,7 @@ private static List getDependencies(Model model) {
}
/**
- * Will process the given module tree node, updating the {@link ModifiedPomXMLEventReader} associated with the
+ *
Will process the given module tree node, updating the {@link MutableXMLStreamReader} associated with the
* node if it finds a dependency matching the filter that needs to be changed or, if {@link #processProperties}
* is {@code true}, a property value that can be updated.
* The method will use the set passed as the {@code backlog} argument to store the properties which it needs
@@ -311,7 +320,7 @@ private static List getDependencies(Model model) {
* be changed. This is then used for conflict detection if a dependency to be changed
* used one of these properties. Such a change is not allowed and must be reported instead.
* @throws MojoExecutionException thrown if a version may not be changed
- * @throws XMLStreamException thrown if a {@link ModifiedPomXMLEventReader} can't be updated
+ * @throws XMLStreamException thrown if a {@link MutableXMLStreamReader} can't be updated
* @throws VersionRetrievalException thrown if dependency versions cannot be retrieved
*/
private void useDepVersion(
@@ -377,7 +386,7 @@ private void useDepVersion(
}
}
if (!propertyName.isPresent()) {
- updateDependencyVersion(node.getModifiedPomXMLEventReader(), dep, depVersion, changeKind);
+ updateDependencyVersion(node.getMutableXMLStreamReader(), dep, depVersion, changeKind);
} else {
// propertyName is present
ofNullable(propertyConflicts.get(propertyName.get()))
@@ -427,14 +436,14 @@ private boolean updatePropertyValue(ModelNode node, String property) {
node.getModel().getProfiles().stream()
.map(profile -> new ImmutablePair<>(profile, profile.getProperties()))
.map(pair -> ofNullable(pair.getRight().getProperty(property))
- .map(value -> new ImmutablePair(pair.getLeft(), value))
+ .map(value -> new ImmutablePair<>(pair.getLeft(), value))
.orElse(null)))
// and processing them
.filter(Objects::nonNull)
.map(pair -> {
try {
boolean result = PomHelper.setPropertyVersion(
- node.getModifiedPomXMLEventReader(),
+ node.getMutableXMLStreamReader(),
ofNullable(pair.getLeft()).map(Profile::getId).orElse(null),
property,
depVersion);
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java
index a45751897c..05faf42852 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java
@@ -44,7 +44,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -123,9 +123,9 @@ public UseLatestReleasesMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -150,7 +150,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useLatestReleases(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
@@ -163,18 +163,17 @@ private void useLatestReleases(
log.info("Assuming allowMajorUpdates false because allowMinorUpdates is false.");
}
- Optional unchangedSegment1 = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
+ Optional unchangedSegment = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
? empty()
: allowMinorUpdates && allowIncrementalUpdates
? of(MAJOR)
: allowIncrementalUpdates ? of(MINOR) : of(INCREMENTAL);
if (log != null && log.isDebugEnabled()) {
- log.debug(unchangedSegment1
+ log.debug(unchangedSegment
.map(Segment::minorTo)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
useLatestVersions(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java
index 847fc3c739..dad9137582 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java
@@ -40,7 +40,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -102,9 +102,9 @@ public UseLatestSnapshotsMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -129,7 +129,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useLatestSnapshots(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
@@ -142,18 +142,17 @@ private void useLatestSnapshots(
log.info("Assuming allowMajorUpdates false because allowMinorUpdates is false.");
}
- Optional unchangedSegment1 = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
+ Optional unchangedSegment = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
? empty()
: allowMinorUpdates && allowIncrementalUpdates
? of(MAJOR)
: allowIncrementalUpdates ? of(MINOR) : of(INCREMENTAL);
if (log != null && log.isDebugEnabled()) {
- log.debug(unchangedSegment1
+ log.debug(unchangedSegment
.map(Segment::minorTo)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
useLatestVersions(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java
index 665b081512..9b3669f7cd 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java
@@ -38,7 +38,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -117,9 +117,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -144,7 +144,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useLatestVersions(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
@@ -157,18 +157,17 @@ private void useLatestVersions(
log.info("Assuming allowMajorUpdates false because allowMinorUpdates is false.");
}
- Optional unchangedSegment1 = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
+ Optional unchangedSegment = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
? empty()
: allowMinorUpdates && allowIncrementalUpdates
? of(MAJOR)
: allowIncrementalUpdates ? of(MINOR) : of(INCREMENTAL);
if (log != null && log.isDebugEnabled()) {
- log.debug(unchangedSegment1
+ log.debug(unchangedSegment
.map(Segment::minorTo)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
useLatestVersions(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java
index 413fd1adc0..c28897beea 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java
@@ -34,7 +34,7 @@
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DefaultArtifactVersionCache;
import org.eclipse.aether.RepositorySystem;
@@ -67,7 +67,7 @@ public UseLatestVersionsMojoBase(
*/
@SafeVarargs
protected final void useLatestVersions(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
BiFunction> newestVersionProducer,
DependencyChangeRecord.ChangeKind changeKind,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java
index 2fd09ea769..b71f25e78f 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextReleasesMojo.java
@@ -37,7 +37,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -78,9 +78,9 @@ public UseNextReleasesMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -104,7 +104,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useNextReleases(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java
index 17c78bc6c0..de093e7aa7 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java
@@ -39,7 +39,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -103,9 +103,9 @@ public UseNextSnapshotsMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
DependencyManagement dependencyManagement =
@@ -128,7 +128,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useNextSnapshots(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
@@ -141,18 +141,17 @@ private void useNextSnapshots(
log.info("Assuming allowMajorUpdates false because allowMinorUpdates is false.");
}
- Optional unchangedSegment1 = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
+ Optional unchangedSegment = allowMajorUpdates && allowMinorUpdates && allowIncrementalUpdates
? empty()
: allowMinorUpdates && allowIncrementalUpdates
? of(MAJOR)
: allowIncrementalUpdates ? of(MINOR) : of(INCREMENTAL);
if (log != null && log.isDebugEnabled()) {
- log.debug(unchangedSegment1
+ log.debug(unchangedSegment
.map(Segment::minorTo)
.map(Segment::toString)
.orElse("ALL") + " version changes allowed");
}
- Optional unchangedSegment = unchangedSegment1;
useLatestVersions(
pom,
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java
index 1b46270940..ab54807649 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextVersionsMojo.java
@@ -37,7 +37,7 @@
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.ordering.InvalidSegmentException;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -80,9 +80,9 @@ public UseNextVersionsMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -104,7 +104,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useNextVersions(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java
index 0808ce0898..3fd045f25f 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReactorMojo.java
@@ -39,7 +39,7 @@
import org.codehaus.mojo.versions.api.PomHelper;
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
/**
@@ -67,9 +67,9 @@ public UseReactorMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingParent() && getProject().hasParent()) {
@@ -90,7 +90,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
}
- private void useReactor(ModifiedPomXMLEventReader pom, Collection dependencies)
+ private void useReactor(MutableXMLStreamReader pom, Collection dependencies)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
for (Dependency dep : dependencies) {
@@ -100,19 +100,18 @@ private void useReactor(ModifiedPomXMLEventReader pom, Collection de
}
for (MavenProject reactorProject : reactorProjects) {
- MavenProject project = reactorProject;
- if (StringUtils.equals(project.getGroupId(), dep.getGroupId())
- && StringUtils.equals(project.getArtifactId(), dep.getArtifactId())
- && !StringUtils.equals(project.getVersion(), dep.getVersion())) {
+ if (StringUtils.equals(reactorProject.getGroupId(), dep.getGroupId())
+ && StringUtils.equals(reactorProject.getArtifactId(), dep.getArtifactId())
+ && !StringUtils.equals(reactorProject.getVersion(), dep.getVersion())) {
if (PomHelper.setDependencyVersion(
pom,
dep.getGroupId(),
dep.getArtifactId(),
dep.getVersion(),
- project.getVersion(),
+ reactorProject.getVersion(),
getProject().getModel(),
getLog())) {
- getLog().info("Updated " + toString(dep) + " to version " + project.getVersion());
+ getLog().info("Updated " + toString(dep) + " to version " + reactorProject.getVersion());
}
break;
}
@@ -120,7 +119,7 @@ private void useReactor(ModifiedPomXMLEventReader pom, Collection de
}
}
- private void useReactor(ModifiedPomXMLEventReader pom, MavenProject parent)
+ private void useReactor(MutableXMLStreamReader pom, MavenProject parent)
throws XMLStreamException, VersionRetrievalException {
for (MavenProject project : reactorProjects) {
if (StringUtils.equals(project.getGroupId(), parent.getGroupId())
diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java
index a115a84f47..ce1249f2c9 100644
--- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java
+++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseReleasesMojo.java
@@ -40,7 +40,7 @@
import org.codehaus.mojo.versions.api.VersionRetrievalException;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.eclipse.aether.RepositorySystem;
import static java.util.Collections.singletonList;
@@ -90,9 +90,9 @@ public UseReleasesMojo(
* @throws org.apache.maven.plugin.MojoExecutionException when things go wrong
* @throws org.apache.maven.plugin.MojoFailureException when things go wrong in a very bad way
* @throws javax.xml.stream.XMLStreamException when things go wrong with XML streaming
- * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader)
+ * @see org.codehaus.mojo.versions.AbstractVersionsUpdaterMojo#update(MutableXMLStreamReader)
*/
- protected void update(ModifiedPomXMLEventReader pom)
+ protected void update(MutableXMLStreamReader pom)
throws MojoExecutionException, MojoFailureException, XMLStreamException, VersionRetrievalException {
try {
if (isProcessingDependencyManagement()) {
@@ -117,7 +117,7 @@ protected void update(ModifiedPomXMLEventReader pom)
}
private void useReleases(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Collection dependencies,
DependencyChangeRecord.ChangeKind changeKind)
throws XMLStreamException, MojoExecutionException, VersionRetrievalException {
@@ -165,7 +165,7 @@ private void useReleases(
}
private Optional findReleaseVersion(
- ModifiedPomXMLEventReader pom,
+ MutableXMLStreamReader pom,
Dependency dep,
String version,
String releaseVersion,
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/LockSnapshotsMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/LockSnapshotsMojoTest.java
index 9d61d1d043..613713be2c 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/LockSnapshotsMojoTest.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/LockSnapshotsMojoTest.java
@@ -27,6 +27,7 @@
import org.apache.maven.plugin.testing.stubs.DefaultArtifactHandlerStub;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.api.PomHelper;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.codehaus.mojo.versions.utils.DependencyBuilder;
import org.codehaus.mojo.versions.utils.MockUtils;
import org.eclipse.aether.RepositorySystem;
@@ -120,7 +121,7 @@ public void testNoTimestampedParentFoundNull()
LockSnapshotsMojo mojo = createMojo(repositorySystem);
try (MockedStatic pomHelper = mockStatic(PomHelper.class)) {
pomHelper
- .when(() -> PomHelper.setProjectParentVersion(any(), any()))
+ .when(() -> PomHelper.setProjectParentVersion(any(MutableXMLStreamReader.class), any()))
.thenThrow(new RuntimeException("Not supposed to modify the parent"));
mojo.lockParentSnapshot(
null,
@@ -153,7 +154,7 @@ public void testNoTimestampedParentFoundSameVersion()
LockSnapshotsMojo mojo = createMojo(repositorySystem);
try (MockedStatic pomHelper = mockStatic(PomHelper.class)) {
pomHelper
- .when(() -> PomHelper.setProjectParentVersion(any(), any()))
+ .when(() -> PomHelper.setProjectParentVersion(any(MutableXMLStreamReader.class), any()))
.thenThrow(new RuntimeException("Not supposed to modify the parent"));
mojo.lockParentSnapshot(
null,
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/RewriteWithStAXTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/RewriteWithStAXTest.java
deleted file mode 100644
index 459a55ea71..0000000000
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/RewriteWithStAXTest.java
+++ /dev/null
@@ -1,293 +0,0 @@
-package org.codehaus.mojo.versions;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import javax.xml.stream.XMLEventReader;
-import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLOutputFactory;
-import javax.xml.stream.events.EndElement;
-import javax.xml.stream.events.StartElement;
-import javax.xml.stream.events.XMLEvent;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Stack;
-
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
-import org.codehaus.stax2.XMLInputFactory2;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
-/**
- * Basic tests for rewriting XML with a StAX (JSR-173) implementation.
- *
- * @author Stephen Connolly
- */
-public class RewriteWithStAXTest {
- @Test
- public void testBasic() throws Exception {
- String input = "\n" + "\n\r\n\r\n\r\n\r" + " \r\n"
- + " org.codehaus.mojo\n"
- + " mojo-&sandbox-parent\n" + " 5-SNAPSHOT\r"
- + " \r" + "";
-
- byte[] rawInput = input.getBytes(StandardCharsets.UTF_8);
- ByteArrayInputStream source = new ByteArrayInputStream(rawInput);
- ByteArrayOutputStream dest = new ByteArrayOutputStream();
- XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
- inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE);
- XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
- XMLEventReader eventReader = inputFactory.createXMLEventReader(source);
- XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(dest, "utf-8");
- while (eventReader.hasNext()) {
- eventWriter.add(eventReader.nextEvent());
- }
-
- String output = dest.toString("utf-8");
-
- assertNotEquals("StAX implementation is not good enough", input, output);
- }
-
- @Test
- public void testReplace() throws Exception {
- String input = "\n" + "\n\r\n\r\n\r\n\r" + " \r\n"
- + " org.codehaus.mojo\n"
- + " mojo-&sandbox-parent\n" + " 5-SNAPSHOT\r"
- + " \r" + "";
- String expected = "\n" + "\n\r\n\r\n\r\n\r" + " \r\n"
- + " org.codehaus.mojo\n"
- + " my-artifact\n"
- + " 5-SNAPSHOT\r" + " \r" + "";
-
- StringBuilder output = new StringBuilder(input);
-
- XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
- inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE);
- ModifiedPomXMLEventReader eventReader = new ModifiedPomXMLEventReader(output, inputFactory, null);
- while (eventReader.hasNext()) {
- XMLEvent event = eventReader.nextEvent();
- if (event instanceof StartElement
- && event.asStartElement().getName().getLocalPart().equals("artifactId")) {
- eventReader.mark(0);
- }
- if (event instanceof EndElement
- && event.asEndElement().getName().getLocalPart().equals("artifactId")) {
- eventReader.mark(1);
- if (eventReader.hasMark(0)) {
- eventReader.replaceBetween(0, 1, "my-artifact");
- }
- }
- }
-
- assertEquals(expected, output.toString());
- }
-
- @SuppressWarnings({"checkstyle:MethodLength", "checkstyle:LineLength"})
- @Test
- public void testReplaceFancy() throws Exception {
- String input =
- "\n"
- + " 4.0.0\n" + "\n" + " \n"
- + " org.codehaus.mojo\n"
- + " mojo-sandbox-parent\n"
- + " 5-SNAPSHOT\n" + " \n" + "\n"
- + " org.codehaus.mojo\n"
- + " versions-maven-plugin\n"
- + " 1.0.0-alpha-1-SNAPSHOT\n" + " maven-plugin\n"
- + "\n"
- + " Versions Maven Plugin\n" + " \n"
- + " Versions plugin for Maven 2. The versions plugin updates the versions of components in the pom.\n"
- + " \n" + " 2008\n" + " \n"
- + " \n" + " The Apache Software License, Version 2.0\n"
- + " http://www.apache.org/licenses/LICENSE-2.0\n"
- + " repo\n" + " \n" + " \n" + "\n"
- + " \n"
- + " scm:svn:http://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " scm:svn:https://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " http://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " \n"
- + "\n" + " \n" + " \n" + " Stephen Connolly\n"
- + " stephen.alan.connolly@gmail.com\n" + " \n"
- + " Java Developer\n" + " \n"
- + " 0\n"
- + " \n" + " \n" + "\n" + " \n"
- + " 2.0.6\n" + " \n" + "\n" + " \n"
- + " \n" + " junit\n"
- + " junit\n"
- + " 3.8.1\n" + " test\n" + " \n"
- + " \n" + " org.apache.maven\n"
- + " maven-project\n" + " 2.0\n"
- + " \n" + " \n" + " org.apache.maven\n"
- + " maven-settings\n" + " 2.0\n"
- + " \n" + " \n" + " org.apache.maven\n"
- + " maven-plugin-api\n" + " 2.0\n"
- + " \n" + " \n"
- + " org.codehaus.plexus\n"
- + " plexus-utils\n" + " 1.3\n"
- + " \n" + " \n"
- + " org.codehaus.plexus\n"
- + " plexus-interactivity-api\n"
- + " 1.0-alpha-6\n"
- + " \n" + " \n"
- + " plexus-utils\n"
- + " plexus\n" + " \n" + " \n"
- + " \n" + " \n" + " javax.xml.stream\n"
- + " stax-api\n" + " 1.0-2\n"
- + " \n" + " \n" + " stax\n"
- + " stax\n" + " 1.1.1-dev\n"
- + " \n" + " \n" + "\n" + " \n" + " \n"
- + " \n" + " maven-plugin-plugin\n"
- + " 2.3\n" + " \n"
- + " versions\n" + " \n"
- + " \n"
- + " \n" + " \n" + "\n" + "";
- String expected =
- "\n"
- + " 4.0.0\n" + "\n" + " \n"
- + " org.codehaus.mojo\n"
- + " mojo-sandbox-parent\n"
- + " 4\n" + " \n" + "\n"
- + " org.codehaus.mojo\n"
- + " versions-maven-plugin\n"
- + " 1.0.0-alpha-1-SNAPSHOT\n"
- + " maven-plugin\n" + "\n" + " Versions Maven Plugin\n"
- + " \n"
- + " Versions plugin for Maven 2. The versions plugin updates the versions of components in the pom.\n"
- + " \n" + " 2008\n" + " \n"
- + " \n" + " The Apache Software License, Version 2.0\n"
- + " http://www.apache.org/licenses/LICENSE-2.0\n"
- + " repo\n" + " \n" + " \n" + "\n"
- + " \n"
- + " scm:svn:http://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " scm:svn:https://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " http://svn.codehaus.org/mojo/trunk/sandbox/versions-maven-plugin\n"
- + " \n"
- + "\n" + " \n" + " \n" + " Stephen Connolly\n"
- + " stephen.alan.connolly@gmail.com\n" + " \n"
- + " Java Developer\n" + " \n"
- + " 0\n"
- + " \n" + " \n" + "\n" + " \n"
- + " 2.0.6\n" + " \n" + "\n" + " \n"
- + " \n" + " junit\n"
- + " junit\n"
- + " 3.8.2\n" + " test\n" + " \n"
- + " \n" + " org.apache.maven\n"
- + " maven-project\n" + " 2.0\n"
- + " \n" + " \n" + " org.apache.maven\n"
- + " maven-settings\n" + " 2.0\n"
- + " \n" + " \n" + " org.apache.maven\n"
- + " maven-plugin-api\n" + " 2.0\n"
- + " \n" + " \n"
- + " org.codehaus.plexus\n"
- + " plexus-utils\n" + " 1.3\n"
- + " \n" + " \n"
- + " org.codehaus.plexus\n"
- + " plexus-interactivity-api\n"
- + " 1.0-alpha-6\n"
- + " \n" + " \n"
- + " plexus-utils\n"
- + " plexus\n" + " \n" + " \n"
- + " \n" + " \n" + " javax.xml.stream\n"
- + " stax-api\n" + " 1.0-2\n"
- + " \n" + " \n" + " stax\n"
- + " stax\n" + " 1.1.1-dev\n"
- + " \n" + " \n" + "\n" + " \n" + " \n"
- + " \n" + " maven-plugin-plugin\n"
- + " 2.3\n" + " \n"
- + " versions\n" + " \n"
- + " \n"
- + " \n" + " \n" + "\n" + "";
-
- StringBuilder output = new StringBuilder(input);
-
- XMLInputFactory inputFactory = XMLInputFactory2.newInstance();
- inputFactory.setProperty(XMLInputFactory2.P_PRESERVE_LOCATION, Boolean.TRUE);
- ModifiedPomXMLEventReader eventReader = new ModifiedPomXMLEventReader(output, inputFactory, null);
-
- Stack stack = new Stack<>();
- String path = "";
-
- while (eventReader.hasNext()) {
- XMLEvent event = eventReader.nextEvent();
- if (event.isStartElement()) {
- stack.push(path);
- path += "/" + event.asStartElement().getName().getLocalPart();
-
- if ("/project/parent/version".equals(path)) {
- eventReader.mark(0);
- }
- }
- if (event.isEndElement()) {
- if ("/project/parent/version".equals(path)) {
- eventReader.mark(1);
- if (eventReader.hasMark(0)) {
- eventReader.replaceBetween(0, 1, "4");
- }
- }
- path = stack.pop();
- }
- }
-
- boolean inDependency = false;
- boolean groupIdMatches = false;
- boolean artifactIdMatches = false;
- eventReader.rewind();
-
- while (eventReader.hasNext()) {
- XMLEvent event = eventReader.nextEvent();
- if (event.isStartElement()) {
- String name = event.asStartElement().getName().getLocalPart();
- if (inDependency) {
- if ("groupId".equals(name)) {
- groupIdMatches = "junit".equals(eventReader.getElementText());
- } else if ("artifactId".equals(name)) {
- artifactIdMatches = "junit".equals(eventReader.getElementText());
- } else if ("version".equals(name)) {
- eventReader.mark(1);
- }
- } else if ("dependency".equals(name)) {
- inDependency = true;
- groupIdMatches = false;
- artifactIdMatches = false;
- }
- }
- if (event.isEndElement()) {
- String name = event.asEndElement().getName().getLocalPart();
- if (inDependency) {
- if ("version".equals(name)) {
- eventReader.mark(2);
-
- } else if ("dependency".equals(name)) {
- if (groupIdMatches && artifactIdMatches && eventReader.hasMark(1) && eventReader.hasMark(2)) {
- eventReader.replaceBetween(1, 2, "3.8.2");
- }
- inDependency = false;
- }
- }
- }
- }
-
- assertEquals(expected, output.toString());
- }
-}
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java
index eddda8473c..1d7c0d9cc3 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SeparatePatternsForIncludesAnExcludesTest.java
@@ -2,7 +2,7 @@
import java.util.List;
-import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader;
+import org.codehaus.mojo.versions.rewriting.MutableXMLStreamReader;
import org.junit.Before;
import org.junit.Test;
@@ -16,7 +16,7 @@ public class SeparatePatternsForIncludesAnExcludesTest {
public void setUp() throws Exception {
mojo = new AbstractVersionsDependencyUpdaterMojo(null, null, null, null) {
@Override
- protected void update(ModifiedPomXMLEventReader pom) {}
+ protected void update(MutableXMLStreamReader pom) {}
};
}
diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java
index b27290997f..9a4f073214 100644
--- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java
+++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTestBase.java
@@ -20,12 +20,10 @@
import java.nio.file.Path;
import java.util.HashMap;
-import java.util.Map;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.plugin.testing.MojoRule;
-import org.codehaus.mojo.versions.api.recording.ChangeRecorder;
import org.codehaus.mojo.versions.utils.TestChangeRecorder;
import org.eclipse.aether.RepositorySystem;
import org.junit.After;
@@ -72,9 +70,9 @@ protected T setUpMojo(String goal) throws Exception {
T mojo = (T) mojoRule.lookupConfiguredMojo(pomDir.toFile(), goal);
setVariableValueToObject(mojo, "repositorySystem", repositorySystem);
setVariableValueToObject(mojo, "generateBackupPoms", false);
- setVariableValueToObject(mojo, "changeRecorderFormat", "test");
- changeRecorder = (TestChangeRecorder)
- ((Map) getVariableValueFromObject(mojo, "changeRecorders")).get("test");
+ setVariableValueToObject(mojo, "changeRecorderFormat", "none");
+ changeRecorder = new TestChangeRecorder();
+ setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap());
return (T) mojo;
}