Skip to content

Commit

Permalink
Adjust version parsing for on-prem Neo4j instances
Browse files Browse the repository at this point in the history
  • Loading branch information
fbiville committed Jan 24, 2025
1 parent 3468c2e commit 2aa8a59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/main/java/liquibase/ext/neo4j/database/KernelVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static KernelVersion parse(String version) {
} else if (minor == -1) {
minor = parseMinor(buffer);
} else {
patch = Integer.parseInt(buffer, 10);
patch = parsePatch(buffer);
}

if (minor == -1) {
Expand Down Expand Up @@ -123,6 +123,15 @@ private static int parseMinor(String buffer) {
return Integer.parseInt(buffer.replace("-aura", ""), 10);
}


private static int parsePatch(String buffer) {
int end = buffer.indexOf('-');
if (end == -1) {
end = buffer.length();
}
return Integer.parseInt(buffer.substring(0, end), 10);
}

private static int signum(int result) {
return (int) Math.signum(result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import static liquibase.ext.neo4j.database.KernelVersionTest.Sign.ZERO

class KernelVersionTest extends Specification {


def "parses versions"() {
expect:
KernelVersion.parse(version) == result

where:
version | result
"1.0.0" | new KernelVersion(1, 0, 0)
"1.0.12" | new KernelVersion(1, 0, 12)
"1.0" | new KernelVersion(1, 0)
"5.26-aura" | new KernelVersion(5, 26)
"5" | new KernelVersion(5)
"2025.01-aura" | new KernelVersion(2025, 1)
"2025.1.2" | new KernelVersion(2025, 1, 2)
version | result
"1.0.0" | new KernelVersion(1, 0, 0)
"1.0.12" | new KernelVersion(1, 0, 12)
"1.0" | new KernelVersion(1, 0)
"5.26-aura" | new KernelVersion(5, 26)
"5" | new KernelVersion(5)
"2025.01-aura" | new KernelVersion(2025, 1)
"2025.1.2" | new KernelVersion(2025, 1, 2)
"2025.1.2-93482" | new KernelVersion(2025, 1, 2)
}

def "rejects invalid versions"() {
Expand All @@ -34,6 +34,7 @@ class KernelVersionTest extends Specification {
where:
version | exceptionType
"" | IllegalArgumentException.class
"foobar" | NumberFormatException.class
"." | NumberFormatException.class
".." | NumberFormatException.class
"5." | IllegalArgumentException.class
Expand Down

0 comments on commit 2aa8a59

Please sign in to comment.