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

Improve version parsing #689

Merged
merged 2 commits into from
Jan 24, 2025
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
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extra:
group_id: org.liquibase.ext
group_id_url: org/liquibase/ext
artifact_id: liquibase-neo4j
version: 4.31.0
version: 4.31.0.1
extra_css:
- css/extra.css
markdown_extensions:
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>org.liquibase.ext</groupId>
<artifactId>liquibase-neo4j</artifactId>
<version>4.32.0-SNAPSHOT</version>
<version>4.31.0.1-SNAPSHOT</version>

<name>Liquibase Neo4j Database Extension</name>
<description>Adds additional Neo4j specific Liquibase functionality</description>
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/liquibase/ext/neo4j/database/KernelVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ public static KernelVersion parse(String version) {
major = Integer.parseInt(buffer, 10);
} else if (minor == -1) {
minor = parseMinor(buffer);
} else {
throw invalidVersion(version);
}
buffer = "";
}
if (!buffer.isEmpty()) {
if (major == -1) {
major = Integer.parseInt(buffer, 10);
} else if (minor == -1) {
minor = parseMinor(buffer);
} else {
patch = Integer.parseInt(buffer, 10);
}
if (buffer.isEmpty()) {
throw invalidVersion(version);
}
if (major == -1) {
throw new IllegalArgumentException(String.format("Invalid Neo4j version: %s", version));
major = Integer.parseInt(buffer, 10);
} else if (minor == -1) {
minor = parseMinor(buffer);
} else {
patch = Integer.parseInt(buffer, 10);
}

if (minor == -1) {
return new KernelVersion(major);
}
Expand Down Expand Up @@ -118,11 +119,15 @@ public String versionString() {
return String.format("%d.%d.%d", major, minor, patch);
}

private static int parseMinor(String buffer) {
return Integer.parseInt(buffer.replace("-aura", ""), 10);
}

private static int signum(int result) {
return (int) Math.signum(result);
}

private static int parseMinor(String buffer) {
return Integer.parseInt(buffer.replace("-aura", ""), 10);
private static IllegalArgumentException invalidVersion(String version) {
return new IllegalArgumentException(String.format("Invalid Neo4j version: %s", version));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,32 @@ class KernelVersionTest extends Specification {
KernelVersion.parse(version) == result

where:
version | result
"1.0.0" | new KernelVersion(1, 0, 0)
"1.0" | new KernelVersion(1, 0)
"5.26-aura" | new KernelVersion(5, 26)
"5" | new KernelVersion(5)
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)
}

def "rejects invalid versions"() {
when:
KernelVersion.parse(version)

then:
thrown(exceptionType)

where:
version | exceptionType
"" | IllegalArgumentException.class
"." | NumberFormatException.class
".." | NumberFormatException.class
"5." | IllegalArgumentException.class
"2025.1." | IllegalArgumentException.class
".5.25" | NumberFormatException.class
"2025.2.1.2" | IllegalArgumentException.class
}

def "compares versions"() {
Expand Down
Loading