Skip to content

Commit a9dbcdd

Browse files
Grzegorz KochańskiGrzegorz Kochański
authored andcommitted
Add artifact classifier to ChangeRocorderXML
1 parent fdc3f43 commit a9dbcdd

13 files changed

Lines changed: 140 additions & 19 deletions

File tree

versions-api/src/main/java/org/codehaus/mojo/versions/api/change/DependencyVersionChange.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public interface DependencyVersionChange extends VersionChange {
3838
*/
3939
String getArtifactId();
4040

41+
/**
42+
* Returns the classifier of the dependency
43+
* @return classifier of the dependency
44+
* @since 2.20.2
45+
*/
46+
String getClassifier();
47+
4148
/**
4249
* Returns the old version of the dependency
4350
* @return old version the dependency

versions-common/src/main/java/org/codehaus/mojo/versions/change/DefaultDependencyVersionChange.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public final class DefaultDependencyVersionChange implements DependencyVersionCh
3030

3131
private final String artifactId;
3232

33+
private final String classifier;
34+
3335
private final String oldVersion;
3436

3537
private final String newVersion;
@@ -42,8 +44,14 @@ public final class DefaultDependencyVersionChange implements DependencyVersionCh
4244
* @param newVersion new version
4345
*/
4446
public DefaultDependencyVersionChange(String groupId, String artifactId, String oldVersion, String newVersion) {
47+
this(groupId, artifactId, null, oldVersion, newVersion);
48+
}
49+
50+
public DefaultDependencyVersionChange(
51+
String groupId, String artifactId, String classifier, String oldVersion, String newVersion) {
4552
this.groupId = groupId;
4653
this.artifactId = artifactId;
54+
this.classifier = classifier;
4755
this.oldVersion = oldVersion;
4856
this.newVersion = newVersion;
4957
}
@@ -64,6 +72,14 @@ public String getArtifactId() {
6472
return artifactId;
6573
}
6674

75+
/**
76+
* Returns the classifier of the dependency
77+
* @return classifier of the dependency
78+
*/
79+
public String getClassifier() {
80+
return classifier;
81+
}
82+
6783
/**
6884
* Returns the old version of the dependency
6985
* @return old version of the dependency
@@ -94,6 +110,11 @@ public boolean equals(Object o) {
94110
if (!Objects.equals(artifactId, versionChange.artifactId)) {
95111
return false;
96112
}
113+
114+
if (!Objects.equals(classifier, versionChange.classifier)) {
115+
return false;
116+
}
117+
97118
if (!Objects.equals(groupId, versionChange.groupId)) {
98119
return false;
99120
}
@@ -107,14 +128,15 @@ public boolean equals(Object o) {
107128
public int hashCode() {
108129
int result = groupId != null ? groupId.hashCode() : 0;
109130
result = 31 * result + (artifactId != null ? artifactId.hashCode() : 0);
131+
result = 31 * result + (classifier != null ? classifier.hashCode() : 0);
110132
result = 31 * result + (oldVersion != null ? oldVersion.hashCode() : 0);
111133
result = 31 * result + (newVersion != null ? newVersion.hashCode() : 0);
112134
return result;
113135
}
114136

115137
@Override
116138
public String toString() {
117-
return "DefaultDependencyVersionChange(" + groupId + ':' + artifactId + ":" + oldVersion + "-->" + newVersion
118-
+ ')';
139+
return "DefaultDependencyVersionChange(" + groupId + ':' + artifactId + ':' + classifier + ":" + oldVersion
140+
+ "-->" + newVersion + ')';
119141
}
120142
}

versions-common/src/main/java/org/codehaus/mojo/versions/recording/ChangeRecorderXML.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public final void recordChange(DependencyChangeRecord changeRecord) {
8282
DependencyVersionChange change = (DependencyVersionChange) changeRecord.getVersionChange();
8383
update.setAttribute("groupId", change.getGroupId());
8484
update.setAttribute("artifactId", change.getArtifactId());
85+
if (change.getClassifier() != null) {
86+
update.setAttribute("classifier", change.getClassifier());
87+
}
8588
update.setAttribute("oldVersion", change.getOldVersion());
8689
update.setAttribute("newVersion", change.getNewVersion());
8790

versions-common/src/main/java/org/codehaus/mojo/versions/recording/DefaultDependencyChangeRecord.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static class Builder {
6363
private ChangeKind kind;
6464
private String groupId;
6565
private String artifactId;
66+
private String classifier;
6667
private String oldVersion;
6768
private String newVersion;
6869

@@ -98,6 +99,16 @@ public Builder withArtifactId(String artifactId) {
9899
return this;
99100
}
100101

102+
/**
103+
* Supplies the classifier
104+
* @param classifier requested classifier
105+
* @return builder instance
106+
*/
107+
public Builder withClassifier(String classifier) {
108+
this.classifier = classifier;
109+
return this;
110+
}
111+
101112
/**
102113
* Supplies the version from before the change
103114
* @param oldVersion version from before the change
@@ -126,6 +137,7 @@ public Builder withNewVersion(String newVersion) {
126137
public Builder withDependency(Dependency dependency) {
127138
groupId = dependency.getGroupId();
128139
artifactId = dependency.getArtifactId();
140+
classifier = dependency.getClassifier();
129141
oldVersion = dependency.getVersion();
130142
return this;
131143
}
@@ -138,6 +150,7 @@ public Builder withDependency(Dependency dependency) {
138150
public Builder withArtifact(Artifact artifact) {
139151
groupId = artifact.getGroupId();
140152
artifactId = artifact.getArtifactId();
153+
classifier = artifact.getClassifier();
141154
oldVersion = artifact.getVersion();
142155
return this;
143156
}
@@ -148,7 +161,7 @@ public Builder withArtifact(Artifact artifact) {
148161
*/
149162
public DependencyChangeRecord build() {
150163
return new DefaultDependencyChangeRecord(
151-
kind, new DefaultDependencyVersionChange(groupId, artifactId, oldVersion, newVersion));
164+
kind, new DefaultDependencyVersionChange(groupId, artifactId, classifier, oldVersion, newVersion));
152165
}
153166
}
154167
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
invoker.goals=-DchangeRecorderFormat=xml ${project.groupId}:${project.artifactId}:${project.version}:update-properties
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>localhost</groupId>
6+
<artifactId>it-changerecord-update-properties-002</artifactId>
7+
<version>1.0</version>
8+
<packaging>pom</packaging>
9+
<name>update-properties with classifier</name>
10+
11+
<properties>
12+
<dummy-impl.version>1.0</dummy-impl.version>
13+
<dummy-impl.classifier1.version>1.0</dummy-impl.classifier1.version>
14+
</properties>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>localhost</groupId>
19+
<artifactId>dummy-impl</artifactId>
20+
<version>${dummy-impl.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>localhost</groupId>
24+
<artifactId>dummy-impl</artifactId>
25+
<classifier>classifier1</classifier>
26+
<version>${dummy-impl.classifier1.version}</version>
27+
</dependency>
28+
29+
</dependencies>
30+
<build>
31+
<pluginManagement>
32+
<plugins>
33+
<plugin>
34+
<artifactId>maven-clean-plugin</artifactId>
35+
<version>2.2</version>
36+
</plugin>
37+
<plugin>
38+
<artifactId>maven-deploy-plugin</artifactId>
39+
<version>2.3</version>
40+
</plugin>
41+
<plugin>
42+
<artifactId>maven-install-plugin</artifactId>
43+
<version>2.2</version>
44+
</plugin>
45+
<plugin>
46+
<artifactId>maven-site-plugin</artifactId>
47+
<version>2.0</version>
48+
</plugin>
49+
</plugins>
50+
</pluginManagement>
51+
52+
<plugins>
53+
<plugin>
54+
<groupId>@project.groupId@</groupId>
55+
<artifactId>@project.artifactId@</artifactId>
56+
<version>@project.version@</version>
57+
</plugin>
58+
</plugins>
59+
</build>
60+
61+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import groovy.xml.XmlSlurper
2+
3+
def changes = new XmlSlurper().parse( new File( basedir, 'target/versions-changes.xml' ) )
4+
assert (changes.dependencyUpdate.findAll { node -> node.@kind == 'property-update'
5+
&& node.@groupId == 'localhost'
6+
&& node.@artifactId == 'dummy-impl'
7+
&& node.@oldVersion == '1.0'
8+
&& node.@newVersion == '2.2' }.size() == 2)
9+
10+
assert (changes.dependencyUpdate.findAll { node -> node.@kind == 'property-update'
11+
&& node.@groupId == 'localhost'
12+
&& node.@artifactId == 'dummy-impl'
13+
&& node.@classifier == 'classifier1'
14+
&& node.@oldVersion == '1.0'
15+
&& node.@newVersion == '2.2' }.size() == 1)

versions-maven-plugin/src/main/resources/org/codehaus/mojo/versions/recording/schema-2.0.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<attribute name="kind" type="string" use="required"/>
2929
<attribute name="groupId" type="string" use="required"/>
3030
<attribute name="artifactId" type="string" use="required"/>
31+
<attribute name="classifier" type="string"/>
3132
<attribute name="oldVersion" type="string" use="required"/>
3233
<attribute name="newVersion" type="string" use="required"/>
3334
</extension>

versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testDependenciesDowngradeIncremental()
9999
assertThat(
100100
changeRecorder.getChanges(),
101101
hasItem(new DefaultDependencyVersionChange(
102-
"default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0")));
102+
"default-group", "dependency-artifact", "default", "1.1.1-SNAPSHOT", "1.1.0")));
103103
}
104104

105105
@Test
@@ -128,8 +128,7 @@ public void testDependenciesDowngradeMinor()
128128
assertThat(
129129
changeRecorder.getChanges(),
130130
hasItem(new DefaultDependencyVersionChange(
131-
"default-group", "dependency-artifact",
132-
"1.1.0-SNAPSHOT", "1.1.0")));
131+
"default-group", "dependency-artifact", "default", "1.1.0-SNAPSHOT", "1.1.0")));
133132
}
134133

135134
@Test
@@ -147,8 +146,7 @@ public void testDependenciesDowngradeMajor()
147146
assertThat(
148147
changeRecorder.getChanges(),
149148
hasItem(new DefaultDependencyVersionChange(
150-
"default-group", "dependency-artifact",
151-
"1.1.1-SNAPSHOT", "1.1.0")));
149+
"default-group", "dependency-artifact", "default", "1.1.1-SNAPSHOT", "1.1.0")));
152150
}
153151

154152
@Test
@@ -166,7 +164,7 @@ public void testDependencyManagementDowngrade()
166164
assertThat(
167165
changeRecorder.getChanges(),
168166
hasItem(new DefaultDependencyVersionChange(
169-
"default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0")));
167+
"default-group", "dependency-artifact", "default", "1.1.1-SNAPSHOT", "1.1.0")));
170168
}
171169

172170
@Test
@@ -235,7 +233,7 @@ public void testPoisonDependencyVersion()
235233
assertThat(
236234
changeRecorder.getChanges(),
237235
hasItem(new DefaultDependencyVersionChange(
238-
"default-group", "dependency-artifact", "1.1.1-SNAPSHOT", "1.1.0")));
236+
"default-group", "dependency-artifact", "default", "1.1.1-SNAPSHOT", "1.1.0")));
239237
}
240238

241239
@Test
@@ -261,7 +259,8 @@ public void testDontUpgradeToPreReleaseByDefault()
261259
// With allowPreReleases=false (default), beta is excluded and 1.1.0 is selected
262260
assertThat(
263261
changeRecorder.getChanges(),
264-
hasItem(new DefaultDependencyVersionChange("default-group", "pre-release-artifact", "1.0.0", "1.1.0")));
262+
hasItem(new DefaultDependencyVersionChange(
263+
"default-group", "pre-release-artifact", "default", "1.0.0", "1.1.0")));
265264
}
266265

267266
@Test
@@ -288,6 +287,6 @@ public void testUpgradeToPreReleaseWhenAllowed()
288287
assertThat(
289288
changeRecorder.getChanges(),
290289
hasItem(new DefaultDependencyVersionChange(
291-
"default-group", "pre-release-artifact", "1.0.0", "1.2.0-beta1")));
290+
"default-group", "pre-release-artifact", "default", "1.0.0", "1.2.0-beta1")));
292291
}
293292
}

versions-maven-plugin/src/test/java/org/codehaus/mojo/versions/UseLatestVersionsMojoTestBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected void testIncludeFilter(String expectedNewVersion)
154154
assertThat(
155155
changeRecorder.getChanges(),
156156
hasItem(new DefaultDependencyVersionChange(
157-
"default-group", "other-artifact", "1.0", expectedNewVersion)));
157+
"default-group", "other-artifact", "default", "1.0", expectedNewVersion)));
158158
}
159159

160160
@Test

0 commit comments

Comments
 (0)