Skip to content

Commit

Permalink
Resolves #880: add information on property updates to the change reco…
Browse files Browse the repository at this point in the history
…rder

Release notes:
- new version and new namespace for the change recorder
- change recorder also records property changes
  • Loading branch information
jarmoniuk committed Jan 25, 2023
1 parent 8022064 commit 227aeed
Show file tree
Hide file tree
Showing 63 changed files with 919 additions and 406 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,9 @@
* 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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,39 +24,12 @@
*
* @author Slawomir Jaranowski
* @since 2.14.0
* @param <T> concrete {@link VersionChange} sub-interface
*/
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();

public interface ChangeRecord<T extends VersionChange> {
/**
* @return a details about changed item
* @since 2.14.0
*/
VersionChange getVersionChange();
T getVersionChange();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ public interface ChangeRecorder {
/**
* Record that a dependency was updated.
*
* @param changeRecord a record described change
* @param changeRecord a dependency record described change
* @since 2.14.0
*/
void recordChange(ChangeRecord changeRecord);
void recordChange(DependencyChangeRecord changeRecord);

/**
* Record that a property was updated.
*
* @param changeRecord a property record described change
* @since 2.14.0
*/
void recordChange(PropertyChangeRecord changeRecord);

/**
* Write the current set of changes to the given output path.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
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.
*
*/

import org.codehaus.mojo.versions.api.change.DependencyVersionChange;

/**
* Represents a change record of an item's version.
*
* @author Slawomir Jaranowski
* @since 2.14.0
*/
public interface DependencyChangeRecord extends ChangeRecord<DependencyVersionChange> {
/**
* 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();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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.
*
*/

import org.codehaus.mojo.versions.api.change.PropertyVersionChange;

/**
* Represents a change record of an item's version.
*
* @author Slawomir Jaranowski
* @since 2.14.0
*/
public interface PropertyChangeRecord extends ChangeRecord<PropertyVersionChange> {}
25 changes: 15 additions & 10 deletions versions-api/src/site/markdown/change-recorder.md.vm
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,31 @@ Write code
----------

```java
import java.io.IOException;
import javax.inject.Named;

import java.nio.file.Path;

import org.codehaus.mojo.versions.api.recording.ChangeRecord;
import org.codehaus.mojo.versions.api.recording.DependencyChangeRecord;
import org.codehaus.mojo.versions.api.recording.PropertyChangeRecord;
import org.codehaus.mojo.versions.api.recording.ChangeRecorder;

@Named( "my-recorder" )
public class MyChangeRecorder implements ChangeRecorder
{
@Named("my-recorder")
public class MyChangeRecorder implements ChangeRecorder {

@Override
public final void recordChange(DependencyChangeRecord changeRecord) {
// your code here
}

@Override
public final void recordChange( ChangeRecord changeRecord )
{
// your code
public final void recordChange(PropertyChangeRecord changeRecord) {
// your code here
}

@Override
public final void writeReport( Path outputPath )
{
// your code
public final void writeReport(Path outputPath) throws IOException {
// your code here
}
}
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -44,7 +44,7 @@ public CompositeVersionChanger(List<VersionChanger> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

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.
*
* @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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -92,6 +92,7 @@ public int hashCode() {
}

public String toString() {
return "DefaultVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion + ')';
return "DefaultDependencyVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion
+ ')';
}
}
Loading

0 comments on commit 227aeed

Please sign in to comment.