Skip to content

Commit cd513f4

Browse files
authored
support snapshot versioning (#1053)
1 parent bb778a0 commit cd513f4

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/main/java/com/fasterxml/jackson/core/Version.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ public String toFullString() {
113113
}
114114

115115
@Override public int hashCode() {
116-
return _artifactId.hashCode() ^ _groupId.hashCode() + _majorVersion - _minorVersion + _patchLevel;
116+
return _artifactId.hashCode() ^ _groupId.hashCode() ^ _snapshotInfo.hashCode()
117+
+ _majorVersion - _minorVersion + _patchLevel;
117118
}
118119

119120
@Override
@@ -126,6 +127,7 @@ public boolean equals(Object o)
126127
return (other._majorVersion == _majorVersion)
127128
&& (other._minorVersion == _minorVersion)
128129
&& (other._patchLevel == _patchLevel)
130+
&& other._snapshotInfo.equals(_snapshotInfo)
129131
&& other._artifactId.equals(_artifactId)
130132
&& other._groupId.equals(_groupId)
131133
;
@@ -145,6 +147,17 @@ public int compareTo(Version other)
145147
diff = _minorVersion - other._minorVersion;
146148
if (diff == 0) {
147149
diff = _patchLevel - other._patchLevel;
150+
if (diff == 0) {
151+
if (isSnapshot() && other.isSnapshot()) {
152+
diff = _snapshotInfo.compareTo(other._snapshotInfo);
153+
} else if (isSnapshot() && !other.isSnapshot()) {
154+
diff = -1;
155+
} else if (!isSnapshot() && other.isSnapshot()) {
156+
diff = 1;
157+
} else {
158+
diff = 0;
159+
}
160+
}
148161
}
149162
}
150163
}

src/test/java/com/fasterxml/jackson/core/VersionTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,36 @@ public void testCompareToAndCreatesVersionTaking6ArgumentsAndUnknownVersion() {
5151

5252
assertTrue(version.compareTo(versionTwo) < 0);
5353
}
54+
55+
@Test
56+
public void testCompareToSnapshotSame() {
57+
Version version = new Version(0, 0, 0, "alpha");
58+
Version versionTwo = new Version(0, 0, 0, "alpha");
59+
60+
assertEquals(0, version.compareTo(versionTwo));
61+
}
62+
63+
@Test
64+
public void testCompareToSnapshotDifferent() {
65+
Version version = new Version(0, 0, 0, "alpha");
66+
Version versionTwo = new Version(0, 0, 0, "beta");
67+
68+
assertTrue(version.compareTo(versionTwo) < 0);
69+
}
70+
71+
@Test
72+
public void testCompareWhenOnlyFirstHasSnapshot() {
73+
Version version = new Version(0, 0, 0, "beta");
74+
Version versionTwo = new Version(0, 0, 0, null);
75+
76+
assertEquals(-1, version.compareTo(versionTwo));
77+
}
78+
79+
@Test
80+
public void testCompareWhenOnlySecondHasSnapshot() {
81+
Version version = new Version(0, 0, 0, "");
82+
Version versionTwo = new Version(0, 0, 0, "beta");
83+
84+
assertEquals(1, version.compareTo(versionTwo));
85+
}
5486
}

0 commit comments

Comments
 (0)