Skip to content

Commit

Permalink
Merge pull request #1 from carmigo/system-initialization-veriables
Browse files Browse the repository at this point in the history
Add server initialization variables
  • Loading branch information
victor-eblock authored Sep 7, 2022
2 parents ca31b2c + 400a7ca commit 4558f2f
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 22 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql-modules</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
<name>Wix Embedded MySql Modules aggregator</name>
<description>Wix Embedded MySql Modules aggregator</description>
<url>https://github.com/wix/wix-embedded-mysql</url>
Expand Down Expand Up @@ -177,6 +177,7 @@
</profiles>

<distributionManagement>

<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
Expand Down
10 changes: 5 additions & 5 deletions wix-embedded-mysql-download-and-extract/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql-download-and-extract</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
<name>Wix Embedded Mysql Download and Extract</name>
<description>Cli tool to predownload/precache mysql artifacts for wix-embedded-mysql</description>
<url>https://github.com/wix/wix-embedded-mysql/tree/master/wix-embedded-mysql-download-and-extract</url>

<parent>
<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql-modules</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
</parent>

<dependencies>

<dependency>
<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -65,7 +65,7 @@
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
Expand Down Expand Up @@ -94,4 +94,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
4 changes: 2 additions & 2 deletions wix-embedded-mysql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
<name>Wix Embedded MySql</name>
<description>Embedded MySql for E2E/IT tests</description>
<url>https://github.com/wix/wix-embedded-mysql/tree/master/wix-embedded-mysql</url>

<parent>
<groupId>com.wix</groupId>
<artifactId>wix-embedded-mysql-modules</artifactId>
<version>4.6.3-SNAPSHOT</version>
<version>4.6.4-SNAPSHOT</version>
</parent>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -233,14 +248,26 @@ public String toString() {
}

public static class ServerVariable<T> {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> 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<String> 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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
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;
import org.apache.commons.io.FileUtils;

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;
Expand All @@ -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<String> 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<String> 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));
}
Expand Down

0 comments on commit 4558f2f

Please sign in to comment.