Skip to content

Commit 5ccf660

Browse files
committed
Coords: : with empty version is respected
1 parent 61e765b commit 5ccf660

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/main/java/org/scm4j/commons/Coords.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class Coords {
1010
private final String groupId;
1111
private final String classifier;
1212
private final Version version;
13+
private final String verPrefix;
14+
private final String verSuffix;
1315
private final String coordsStringNoComment;
1416

1517
public String getComment() {
@@ -69,7 +71,11 @@ public Coords(String coordsString) {
6971
groupId = strs[0];
7072
artifactId = strs[1];
7173

72-
classifier = strs.length > 3 ? ":" + strs[3].trim() : "";
74+
verPrefix = strs.length > 2 ? ":" : "";
75+
76+
verSuffix = strs.length > 3 ? ":" : "";
77+
78+
classifier = strs.length > 3 ? strs[3].trim() : "";
7379

7480
version = new Version(strs.length > 2 ? strs[2] : "");
7581
}
@@ -109,8 +115,9 @@ public String toString() {
109115
}
110116

111117
public String toString(String versionStr) {
112-
String str = versionStr + classifier + extension;
113-
return getName() + (str.isEmpty() ? "" : ":" + str) + commentStr;
118+
String str = verPrefix.isEmpty() && !versionStr.isEmpty() ? ":" : verPrefix;
119+
str += versionStr + verSuffix + classifier + extension;
120+
return getName() + str + commentStr;
114121
}
115122

116123
public String getName() {

src/test/java/org/scm4j/commons/CoordsTest.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.scm4j.commons;
22

3-
import static org.junit.Assert.*;
4-
3+
import nl.jqno.equalsverifier.EqualsVerifier;
54
import org.junit.Test;
65

7-
import nl.jqno.equalsverifier.EqualsVerifier;
6+
import static org.junit.Assert.*;
87

98
public class CoordsTest {
109

@@ -40,8 +39,8 @@ public void testExtension() {
4039
@Test
4140
public void testClassifier() {
4241
assertEquals("", dc("com.myproject:c1").getClassifier());
43-
assertEquals(":", dc("com.myproject:c1::").getClassifier());
44-
assertEquals(":class", dc("com.myproject:c1::class:").getClassifier());
42+
assertEquals("", dc("com.myproject:c1::").getClassifier());
43+
assertEquals("class", dc("com.myproject:c1::class:").getClassifier());
4544
}
4645

4746
@Test
@@ -50,8 +49,8 @@ public void testToSting() {
5049
assertEquals("com.myproject: c1:1.0.0", dc("com.myproject: c1:1.0.0").toString());
5150
assertEquals(" com.myproject: c1:1.0.0", dc(" com.myproject: c1:1.0.0").toString());
5251
assertEquals("com.myproject:c1:1.0.0#comment", dc("com.myproject:c1:1.0.0#comment").toString());
53-
assertEquals("com.myproject:c1:1.0.0@ext #comment", dc("com.myproject:c1:1.0.0@ext #comment").toString());
54-
assertEquals("com.myproject:c1::dfgd@ext #comment", dc("com.myproject:c1::dfgd@ext #comment").toString());
52+
assertEquals("com.myproject:c1:1.0.0@ext # comment", dc("com.myproject:c1:1.0.0@ext # comment").toString());
53+
assertEquals("com.myproject:c1::dfgd@ext # comment", dc("com.myproject:c1::dfgd@ext # comment").toString());
5554
}
5655

5756
@Test
@@ -85,5 +84,15 @@ public void testEqualsAndHashCode() {
8584
.usingGetClass()
8685
.verify();
8786
}
88-
87+
88+
@Test
89+
public void testVersionChange() {
90+
assertEquals("eu.untill:JTerminal:12.13 # comment", new Coords("eu.untill:JTerminal: # comment").toString("12.13"));
91+
assertEquals("eu.untill:JTerminal:12.13:abc@efg # comment", new Coords("eu.untill:JTerminal::abc@efg # comment").toString("12.13"));
92+
assertEquals("eu.untill:JTerminal::abc@efg # comment", new Coords("eu.untill:JTerminal:12.13:abc@efg # comment").toString(""));
93+
assertEquals("eu.untill:JTerminal::# comment", new Coords("eu.untill:JTerminal:12.13:# comment").toString(""));
94+
assertEquals("eu.untill:JTerminal: # comment", new Coords("eu.untill:JTerminal:12.13 # comment").toString(""));
95+
assertEquals("eu.untill:JTerminal # comment", new Coords("eu.untill:JTerminal # comment").toString(""));
96+
assertEquals("eu.untill:JTerminal:12.13 # comment", new Coords("eu.untill:JTerminal # comment").toString("12.13"));
97+
}
8998
}

0 commit comments

Comments
 (0)