Skip to content

Commit

Permalink
Applying review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejj0 committed Jan 24, 2023
1 parent 67374d9 commit 636968f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import java.io.IOException;
import java.nio.file.Path;

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

/**
* Interface for implement a recorder of version changes.
*
Expand All @@ -32,11 +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(DependencyChangeRecord changeRecord);

/**
* Record that a dependency was updated.
*
* @param changeRecord a dependency record described change
* @since 2.14.0
* @param <T> concrete {@link VersionChange} sub-interface
*/
<T extends VersionChange> void recordChange(ChangeRecord<T> changeRecord);
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
Expand Up @@ -23,8 +23,9 @@

import java.nio.file.Path;

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.api.recording.PropertyChangeRecord;

/**
* A recorder that ignores updates.
Expand All @@ -37,7 +38,10 @@ public class ChangeRecorderNull implements ChangeRecorder {
public ChangeRecorderNull() {}

@Override
public final void recordChange(ChangeRecord changeRecord) {}
public final void recordChange(PropertyChangeRecord changeRecord) {}

@Override
public final void recordChange(DependencyChangeRecord changeRecord) {}

@Override
public final void writeReport(final Path outputPath) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@

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.codehaus.mojo.versions.api.recording.PropertyChangeRecord;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -78,27 +78,29 @@ public ChangeRecorderXML() {
}

@Override
public final void recordChange(ChangeRecord changeRecord) {
public final void recordChange(DependencyChangeRecord changeRecord) {
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());
}
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());

this.root.appendChild(update);
}

@Override
public final void recordChange(PropertyChangeRecord changeRecord) {
Element update;
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());

this.root.appendChild(update);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,21 @@
import java.util.Map;

import org.codehaus.mojo.versions.api.change.VersionChange;
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.api.recording.PropertyChangeRecord;

@Named("test")
public class TestChangeRecorder implements ChangeRecorder {
private final List<VersionChange> changes = new LinkedList<>();

@Override
public void recordChange(ChangeRecord changeRecord) {
public void recordChange(DependencyChangeRecord changeRecord) {
changes.add(changeRecord.getVersionChange());
}

@Override
public void recordChange(PropertyChangeRecord changeRecord) {
changes.add(changeRecord.getVersionChange());
}

Expand Down

0 comments on commit 636968f

Please sign in to comment.