diff --git a/neo4j-adapter/src/main/java/org/neo4j/gds/compat/Neo4jVersion.java b/neo4j-adapter/src/main/java/org/neo4j/gds/compat/Neo4jVersion.java index 45ff824b62..cd73d9a8e5 100644 --- a/neo4j-adapter/src/main/java/org/neo4j/gds/compat/Neo4jVersion.java +++ b/neo4j-adapter/src/main/java/org/neo4j/gds/compat/Neo4jVersion.java @@ -41,81 +41,11 @@ public enum Neo4jVersion { V_5_11, V_5_12, V_5_13, + V_5_14, V_Dev; private static final int MINOR_DEV_VERSION = 14; - @Override - public String toString() { - switch (this) { - case V_4_4: - return "4.4"; - case V_5_6: - return "5.6"; - case V_5_7: - return "5.7"; - case V_5_8: - return "5.8"; - case V_5_9: - return "5.9"; - case V_5_10: - return "5.10"; - case V_5_11: - return "5.11"; - case V_5_12: - return "5.12"; - case V_5_13: - return "5.13"; - case V_Dev: - return "dev"; - default: - throw new IllegalArgumentException("Unexpected value: " + this.name() + " (sad java 😞)"); - } - } - - public MajorMinorVersion semanticVersion() { - if (this == V_Dev) { - return ImmutableMajorMinorVersion.of(5, MINOR_DEV_VERSION); - } - - String version = toString(); - var subVersions = version.split("\\."); - - if (subVersions.length < 2) { - throw new IllegalStateException("Cannot derive version from " + version); - } - - return ImmutableMajorMinorVersion.of(Integer.parseInt(subVersions[0]), Integer.parseInt(subVersions[1])); - } - - public static Neo4jVersion findNeo4jVersion() { - return Neo4jVersionHolder.VERSION; - } - - private static final class Neo4jVersionHolder { - private static final Neo4jVersion VERSION = parse(neo4jVersion()); - } - - static String neo4jVersion() { - var neo4jVersion = Objects.requireNonNullElse(Version.class.getPackage().getImplementationVersion(), "dev"); - // some versions have a build thing attached at the end - // e.g. 4.0.8,8e921029f7daebacc749034f0cb174f1f2c7a258 - // This regex follows the logic from org.neo4j.kernel.internal.Version.parseReleaseVersion - Pattern pattern = Pattern.compile( - "(\\d+" + // Major version - "\\.\\d+" + // Minor version - "(\\.\\d+)?" + // Optional patch version - "(-?[^,]+)?)" + // Optional marker, like M01, GA, SNAPSHOT - anything other than a comma - ".*" // Anything else, such as git revision - ); - var matcher = pattern.matcher(neo4jVersion); - if (matcher.find()) { - return matcher.group(1); - } - // If no match is found, return the full version. - return neo4jVersion; - } - static Neo4jVersion parse(String version) { var versionSegments = Pattern.compile("[.-]") .splitAsStream(version) @@ -155,6 +85,8 @@ static Neo4jVersion parse(String version) { return Neo4jVersion.V_5_12; case 13: return Neo4jVersion.V_5_13; + case 14: + return Neo4jVersion.V_5_14; default: if (minorVersion >= MINOR_DEV_VERSION) { return Neo4jVersion.V_Dev; @@ -165,6 +97,79 @@ static Neo4jVersion parse(String version) { throw new UnsupportedOperationException("Cannot run on Neo4j Version " + version); } + public MajorMinorVersion semanticVersion() { + if (this == V_Dev) { + return ImmutableMajorMinorVersion.of(5, MINOR_DEV_VERSION); + } + + String version = toString(); + var subVersions = version.split("\\."); + + if (subVersions.length < 2) { + throw new IllegalStateException("Cannot derive version from " + version); + } + + return ImmutableMajorMinorVersion.of(Integer.parseInt(subVersions[0]), Integer.parseInt(subVersions[1])); + } + + public static Neo4jVersion findNeo4jVersion() { + return Neo4jVersionHolder.VERSION; + } + + private static final class Neo4jVersionHolder { + private static final Neo4jVersion VERSION = parse(neo4jVersion()); + } + + static String neo4jVersion() { + var neo4jVersion = Objects.requireNonNullElse(Version.class.getPackage().getImplementationVersion(), "dev"); + // some versions have a build thing attached at the end + // e.g. 4.0.8,8e921029f7daebacc749034f0cb174f1f2c7a258 + // This regex follows the logic from org.neo4j.kernel.internal.Version.parseReleaseVersion + Pattern pattern = Pattern.compile( + "(\\d+" + // Major version + "\\.\\d+" + // Minor version + "(\\.\\d+)?" + // Optional patch version + "(-?[^,]+)?)" + // Optional marker, like M01, GA, SNAPSHOT - anything other than a comma + ".*" // Anything else, such as git revision + ); + var matcher = pattern.matcher(neo4jVersion); + if (matcher.find()) { + return matcher.group(1); + } + // If no match is found, return the full version. + return neo4jVersion; + } + + @Override + public String toString() { + switch (this) { + case V_4_4: + return "4.4"; + case V_5_6: + return "5.6"; + case V_5_7: + return "5.7"; + case V_5_8: + return "5.8"; + case V_5_9: + return "5.9"; + case V_5_10: + return "5.10"; + case V_5_11: + return "5.11"; + case V_5_12: + return "5.12"; + case V_5_13: + return "5.13"; + case V_5_14: + return "5.14"; + case V_Dev: + return "dev"; + default: + throw new IllegalArgumentException("Unexpected value: " + this.name() + " (sad java 😞)"); + } + } + @ValueClass public interface MajorMinorVersion { int major(); diff --git a/neo4j-adapter/src/test/java/org/neo4j/gds/compat/Neo4jVersionTest.java b/neo4j-adapter/src/test/java/org/neo4j/gds/compat/Neo4jVersionTest.java index 32935a6983..81019201d8 100644 --- a/neo4j-adapter/src/test/java/org/neo4j/gds/compat/Neo4jVersionTest.java +++ b/neo4j-adapter/src/test/java/org/neo4j/gds/compat/Neo4jVersionTest.java @@ -48,7 +48,8 @@ class Neo4jVersionTest { "5.11.0, V_5_11", "5.12.0, V_5_12", "5.13.0, V_5_13", - "5.14.0, V_Dev", + "5.14.0, V_5_14", + "5.15.0, V_Dev", }) void testParse(String input, Neo4jVersion expected) { assertEquals(expected.name(), Neo4jVersion.parse(input).name());