From 63b707478cbb7a32145ea02f1fbcfc6165de9bc1 Mon Sep 17 00:00:00 2001 From: Slawomir Jaranowski Date: Sun, 20 Nov 2022 16:46:52 +0100 Subject: [PATCH] Introduce Plugin API for ChangeRecorder --- pom.xml | 5 +- versions-api/pom.xml | 15 +++ .../versions/api/change/VersionChange.java | 14 +++ .../versions/api/recording/ChangeRecord.java | 40 +++++++ .../api}/recording/ChangeRecorder.java | 22 ++-- versions-common/pom.xml | 22 ++++ .../change/CompositeVersionChanger.java | 2 + ...nChange.java => DefaultVersionChange.java} | 10 +- .../change/DependencyVersionChanger.java | 1 + .../versions/change/ParentVersionChanger.java | 1 + .../versions/change/PluginVersionChanger.java | 1 + .../change/ProjectVersionChanger.java | 1 + .../mojo/versions/change/VersionChanger.java | 2 + .../recording/ChangeRecorderNull.java | 14 ++- .../versions/recording/ChangeRecorderXML.java | 55 ++++++--- .../recording/DefaultChangeRecord.java | 104 ++++++++++++++++++ .../recording/ChangeRecorderXMLTest.java | 75 ++++++++----- versions-maven-plugin/pom.xml | 14 +++ ...AbstractVersionsDependencyUpdaterMojo.java | 39 ++++--- .../versions/AbstractVersionsDisplayMojo.java | 8 +- .../versions/AbstractVersionsUpdaterMojo.java | 62 ++++------- .../versions/CompareDependenciesMojo.java | 11 +- .../DisplayDependencyUpdatesMojo.java | 13 ++- .../versions/DisplayParentUpdatesMojo.java | 15 ++- .../versions/DisplayPluginUpdatesMojo.java | 7 +- .../versions/DisplayPropertyUpdatesMojo.java | 13 ++- .../mojo/versions/ForceReleasesMojo.java | 20 ++-- .../mojo/versions/LockSnapshotsMojo.java | 14 ++- .../mojo/versions/ResolveRangesMojo.java | 13 ++- .../org/codehaus/mojo/versions/SetMojo.java | 23 ++-- .../mojo/versions/SetPropertyMojo.java | 13 ++- .../codehaus/mojo/versions/SetScmTagMojo.java | 14 ++- .../mojo/versions/UnlockSnapshotsMojo.java | 26 +++-- .../mojo/versions/UpdateChildModulesMojo.java | 13 ++- .../mojo/versions/UpdateParentMojo.java | 26 +++-- .../mojo/versions/UpdatePropertiesMojo.java | 25 +++-- .../mojo/versions/UpdatePropertyMojo.java | 18 ++- .../mojo/versions/UseDepVersionMojo.java | 17 ++- .../mojo/versions/UseLatestReleasesMojo.java | 19 ++-- .../mojo/versions/UseLatestSnapshotsMojo.java | 21 ++-- .../mojo/versions/UseLatestVersionsMojo.java | 19 ++-- .../versions/UseLatestVersionsMojoBase.java | 21 ++-- .../mojo/versions/UseNextReleasesMojo.java | 14 ++- .../mojo/versions/UseNextSnapshotsMojo.java | 15 ++- .../mojo/versions/UseNextVersionsMojo.java | 13 ++- .../mojo/versions/UseReactorMojo.java | 14 ++- .../mojo/versions/UseReleasesMojo.java | 17 ++- .../DisplayDependencyUpdatesMojoTest.java | 73 +++++++----- .../mojo/versions/ForceReleasesMojoTest.java | 25 ++--- ...ratePatternsForIncludesAnExcludesTest.java | 2 +- .../codehaus/mojo/versions/SetMojoTest.java | 8 +- .../mojo/versions/UpdateParentMojoTest.java | 34 +++--- .../versions/UpdatePropertiesMojoTest.java | 14 +-- .../UpdatePropertiesMojoTestBase.java | 9 +- .../mojo/versions/UpdatePropertyMojoTest.java | 14 +-- .../versions/UseLatestReleasesMojoTest.java | 14 +-- .../versions/UseLatestVersionsMojoTest.java | 47 ++++---- .../mojo/versions/UseReleasesMojoTest.java | 17 ++- .../versions/utils/TestChangeRecorder.java | 27 +++-- 59 files changed, 824 insertions(+), 401 deletions(-) create mode 100644 versions-api/pom.xml create mode 100644 versions-api/src/main/java/org/codehaus/mojo/versions/api/change/VersionChange.java create mode 100644 versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecord.java rename {versions-common/src/main/java/org/codehaus/mojo/versions => versions-api/src/main/java/org/codehaus/mojo/versions/api}/recording/ChangeRecorder.java (66%) rename versions-common/src/main/java/org/codehaus/mojo/versions/change/{VersionChange.java => DefaultVersionChange.java} (86%) create mode 100644 versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java diff --git a/pom.xml b/pom.xml index 14c99efdc4..b9f42edeae 100644 --- a/pom.xml +++ b/pom.xml @@ -96,10 +96,11 @@ - versions-maven-plugin - model-ruleset model-report + model-ruleset + versions-api versions-common + versions-maven-plugin diff --git a/versions-api/pom.xml b/versions-api/pom.xml new file mode 100644 index 0000000000..58bcd09425 --- /dev/null +++ b/versions-api/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + + org.codehaus.mojo.versions + versions + 2.14.0-SNAPSHOT + + + versions-api + Versions API + diff --git a/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/VersionChange.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/VersionChange.java new file mode 100644 index 0000000000..99362e32eb --- /dev/null +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/VersionChange.java @@ -0,0 +1,14 @@ +package org.codehaus.mojo.versions.api.change; + +public interface VersionChange +{ + + String getGroupId(); + + String getArtifactId(); + + String getOldVersion(); + + String getNewVersion(); + +} diff --git a/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecord.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecord.java new file mode 100644 index 0000000000..b277f5318e --- /dev/null +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecord.java @@ -0,0 +1,40 @@ +package org.codehaus.mojo.versions.api.recording; + +import org.codehaus.mojo.versions.api.change.VersionChange; + +public interface ChangeRecord +{ + enum ChangeKind + { + COMPARE_DEPENDENCIES( "compareDependencies" ), + FORCE_RELEASES( "forceReleases" ), + UNLOCK_PARENT_VERSION( "unlockParentVersion" ), + UNLOCK_SNAPSHOT( "unlockSnapshot" ), + UPDATE_PARENT( "updateParent" ), + UPDATE_PROPERTY( "updateProperty" ), + USE_DEPENDENCY_VERSION( "useDependencyVersion" ), + USE_LATEST_RELEASES( "useLatestReleases" ), + USE_LATEST_SNAPSHOTS( "useLatestSnapshots" ), + USE_LATEST_VERSIONS( "useLatestVersions" ), + USE_NEXT_RELEASES( "useNextReleases" ), + USE_NEXT_SNAPSHOTS( "useNextSnapshots" ), + USE_NEXT_VERSIONS( "useNextVersions" ), + USE_RELEASES( "useReleases" ); + + private final String label; + + ChangeKind( String label ) + { + this.label = label; + } + + public String getLabel() + { + return label; + } + } + + ChangeKind getKind(); + + VersionChange getVersionChange(); +} diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorder.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecorder.java similarity index 66% rename from versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorder.java rename to versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecorder.java index 32483c4906..ba0faa8fd1 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorder.java +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/ChangeRecorder.java @@ -1,4 +1,4 @@ -package org.codehaus.mojo.versions.recording; +package org.codehaus.mojo.versions.api.recording; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -20,7 +20,7 @@ */ import java.io.IOException; -import java.io.OutputStream; +import java.nio.file.Path; /** * A recorder of version updates. @@ -31,21 +31,21 @@ public interface ChangeRecorder /** * Record that a dependency was updated. * - * @param kind The kind of version change - * @param groupId The dependency group ID - * @param artifactId The dependency artifact ID - * @param oldVersion The old version of the dependency - * @param newVersion The new version of the dependency + * @param changeRecord a record described change */ - void recordUpdate( String kind, String groupId, String artifactId, String oldVersion, String newVersion ); + void recordUpdate( ChangeRecord changeRecord ); /** - * Serialize the current set of changes to the given output stream. + * Serialize the current set of changes to the given output path. + *

+ * Implementation is responsible for creating all missing directories. + *

+ * Output should not be created for empty record sets. * - * @param outputStream The output stream + * @param outputPath The output path, can be null * @throws IOException On serialization and/or I/O errors */ - void serialize( OutputStream outputStream ) throws IOException; + void serialize( Path outputPath ) throws IOException; } diff --git a/versions-common/pom.xml b/versions-common/pom.xml index dffbe388bc..9194177360 100644 --- a/versions-common/pom.xml +++ b/versions-common/pom.xml @@ -15,6 +15,11 @@ Common components for the Versions Maven Plugin + + org.codehaus.mojo.versions + versions-api + 2.14.0-SNAPSHOT + org.codehaus.mojo.versions model-ruleset @@ -120,4 +125,21 @@ + + + + org.eclipse.sisu + sisu-maven-plugin + 0.9.0.M1 + + + generate-index + + main-index + + + + + + diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/CompositeVersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/CompositeVersionChanger.java index 26ee76a7cb..b0bb3b9421 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/CompositeVersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/CompositeVersionChanger.java @@ -25,6 +25,8 @@ import java.util.Arrays; import java.util.List; +import org.codehaus.mojo.versions.api.change.VersionChange; + /** * Created by IntelliJ IDEA. * diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChange.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java similarity index 86% rename from versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChange.java rename to versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java index 753f3c81a6..f0f43ba25e 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChange.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java @@ -21,13 +21,15 @@ import java.util.Objects; +import org.codehaus.mojo.versions.api.change.VersionChange; + /** * Represents a change of an artifact's version. * * @author Stephen Connolly * @since 15-Sep-2010 14:48:10 */ -public final class VersionChange +public final class DefaultVersionChange implements VersionChange { private final String groupId; @@ -37,7 +39,7 @@ public final class VersionChange private final String newVersion; - public VersionChange( String groupId, String artifactId, String oldVersion, String newVersion ) + public DefaultVersionChange( String groupId, String artifactId, String oldVersion, String newVersion ) { this.groupId = groupId; this.artifactId = artifactId; @@ -76,7 +78,7 @@ public boolean equals( Object o ) return false; } - VersionChange versionChange = (VersionChange) o; + DefaultVersionChange versionChange = (DefaultVersionChange) o; if ( !Objects.equals( artifactId, versionChange.artifactId ) ) { @@ -104,6 +106,6 @@ public int hashCode() public String toString() { - return "VersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion + ')'; + return "DefaultVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion + ')'; } } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/DependencyVersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DependencyVersionChanger.java index 2ae7173224..a106150773 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/DependencyVersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DependencyVersionChanger.java @@ -24,6 +24,7 @@ import org.apache.maven.model.Model; import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.change.VersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/ParentVersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/ParentVersionChanger.java index 7d39e15a07..a0220049b1 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/ParentVersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/ParentVersionChanger.java @@ -24,6 +24,7 @@ import org.apache.maven.model.Model; import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.change.VersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/PluginVersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/PluginVersionChanger.java index 8c2f80ea11..60ddce5831 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/PluginVersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/PluginVersionChanger.java @@ -24,6 +24,7 @@ import org.apache.maven.model.Model; import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.change.VersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/ProjectVersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/ProjectVersionChanger.java index 17fc8b9c85..64e8a87605 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/ProjectVersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/ProjectVersionChanger.java @@ -24,6 +24,7 @@ import org.apache.maven.model.Model; import org.apache.maven.plugin.logging.Log; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.change.VersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChanger.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChanger.java index ae3a62d717..dd86e8e8b1 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChanger.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/VersionChanger.java @@ -21,6 +21,8 @@ import javax.xml.stream.XMLStreamException; +import org.codehaus.mojo.versions.api.change.VersionChange; + /** * Created by IntelliJ IDEA. * diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderNull.java b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderNull.java index dc8c013c1d..8f8c3a6f82 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderNull.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderNull.java @@ -19,12 +19,17 @@ * under the License. */ -import java.io.OutputStream; +import javax.inject.Named; + +import java.nio.file.Path; + +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; /** * A recorder that ignores updates. */ - +@Named( "none" ) public class ChangeRecorderNull implements ChangeRecorder { /** @@ -35,13 +40,12 @@ public ChangeRecorderNull() } @Override - public final void recordUpdate( final String kind, final String groupId, final String artifactId, - final String oldVersion, final String newVersion ) + public final void recordUpdate( ChangeRecord changeRecord ) { } @Override - public final void serialize( final OutputStream outputStream ) + public final void serialize( final Path outputPath ) { } } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java index 6fa2a82c41..cf7013b360 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java @@ -19,6 +19,8 @@ * under the License. */ +import javax.inject.Named; +import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -31,16 +33,24 @@ import java.io.IOException; import java.io.OutputStream; -import java.util.Objects; +import java.nio.file.Files; +import java.nio.file.Path; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; +import static java.nio.file.StandardOpenOption.CREATE; +import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING; +import static java.nio.file.StandardOpenOption.WRITE; + /** * A recorder of version updates. */ +@Named( "xml" ) public class ChangeRecorderXML implements ChangeRecorder { /** @@ -72,31 +82,40 @@ public ChangeRecorderXML() } @Override - public final void recordUpdate( final String kind, final String groupId, final String artifactId, - final String oldVersion, final String newVersion ) + public final void recordUpdate( ChangeRecord changeRecord ) { - Objects.requireNonNull( kind, "kind" ); - Objects.requireNonNull( groupId, "groupId" ); - Objects.requireNonNull( artifactId, "artifactId" ); - Objects.requireNonNull( oldVersion, "oldVersion" ); - Objects.requireNonNull( newVersion, "newVersion" ); - final Element update = this.document.createElementNS( CHANGES_NAMESPACE, "update" ); - update.setAttribute( "kind", kind ); - update.setAttribute( "groupId", groupId ); - update.setAttribute( "artifactId", artifactId ); - update.setAttribute( "oldVersion", oldVersion ); - update.setAttribute( "newVersion", newVersion ); + update.setAttribute( "kind", changeRecord.getKind().getLabel() ); + update.setAttribute( "groupId", changeRecord.getVersionChange().getGroupId() ); + update.setAttribute( "artifactId", changeRecord.getVersionChange().getArtifactId() ); + update.setAttribute( "oldVersion", changeRecord.getVersionChange().getOldVersion() ); + update.setAttribute( "newVersion", changeRecord.getVersionChange().getNewVersion() ); this.root.appendChild( update ); } @Override - public final void serialize( final OutputStream outputStream ) throws IOException + public final void serialize( final Path outputPath ) throws IOException { - try + if ( outputPath == null ) + { + throw new IOException( "changeRecorderOutputFile not provided" ); + } + + if ( root.getChildNodes().getLength() == 0 ) + { + // don't generate empty file + return; + } + + Files.createDirectories( outputPath.getParent() ); + + try ( OutputStream outputStream = Files.newOutputStream( outputPath, CREATE, TRUNCATE_EXISTING, WRITE ) ) { - final Transformer transformer = TransformerFactory.newInstance().newTransformer(); - final Source source = new DOMSource( this.document ); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute( XMLConstants.ACCESS_EXTERNAL_DTD, "" ); + transformerFactory.setAttribute( XMLConstants.ACCESS_EXTERNAL_STYLESHEET, "" ); + Transformer transformer = transformerFactory.newTransformer(); + Source source = new DOMSource( this.document ); transformer.transform( source, new StreamResult( outputStream ) ); outputStream.flush(); } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java new file mode 100644 index 0000000000..a3c8d82d7d --- /dev/null +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java @@ -0,0 +1,104 @@ +package org.codehaus.mojo.versions.recording; + +import java.util.Objects; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.model.Dependency; +import org.codehaus.mojo.versions.api.change.VersionChange; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.change.DefaultVersionChange; + +public class DefaultChangeRecord implements ChangeRecord +{ + private final ChangeKind kind; + private final VersionChange versionChange; + + private DefaultChangeRecord( ChangeKind kind, VersionChange versionChange ) + { + this.kind = Objects.requireNonNull( kind, "kind must not be null" ); + this.versionChange = Objects.requireNonNull( versionChange, "versionChange must not be null" ); + + } + + @Override + public ChangeKind getKind() + { + return kind; + } + + @Override + public VersionChange getVersionChange() + { + return versionChange; + } + + + public static Builder builder() + { + return new Builder(); + } + + public static class Builder + { + + private ChangeKind kind; + private String groupId; + private String artifactId; + private String oldVersion; + private String newVersion; + + public Builder withKind( ChangeKind kind ) + { + this.kind = kind; + return this; + } + + public Builder withGroupId( String groupId ) + { + this.groupId = groupId; + return this; + } + + public Builder withArtifactId( String artifactId ) + { + this.artifactId = artifactId; + return this; + } + + public Builder withOldVersion( String oldVersion ) + { + this.oldVersion = oldVersion; + return this; + } + + public Builder withNewVersion( String newVersion ) + { + this.newVersion = newVersion; + return this; + } + + public Builder withDependency( Dependency dependency ) + { + groupId = dependency.getGroupId(); + artifactId = dependency.getArtifactId(); + oldVersion = dependency.getVersion(); + return this; + } + + public Builder withArtifact( Artifact artifact ) + { + groupId = artifact.getGroupId(); + artifactId = artifact.getArtifactId(); + oldVersion = artifact.getVersion(); + return this; + } + + public ChangeRecord build() + { + return new DefaultChangeRecord( kind, + new DefaultVersionChange( groupId, artifactId, oldVersion, newVersion ) ); + } + } + + +} diff --git a/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java b/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java index 32c602805c..5f9be60bfc 100644 --- a/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java +++ b/versions-common/src/test/java/org/codehaus/mojo/versions/recording/ChangeRecorderXMLTest.java @@ -23,12 +23,14 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; -import org.apache.commons.io.IOUtils; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.junit.Assert; import org.junit.Test; import org.w3c.dom.Document; @@ -38,43 +40,52 @@ public final class ChangeRecorderXMLTest { - private static void copyResource( final String name, final File output ) throws IOException + private static void copyResource( final String name, final Path output ) throws IOException { - try ( FileOutputStream outputStream = new FileOutputStream( output ) ) + try ( InputStream inputStream = ChangeRecorderXMLTest.class.getResourceAsStream( name ) ) { - try ( InputStream inputStream = ChangeRecorderXMLTest.class.getResourceAsStream( name ) ) - { - IOUtils.copy( inputStream, outputStream ); - } + Files.copy( inputStream, output, StandardCopyOption.REPLACE_EXISTING ); } } - private static Document parseXML( final File file ) throws ParserConfigurationException, IOException, SAXException + private static Document parseXML( final Path path ) throws ParserConfigurationException, IOException, SAXException { final DocumentBuilderFactory documentBuilders = DocumentBuilderFactory.newInstance(); final DocumentBuilder documentBuilder = documentBuilders.newDocumentBuilder(); - return documentBuilder.parse( file ); + return documentBuilder.parse( path.toFile() ); } @Test public void testChanges() throws Exception { - final File file0 = File.createTempFile( "ChangeRecorderTest", ".xml" ); - final File file1 = File.createTempFile( "ChangeRecorderTest", ".xml" ); + final Path path0 = Files.createTempFile( "ChangeRecorderTest", ".xml" ); + final Path path1 = Files.createTempDirectory( "ChangeRecorderTest" ) + .resolve( "subDirectory" ) + .resolve( "ChangeRecorderTest.xml" ); - copyResource( "expectedFile.xml", file0 ); + copyResource( "expectedFile.xml", path0 ); final ChangeRecorder recorder = new ChangeRecorderXML(); - recorder.recordUpdate( "exampleKind", "org.codehaus", "example0", "0.0.1", "0.0.2" ); - recorder.recordUpdate( "exampleKind", "org.codehaus", "example1", "1.0.0", "2.0.0" ); + recorder.recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.FORCE_RELEASES ) + .withGroupId( "org.codehaus" ) + .withArtifactId( "example0" ) + .withOldVersion( "0.0.1" ) + .withNewVersion( "0.0.2" ) + .build() ); - try ( FileOutputStream outputStream = new FileOutputStream( file1 ) ) - { - recorder.serialize( outputStream ); - } + recorder.recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.FORCE_RELEASES ) + .withGroupId( "org.codehaus" ) + .withArtifactId( "example1" ) + .withOldVersion( "1.0.0" ) + .withNewVersion( "2.0.0" ) + .build() ); + + recorder.serialize( path1 ); - final Document document0 = parseXML( file0 ); - final Document document1 = parseXML( file1 ); + final Document document0 = parseXML( path0 ); + final Document document1 = parseXML( path1 ); final NodeList elements0 = document0.getElementsByTagNameNS( ChangeRecorderXML.CHANGES_NAMESPACE, "updated" ); final NodeList elements1 = document1.getElementsByTagNameNS( ChangeRecorderXML.CHANGES_NAMESPACE, "updated" ); @@ -87,13 +98,25 @@ public void testChanges() throws Exception final Element element1 = (Element) elements1.item( index ); Assert.assertEquals( element0.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "artifactId" ), - element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "artifactId" ) ); + element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "artifactId" ) ); Assert.assertEquals( element0.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "groupId" ), - element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "groupId" ) ); + element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "groupId" ) ); Assert.assertEquals( element0.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "oldVersion" ), - element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "oldVersion" ) ); + element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "oldVersion" ) ); Assert.assertEquals( element0.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "newVersion" ), - element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "newVersion" ) ); + element1.getAttributeNS( ChangeRecorderXML.CHANGES_NAMESPACE, "newVersion" ) ); } } + + @Test + public void emptyResultShouldNotGenerateReports() throws Exception + { + Path path = Files.createTempDirectory( "ChangeRecorderTest" ).resolve( "ChangeRecorderTest.xml" ); + + ChangeRecorder recorder = new ChangeRecorderXML(); + recorder.serialize( path ); + + Assert.assertFalse( "File should not be created", Files.isRegularFile( path ) ); + + } } diff --git a/versions-maven-plugin/pom.xml b/versions-maven-plugin/pom.xml index 3881b4f003..3e1d8a64a3 100644 --- a/versions-maven-plugin/pom.xml +++ b/versions-maven-plugin/pom.xml @@ -159,6 +159,20 @@ + + org.eclipse.sisu + sisu-maven-plugin + 0.9.0.M1 + + + generate-index + + main-index + test-index + + + + org.apache.maven.plugins maven-invoker-plugin 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 9b8cc5c5cd..ced4841828 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 @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; @@ -44,7 +45,9 @@ import org.apache.maven.shared.artifact.filter.PatternExcludesArtifactFilter; import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.DependencyComparator; @@ -157,12 +160,14 @@ public abstract class AbstractVersionsDependencyUpdaterMojo @Inject protected AbstractVersionsDependencyUpdaterMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -540,13 +545,13 @@ private int findFirstChar( final String includeString, final String chars ) * @param pom {@link ModifiedPomXMLEventReader} 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 changeRecorderTitle title for the {@link ChangeRecorder} log + * @param changeKind title for the {@link ChangeRecorder} log * @return {@code true} if an update has been made, {@code false} otherwise * @throws XMLStreamException thrown if updating the XML doesn't succeed */ protected boolean updateDependencyVersion( ModifiedPomXMLEventReader pom, Dependency dep, - String newVersion, String changeRecorderTitle ) - throws XMLStreamException + String newVersion, ChangeRecord.ChangeKind changeKind ) + throws XMLStreamException, MojoExecutionException { boolean updated = false; if ( isProcessingParent() @@ -562,9 +567,11 @@ && getProject().getParent() != null { getLog().debug( "Made parent update from " + dep.getVersion() + " to " + newVersion ); } - getChangeRecorder().recordUpdate( changeRecorderTitle, - dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), - newVersion ); + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( changeKind ) + .withDependency( dep ) + .withNewVersion( newVersion ) + .build() ); updated = true; } @@ -576,9 +583,11 @@ && getProject().getParent() != null { getLog().info( "Updated " + toString( dep ) + " to version " + newVersion ); } - getChangeRecorder().recordUpdate( changeRecorderTitle, - dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), - newVersion ); + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( changeKind ) + .withDependency( dep ) + .withNewVersion( newVersion ) + .build() ); updated = true; } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java index 47057ffd46..fd01229369 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDisplayMojo.java @@ -26,6 +26,7 @@ import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.LinkedHashSet; +import java.util.Map; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -35,6 +36,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; /** * Abstract base class for the Display___ mojos. @@ -88,9 +90,11 @@ protected AbstractVersionsDisplayMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } @SuppressWarnings( "unchecked" ) 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 ad4bbf6425..bdd77c63c2 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 @@ -24,10 +24,10 @@ import javax.xml.stream.XMLStreamException; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.Writer; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; @@ -59,11 +59,9 @@ import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionsHelper; +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.recording.ChangeRecorder; -import org.codehaus.mojo.versions.recording.ChangeRecorderNull; -import org.codehaus.mojo.versions.recording.ChangeRecorderXML; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.IOUtil; @@ -194,8 +192,7 @@ public abstract class AbstractVersionsUpdaterMojo * * @since 2.11 */ - @Parameter( property = "changeRecorderFormat", - defaultValue = "none" ) + @Parameter( property = "changeRecorderFormat", defaultValue = "none" ) private String changeRecorderFormat = "none"; /** * The output file used to record changes. @@ -207,9 +204,9 @@ public abstract class AbstractVersionsUpdaterMojo private File changeRecorderOutputFile; /** - * The change recorder implementation. + * The change recorders implementation. */ - private ChangeRecorder changeRecorder; + private Map changeRecorders; /** *

Allows specifying the {@linkplain RuleSet} object describing rules @@ -242,16 +239,18 @@ public abstract class AbstractVersionsUpdaterMojo @Inject protected AbstractVersionsUpdaterMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { this.repositorySystem = repositorySystem; this.projectBuilder = projectBuilder; this.artifactMetadataSource = artifactMetadataSource; this.wagonManager = wagonManager; this.artifactResolver = artifactResolver; + this.changeRecorders = changeRecorders; } public VersionsHelper getHelper() throws MojoExecutionException @@ -332,10 +331,6 @@ public void execute() */ protected void validateInput() throws MojoExecutionException { - if ( !"none".equals( changeRecorderFormat ) && !"xml".equals( changeRecorderFormat ) ) - { - throw new MojoExecutionException( "Only 'xml' or 'none' formats are supported for change recordings" ); - } } /** * Finds the latest version of the specified artifact that matches the version range. @@ -575,17 +570,14 @@ else if ( PomHelper.setPropertyVersion( pom, version.getProfileId(), property.ge * * @return The change recorder */ - protected ChangeRecorder getChangeRecorder() + protected ChangeRecorder getChangeRecorder() throws MojoExecutionException { + ChangeRecorder changeRecorder = changeRecorders.get( changeRecorderFormat ); if ( changeRecorder == null ) { - changeRecorder = "none".equals( this.changeRecorderFormat ) - ? new ChangeRecorderNull() - : "xml".equals( this.changeRecorderFormat ) - ? new ChangeRecorderXML() - : null; + throw new MojoExecutionException( "Only " + changeRecorders.keySet() + + " formats are supported for change recordings" ); } - return changeRecorder; } @@ -595,28 +587,12 @@ protected ChangeRecorder getChangeRecorder() * @throws IOException On I/O errors */ - protected void saveChangeRecorderResults() throws IOException + protected void saveChangeRecorderResults() throws IOException, MojoExecutionException { - /* - * Nobody did anything that required a change recorder. - */ - - if ( this.changeRecorder == null ) - { - return; - } - - if ( "none".equals( this.changeRecorderFormat ) ) - { - return; - } this.getLog().debug( "writing change record to " + this.changeRecorderOutputFile ); - - this.changeRecorderOutputFile.getParentFile().mkdirs(); - try ( FileOutputStream outputStream = new FileOutputStream( this.changeRecorderOutputFile ) ) - { - this.changeRecorder.serialize( outputStream ); - } + getChangeRecorder().serialize( Optional.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 1182945f14..98eeaa0f64 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 @@ -49,6 +49,8 @@ import org.codehaus.mojo.versions.api.Property; import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.VersionsHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -130,9 +132,11 @@ public CompareDependenciesMojo( RepositorySystem repositorySystem, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, ArtifactResolver artifactResolver, - MavenProjectBuilder mavenProjectBuilder ) + MavenProjectBuilder mavenProjectBuilder, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); this.mavenProjectBuilder = mavenProjectBuilder; } @@ -299,7 +303,8 @@ private List compareVersions( ModifiedPomXMLEventReader pom, List changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } private static Set extractPluginDependenciesFromPluginsInPluginManagement( Build build ) 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 066aab7e2b..c07dd91c74 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 @@ -22,6 +22,8 @@ import javax.inject.Inject; import javax.xml.stream.XMLStreamException; +import java.util.Map; + import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -35,6 +37,7 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -53,12 +56,14 @@ public class DisplayParentUpdatesMojo @Inject public DisplayParentUpdatesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } @Override 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 fe15039f7c..85e64ea4ca 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 @@ -94,6 +94,7 @@ import org.apache.maven.settings.Settings; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +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.utils.DependencyBuilder; @@ -171,9 +172,11 @@ public DisplayPluginUpdatesMojo( RepositorySystem repositorySystem, LifecycleExecutor lifecycleExecutor, ModelInterpolator modelInterpolator, PluginManager pluginManager, - RuntimeInformation runtimeInformation ) + RuntimeInformation runtimeInformation, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); this.lifecycleExecutor = lifecycleExecutor; this.modelInterpolator = modelInterpolator; this.pluginManager = pluginManager; 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 c39f11ac1e..8b81d31be6 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 @@ -44,6 +44,7 @@ import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; 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.utils.SegmentUtils; @@ -144,12 +145,14 @@ public class DisplayPropertyUpdatesMojo @Inject public DisplayPropertyUpdatesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } public void execute() 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 abd249228b..ccfa9fdac4 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import java.util.regex.Matcher; import org.apache.maven.artifact.Artifact; @@ -42,6 +43,8 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -69,12 +72,14 @@ public class ForceReleasesMojo @Inject public ForceReleasesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -144,7 +149,7 @@ private void useReleases( ModifiedPomXMLEventReader pom, Collection ArtifactVersions versions = getHelper().lookupArtifactVersions( artifact, false ); if ( versions.containsVersion( releaseVersion ) ) { - updateDependencyVersion( pom, dep, releaseVersion, "forceReleases" ); + updateDependencyVersion( pom, dep, releaseVersion, ChangeRecord.ChangeKind.FORCE_RELEASES ); } else { @@ -161,7 +166,8 @@ private void useReleases( ModifiedPomXMLEventReader pom, Collection } else { - updateDependencyVersion( pom, dep, newestRelease.toString(), "forceReleases" ); + updateDependencyVersion( pom, dep, newestRelease.toString(), + ChangeRecord.ChangeKind.FORCE_RELEASES ); } } } 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 2749037519..992105005b 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,6 +41,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -67,12 +69,14 @@ public class LockSnapshotsMojo @Inject public LockSnapshotsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java index 7729cba15a..3119770446 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/ResolveRangesMojo.java @@ -48,6 +48,7 @@ import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; 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.utils.SegmentUtils; @@ -128,12 +129,14 @@ public class ResolveRangesMojo @Inject public ResolveRangesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** 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 fef10ea975..595f4d30d3 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,8 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.change.VersionChanger; import org.codehaus.mojo.versions.change.VersionChangerFactory; import org.codehaus.mojo.versions.ordering.ReactorDepthComparator; @@ -243,17 +244,19 @@ public class SetMojo extends AbstractVersionsUpdaterMojo /** * The changes to module coordinates. Guarded by this. */ - private final transient List sourceChanges = new ArrayList<>(); + private final transient List sourceChanges = new ArrayList<>(); @Inject public SetMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver, - Prompter prompter ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders, + Prompter prompter ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); this.prompter = prompter; } @@ -261,7 +264,7 @@ private synchronized void addChange( String groupId, String artifactId, String o { if ( !newVersion.equals( oldVersion ) ) { - sourceChanges.add( new VersionChange( groupId, artifactId, oldVersion, newVersion ) ); + sourceChanges.add( new DefaultVersionChange( groupId, artifactId, oldVersion, newVersion ) ); } } @@ -583,7 +586,7 @@ protected synchronized void update( ModifiedPomXMLEventReader pom ) versionChangerFactory.newVersionChanger( processParent, processProject, processDependencies, processPlugins ); - for ( VersionChange versionChange : sourceChanges ) + for ( DefaultVersionChange versionChange : sourceChanges ) { changer.apply( versionChange ); } 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 f2e6787122..804339fc76 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 @@ -39,6 +39,7 @@ import org.codehaus.mojo.versions.api.Property; 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.utils.PropertiesVersionsFileReader; @@ -92,12 +93,14 @@ public class SetPropertyMojo @Inject public SetPropertyMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** 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 b11d51d33a..32d5e3f8bc 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 @@ -6,6 +6,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -19,6 +20,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static org.apache.commons.lang3.StringUtils.isAllBlank; @@ -68,12 +70,14 @@ public class SetScmTagMojo extends AbstractVersionsUpdaterMojo @Inject public SetScmTagMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** 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 408cec4349..58795f1fea 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,6 +41,9 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -69,9 +73,11 @@ public UnlockSnapshotsMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -140,8 +146,12 @@ private void unlockSnapshots( ModifiedPomXMLEventReader pom, List de if ( PomHelper.setDependencyVersion( pom, dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), unlockedVersion, getProject().getModel() ) ) { - getChangeRecorder().recordUpdate( "unlockSnapshot", dep.getGroupId(), dep.getArtifactId(), - dep.getVersion(), unlockedVersion ); + + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.UNLOCK_SNAPSHOT ) + .withDependency( dep ) + .withNewVersion( unlockedVersion ) + .build() ); getLog().info( "Unlocked " + toString( dep ) + " to version " + unlockedVersion ); } } @@ -174,9 +184,11 @@ private void unlockParentSnapshot( ModifiedPomXMLEventReader pom, MavenProject p { getLog().info( "Unlocked parent " + parentArtifact + " to version " + unlockedParentVersion ); - getChangeRecorder().recordUpdate( "unlockParentVersion", parentArtifact.getGroupId(), - parentArtifact.getArtifactId(), parentArtifact.getVersion(), - unlockedParentVersion ); + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.UNLOCK_PARENT_VERSION ) + .withArtifact( parentArtifact ) + .withNewVersion( unlockedParentVersion ) + .build() ); } } } 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 be50bbeb08..dc52b603bd 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 @@ -40,6 +40,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -71,12 +72,14 @@ public class UpdateChildModulesMojo @Inject public UpdateChildModulesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** 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 caa60b4ce8..7d71969542 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 @@ -24,6 +24,7 @@ import java.util.Arrays; import java.util.Collections; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -45,7 +46,10 @@ import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -137,12 +141,14 @@ public class UpdateParentMojo extends AbstractVersionsUpdaterMojo @Inject public UpdateParentMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -193,9 +199,13 @@ protected void update( ModifiedPomXMLEventReader pom ) getLog().debug( "Made an update from " + getProject().getParent().getVersion() + " to " + artifactVersion ); } - getChangeRecorder().recordUpdate( "updateParent", getProject().getParent().getGroupId(), - getProject().getParent().getArtifactId(), getProject().getParent().getVersion(), - artifactVersion.toString() ); + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.UPDATE_PARENT ) + .withGroupId( getProject().getParent().getGroupId() ) + .withArtifactId( getProject().getParent().getArtifactId() ) + .withOldVersion( getProject().getParent().getVersion() ) + .withNewVersion( artifactVersion.toString() ) + .build() ); } } } 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 8211e28179..ace363963b 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 @@ -41,7 +41,10 @@ import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionsHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment; @@ -139,12 +142,14 @@ public class UpdatePropertiesMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UpdatePropertiesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -207,9 +212,13 @@ protected void update( ModifiedPomXMLEventReader pom ) { if ( ( isIncluded( association.getArtifact() ) ) ) { - this.getChangeRecorder().recordUpdate( "updateProperty", association.getGroupId(), - association.getArtifactId(), currentVersion, - targetVersion.toString() ); + getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( + ChangeRecord.ChangeKind.UPDATE_PROPERTY ) + .withArtifact( association.getArtifact() ) + .withOldVersion( currentVersion ) + .withNewVersion( targetVersion.toString() ) + .build() ); } } } 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 9e22942623..979d98f987 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 @@ -41,7 +41,10 @@ import org.codehaus.mojo.versions.api.PropertyVersions; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionsHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; +import org.codehaus.mojo.versions.recording.DefaultChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -141,9 +144,11 @@ public UpdatePropertyMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -190,9 +195,12 @@ protected void update( ModifiedPomXMLEventReader pom ) { for ( final ArtifactAssociation association : version.getAssociations() ) { - this.getChangeRecorder().recordUpdate( "updateProperty", association.getGroupId(), - association.getArtifactId(), currentVersion, - targetVersion.toString() ); + this.getChangeRecorder().recordUpdate( DefaultChangeRecord.builder() + .withKind( ChangeRecord.ChangeKind.UPDATE_PROPERTY ) + .withArtifact( association.getArtifact() ) + .withOldVersion( currentVersion ) + .withNewVersion( targetVersion.toString() ) + .build() ); } } } 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 bfbc42d9eb..838ce95705 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.manager.WagonManager; @@ -40,6 +41,8 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -73,12 +76,14 @@ public class UseDepVersionMojo extends AbstractVersionsDependencyUpdaterMojo @Inject public UseDepVersionMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } @Override @@ -160,7 +165,7 @@ private void useDepVersion( ModifiedPomXMLEventReader pom, Collection changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -153,7 +158,7 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection + ( dep, versions ) -> { try { @@ -166,7 +171,7 @@ private void useLatestReleases( ModifiedPomXMLEventReader pom, Collection !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); } 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 33d1785553..a3aaa8d0d7 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 @@ -26,6 +26,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Comparator; +import java.util.Map; import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; @@ -42,6 +43,8 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +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.utils.SegmentUtils; @@ -91,12 +94,14 @@ public class UseLatestSnapshotsMojo @Inject public UseLatestSnapshotsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -142,7 +147,7 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection + ( dep, versions ) -> { try { @@ -156,7 +161,7 @@ private void useLatestSnapshots( ModifiedPomXMLEventReader pom, Collection !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); + }, ChangeRecord.ChangeKind.USE_LATEST_SNAPSHOTS, + dep -> !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); } } 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 57235889ca..3b23408c63 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; @@ -40,6 +41,8 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +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.utils.SegmentUtils; @@ -99,12 +102,14 @@ public class UseLatestVersionsMojo @Inject public UseLatestVersionsMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } @Override @@ -160,7 +165,7 @@ private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection + ( dep, versions ) -> { try { @@ -173,6 +178,6 @@ private void useLatestVersions( ModifiedPomXMLEventReader pom, Collection changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -65,7 +70,7 @@ public UseLatestVersionsMojoBase( RepositorySystem repositorySystem, * @param dependencies collection of dependencies with the dependency versions before the change * @param newestVersionProducer function providing the newest version given a dependency and * an {@link ArtifactVersions} instance - * @param changeRecorderTitle title for the change recorder records + * @param changeKind title for the change recorder records * @param filters optional array of filters * @throws XMLStreamException thrown if the POM update doesn't succeed * @throws ArtifactMetadataRetrievalException thrown if an artifact cannot be retried @@ -75,7 +80,7 @@ protected final void useLatestVersions( ModifiedPomXMLEventReader pom, Collection dependencies, BiFunction> newestVersionProducer, - String changeRecorderTitle, + ChangeRecord.ChangeKind changeKind, Predicate... filters ) throws XMLStreamException, MojoExecutionException, ArtifactMetadataRetrievalException { @@ -114,7 +119,7 @@ protected final void useLatestVersions( ModifiedPomXMLEventReader pom, Optional newestVer = newestVersionProducer.apply( dep, versions ); if ( newestVer.isPresent() ) { - updateDependencyVersion( pom, dep, newestVer.get().toString(), changeRecorderTitle ); + updateDependencyVersion( pom, dep, newestVer.get().toString(), 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 05705f90dc..4e458fcf21 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import java.util.regex.Pattern; import org.apache.maven.artifact.manager.WagonManager; @@ -37,6 +38,8 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -68,9 +71,11 @@ public UseNextReleasesMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -114,7 +119,8 @@ private void useNextReleases( ModifiedPomXMLEventReader pom, Collection of( versions.getNewerVersions( dep.getVersion(), false )[0] ), - "useNextReleases", dep -> !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); + ( dep, versions ) -> of( versions.getNewerVersions( dep.getVersion(), false )[0] ), + ChangeRecord.ChangeKind.USE_NEXT_RELEASES, + dep -> !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); } } 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 afaf413029..ed135c9b86 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 @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.Map; import java.util.Optional; import org.apache.maven.artifact.manager.WagonManager; @@ -41,6 +42,8 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +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.utils.SegmentUtils; @@ -93,9 +96,11 @@ public UseNextSnapshotsMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); // the below is necessary for UseLatestVersionsMojoBase.useLatestVersions to select snapshots allowSnapshots = true; } @@ -141,7 +146,7 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection + ( dep, versions ) -> { try { @@ -155,7 +160,7 @@ private void useNextSnapshots( ModifiedPomXMLEventReader pom, Collection !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); + }, ChangeRecord.ChangeKind.USE_NEXT_SNAPSHOTS, + dep -> !SNAPSHOT_REGEX.matcher( dep.getVersion() ).matches() ); } } 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 529e983e40..9a96bcff80 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -36,6 +37,8 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; @@ -60,9 +63,11 @@ public UseNextVersionsMojo( RepositorySystem repositorySystem, MavenProjectBuilder projectBuilder, ArtifactMetadataSource artifactMetadataSource, WagonManager wagonManager, - ArtifactResolver artifactResolver ) + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -105,7 +110,7 @@ private void useNextVersions( ModifiedPomXMLEventReader pom, Collection of( versions.getNewerVersions( dep.getVersion(), allowSnapshots )[0] ), - "useNextVersions" ); + ( dep, versions ) -> of( versions.getNewerVersions( dep.getVersion(), allowSnapshots )[0] ), + ChangeRecord.ChangeKind.USE_NEXT_VERSIONS ); } } 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 a8333cb370..c2b5802978 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 @@ -24,6 +24,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.maven.artifact.Artifact; @@ -40,6 +41,7 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -57,12 +59,14 @@ public class UseReactorMojo @Inject public UseReactorMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** 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 1a4704f8f2..ea6efde7d9 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 @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collection; +import java.util.Map; import java.util.Optional; import java.util.regex.Matcher; @@ -44,6 +45,8 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -83,12 +86,14 @@ public class UseReleasesMojo @Inject public UseReleasesMojo( RepositorySystem repositorySystem, - MavenProjectBuilder projectBuilder, - ArtifactMetadataSource artifactMetadataSource, - WagonManager wagonManager, - ArtifactResolver artifactResolver ) + MavenProjectBuilder projectBuilder, + ArtifactMetadataSource artifactMetadataSource, + WagonManager wagonManager, + ArtifactResolver artifactResolver, + Map changeRecorders ) { - super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver ); + super( repositorySystem, projectBuilder, artifactMetadataSource, wagonManager, artifactResolver, + changeRecorders ); } /** @@ -168,7 +173,7 @@ private void useReleases( ModifiedPomXMLEventReader pom, Collection getHelper().lookupArtifactVersions( artifact, false ) ); if ( targetVersion.isPresent() ) { - updateDependencyVersion( pom, dep, targetVersion.get(), "useReleases" ); + updateDependencyVersion( pom, dep, targetVersion.get(), ChangeRecord.ChangeKind.USE_RELEASES ); } else { diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java index 25250b203d..6c0207ec2d 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/DisplayDependencyUpdatesMojoTest.java @@ -157,12 +157,16 @@ public void testVersionsWithQualifiersNotConsideredAsMinorUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0-SNAPSHOT", "2.0.0-beta", - "2.0.0-rc1"} ); - }} ), null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) + null, + mockArtifactMetadataSource( new HashMap() + {{ + put( "default-dependency", + new String[] {"1.0.0", "1.1.0", "2.0.0-SNAPSHOT", "2.0.0-beta", + "2.0.0-rc1"} ); + }} ), + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -200,11 +204,14 @@ public void testAllowMajorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0"} ); - }} ), null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) + null, + mockArtifactMetadataSource( new HashMap() + {{ + put( "default-dependency", new String[] {"1.0.0", "1.1.0", "2.0.0"} ); + }} ), + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -241,11 +248,15 @@ public void testAllowMinorUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0"} ); - }} ), null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) + null, + mockArtifactMetadataSource( new HashMap() + {{ + put( "default-dependency", + new String[] {"1.0.0", "1.0.1", "1.1.0", "2.0.0"} ); + }} ), + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -283,11 +294,15 @@ public void testAllowIncrementalUpdatesFalse() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"} ); - }} ), null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) + null, + mockArtifactMetadataSource( new HashMap() + {{ + put( "default-dependency", + new String[] {"1.0.0", "1.0.0-1", "1.0.1", "1.1.0", "2.0.0"} ); + }} ), + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); @@ -326,12 +341,16 @@ public void testVersionsWithQualifiersNotConsideredAsIncrementalUpdates() tempPath = Files.createTempFile( "display-dependency-updates", "" ); final File tempFile = tempPath.toFile(); new DisplayDependencyUpdatesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource( new HashMap() - {{ - put( "default-dependency", new String[] {"1.0.0", "1.1.0", "1.9.0-SNAPSHOT", "1.9.0-beta", - "1.9.0-rc1"} ); - }} ), null, - new StubArtifactResolver( new ArtifactStubFactory(), false, false ) ) + null, + mockArtifactMetadataSource( new HashMap() + {{ + put( "default-dependency", + new String[] {"1.0.0", "1.1.0", "1.9.0-SNAPSHOT", "1.9.0-beta", + "1.9.0-rc1"} ); + }} ), + null, + new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + null ) {{ setProject( createProject() ); setVariableValueToObject( this, "allowAnyUpdates", false ); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java index 983fa90629..3bdf537f95 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/ForceReleasesMojoTest.java @@ -11,7 +11,7 @@ import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -63,11 +63,10 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new ForceReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), - false, false ) ); + null, mockArtifactMetadataSource(), + null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + changeRecorder.asTestMap() ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); - setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); mojo.project = new MavenProject() {{ setModel( new Model() @@ -102,8 +101,8 @@ public void testProcessParent() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "1.0.0-SNAPSHOT", "1.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "1.0.0-SNAPSHOT", "1.0.0" ) ) ); } @Test @@ -126,8 +125,8 @@ public void testReplaceSnapshotWithRelease() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "1.0.0-SNAPSHOT", "1.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "1.0.0-SNAPSHOT", "1.0.0" ) ) ); } @Test @@ -150,8 +149,8 @@ public void testUpgrade() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "1.1.0-SNAPSHOT", "2.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "1.1.0-SNAPSHOT", "2.0.0" ) ) ); } @Test @@ -174,8 +173,8 @@ public void testDowngrade() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "2.1.0-SNAPSHOT", "2.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "2.1.0-SNAPSHOT", "2.0.0" ) ) ); } @Test 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 f17e63817c..5605952eb2 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 @@ -21,7 +21,7 @@ public class SeparatePatternsForIncludesAnExcludesTest public void setUp() throws Exception { - mojo = new AbstractVersionsDependencyUpdaterMojo( null, null, null, null, null ) + mojo = new AbstractVersionsDependencyUpdaterMojo( null, null, null, null, null, null ) { protected void update( ModifiedPomXMLEventReader pom ) throws MojoExecutionException, MojoFailureException, XMLStreamException diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java index bce9eaa048..3a34edd890 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/SetMojoTest.java @@ -48,7 +48,7 @@ public void tearDown() throws IOException @Test public void testGetIncrementedVersion() throws MojoExecutionException { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null, null, null ) { { assertThat( getIncrementedVersion( "1.0.0", null ), is( "1.0.1-SNAPSHOT" ) ); @@ -63,7 +63,7 @@ public void testGetIncrementedVersion() throws MojoExecutionException @Test public void testNextSnapshotIndexLowerBound() { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null, null, null ) { { try @@ -83,7 +83,7 @@ public void testNextSnapshotIndexLowerBound() @Test public void testNextSnapshotIndexUpperBound() { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null, null, null ) { { try @@ -105,7 +105,7 @@ public void testNextSnapshotIndexWithoutNextSnapshot() throws MojoFailureExcepti { try { - new SetMojo( null, null, null, null, null, null ) + new SetMojo( null, null, null, null, null, null, null ) { { project = new MavenProject(); diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java index 0350f8c684..27b9724589 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdateParentMojoTest.java @@ -20,7 +20,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -76,14 +76,14 @@ public void setUp() throws IllegalAccessException artifactResolver = mock( ArtifactResolver.class ); mojo = new UpdateParentMojo( repositorySystem, - null, - artifactMetadataSource, - null, - artifactResolver ) + null, + artifactMetadataSource, + null, + artifactResolver, + changeRecorder.asTestMap() ) {{ setProject( createProject() ); reactorProjects = Collections.emptyList(); - setVariableValueToObject( this, "changeRecorder", changeRecorder ); }}; } @@ -159,8 +159,8 @@ public void testParentDowngradeAllowed() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "parent-artifact", "1.0.1-SNAPSHOT", - "1.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "parent-artifact", "1.0.1-SNAPSHOT", + "1.0.0" ) ) ); } @Test @@ -240,9 +240,9 @@ public void testAllowSnapshotsWithParentVersion() .thenReturn( true ); mojo.update( null ); } - assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", - "issue-670-artifact", "0.0.1-1", - "0.0.1-1-impl-SNAPSHOT" ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( new DefaultVersionChange( "default-group", + "issue-670-artifact", "0.0.1-1", + "0.0.1-1-impl-SNAPSHOT" ) ) ); } @Test @@ -299,8 +299,8 @@ private void testSkipResolution( String version ) throw new RuntimeException( e ); } - assertThat( changeRecorder.getChanges(), hasItem( new VersionChange( "default-group", - "parent-artifact", "1.0.0", version ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( + new DefaultVersionChange( "default-group", "parent-artifact", "1.0.0", version ) ) ); } @Test @@ -320,8 +320,8 @@ public void testShouldUpgradeToSnapshot() throws MojoExecutionException, XMLStre mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "parent-artifact", "0.9.0", - "1.0.1-SNAPSHOT" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "parent-artifact", "0.9.0", + "1.0.1-SNAPSHOT" ) ) ); } @Test @@ -382,8 +382,8 @@ public void testParentVersionRange() throws MojoExecutionException, XMLStreamExc mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dummy-parent2", "1.0", - "2.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "dummy-parent2", "1.0", + "2.0" ) ) ); } @Test diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java index 3877397f16..62c034b105 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertiesMojoTest.java @@ -21,7 +21,7 @@ import java.nio.file.Files; import java.nio.file.Paths; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.hamcrest.Matchers; import org.junit.Test; @@ -39,8 +39,8 @@ public void testAllowMajorUpdates() throws Exception Files.copy( Paths.get( "src/test/resources/org/codehaus/mojo/update-properties/issue-454-pom.xml" ), Paths.get( pomDir.toString(), "pom.xml" ), REPLACE_EXISTING ); setUpMojo( "update-properties" ).execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "2.0.0-M1" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "2.0.0-M1" ) ) ); } @Test @@ -51,8 +51,8 @@ public void testAllowMinorUpdates() throws Exception UpdatePropertiesMojo mojo = setUpMojo( "update-properties" ); mojo.allowMajorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "1.1.0-alpha" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.1.0-alpha" ) ) ); } @Test @@ -64,7 +64,7 @@ public void testAllowIncrementalUpdates() throws Exception mojo.allowMajorUpdates = false; mojo.allowMinorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "1.0.1-rc1" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.0.1-rc1" ) ) ); } } 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 431bc30906..afcb78fe8c 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,14 @@ import java.nio.file.Path; import java.util.HashMap; +import java.util.Map; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.plugin.Mojo; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; import org.apache.maven.plugin.testing.stubs.StubArtifactRepository; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.After; import org.junit.Before; @@ -51,7 +53,6 @@ public void setUp() throws Exception { super.setUp(); pomDir = createTempDir( "update-property" ); - changeRecorder = new TestChangeRecorder(); artifactMetadataSource = mockArtifactMetadataSource( new HashMap() {{ put( "default-artifact", new String[] {"1.0.0", "1.0.1-rc1", "1.1.0-alpha", "2.0.0-M1"} ); @@ -77,8 +78,12 @@ protected T setUpMojo( String goal ) throws Exception T mojo = (T) mojoRule.lookupConfiguredMojo( pomDir.toFile(), goal ); setVariableValueToObject( mojo, "localRepository", new StubArtifactRepository( pomDir.toString() ) ); setVariableValueToObject( mojo, "artifactMetadataSource", artifactMetadataSource ); - setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); setVariableValueToObject( mojo, "generateBackupPoms", false ); + setVariableValueToObject( mojo, "changeRecorderFormat", "test" ); + changeRecorder = (TestChangeRecorder) + ( (Map) getVariableValueFromObject( mojo, "changeRecorders" ) ) + .get( "test" ); + return (T) mojo; } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertyMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertyMojoTest.java index 8e1ec84eab..1a63831a8d 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertyMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UpdatePropertyMojoTest.java @@ -21,7 +21,7 @@ import java.nio.file.Files; import java.nio.file.Paths; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.hamcrest.Matchers; import org.junit.Test; @@ -41,8 +41,8 @@ public void testAllowMajorUpdates() throws Exception UpdatePropertyMojo mojo = setUpMojo( "update-property" ); mojo.property = "artifact-version"; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "2.0.0-M1" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "2.0.0-M1" ) ) ); } @Test @@ -54,8 +54,8 @@ public void testAllowMinorUpdates() throws Exception mojo.property = "artifact-version"; mojo.allowMajorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "1.1.0-alpha" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.1.0-alpha" ) ) ); } @Test @@ -68,7 +68,7 @@ public void testAllowIncrementalUpdates() throws Exception mojo.allowMajorUpdates = false; mojo.allowMinorUpdates = false; mojo.execute(); - assertThat( changeRecorder.getChanges(), Matchers.hasItem( new VersionChange( "default-group", - "default-artifact", "1.0.0", "1.0.1-rc1" ) ) ); + assertThat( changeRecorder.getChanges(), Matchers.hasItem( + new DefaultVersionChange( "default-group", "default-artifact", "1.0.0", "1.0.1-rc1" ) ) ); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java index 72fd58f2d5..82446fda07 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestReleasesMojoTest.java @@ -54,11 +54,14 @@ public void setUp() throws Exception put( "dependency-artifact", new String[] {"0.9.0", "1.0.0-beta"} ); }} ); + changeRecorder = new TestChangeRecorder(); + mojo = new UseLatestReleasesMojo( repositorySystemMock, - null, - artifactMetadataSourceMock, - null, - null ) + null, + artifactMetadataSourceMock, + null, + null, + changeRecorder.asTestMap() ) {{ reactorProjects = emptyList(); MavenProject project = new MavenProject() @@ -81,9 +84,6 @@ public void setUp() throws Exception }} ); }}; setProject( project ); - - changeRecorder = new TestChangeRecorder(); - setVariableValueToObject( this, "changeRecorder", changeRecorder ); }}; } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java index 98c5a34f1a..ed0b35723e 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java @@ -16,7 +16,7 @@ import org.apache.maven.project.MavenProject; import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.hamcrest.core.Is; @@ -66,11 +66,14 @@ public void setUp() throws Exception put( "other-artifact", new String[] {"1.0", "2.0"} ); }} ); + changeRecorder = new TestChangeRecorder(); + mojo = new UseLatestVersionsMojo( repositorySystemMock, - null, - artifactMetadataSourceMock, - null, - null ) + null, + artifactMetadataSourceMock, + null, + null, + changeRecorder.asTestMap() ) {{ reactorProjects = emptyList(); MavenProject project = new MavenProject() @@ -93,9 +96,7 @@ public void setUp() throws Exception }}; setProject( project ); }}; - changeRecorder = new TestChangeRecorder(); setVariableValueToObject( mojo, "processDependencyManagement", false ); - setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); } @Test @@ -115,8 +116,8 @@ public void testDependenciesDowngradeIncremental() .thenReturn( true ); mojo.update( null ); } - assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( + new DefaultVersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -141,8 +142,8 @@ public void testDependenciesDowngradeMinor() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", - "1.1.0-SNAPSHOT", "1.1.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "dependency-artifact", + "1.1.0-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -163,8 +164,8 @@ public void testDependenciesDowngradeMajor() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", - "1.1.1-SNAPSHOT", "1.1.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "dependency-artifact", + "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -186,8 +187,8 @@ public void testDependencyManagementDowngrade() .thenReturn( true ); mojo.update( null ); } - assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( + new DefaultVersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -218,8 +219,8 @@ public void testParentDowngrade() .thenReturn( true ); mojo.update( null ); } - assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( + new DefaultVersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -248,9 +249,8 @@ public void testPoisonDependencyVersion() } // So, the regular update should take place despite an irregular, or — if I may — "poison", dependency // being present in the dependency list - assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", - "1.1.0" ) ) ); + assertThat( changeRecorder.getChanges(), hasItem( + new DefaultVersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0" ) ) ); } @Test @@ -291,8 +291,7 @@ public void testIncludeFilter() } assertThat( changeRecorder.getChanges(), hasSize( 1 ) ); assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "other-artifact", "1.0", - "2.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "other-artifact", "1.0", "2.0" ) ) ); } @Test @@ -317,7 +316,7 @@ public void testExcludeFilter() } assertThat( changeRecorder.getChanges(), hasSize( 1 ) ); assertThat( changeRecorder.getChanges(), - not( hasItem( new VersionChange( "default-group", "other-artifact", "1.0", - "2.0" ) ) ) ); + not( hasItem( new DefaultVersionChange( "default-group", "other-artifact", "1.0", + "2.0" ) ) ) ); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java index 6e2b40bfbf..fe28fdf43a 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseReleasesMojoTest.java @@ -11,7 +11,7 @@ import org.apache.maven.plugin.testing.stubs.StubArtifactResolver; import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; -import org.codehaus.mojo.versions.change.VersionChange; +import org.codehaus.mojo.versions.change.DefaultVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -63,11 +63,10 @@ public void setUp() throws IllegalAccessException { changeRecorder = new TestChangeRecorder(); mojo = new UseReleasesMojo( mockRepositorySystem(), - null, mockArtifactMetadataSource(), - null, new StubArtifactResolver( new ArtifactStubFactory(), - false, false ) ); + null, mockArtifactMetadataSource(), + null, new StubArtifactResolver( new ArtifactStubFactory(), false, false ), + changeRecorder.asTestMap() ); setVariableValueToObject( mojo, "reactorProjects", emptyList() ); - setVariableValueToObject( mojo, "changeRecorder", changeRecorder ); mojo.project = new MavenProject() {{ setModel( new Model() @@ -102,8 +101,8 @@ public void testProcessParent() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "1.0.0-SNAPSHOT", "1.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "1.0.0-SNAPSHOT", "1.0.0" ) ) ); } @Test @@ -126,8 +125,8 @@ public void testReplaceSnapshotWithRelease() mojo.update( null ); } assertThat( changeRecorder.getChanges(), - hasItem( new VersionChange( "default-group", "artifactA", - "1.0.0-SNAPSHOT", "1.0.0" ) ) ); + hasItem( new DefaultVersionChange( "default-group", "artifactA", + "1.0.0-SNAPSHOT", "1.0.0" ) ) ); } @Test diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/TestChangeRecorder.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/TestChangeRecorder.java index 2966cafe6e..7d9540cec6 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/TestChangeRecorder.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/utils/TestChangeRecorder.java @@ -19,25 +19,31 @@ * under the License. */ -import java.io.OutputStream; +import javax.inject.Named; + +import java.nio.file.Path; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; -import org.codehaus.mojo.versions.change.VersionChange; -import org.codehaus.mojo.versions.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.change.VersionChange; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +@Named( "test" ) public class TestChangeRecorder implements ChangeRecorder { private final List changes = new LinkedList<>(); @Override - public void recordUpdate( String kind, String groupId, String artifactId, String oldVersion, String newVersion ) + public void recordUpdate( ChangeRecord changeRecord ) { - changes.add( new VersionChange( groupId, artifactId, oldVersion, newVersion ) ); + changes.add( changeRecord.getVersionChange() ); } @Override - public void serialize( OutputStream outputStream ) + public void serialize( Path outputPath ) { } @@ -45,4 +51,11 @@ public List getChanges() { return changes; } -} \ No newline at end of file + + public Map asTestMap() + { + HashMap map = new HashMap<>(); + map.put( "none", this ); + return map; + } +}