From 29b1aec4b5897c13344252904e22306169bf51b8 Mon Sep 17 00:00:00 2001 From: Dominik Guhr Date: Mon, 1 Nov 2021 13:16:25 +0100 Subject: [PATCH] KEYCLOAK-19711 Change Locations of h2-db files and gzip files --- .../main/java/org/keycloak/quarkus/runtime/Environment.java | 5 +++++ .../quarkus/runtime/integration/QuarkusPlatform.java | 3 ++- .../keycloak/quarkus/runtime/storage/database/Database.java | 2 +- .../org/keycloak/provider/quarkus/ConfigurationTest.java | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/Environment.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/Environment.java index c34f1dc079..6368ab8965 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/Environment.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/Environment.java @@ -39,6 +39,7 @@ public final class Environment { public static final String CLI_ARGS = "kc.config.args"; public static final String PROFILE ="kc.profile"; public static final String ENV_PROFILE ="KC_PROFILE"; + public static final String DATA_PATH = "/data"; private Environment() {} @@ -60,6 +61,10 @@ public final class Environment { return null; } + public static String getDataDir() { + return getHomeDir() + DATA_PATH; + } + public static Path getProvidersPath() { Path homePath = Environment.getHomePath(); diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/QuarkusPlatform.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/QuarkusPlatform.java index 0f716c2c94..ee14a30485 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/QuarkusPlatform.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/integration/QuarkusPlatform.java @@ -148,7 +148,8 @@ public class QuarkusPlatform implements PlatformProvider { throw new RuntimeException("It was not possible to create temporary directory keycloak-quarkus-tmp", ioex); } } else { - tmpDir = new File(homeDir, "tmp"); + String dataDir = Environment.getDataDir(); + tmpDir = new File(dataDir, "tmp"); tmpDir.mkdir(); } diff --git a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/Database.java b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/Database.java index ca1b6430ba..ddaed8db0d 100644 --- a/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/Database.java +++ b/quarkus/runtime/src/main/java/org/keycloak/quarkus/runtime/storage/database/Database.java @@ -94,7 +94,7 @@ public final class Database { public String apply(String alias) { if ("h2-file".equalsIgnoreCase(alias)) { return "jdbc:h2:file:${kc.home.dir:${kc.db.url.path:~}}" + File.separator + "${kc.data.dir:data}" - + File.separator + "keycloakdb${kc.db.url.properties:;;AUTO_SERVER=TRUE}"; + + File.separator + "h2" + File.separator + "keycloakdb${kc.db.url.properties:;;AUTO_SERVER=TRUE}"; } return "jdbc:h2:mem:keycloakdb${kc.db.url.properties:}"; } diff --git a/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java b/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java index 2f44c5603e..b71e768f45 100644 --- a/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java +++ b/quarkus/runtime/src/test/java/org/keycloak/provider/quarkus/ConfigurationTest.java @@ -224,7 +224,7 @@ public class ConfigurationTest { System.setProperty(CLI_ARGS, "--db=h2-file"); SmallRyeConfig config = createConfig(); assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); - assertEquals("jdbc:h2:file:~/data/keycloakdb;;AUTO_SERVER=TRUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); + assertEquals("jdbc:h2:file:~/data/h2/keycloakdb;;AUTO_SERVER=TRUE", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); System.setProperty(CLI_ARGS, "--db=h2-mem"); config = createConfig(); @@ -250,7 +250,7 @@ public class ConfigurationTest { System.setProperty(CLI_ARGS, "--db=h2-file"); SmallRyeConfig config = createConfig(); assertEquals(QuarkusH2Dialect.class.getName(), config.getConfigValue("quarkus.hibernate-orm.dialect").getValue()); - assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "keycloakdb;;test=test;test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); + assertEquals("jdbc:h2:file:test-dir" + File.separator + "data" + File.separator + "h2" + File.separator + "keycloakdb;;test=test;test1=test1", config.getConfigValue("quarkus.datasource.jdbc.url").getValue()); System.setProperty("kc.db.url.properties", "?test=test&test1=test1"); System.setProperty(CLI_ARGS, "--db=mariadb");