From 400a7cac2d3d46c65bc5a8625fa5242f8228e3ec Mon Sep 17 00:00:00 2001 From: Victor Alvarez Date: Thu, 1 Sep 2022 15:21:41 -0400 Subject: [PATCH] Add server initialization variables --- pom.xml | 3 ++- .../pom.xml | 10 +++---- wix-embedded-mysql/pom.xml | 4 +-- .../com/wix/mysql/config/MysqldConfig.java | 27 +++++++++++++++++++ .../setup/Mysql57Initializer.java | 26 ++++++++++++------ .../distribution/setup/Mysql8Initializer.java | 24 ++++++++++++----- 6 files changed, 72 insertions(+), 22 deletions(-) diff --git a/pom.xml b/pom.xml index 6e52b56f..be8fa1b0 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wix wix-embedded-mysql-modules - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT Wix Embedded MySql Modules aggregator Wix Embedded MySql Modules aggregator https://github.com/wix/wix-embedded-mysql @@ -177,6 +177,7 @@ + ossrh https://oss.sonatype.org/service/local/staging/deploy/maven2/ diff --git a/wix-embedded-mysql-download-and-extract/pom.xml b/wix-embedded-mysql-download-and-extract/pom.xml index a1015935..c953b850 100644 --- a/wix-embedded-mysql-download-and-extract/pom.xml +++ b/wix-embedded-mysql-download-and-extract/pom.xml @@ -4,7 +4,7 @@ com.wix wix-embedded-mysql-download-and-extract - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT Wix Embedded Mysql Download and Extract Cli tool to predownload/precache mysql artifacts for wix-embedded-mysql https://github.com/wix/wix-embedded-mysql/tree/master/wix-embedded-mysql-download-and-extract @@ -12,7 +12,7 @@ com.wix wix-embedded-mysql-modules - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT @@ -20,7 +20,7 @@ com.wix wix-embedded-mysql - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT @@ -65,7 +65,7 @@ - + @@ -94,4 +94,4 @@ - \ No newline at end of file + diff --git a/wix-embedded-mysql/pom.xml b/wix-embedded-mysql/pom.xml index 9b32a328..a34bd7c4 100644 --- a/wix-embedded-mysql/pom.xml +++ b/wix-embedded-mysql/pom.xml @@ -3,7 +3,7 @@ com.wix wix-embedded-mysql - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT Wix Embedded MySql Embedded MySql for E2E/IT tests https://github.com/wix/wix-embedded-mysql/tree/master/wix-embedded-mysql @@ -11,7 +11,7 @@ com.wix wix-embedded-mysql-modules - 4.6.3-SNAPSHOT + 4.6.4-SNAPSHOT diff --git a/wix-embedded-mysql/src/main/java/com/wix/mysql/config/MysqldConfig.java b/wix-embedded-mysql/src/main/java/com/wix/mysql/config/MysqldConfig.java index 1c18df32..eadb0c73 100644 --- a/wix-embedded-mysql/src/main/java/com/wix/mysql/config/MysqldConfig.java +++ b/wix-embedded-mysql/src/main/java/com/wix/mysql/config/MysqldConfig.java @@ -157,6 +157,21 @@ public Builder withTimeZone(String timeZoneId) { return withTimeZone(TimeZone.getTimeZone(timeZoneId)); } + public Builder withInitServerVariable(String name, boolean value) { + this.serverVariables.add(new ServerVariable<>(true, name, value)); + return this; + } + + public Builder withInitServerVariable(String name, int value) { + this.serverVariables.add(new ServerVariable<>(true, name, value)); + return this; + } + + public Builder withInitServerVariable(String name, String value) { + this.serverVariables.add(new ServerVariable<>(true, name, value)); + return this; + } + /** * Provide mysql server option * @@ -233,14 +248,26 @@ public String toString() { } public static class ServerVariable { + private final boolean initializer; private final String name; private final T value; + ServerVariable(final boolean initializer, final String name, final T value) { + this.initializer = initializer; + this.name = name; + this.value = value; + } + ServerVariable(final String name, final T value) { + this.initializer = false; this.name = name; this.value = value; } + public boolean isInitializer() { + return initializer; + } + public String toCommandLineArgument() { return String.format("--%s=%s", name, value); } diff --git a/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql57Initializer.java b/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql57Initializer.java index db90342b..8e9420da 100644 --- a/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql57Initializer.java +++ b/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql57Initializer.java @@ -8,6 +8,9 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -23,14 +26,21 @@ public void apply(IExtractedFileSet files, IRuntimeConfig runtimeConfig, MysqldC File baseDir = files.baseDir(); FileUtils.deleteDirectory(new File(baseDir, "data")); - Process p = Runtime.getRuntime().exec(new String[] { - files.executable().getAbsolutePath(), - "--no-defaults", - "--initialize-insecure", - "--ignore-db-dir", - format("--basedir=%s", baseDir), - format("--datadir=%s/data", baseDir) - }); + List systemVariables = new ArrayList<>(); + systemVariables.add(files.executable().getAbsolutePath()); + systemVariables.add("--no-defaults"); + systemVariables.add("--initialize-insecure"); + systemVariables.add("--ignore-db-dir"); + systemVariables.add(format("--basedir=%s", baseDir)); + systemVariables.add(format("--datadir=%s/data", baseDir)); + + List configSystemVariables = config.getServerVariables().stream() + .filter(MysqldConfig.ServerVariable::isInitializer) + .map(MysqldConfig.ServerVariable::toCommandLineArgument) + .collect(Collectors.toList()); + systemVariables.addAll(configSystemVariables); + + Process p = Runtime.getRuntime().exec(systemVariables.toArray(new String[0])); new ProcessRunner(files.executable().getAbsolutePath()).run(p, runtimeConfig, config.getTimeout(NANOSECONDS)); } diff --git a/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql8Initializer.java b/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql8Initializer.java index 176984c2..02a94ca0 100644 --- a/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql8Initializer.java +++ b/wix-embedded-mysql/src/main/java/com/wix/mysql/distribution/setup/Mysql8Initializer.java @@ -1,6 +1,7 @@ package com.wix.mysql.distribution.setup; import com.wix.mysql.config.MysqldConfig; +import com.wix.mysql.config.MysqldConfig.ServerVariable; import com.wix.mysql.distribution.Version; import de.flapdoodle.embed.process.config.IRuntimeConfig; import de.flapdoodle.embed.process.extract.IExtractedFileSet; @@ -8,6 +9,9 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import static java.lang.String.format; import static java.util.concurrent.TimeUnit.NANOSECONDS; @@ -23,12 +27,20 @@ public void apply(IExtractedFileSet files, IRuntimeConfig runtimeConfig, MysqldC File baseDir = files.baseDir(); FileUtils.deleteDirectory(new File(baseDir, "data")); - Process p = Runtime.getRuntime().exec(new String[]{ - files.executable().getAbsolutePath(), - "--no-defaults", - "--initialize-insecure", - format("--basedir=%s", baseDir), - format("--datadir=%s/data", baseDir)}); + List systemVariables = new ArrayList<>(); + systemVariables.add(files.executable().getAbsolutePath()); + systemVariables.add("--no-defaults"); + systemVariables.add("--initialize-insecure"); + systemVariables.add(format("--basedir=%s", baseDir)); + systemVariables.add(format("--datadir=%s/data", baseDir)); + + List configSystemVariables = config.getServerVariables().stream() + .filter(ServerVariable::isInitializer) + .map(ServerVariable::toCommandLineArgument) + .collect(Collectors.toList()); + systemVariables.addAll(configSystemVariables); + + Process p = Runtime.getRuntime().exec(systemVariables.toArray(new String[0])); new ProcessRunner(files.executable().getAbsolutePath()).run(p, runtimeConfig, config.getTimeout(NANOSECONDS)); }