From 5b663dbc6928e735e121ed9fbb0a7227a8a05ba0 Mon Sep 17 00:00:00 2001 From: mposolda Date: Fri, 1 Mar 2019 10:26:37 +0100 Subject: [PATCH] KEYCLOAK-9713 Warning in the log during export/import on current master --- .../org/keycloak/migration/ModelVersion.java | 21 ++++++++++++++++++- .../keycloak/models/MigrationVersionTest.java | 13 +++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/server-spi-private/src/main/java/org/keycloak/migration/ModelVersion.java b/server-spi-private/src/main/java/org/keycloak/migration/ModelVersion.java index 884587917e..4504724c96 100755 --- a/server-spi-private/src/main/java/org/keycloak/migration/ModelVersion.java +++ b/server-spi-private/src/main/java/org/keycloak/migration/ModelVersion.java @@ -29,6 +29,7 @@ public class ModelVersion { int minor; int micro; String qualifier; + boolean snapshot; public ModelVersion(int major, int minor, int micro) { this.major = major; @@ -37,6 +38,11 @@ public class ModelVersion { } public ModelVersion(String version) { + if (version.endsWith("-SNAPSHOT") || version.endsWith("-snapshot")) { + snapshot = true; + version = version.substring(0, version.length() - 9); + } + String[] split = version.split("\\."); try { if (split.length > 0) { @@ -72,6 +78,10 @@ public class ModelVersion { return qualifier; } + public boolean isSnapshot() { + return snapshot; + } + public boolean lessThan(ModelVersion version) { if (major < version.major) { return true; @@ -95,7 +105,16 @@ public class ModelVersion { if (qualifier == null) return false; if (version.qualifier == null) return true; int comp = qualifier.compareTo(version.qualifier); - if (comp < 0) return true; + if (comp < 0) { + return true; + } else if (comp > 0){ + return false; + } + + if (snapshot && !version.snapshot) { + return true; + } + return false; } diff --git a/server-spi-private/src/test/java/org/keycloak/models/MigrationVersionTest.java b/server-spi-private/src/test/java/org/keycloak/models/MigrationVersionTest.java index c058882aff..e1887f1736 100755 --- a/server-spi-private/src/test/java/org/keycloak/models/MigrationVersionTest.java +++ b/server-spi-private/src/test/java/org/keycloak/models/MigrationVersionTest.java @@ -29,10 +29,11 @@ public class MigrationVersionTest { @Test public void testVersion() { - ModelVersion version_100Beta1 = new ModelVersion("1.0.0.Beta1"); + ModelVersion version_100Beta1 = new ModelVersion("1.0.0.Beta1-SNAPSHOT"); Assert.assertEquals(version_100Beta1.getMajor(), 1); Assert.assertEquals(version_100Beta1.getMinor(), 0); Assert.assertEquals(version_100Beta1.getMicro(), 0); + Assert.assertTrue(version_100Beta1.isSnapshot()); ModelVersion version_100CR1 = new ModelVersion("1.0.0.CR1"); ModelVersion version_100 = new ModelVersion("1.0.0"); ModelVersion version_110Beta1 = new ModelVersion("1.1.0.Beta1"); @@ -49,8 +50,16 @@ public class MigrationVersionTest { Assert.assertEquals(version_211CR1.getMinor(), 1); Assert.assertEquals(version_211CR1.getMicro(), 1); Assert.assertEquals(version_211CR1.getQualifier(), "CR1"); + Assert.assertFalse(version_211CR1.isSnapshot()); ModelVersion version_211 = new ModelVersion("2.1.1"); + ModelVersion version50Snapshot = new ModelVersion("5.0.0-SNAPSHOT"); + Assert.assertEquals(version50Snapshot.getMajor(), 5); + Assert.assertEquals(version50Snapshot.getMinor(), 0); + Assert.assertEquals(version50Snapshot.getMicro(), 0); + Assert.assertNull(version50Snapshot.getQualifier()); + Assert.assertTrue(version50Snapshot.isSnapshot()); + Assert.assertFalse(version_100Beta1.lessThan(version_100Beta1)); Assert.assertTrue(version_100Beta1.lessThan(version_100CR1)); Assert.assertTrue(version_100Beta1.lessThan(version_100)); @@ -66,5 +75,7 @@ public class MigrationVersionTest { Assert.assertFalse(version_211.lessThan(version_110CR1)); + Assert.assertTrue(version_211CR1.lessThan(version50Snapshot)); + } }