From 120d680de01c55e4125e29598347d97de2d58f20 Mon Sep 17 00:00:00 2001 From: Andrzej Jarmoniuk Date: Sat, 24 Dec 2022 09:00:14 +0100 Subject: [PATCH] Resolves #880: add information on property updates to the change recorder Release notes: - new version and new namespace for the change recorder - change recorder also records property changes --- .../api/change/DependencyVersionChange.java | 50 ++++++++++ .../api/change/PropertyVersionChange.java | 42 ++++++++ .../versions/api/change/VersionChange.java | 58 +++-------- .../versions/api/recording/ChangeRecord.java | 28 ------ .../api/recording/DependencyChangeRecord.java | 54 +++++++++++ .../change/CompositeVersionChanger.java | 4 +- ...va => DefaultDependencyVersionChange.java} | 11 ++- .../change/DefaultPropertyVersionChange.java | 87 +++++++++++++++++ .../change/DependencyVersionChanger.java | 4 +- .../versions/change/ParentVersionChanger.java | 4 +- .../versions/change/PluginVersionChanger.java | 4 +- .../change/ProjectVersionChanger.java | 4 +- .../mojo/versions/change/VersionChanger.java | 4 +- .../versions/recording/ChangeRecorderXML.java | 31 ++++-- ...ava => DefaultDependencyChangeRecord.java} | 16 +-- .../DefaultPropertyChangeRecord.java | 68 +++++++++++++ .../recording/ChangeRecorderXMLTest.java | 10 +- .../mojo/versions/recording/expectedFile.xml | 11 +-- .../verify.bsh | 22 ----- .../verify.groovy | 25 +++++ .../verify.bsh | 21 ---- .../verify.groovy | 28 ++++++ .../verify.bsh | 21 ---- .../verify.groovy | 25 +++++ .../verify.bsh | 21 ---- .../verify.groovy | 25 +++++ .../verify.bsh | 21 ---- .../verify.groovy | 25 +++++ .../verify.bsh | 21 ---- .../verify.groovy | 25 +++++ ...AbstractVersionsDependencyUpdaterMojo.java | 13 ++- .../versions/CompareDependenciesMojo.java | 13 ++- .../mojo/versions/ForceReleasesMojo.java | 14 ++- .../org/codehaus/mojo/versions/SetMojo.java | 8 +- .../mojo/versions/UnlockSnapshotsMojo.java | 18 ++-- .../mojo/versions/UpdateParentMojo.java | 8 +- .../versions/UpdatePropertiesMojoBase.java | 16 ++- .../mojo/versions/UseDepVersionMojo.java | 97 ++++++++++++------- .../mojo/versions/UseLatestReleasesMojo.java | 14 ++- .../mojo/versions/UseLatestSnapshotsMojo.java | 14 ++- .../mojo/versions/UseLatestVersionsMojo.java | 14 ++- .../versions/UseLatestVersionsMojoBase.java | 4 +- .../mojo/versions/UseNextReleasesMojo.java | 14 ++- .../mojo/versions/UseNextSnapshotsMojo.java | 14 ++- .../mojo/versions/UseNextVersionsMojo.java | 14 ++- .../mojo/versions/UseReleasesMojo.java | 14 ++- .../mojo/versions/recording/schema-2.0.xsd | 62 ++++++++++++ .../markdown/examples/recording-changes.md | 17 ++-- .../mojo/versions/ForceReleasesMojoTest.java | 10 +- .../mojo/versions/UpdateParentMojoTest.java | 14 +-- .../versions/UpdatePropertiesMojoTest.java | 9 +- .../mojo/versions/UpdatePropertyMojoTest.java | 12 ++- .../mojo/versions/UseDepVersionMojoTest.java | 28 ++++++ .../versions/UseLatestVersionsMojoTest.java | 22 +++-- .../versions/UseNextReleasesMojoTest.java | 4 +- .../versions/UseNextVersionsMojoTest.java | 5 +- .../mojo/versions/UseReleasesMojoTest.java | 6 +- 57 files changed, 858 insertions(+), 390 deletions(-) create mode 100644 versions-api/src/main/java/org/codehaus/mojo/versions/api/change/DependencyVersionChange.java create mode 100644 versions-api/src/main/java/org/codehaus/mojo/versions/api/change/PropertyVersionChange.java create mode 100644 versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/DependencyChangeRecord.java rename versions-common/src/main/java/org/codehaus/mojo/versions/change/{DefaultVersionChange.java => DefaultDependencyVersionChange.java} (83%) create mode 100644 versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultPropertyVersionChange.java rename versions-common/src/main/java/org/codehaus/mojo/versions/recording/{DefaultChangeRecord.java => DefaultDependencyChangeRecord.java} (75%) create mode 100644 versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultPropertyChangeRecord.java delete mode 100644 versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.groovy delete mode 100644 versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.groovy delete mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.groovy delete mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.groovy delete mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.groovy delete mode 100644 versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.bsh create mode 100644 versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.groovy create mode 100644 versions-maven-plugin/src/main/resources/org/codehaus/mojo/versions/recording/schema-2.0.xsd diff --git a/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/DependencyVersionChange.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/DependencyVersionChange.java new file mode 100644 index 0000000000..f1bc107c62 --- /dev/null +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/DependencyVersionChange.java @@ -0,0 +1,50 @@ +package org.codehaus.mojo.versions.api.change; + +/* + * Copyright MojoHaus and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * Represents a change of an item's version. + * + * @author Slawomir Jaranowski + * @since 2.14.0 + */ +public interface DependencyVersionChange extends VersionChange { + /** + * @return a groupId of changed item + * @since 2.14.0 + */ + String getGroupId(); + + /** + * @return an ArtifactId of change item + * @since 2.14.0 + */ + String getArtifactId(); + + /** + * @return an old version of changed item + * @since 2.14.0 + */ + String getOldVersion(); + + /** + * @return a new version of changed item + * @since 2.14.0 + */ + String getNewVersion(); +} diff --git a/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/PropertyVersionChange.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/PropertyVersionChange.java new file mode 100644 index 0000000000..ebe60200c1 --- /dev/null +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/change/PropertyVersionChange.java @@ -0,0 +1,42 @@ +package org.codehaus.mojo.versions.api.change; + +/* + * Copyright MojoHaus and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * Represents a change of a property value. + * + * @author Andrzej Jarmoniuk + * @since 2.15.0 + */ +public interface PropertyVersionChange extends VersionChange { + + /** + * @return the property that has changed + */ + String getProperty(); + + /** + * @return the old value of the property + */ + String getOldValue(); + + /** + * @return the new value of the property + */ + String getNewValue(); +} 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 index c8b6f63216..c934f2e04a 100644 --- 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 @@ -1,50 +1,24 @@ package org.codehaus.mojo.versions.api.change; - /* - * Copyright MojoHaus and Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * http://www.apache.org/licenses/LICENSE-2.0 * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ /** - * Represents a change of an item's version. - * - * @author Slawomir Jaranowski - * @since 2.14.0 + * Base class for version changes */ -public interface VersionChange { - /** - * @return a groupId of changed item - * @since 2.14.0 - */ - String getGroupId(); - - /** - * @return an ArtifactId of change item - * @since 2.14.0 - */ - String getArtifactId(); - - /** - * @return an old version of changed item - * @since 2.14.0 - */ - String getOldVersion(); - - /** - * @return a new version of changed item - * @since 2.14.0 - */ - String getNewVersion(); -} +public interface VersionChange {} 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 index 9328aac507..0a050639da 100644 --- 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 @@ -26,34 +26,6 @@ * @since 2.14.0 */ public interface ChangeRecord { - /** - * Describe where version item is updated. - */ - enum ChangeKind { - DEPENDENCY("dependency-update"), - DEPENDENCY_MANAGEMENT("dependency-management-update"), - PARENT("parent-update"), - PLUGIN("plugin-update"), - PLUGIN_MANAGEMENT("plugin-management-update"), - PROPERTY("property-update"); - - private final String label; - - ChangeKind(String label) { - this.label = label; - } - - public String getLabel() { - return label; - } - } - - /** - * @return a version item change kind - * @since 2.14.0 - */ - ChangeKind getKind(); - /** * @return a details about changed item * @since 2.14.0 diff --git a/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/DependencyChangeRecord.java b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/DependencyChangeRecord.java new file mode 100644 index 0000000000..556c642cf5 --- /dev/null +++ b/versions-api/src/main/java/org/codehaus/mojo/versions/api/recording/DependencyChangeRecord.java @@ -0,0 +1,54 @@ +package org.codehaus.mojo.versions.api.recording; + +/* + * Copyright MojoHaus and Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * Represents a change record of an item's version. + * + * @author Slawomir Jaranowski + * @since 2.14.0 + */ +public interface DependencyChangeRecord extends ChangeRecord { + /** + * Describe where version item is updated. + */ + enum ChangeKind { + DEPENDENCY("dependency-update"), + DEPENDENCY_MANAGEMENT("dependency-management-update"), + PARENT("parent-update"), + PLUGIN("plugin-update"), + PLUGIN_MANAGEMENT("plugin-management-update"), + PROPERTY("property-update"); + + private final String label; + + ChangeKind(String label) { + this.label = label; + } + + public String getLabel() { + return label; + } + } + + /** + * @return a version item change kind + * @since 2.14.0 + */ + ChangeKind getKind(); +} 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 a3ad9c0b8a..694b0760b5 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,7 +25,7 @@ import java.util.Arrays; import java.util.List; -import org.codehaus.mojo.versions.api.change.VersionChange; +import org.codehaus.mojo.versions.api.change.DependencyVersionChange; /** * Created by IntelliJ IDEA. @@ -44,7 +44,7 @@ public CompositeVersionChanger(List composites) { this.composites = new ArrayList<>(composites); } - public void apply(VersionChange versionChange) throws XMLStreamException { + public void apply(DependencyVersionChange versionChange) throws XMLStreamException { for (VersionChanger delegate : composites) { delegate.apply(versionChange); } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultDependencyVersionChange.java similarity index 83% rename from versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java rename to versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultDependencyVersionChange.java index 105f67f902..cddec92ff7 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultVersionChange.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultDependencyVersionChange.java @@ -21,7 +21,7 @@ import java.util.Objects; -import org.codehaus.mojo.versions.api.change.VersionChange; +import org.codehaus.mojo.versions.api.change.DependencyVersionChange; /** * Represents a change of an artifact's version. @@ -29,7 +29,7 @@ * @author Stephen Connolly * @since 15-Sep-2010 14:48:10 */ -public final class DefaultVersionChange implements VersionChange { +public final class DefaultDependencyVersionChange implements DependencyVersionChange { private final String groupId; private final String artifactId; @@ -38,7 +38,7 @@ public final class DefaultVersionChange implements VersionChange { private final String newVersion; - public DefaultVersionChange(String groupId, String artifactId, String oldVersion, String newVersion) { + public DefaultDependencyVersionChange(String groupId, String artifactId, String oldVersion, String newVersion) { this.groupId = groupId; this.artifactId = artifactId; this.oldVersion = oldVersion; @@ -69,7 +69,7 @@ public boolean equals(Object o) { return false; } - DefaultVersionChange versionChange = (DefaultVersionChange) o; + DefaultDependencyVersionChange versionChange = (DefaultDependencyVersionChange) o; if (!Objects.equals(artifactId, versionChange.artifactId)) { return false; @@ -92,6 +92,7 @@ public int hashCode() { } public String toString() { - return "DefaultVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion + ')'; + return "DefaultDependencyVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion + + ')'; } } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultPropertyVersionChange.java b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultPropertyVersionChange.java new file mode 100644 index 0000000000..224d4f611c --- /dev/null +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultPropertyVersionChange.java @@ -0,0 +1,87 @@ +package org.codehaus.mojo.versions.change; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Objects; + +import org.codehaus.mojo.versions.api.change.PropertyVersionChange; + +/** + * Represents a change of a property value + * + * @author Andrzej Jarmoniuk + */ +public final class DefaultPropertyVersionChange implements PropertyVersionChange { + + private final String property; + + private final String oldValue; + + private final String newValue; + + public DefaultPropertyVersionChange(String property, String oldValue, String newValue) { + this.property = property; + this.oldValue = oldValue; + this.newValue = newValue; + } + + public String getProperty() { + return property; + } + + public String getOldValue() { + return oldValue; + } + + public String getNewValue() { + return newValue; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + DefaultPropertyVersionChange versionChange = (DefaultPropertyVersionChange) o; + + if (!Objects.equals(property, versionChange.property)) { + return false; + } + if (!Objects.equals(oldValue, versionChange.oldValue)) { + return false; + } + return Objects.equals(newValue, versionChange.newValue); + } + + @SuppressWarnings("checkstyle:MagicNumber") + public int hashCode() { + int result = property != null ? property.hashCode() : 0; + result = 7 * result + (oldValue != null ? oldValue.hashCode() : 0); + result = 31 * result + (newValue != null ? newValue.hashCode() : 0); + return result; + } + + public String toString() { + return "DefaultPropertyVersionChange(" + property + ':' + oldValue + "-->" + newValue + ')'; + } +} 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 9995d47fce..f280b418ea 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,7 +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.api.change.DependencyVersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -39,7 +39,7 @@ public DependencyVersionChanger(Model model, ModifiedPomXMLEventReader pom, Log super(model, pom, reporter); } - public void apply(VersionChange versionChange) throws XMLStreamException { + public void apply(DependencyVersionChange versionChange) throws XMLStreamException { if (PomHelper.setDependencyVersion( getPom(), versionChange.getGroupId(), 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 fea98f8649..6ac72bcdc7 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,7 +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.api.change.DependencyVersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -36,7 +36,7 @@ public ParentVersionChanger(Model model, ModifiedPomXMLEventReader pom, Log repo super(model, pom, reporter); } - public void apply(VersionChange versionChange) throws XMLStreamException { + public void apply(DependencyVersionChange versionChange) throws XMLStreamException { if (getModel().getParent() != null && versionChange.getGroupId().equals(getModel().getParent().getGroupId()) && versionChange.getArtifactId().equals(getModel().getParent().getArtifactId())) { 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 279fee78dd..97723969ae 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,7 +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.api.change.DependencyVersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -39,7 +39,7 @@ public PluginVersionChanger(Model model, ModifiedPomXMLEventReader pom, Log repo super(model, pom, reporter); } - public void apply(VersionChange versionChange) throws XMLStreamException { + public void apply(DependencyVersionChange versionChange) throws XMLStreamException { if (PomHelper.setPluginVersion( getPom(), versionChange.getGroupId(), 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 f75013251e..19d370ad98 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,7 +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.api.change.DependencyVersionChange; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -39,7 +39,7 @@ public ProjectVersionChanger(Model model, ModifiedPomXMLEventReader pom, Log rep super(model, pom, reporter); } - public void apply(VersionChange versionChange) throws XMLStreamException { + public void apply(DependencyVersionChange versionChange) throws XMLStreamException { if (versionChange.getGroupId().equals(PomHelper.getGroupId(getModel())) && versionChange.getArtifactId().equals(PomHelper.getArtifactId(getModel()))) { if (PomHelper.setProjectVersion(getPom(), versionChange.getNewVersion())) { 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 b2a91a68f1..5a32412e6f 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,7 +21,7 @@ import javax.xml.stream.XMLStreamException; -import org.codehaus.mojo.versions.api.change.VersionChange; +import org.codehaus.mojo.versions.api.change.DependencyVersionChange; /** * Created by IntelliJ IDEA. @@ -30,5 +30,5 @@ * @since 15-Sep-2010 15:59:00 */ public interface VersionChanger { - void apply(VersionChange versionChange) throws XMLStreamException; + void apply(DependencyVersionChange versionChange) throws XMLStreamException; } 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 b924a5dcbc..f1dbec396b 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 @@ -36,8 +36,11 @@ import java.nio.file.Files; import java.nio.file.Path; +import org.codehaus.mojo.versions.api.change.DependencyVersionChange; +import org.codehaus.mojo.versions.api.change.PropertyVersionChange; import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.w3c.dom.DOMException; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -54,7 +57,7 @@ public class ChangeRecorderXML implements ChangeRecorder { /** * The XML namespace used for serialized changes. */ - public static final String CHANGES_NAMESPACE = "http://www.mojohaus.org/versions-maven-plugin/schema/updates/1.0"; + public static final String CHANGES_NAMESPACE = "http://www.mojohaus.org/versions-maven-plugin/schema/updates/2.0"; private final Document document; private final Element root; @@ -76,12 +79,26 @@ public ChangeRecorderXML() { @Override public final void recordChange(ChangeRecord changeRecord) { - final Element update = this.document.createElementNS(CHANGES_NAMESPACE, "update"); - 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()); + Element update; + if (changeRecord.getVersionChange() instanceof DependencyVersionChange) { + update = this.document.createElementNS(CHANGES_NAMESPACE, "dependencyUpdate"); + update.setAttribute( + "kind", ((DependencyChangeRecord) changeRecord).getKind().getLabel()); + DependencyVersionChange change = (DependencyVersionChange) changeRecord.getVersionChange(); + update.setAttribute("groupId", change.getGroupId()); + update.setAttribute("artifactId", change.getArtifactId()); + update.setAttribute("oldVersion", change.getOldVersion()); + update.setAttribute("newVersion", change.getNewVersion()); + } else if (changeRecord.getVersionChange() instanceof PropertyVersionChange) { + update = this.document.createElementNS(CHANGES_NAMESPACE, "propertyUpdate"); + PropertyVersionChange change = (PropertyVersionChange) changeRecord.getVersionChange(); + update.setAttribute("property", change.getProperty()); + update.setAttribute("oldValue", change.getOldValue()); + update.setAttribute("newValue", change.getNewValue()); + } else { + throw new IllegalArgumentException( + "Illegal change type: " + changeRecord.getVersionChange().getClass()); + } this.root.appendChild(update); } 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/DefaultDependencyChangeRecord.java similarity index 75% rename from versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java rename to versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultDependencyChangeRecord.java index 8334415fe7..ec97c2f098 100644 --- a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultChangeRecord.java +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultDependencyChangeRecord.java @@ -4,15 +4,16 @@ 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.change.DependencyVersionChange; import org.codehaus.mojo.versions.api.recording.ChangeRecord; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; -public class DefaultChangeRecord implements ChangeRecord { +public class DefaultDependencyChangeRecord implements DependencyChangeRecord { private final ChangeKind kind; - private final VersionChange versionChange; + private final DependencyVersionChange versionChange; - private DefaultChangeRecord(ChangeKind kind, VersionChange versionChange) { + private DefaultDependencyChangeRecord(ChangeKind kind, DependencyVersionChange versionChange) { this.kind = Objects.requireNonNull(kind, "kind must not be null"); this.versionChange = Objects.requireNonNull(versionChange, "versionChange must not be null"); } @@ -23,7 +24,7 @@ public ChangeKind getKind() { } @Override - public VersionChange getVersionChange() { + public DependencyVersionChange getVersionChange() { return versionChange; } @@ -79,7 +80,8 @@ public Builder withArtifact(Artifact artifact) { } public ChangeRecord build() { - return new DefaultChangeRecord(kind, new DefaultVersionChange(groupId, artifactId, oldVersion, newVersion)); + return new DefaultDependencyChangeRecord( + kind, new DefaultDependencyVersionChange(groupId, artifactId, oldVersion, newVersion)); } } } diff --git a/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultPropertyChangeRecord.java b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultPropertyChangeRecord.java new file mode 100644 index 0000000000..eef429a8c1 --- /dev/null +++ b/versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultPropertyChangeRecord.java @@ -0,0 +1,68 @@ +package org.codehaus.mojo.versions.recording; + +import java.util.Objects; + +import org.codehaus.mojo.versions.api.change.PropertyVersionChange; +import org.codehaus.mojo.versions.api.recording.ChangeRecord; +import org.codehaus.mojo.versions.change.DefaultPropertyVersionChange; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +public class DefaultPropertyChangeRecord implements ChangeRecord { + private final PropertyVersionChange versionChange; + + private DefaultPropertyChangeRecord(PropertyVersionChange versionChange) { + this.versionChange = Objects.requireNonNull(versionChange, "versionChange must not be null"); + } + + @Override + public PropertyVersionChange getVersionChange() { + return versionChange; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String property; + private String oldValue; + private String newValue; + + public Builder withProperty(String property) { + this.property = property; + return this; + } + + public Builder withOldValue(String oldValue) { + this.oldValue = oldValue; + return this; + } + + public Builder withNewValue(String newValue) { + this.newValue = newValue; + return this; + } + + public ChangeRecord build() { + return new DefaultPropertyChangeRecord(new DefaultPropertyVersionChange(property, oldValue, newValue)); + } + } +} 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 7d49e2bcd6..2630e0dff6 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 @@ -29,8 +29,8 @@ import java.nio.file.Path; import java.nio.file.StandardCopyOption; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.junit.Assert; import org.junit.Test; import org.w3c.dom.Document; @@ -61,16 +61,16 @@ public void testChanges() throws Exception { copyResource("expectedFile.xml", path0); final ChangeRecorder recorder = new ChangeRecorderXML(); - recorder.recordChange(DefaultChangeRecord.builder() - .withKind(ChangeRecord.ChangeKind.DEPENDENCY) + recorder.recordChange(DefaultDependencyChangeRecord.builder() + .withKind(DependencyChangeRecord.ChangeKind.DEPENDENCY) .withGroupId("org.codehaus") .withArtifactId("example0") .withOldVersion("0.0.1") .withNewVersion("0.0.2") .build()); - recorder.recordChange(DefaultChangeRecord.builder() - .withKind(ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT) + recorder.recordChange(DefaultDependencyChangeRecord.builder() + .withKind(DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT) .withGroupId("org.codehaus") .withArtifactId("example1") .withOldVersion("1.0.0") diff --git a/versions-common/src/test/resources/org/codehaus/mojo/versions/recording/expectedFile.xml b/versions-common/src/test/resources/org/codehaus/mojo/versions/recording/expectedFile.xml index 868b406073..0522410e05 100644 --- a/versions-common/src/test/resources/org/codehaus/mojo/versions/recording/expectedFile.xml +++ b/versions-common/src/test/resources/org/codehaus/mojo/versions/recording/expectedFile.xml @@ -1,6 +1,5 @@ - - - - - - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.bsh deleted file mode 100644 index 296bf76ed6..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.bsh +++ /dev/null @@ -1,22 +0,0 @@ -import java.io.*; -import java.util.regex.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.groovy new file mode 100644 index 0000000000..a3dab7e814 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-update-parent-001/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'parent-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-parent' + && node.@oldVersion == '1.0' + && node.@newVersion == '3.0' } != null diff --git a/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.bsh deleted file mode 100644 index d0cedff849..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.bsh +++ /dev/null @@ -1,21 +0,0 @@ -import java.io.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.groovy new file mode 100644 index 0000000000..9bd2bd2dd3 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-update-properties-001/verify.groovy @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'property-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-api' + && node.@oldVersion == '1.0' + && node.@newVersion == '3.0' } != null +assert changes.propertyUpdate.find { node -> node.@property == 'api' + && node.@oldValue == '1.0' + && node.@newValue == '3.0' } != null diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.bsh deleted file mode 100644 index 80f6400beb..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.bsh +++ /dev/null @@ -1,21 +0,0 @@ -import java.io.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.groovy new file mode 100644 index 0000000000..ae1671bb56 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-use-latest-releases-001/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'dependency-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-api' + && node.@oldVersion == '1.1.1-2' + && node.@newVersion == '3.0' } != null diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.bsh deleted file mode 100644 index 6aa68bf4f7..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.bsh +++ /dev/null @@ -1,21 +0,0 @@ -import java.io.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.groovy new file mode 100644 index 0000000000..e69a2eeda7 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-use-latest-snapshots-001/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'dependency-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-api' + && node.@oldVersion == '1.0' + && node.@newVersion == '1.9.1-SNAPSHOT' } != null diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.bsh deleted file mode 100644 index 80f6400beb..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.bsh +++ /dev/null @@ -1,21 +0,0 @@ -import java.io.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.groovy new file mode 100644 index 0000000000..ae1671bb56 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-use-latest-versions-001/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'dependency-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-api' + && node.@oldVersion == '1.1.1-2' + && node.@newVersion == '3.0' } != null diff --git a/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.bsh b/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.bsh deleted file mode 100644 index 3775f4ca4d..0000000000 --- a/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.bsh +++ /dev/null @@ -1,21 +0,0 @@ -import java.io.*; -import org.codehaus.plexus.util.FileUtils; - -try -{ - File file = new File( basedir, "target/versions-changes.xml" ); - String buf = FileUtils.fileRead( file, "UTF-8" ); - - if ( buf.indexOf( "" ) < 0 ) - { - System.err.println( "Version change recorded" ); - return false; - } -} -catch( Throwable t ) -{ - t.printStackTrace(); - return false; -} - -return true; diff --git a/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.groovy b/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.groovy new file mode 100644 index 0000000000..d7cf12d750 --- /dev/null +++ b/versions-maven-plugin/src/it/it-changerecord-use-next-versions-001/verify.groovy @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) ) +assert changes.dependencyUpdate.find { node -> node.@kind == 'dependency-update' + && node.@groupId == 'localhost' + && node.@artifactId == 'dummy-api' + && node.@oldVersion == '1.1.1-2' + && node.@newVersion == '1.1.2' } != null 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 dd27032b9b..0b317a953d 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/AbstractVersionsDependencyUpdaterMojo.java @@ -42,9 +42,9 @@ import org.apache.maven.shared.artifact.filter.PatternIncludesArtifactFilter; import org.apache.maven.wagon.Wagon; 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.api.recording.DependencyChangeRecord; +import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.DependencyComparator; @@ -483,7 +483,10 @@ private int findFirstChar(final String includeString, final String chars) { * @throws XMLStreamException thrown if updating the XML doesn't succeed */ protected boolean updateDependencyVersion( - ModifiedPomXMLEventReader pom, Dependency dep, String newVersion, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Dependency dep, + String newVersion, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException { boolean updated = false; if (isProcessingParent() @@ -504,7 +507,7 @@ && getProject().getParent() != null getLog().debug("Made parent update from " + dep.getVersion() + " to " + newVersion); } getChangeRecorder() - .recordChange(DefaultChangeRecord.builder() + .recordChange(DefaultDependencyChangeRecord.builder() .withKind(changeKind) .withDependency(dep) .withNewVersion(newVersion) @@ -523,7 +526,7 @@ && getProject().getParent() != null getLog().info("Updated " + toString(dep) + " to version " + newVersion); } getChangeRecorder() - .recordChange(DefaultChangeRecord.builder() + .recordChange(DefaultDependencyChangeRecord.builder() .withKind(changeKind) .withDependency(dep) .withNewVersion(newVersion) 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 13fb201ee2..5246c70732 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,8 +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.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; @@ -187,11 +187,11 @@ protected void update(ModifiedPomXMLEventReader pom) pom, getProject().getDependencyManagement().getDependencies(), remoteDepsMap, - ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT)); + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT)); } if (getProject().getDependencies() != null && isProcessingDependencies()) { totalDiffs.addAll(compareVersions( - pom, getProject().getDependencies(), remoteDepsMap, ChangeRecord.ChangeKind.DEPENDENCY)); + pom, getProject().getDependencies(), remoteDepsMap, DependencyChangeRecord.ChangeKind.DEPENDENCY)); } if (updatePropertyVersions) { Map versionProperties = this.getHelper() @@ -214,7 +214,10 @@ protected void update(ModifiedPomXMLEventReader pom) } remoteDepsMap.putIfAbsent(parent.getManagementKey(), parent); totalDiffs.addAll(compareVersions( - pom, singletonList(getParentDependency()), remoteDepsMap, ChangeRecord.ChangeKind.PARENT)); + pom, + singletonList(getParentDependency()), + remoteDepsMap, + DependencyChangeRecord.ChangeKind.PARENT)); } if (reportMode) { @@ -282,7 +285,7 @@ private List compareVersions( ModifiedPomXMLEventReader pom, List dependencies, Map remoteDependencies, - ChangeRecord.ChangeKind changeKind) + DependencyChangeRecord.ChangeKind changeKind) throws MojoExecutionException, XMLStreamException { List updates = new ArrayList<>(); for (Dependency dep : dependencies) { 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 2bdb0f298d..cc2c80a565 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 @@ -41,8 +41,8 @@ import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -89,14 +89,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useReleases( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useReleases(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useReleases(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useReleases(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useReleases(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -104,7 +106,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useReleases( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for (Dependency dep : dependencies) { if (isExcludeReactor() && isProducedByReactor(dep)) { 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 57e25182db..fb489de4c6 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/SetMojo.java @@ -54,7 +54,7 @@ import org.apache.maven.wagon.Wagon; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.change.VersionChanger; import org.codehaus.mojo.versions.change.VersionChangerFactory; import org.codehaus.mojo.versions.ordering.ReactorDepthComparator; @@ -243,7 +243,7 @@ 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<>(); /** * The (injected) instance of {@link ProjectBuilder} @@ -267,7 +267,7 @@ public SetMojo( private synchronized void addChange(String groupId, String artifactId, String oldVersion, String newVersion) { if (!newVersion.equals(oldVersion)) { - sourceChanges.add(new DefaultVersionChange(groupId, artifactId, oldVersion, newVersion)); + sourceChanges.add(new DefaultDependencyVersionChange(groupId, artifactId, oldVersion, newVersion)); } } @@ -551,7 +551,7 @@ protected synchronized void update(ModifiedPomXMLEventReader pom) VersionChanger changer = versionChangerFactory.newVersionChanger( processParent, processProject, processDependencies, processPlugins); - for (DefaultVersionChange versionChange : sourceChanges) { + for (DefaultDependencyVersionChange versionChange : sourceChanges) { changer.apply(versionChange); } 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 7276940a2c..81bde92343 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 @@ -38,9 +38,9 @@ import org.apache.maven.repository.RepositorySystem; import org.apache.maven.wagon.Wagon; 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.api.recording.DependencyChangeRecord; +import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -88,11 +88,13 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { unlockSnapshots( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - unlockSnapshots(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + unlockSnapshots(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { unlockParentSnapshot(pom, getProject().getParent()); @@ -103,7 +105,7 @@ protected void update(ModifiedPomXMLEventReader pom) } private void unlockSnapshots( - ModifiedPomXMLEventReader pom, List dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, List dependencies, DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException { for (Dependency dep : dependencies) { if (isExcludeReactor() && isProducedByReactor(dep)) { @@ -133,7 +135,7 @@ private void unlockSnapshots( getProject().getModel())) { getChangeRecorder() - .recordChange(DefaultChangeRecord.builder() + .recordChange(DefaultDependencyChangeRecord.builder() .withKind(changeKind) .withDependency(dep) .withNewVersion(unlockedVersion) @@ -165,8 +167,8 @@ private void unlockParentSnapshot(ModifiedPomXMLEventReader pom, MavenProject pa if (PomHelper.setProjectParentVersion(pom, unlockedParentVersion)) { getLog().info("Unlocked parent " + parentArtifact + " to version " + unlockedParentVersion); getChangeRecorder() - .recordChange(DefaultChangeRecord.builder() - .withKind(ChangeRecord.ChangeKind.PARENT) + .recordChange(DefaultDependencyChangeRecord.builder() + .withKind(DependencyChangeRecord.ChangeKind.PARENT) .withArtifact(parentArtifact) .withNewVersion(unlockedParentVersion) .build()); 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 3ede5832ac..e6c1fe109a 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 @@ -43,10 +43,10 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.recording.DefaultChangeRecord; +import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -181,8 +181,8 @@ protected void update(ModifiedPomXMLEventReader pom) + getProject().getParent().getVersion() + " to " + artifactVersion); } getChangeRecorder() - .recordChange(DefaultChangeRecord.builder() - .withKind(ChangeRecord.ChangeKind.PARENT) + .recordChange(DefaultDependencyChangeRecord.builder() + .withKind(DependencyChangeRecord.ChangeKind.PARENT) .withGroupId(getProject().getParent().getGroupId()) .withArtifactId(getProject().getParent().getArtifactId()) .withOldVersion(getProject().getParent().getVersion()) diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java index 40f1d87aaf..799f3af4df 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UpdatePropertiesMojoBase.java @@ -33,10 +33,11 @@ import org.codehaus.mojo.versions.api.Property; import org.codehaus.mojo.versions.api.PropertyVersions; 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.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; -import org.codehaus.mojo.versions.recording.DefaultChangeRecord; +import org.codehaus.mojo.versions.recording.DefaultDependencyChangeRecord; +import org.codehaus.mojo.versions.recording.DefaultPropertyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static org.codehaus.mojo.versions.utils.SegmentUtils.determineUnchangedSegment; @@ -142,11 +143,18 @@ protected void update(ModifiedPomXMLEventReader pom, Map getDependencies(Model model) { * @param node model tree node to process * @param dependencies collection of dependencies to process (can be taken from dependency management, * parent, or dependencies) - * @param changeKind {@link ChangeRecord.ChangeKind} instance for the change recorder + * @param changeKind {@link ChangeKind} instance for the change recorder * @param propertyBacklog a {@link Set} instance used to store dependencies to be updated, but which were not found * in the current subtree. These properties need to be carried over to the parent node for * processing. @@ -300,7 +312,7 @@ private static List getDependencies(Model model) { private void useDepVersion( ModelNode node, Collection dependencies, - ChangeRecord.ChangeKind changeKind, + ChangeKind changeKind, Set propertyBacklog, Map> propertyConflicts) throws MojoExecutionException, XMLStreamException, VersionRetrievalException { @@ -373,7 +385,8 @@ private void useDepVersion( } else { if (getLog().isDebugEnabled()) { getLog().debug(String.format( - "Updated the %s property value to %s.", dep.getVersion(), depVersion)); + "Updated the %s property value to %s.", + propertyName.get(), depVersion)); } } return true; @@ -394,34 +407,46 @@ private void useDepVersion( } private boolean updatePropertyValue(ModelNode node, String property) { - return ofNullable(node.getModel().getProperties()) - .filter(p -> p.containsKey(property)) - .map(ignored -> { + // concatenating properties from the main build section + // with properties from profiles + return Stream.concat( + Stream.of(node.getModel().getProperties().getProperty(property)) + .filter(Objects::nonNull) + .map(value -> new ImmutablePair(null, value)), + node.getModel().getProfiles().stream() + .map(profile -> new ImmutablePair<>(profile, profile.getProperties())) + .map(pair -> ofNullable(pair.getRight().getProperty(property)) + .map(value -> new ImmutablePair(pair.getLeft(), value)) + .orElse(null))) + // and processing them + .filter(Objects::nonNull) + .map(pair -> { + try { + boolean result = PomHelper.setPropertyVersion( + node.getModifiedPomXMLEventReader(), + ofNullable(pair.getLeft()) + .map(Profile::getId) + .orElse(null), + property, + depVersion); + if (result) { try { - return PomHelper.setPropertyVersion( - node.getModifiedPomXMLEventReader(), null, property, depVersion); - } catch (XMLStreamException e) { + getChangeRecorder() + .recordChange(DefaultPropertyChangeRecord.builder() + .withProperty(property) + .withOldValue(pair.getRight()) + .withNewValue(depVersion) + .build()); + } catch (MojoExecutionException e) { throw new RuntimeException(e); } - }) - .orElse(false) - | ofNullable(node.getModel().getProfiles()) - .flatMap(profiles -> profiles.stream() - .map(profile -> ofNullable(profile.getProperties()) - .filter(p -> p.containsKey(property)) - .map(ignored -> { - try { - return PomHelper.setPropertyVersion( - node.getModifiedPomXMLEventReader(), - profile.getId(), - property, - depVersion); - } catch (XMLStreamException e) { - throw new RuntimeException(e); - } - }) - .orElse(false)) - .reduce(Boolean::logicalOr)) - .orElse(false); + } + return result; + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } + }) + .reduce(Boolean::logicalOr) + .orElse(false); } } diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java index 44c5d57c7a..57652fdf50 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestReleasesMojo.java @@ -44,8 +44,8 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -122,14 +122,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useLatestReleases( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useLatestReleases(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useLatestReleases(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useLatestReleases(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useLatestReleases(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -137,7 +139,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useLatestReleases( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog()); 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 4f7b38636c..ce140f260e 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestSnapshotsMojo.java @@ -40,8 +40,8 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -111,14 +111,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useLatestSnapshots( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useLatestSnapshots(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useLatestSnapshots(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useLatestSnapshots(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useLatestSnapshots(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -126,7 +128,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useLatestSnapshots( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog()); 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 a600a98ce7..6ca6231a9a 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojo.java @@ -38,8 +38,8 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -126,14 +126,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useLatestVersions( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useLatestVersions(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useLatestVersions(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useLatestVersions(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useLatestVersions(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -141,7 +143,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useLatestVersions( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog()); diff --git a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java index 41c7692001..97e99c8ead 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseLatestVersionsMojoBase.java @@ -37,8 +37,8 @@ import org.apache.maven.wagon.Wagon; import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; /** @@ -73,7 +73,7 @@ protected final void useLatestVersions( ModifiedPomXMLEventReader pom, Collection dependencies, BiFunction> newestVersionProducer, - ChangeRecord.ChangeKind changeKind, + DependencyChangeRecord.ChangeKind changeKind, Predicate... filters) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for (Dependency dep : dependencies) { 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 a0fdfddcc9..bc3ff2683b 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 @@ -36,8 +36,8 @@ import org.apache.maven.wagon.Wagon; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -77,16 +77,18 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useNextReleases( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useNextReleases(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useNextReleases(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useNextReleases(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useNextReleases(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -94,7 +96,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useNextReleases( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { useLatestVersions( pom, 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 12378ad8ca..9ecbf9989a 100644 --- a/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java +++ b/versions-maven-plugin/src/main/java/org/codehaus/mojo/versions/UseNextSnapshotsMojo.java @@ -39,8 +39,8 @@ import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.Segment; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import org.codehaus.mojo.versions.utils.SegmentUtils; @@ -111,13 +111,15 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useNextSnapshots( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useNextSnapshots(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useNextSnapshots(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useNextSnapshots(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useNextSnapshots(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -125,7 +127,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useNextSnapshots( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { Optional unchangedSegment = SegmentUtils.determineUnchangedSegment( allowMajorUpdates, allowMinorUpdates, allowIncrementalUpdates, getLog()); 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 b263c0887c..3564bedd9a 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 @@ -36,8 +36,8 @@ import org.apache.maven.wagon.Wagon; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -77,14 +77,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useNextVersions( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useNextVersions(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useNextVersions(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useNextVersions(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useNextVersions(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -92,7 +94,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useNextVersions( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { useLatestVersions( pom, 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 7bdda8be44..192358caf8 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 @@ -42,8 +42,8 @@ import org.codehaus.mojo.versions.api.ArtifactVersions; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.api.recording.ChangeRecord; import org.codehaus.mojo.versions.api.recording.ChangeRecorder; +import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord; import org.codehaus.mojo.versions.rewriting.ModifiedPomXMLEventReader; import static java.util.Collections.singletonList; @@ -103,14 +103,16 @@ protected void update(ModifiedPomXMLEventReader pom) PomHelper.getRawModel(getProject()).getDependencyManagement(); if (dependencyManagement != null) { useReleases( - pom, dependencyManagement.getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); + pom, + dependencyManagement.getDependencies(), + DependencyChangeRecord.ChangeKind.DEPENDENCY_MANAGEMENT); } } if (getProject().getDependencies() != null && isProcessingDependencies()) { - useReleases(pom, getProject().getDependencies(), ChangeRecord.ChangeKind.DEPENDENCY); + useReleases(pom, getProject().getDependencies(), DependencyChangeRecord.ChangeKind.DEPENDENCY); } if (getProject().getParent() != null && isProcessingParent()) { - useReleases(pom, singletonList(getParentDependency()), ChangeRecord.ChangeKind.PARENT); + useReleases(pom, singletonList(getParentDependency()), DependencyChangeRecord.ChangeKind.PARENT); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); @@ -118,7 +120,9 @@ protected void update(ModifiedPomXMLEventReader pom) } private void useReleases( - ModifiedPomXMLEventReader pom, Collection dependencies, ChangeRecord.ChangeKind changeKind) + ModifiedPomXMLEventReader pom, + Collection dependencies, + DependencyChangeRecord.ChangeKind changeKind) throws XMLStreamException, MojoExecutionException, VersionRetrievalException { for (Dependency dep : dependencies) { if (isExcludeReactor() && isProducedByReactor(dep)) { diff --git a/versions-maven-plugin/src/main/resources/org/codehaus/mojo/versions/recording/schema-2.0.xsd b/versions-maven-plugin/src/main/resources/org/codehaus/mojo/versions/recording/schema-2.0.xsd new file mode 100644 index 0000000000..79da098ab0 --- /dev/null +++ b/versions-maven-plugin/src/main/resources/org/codehaus/mojo/versions/recording/schema-2.0.xsd @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/versions-maven-plugin/src/site/markdown/examples/recording-changes.md b/versions-maven-plugin/src/site/markdown/examples/recording-changes.md index 9497d8248b..fd5dac3ebe 100644 --- a/versions-maven-plugin/src/site/markdown/examples/recording-changes.md +++ b/versions-maven-plugin/src/site/markdown/examples/recording-changes.md @@ -31,14 +31,17 @@ Which writes a file to `target/versions-changes.xml` that looks something like: ```xml - - + + + ``` The contents of this file records the fact that `localhost:dummy-api:1.1.1-2` -was upgraded to `3.0`. +was upgraded to `3.0` and that the property `revision` changed its value from `3.0` to `3.1`. 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 6dd54904aa..986f02ff00 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 @@ -10,7 +10,7 @@ import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -104,7 +104,7 @@ public void testProcessParent() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0"))); } @@ -131,7 +131,7 @@ public void testReplaceSnapshotWithRelease() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0"))); } @@ -158,7 +158,7 @@ public void testUpgrade() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "1.1.0-SNAPSHOT", "2.0.0"))); } @@ -185,7 +185,7 @@ public void testDowngrade() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "2.1.0-SNAPSHOT", "2.0.0"))); } 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 56619688b3..5ac34deb43 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 @@ -19,7 +19,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.ordering.InvalidSegmentException; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -162,7 +162,8 @@ public void testParentDowngradeAllowed() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "parent-artifact", "1.0.1-SNAPSHOT", "1.0.0"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "parent-artifact", "1.0.1-SNAPSHOT", "1.0.0"))); } @Test @@ -242,7 +243,7 @@ public void testAllowSnapshotsWithParentVersion() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "issue-670-artifact", "0.0.1-1", "0.0.1-1-impl-SNAPSHOT"))); } @@ -297,7 +298,7 @@ private void testSkipResolution(String version) throws VersionRetrievalException assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "parent-artifact", "1.0.0", version))); + hasItem(new DefaultDependencyVersionChange("default-group", "parent-artifact", "1.0.0", version))); } @Test @@ -320,7 +321,8 @@ public void testShouldUpgradeToSnapshot() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "parent-artifact", "0.9.0", "1.0.1-SNAPSHOT"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "parent-artifact", "0.9.0", "1.0.1-SNAPSHOT"))); } @Test @@ -384,7 +386,7 @@ public void testParentVersionRange() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dummy-parent2", "1.0", "2.0"))); + hasItem(new DefaultDependencyVersionChange("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 af9be7435c..5971061afb 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.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.codehaus.mojo.versions.utils.TestUtils; import org.junit.Test; @@ -45,7 +45,7 @@ public void testAllowMajorUpdates() throws Exception { setUpMojo("update-properties").execute(); assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "2.0.0-M1"))); + hasItem(new DefaultDependencyVersionChange("default-group", "default-artifact", "1.0.0", "2.0.0-M1"))); } @Test @@ -59,7 +59,8 @@ public void testAllowMinorUpdates() throws Exception { mojo.execute(); assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "1.1.0-alpha"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "default-artifact", "1.0.0", "1.1.0-alpha"))); } @Test @@ -74,7 +75,7 @@ public void testAllowIncrementalUpdates() throws Exception { mojo.execute(); assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "1.0.1-rc1"))); + hasItem(new DefaultDependencyVersionChange("default-group", "default-artifact", "1.0.0", "1.0.1-rc1"))); } @Test 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 3005da328b..bfd7bc2bac 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.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.hamcrest.Matchers; import org.junit.Test; @@ -43,7 +43,8 @@ public void testAllowMajorUpdates() throws Exception { mojo.execute(); assertThat( changeRecorder.getChanges(), - Matchers.hasItem(new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "2.0.0-M1"))); + Matchers.hasItem( + new DefaultDependencyVersionChange("default-group", "default-artifact", "1.0.0", "2.0.0-M1"))); } @Test @@ -58,8 +59,8 @@ public void testAllowMinorUpdates() throws Exception { mojo.execute(); assertThat( changeRecorder.getChanges(), - Matchers.hasItem( - new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "1.1.0-alpha"))); + Matchers.hasItem(new DefaultDependencyVersionChange( + "default-group", "default-artifact", "1.0.0", "1.1.0-alpha"))); } @Test @@ -75,6 +76,7 @@ public void testAllowIncrementalUpdates() throws Exception { mojo.execute(); assertThat( changeRecorder.getChanges(), - Matchers.hasItem(new DefaultVersionChange("default-group", "default-artifact", "1.0.0", "1.0.1-rc1"))); + Matchers.hasItem( + new DefaultDependencyVersionChange("default-group", "default-artifact", "1.0.0", "1.0.1-rc1"))); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseDepVersionMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseDepVersionMojoTest.java index f1aaf8bf0d..f66cff93f5 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseDepVersionMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseDepVersionMojoTest.java @@ -28,6 +28,7 @@ import org.apache.maven.plugin.logging.SystemStreamLog; import org.apache.maven.plugin.testing.AbstractMojoTestCase; import org.apache.maven.plugin.testing.MojoRule; +import org.codehaus.mojo.versions.change.DefaultPropertyVersionChange; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.codehaus.mojo.versions.utils.TestUtils; import org.junit.After; @@ -40,6 +41,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.hasItem; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -54,6 +56,7 @@ public class UseDepVersionMojoTest extends AbstractMojoTestCase { public MojoRule mojoRule = new MojoRule(this); private Path tempDir; + private TestChangeRecorder changeRecorder = new TestChangeRecorder(); @Before public void setUp() throws Exception { @@ -65,6 +68,7 @@ public void setUp() throws Exception { public void tearDown() throws Exception { try { TestUtils.tearDownTempDir(tempDir); + changeRecorder.getChanges().clear(); } finally { super.tearDown(); } @@ -127,12 +131,16 @@ public boolean isDebugEnabled() { setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); setVariableValueToObject(mojo, "log", logger); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); String pom = String.join("", Files.readAllLines(tempDir.resolve("pom.xml"))); assertThat(pom, containsString("${revision}")); assertThat(pom, containsString("2.0.0")); + assertThat( + changeRecorder.getChanges(), + hasItem(new DefaultPropertyVersionChange("revision", "1.0.0-SNAPSHOT", "2.0.0"))); } /** @@ -155,6 +163,7 @@ public void testPropertiesConflict() throws Exception { setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); setVariableValueToObject(mojo, "log", logger); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -162,6 +171,7 @@ public void testPropertiesConflict() throws Exception { assertThat( warnLog.toString(), containsString("Cannot update property ${revision}: controls more than one dependency: artifactB")); + assertThat(changeRecorder.getChanges(), empty()); } /** @@ -179,6 +189,7 @@ public void testPropertiesConflictRedefinition() throws Exception { setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(mojo.getProject())); setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -188,6 +199,8 @@ public void testPropertiesConflictRedefinition() throws Exception { assertThat(parent, containsString("${revision}")); assertThat(child, containsString("2.0.0")); assertThat(parent, containsString("1.0.0-SNAPSHOT")); + assertThat( + changeRecorder.getChanges(), hasItem(new DefaultPropertyVersionChange("revision", "1.0.1", "2.0.0"))); } /** @@ -206,6 +219,7 @@ public void testPropertiesConflictCancellation() throws Exception { setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(mojo.getProject())); setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -215,6 +229,9 @@ public void testPropertiesConflictCancellation() throws Exception { assertThat(parent, containsString("${revision}")); assertThat(parent, containsString("2.0.0")); assertThat(child, containsString("1.0.1")); + assertThat( + changeRecorder.getChanges(), + hasItem(new DefaultPropertyVersionChange("revision", "1.0.0-SNAPSHOT", "2.0.0"))); } /** @@ -231,6 +248,7 @@ public void testPropertiesConflictCancellationProfiles() throws Exception { setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(mojo.getProject())); setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -240,6 +258,9 @@ public void testPropertiesConflictCancellationProfiles() throws Exception { assertThat(parent, containsString("${revision}")); assertThat(parent, containsString("2.0.0")); assertThat(child, containsString("1.0.1")); + assertThat( + changeRecorder.getChanges(), + hasItem(new DefaultPropertyVersionChange("revision", "1.0.0-SNAPSHOT", "2.0.0"))); } /** @@ -262,6 +283,7 @@ public boolean isDebugEnabled() { setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); setVariableValueToObject(mojo, "log", logger); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -269,6 +291,8 @@ public boolean isDebugEnabled() { String parent = String.join("", Files.readAllLines(tempDir.resolve("pom.xml"))); assertThat(child, containsString("${revision}")); assertThat(parent, containsString("2.0.0")); + assertThat( + changeRecorder.getChanges(), hasItem(new DefaultPropertyVersionChange("revision", "1.0.0", "2.0.0"))); } /** @@ -285,6 +309,7 @@ public void testPropertiesChildParentRedefinition() throws Exception { setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(mojo.getProject())); setVariableValueToObject(mojo, "repositorySystem", mockRepositorySystem()); setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); @@ -293,6 +318,8 @@ public void testPropertiesChildParentRedefinition() throws Exception { assertThat(child, containsString("${revision}")); assertThat(parent, containsString("1.0.0-SNAPSHOT")); assertThat(child, containsString("2.0.0")); + assertThat( + changeRecorder.getChanges(), hasItem(new DefaultPropertyVersionChange("revision", "1.0.1", "2.0.0"))); } /** @@ -318,6 +345,7 @@ public void testPropertyFromParent() throws Exception { setVariableValueToObject(mojo, "aetherRepositorySystem", mockAetherRepositorySystem()); setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); setVariableValueToObject(mojo, "log", logger); + setVariableValueToObject(mojo, "changeRecorders", changeRecorder.asTestMap()); mojo.execute(); 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 ea7a12b135..ef7e50e480 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 @@ -15,7 +15,7 @@ import org.apache.maven.repository.RepositorySystem; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.hamcrest.core.Is; @@ -122,7 +122,8 @@ public void testDependenciesDowngradeIncremental() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); } @Test @@ -149,7 +150,7 @@ public void testDependenciesDowngradeMinor() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "dependency-artifact", "1.1.0-SNAPSHOT", "1.1.0"))); } @@ -173,7 +174,7 @@ public void testDependenciesDowngradeMajor() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); } @@ -200,7 +201,8 @@ public void testDependencyManagementDowngrade() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); } @Test @@ -233,7 +235,8 @@ public void testParentDowngrade() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); } @Test @@ -275,7 +278,8 @@ public void testPoisonDependencyVersion() // being present in the dependency list assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0"))); } @Test @@ -317,7 +321,7 @@ public void testIncludeFilter() assertThat(changeRecorder.getChanges(), hasSize(1)); assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "other-artifact", "1.0", "2.0"))); + hasItem(new DefaultDependencyVersionChange("default-group", "other-artifact", "1.0", "2.0"))); } @Test @@ -343,6 +347,6 @@ public void testExcludeFilter() assertThat(changeRecorder.getChanges(), hasSize(1)); assertThat( changeRecorder.getChanges(), - not(hasItem(new DefaultVersionChange("default-group", "other-artifact", "1.0", "2.0")))); + not(hasItem(new DefaultDependencyVersionChange("default-group", "other-artifact", "1.0", "2.0")))); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextReleasesMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextReleasesMojoTest.java index 3a8329f343..6e547f4bb6 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextReleasesMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextReleasesMojoTest.java @@ -25,7 +25,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.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.hamcrest.Matchers; @@ -121,6 +121,6 @@ public void testFindANewerRelease() throws IllegalAccessException { } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.0", "1.1.1"))); + hasItem(new DefaultDependencyVersionChange("default-group", "dependency-artifact", "1.1.0", "1.1.1"))); } } diff --git a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextVersionsMojoTest.java b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextVersionsMojoTest.java index 0dddd3f4b5..01237a4fac 100644 --- a/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextVersionsMojoTest.java +++ b/versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseNextVersionsMojoTest.java @@ -25,7 +25,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.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.hamcrest.Matchers; @@ -127,6 +127,7 @@ public void testFindANewerVersion() throws IllegalAccessException { } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange("default-group", "dependency-artifact", "1.1.0-SNAPSHOT", "1.1.1"))); + hasItem(new DefaultDependencyVersionChange( + "default-group", "dependency-artifact", "1.1.0-SNAPSHOT", "1.1.1"))); } } 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 cfac64c8c1..c08dc95d0a 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 @@ -10,7 +10,7 @@ import org.apache.maven.project.MavenProject; import org.codehaus.mojo.versions.api.PomHelper; import org.codehaus.mojo.versions.api.VersionRetrievalException; -import org.codehaus.mojo.versions.change.DefaultVersionChange; +import org.codehaus.mojo.versions.change.DefaultDependencyVersionChange; import org.codehaus.mojo.versions.utils.DependencyBuilder; import org.codehaus.mojo.versions.utils.TestChangeRecorder; import org.junit.Before; @@ -104,7 +104,7 @@ public void testProcessParent() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0"))); } @@ -131,7 +131,7 @@ public void testReplaceSnapshotWithRelease() } assertThat( changeRecorder.getChanges(), - hasItem(new DefaultVersionChange( + hasItem(new DefaultDependencyVersionChange( "default-group", "artifactA", "1.0.0-SNAPSHOT", "1.0.0"))); }