Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replicate Maven rules more exactly #374

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ public void next() throws NoSuchElementException, VersionSyntaxException {
i += Character.charCount(cp);
}
}
if (end == start) {
// capture the zero string (last digit only)
start = end - 1;
}
} else if (isSeparatorCodePoint(cp)) {
token = TokenType.SEP;
end = start + Character.charCount(cp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public boolean isNonEmptySeparator() {
}

public boolean isNumberPart() {
return super.isNumberPart() || isReleaseString();
return super.isNumberPart() || super.isAlphaPart() && super.alphaPartEquals("", true);
}

public boolean isAlphaPart() {
return super.isAlphaPart() && !isReleaseString();
return super.isAlphaPart() && !isReleaseString() && !super.alphaPartEquals("", true);
}

public int getSeparatorCodePoint() {
Expand Down Expand Up @@ -85,7 +85,7 @@ public boolean hasNext() {
public void next() throws NoSuchElementException, VersionSyntaxException {
super.next();
// skip trailing 0. segments until next - or EOS
if (isDotSeparator()) {
if (isSeparator()) {
final long mark = mark();
try {
skipTrailer(mark);
Expand Down Expand Up @@ -123,35 +123,31 @@ boolean nextSeparatorIsEmpty() {
}

boolean isReleaseString() {
return alphaPartEquals("", true) || alphaPartEquals("ga", true) || alphaPartEquals("final", true)
|| alphaPartEquals("release", true);
return alphaPartEquals("ga", true) || alphaPartEquals("final", true) || alphaPartEquals("release", true);
}

boolean isZeroSegment() {
return super.isNumberPart() && super.numberPartEquals(0) || super.isAlphaPart() && isReleaseString();
}

boolean isDashSeparator() {
return isSeparator() && getSeparatorCodePoint() == '-';
}

boolean isDotSeparator() {
return isSeparator() && getSeparatorCodePoint() == '.';
}

void skipTrailer(long mark) {
assert isDotSeparator();
assert isSeparator();
assert hasNext();
next();
if (isZeroSegment()) {
long sep = mark();
super.next();
if (isNumberPart() && numberPartEquals(0)) {
// could be more zeros
assert hasNext();
next();
if (!isDashSeparator()) {
assert isDotSeparator();
if (hasNext()) {
super.next();
assert isSeparator();
skipTrailer(mark);
} else {
// done! it was all trailing junk
return;
}
// return the dash separator
} else if (isAlphaPart() || getMilestoneMagnitude() != -1) {
// qualifier!
reset(sep);
} else {
// can't skip
reset(mark);
Expand Down Expand Up @@ -182,8 +178,6 @@ int getMilestoneMagnitude() {
} else if (alphaPartEquals("sp", true)) {
return 6;
}
} else if (isZeroSegment()) {
return 5;
}
return -1; // not a milestone
}
Expand All @@ -194,7 +188,6 @@ int getMilestoneMagnitude() {
"milestone",
"rc",
"snapshot",
"", // this is really lame but it's how Maven does it
"sp",
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ protected int compareZero(MavenVersionIterator i) {
protected int compare(MavenVersionIterator i1, MavenVersionIterator i2) {
// pad separators
if (i1.isSeparator()) {
i1.insertEmptyAlpha();
i1.insertEmptyNumber();
}
if (i2.isSeparator()) {
i2.insertEmptyAlpha();
i2.insertEmptyNumber();
}

// there is a current element
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,28 @@ public void testMavenCompare() throws Exception {
checkMavenConsistency("3.6.0.SP1", "3.6.0");
}

@Test
public void testMavenCompare2() throws Exception {
checkMavenConsistency("3.6.0-CR1", "3.6.0");
checkMavenConsistency("3.6.0-FINAL", "3.6.0");
checkMavenConsistency("3.6.0-SP1", "3.6.0");
checkMavenConsistency("2.13.5.SP1.redhat-00002", "2.13.5.0.redhat-00002");
checkMavenConsistency("2.13.5.SP1.redhat-00002", "2.13.5.Final.redhat-00002");
checkMavenConsistency("2.13.5.SP1-redhat-00002", "2.13.5.Final-redhat-00002");
checkMavenConsistency("2.13.5-redhat-00002", "2.13.5.Final-redhat-00002");
checkMavenConsistency("2.1", "2.0.0.0.0.1");
checkMavenConsistency("2.0.0.0.0.1", "2.final.0.0.0.1");
checkMavenConsistency("2.1", "2.0.0.final.0.1");
checkMavenConsistency("2.sp", "2.0.0.0.0.sp");
checkMavenConsistency("2.beta", "2.0.0.0.0.beta");
checkMavenConsistency("2.0.0.foo", "2.0.foo");
checkMavenConsistency("4.0.4", "4.final.4");
checkMavenConsistency("4.0.4", "4..4");
checkMavenConsistency("4.final.4", "4..4");
checkMavenConsistency("4.final.4", "4.0.4");
checkMavenConsistency("0.4.final.4", "0.4.0.4");
}

private static final org.eclipse.aether.version.VersionScheme MR_SCHEME = new GenericVersionScheme();

private static void checkMavenConsistency(String v1, String v2) throws InvalidVersionSpecificationException {
Expand Down