Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.github.michaelruocco:embedded-mysql-plugin:2.1.8'
classpath 'com.github.michaelruocco:embedded-mysql-plugin:2.1.9'
}
}

Expand All @@ -40,7 +40,7 @@ or alternatively:

```
plugins {
id 'com.github.michaelruocco.embedded-mysql-plugin' version '2.1.8'
id 'com.github.michaelruocco.embedded-mysql-plugin' version '2.1.9'
}
```

Expand Down Expand Up @@ -176,6 +176,7 @@ The default values for each of the underlying properties are:
* baseDownloadUrl = 'https://dev.mysql.com/get/Downloads/'
* timeoutSeconds = 30 (default start/stop timeout)
* schema = '' (empty set, process will not create additional schemas and will use 'databaseName')
* tempDir = 'build/mysql-temp/' (default temporary directory)

This means the example configuration above could also be expressed as shown below.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'jacoco'

sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '2.1.8'
version = '2.1.9'

repositories {
mavenCentral()
Expand Down
11 changes: 11 additions & 0 deletions src/main/groovy/uk/co/mruoc/mysql/EmbeddedMysqlExtension.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EmbeddedMysqlExtension {
private static final Version DEFAULT_VERSION = v5_7_latest
private static final Charset DEFAULT_CHARSET = Charset.defaults()
private static final int DEFAULT_TIMEOUT_SECONDS = 30
private static final String DEFAULT_TEMP_DIR = "build/mysql-temp/"

private final ServerVariableValidator serverVariableValidator = new ServerVariableValidator()
private final CharsetValidator charsetValidator = new CharsetValidator()
Expand All @@ -36,6 +37,7 @@ class EmbeddedMysqlExtension {
private Version version = DEFAULT_VERSION
private Charset charset = DEFAULT_CHARSET
private int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS
private String tempDir = DEFAULT_TEMP_DIR
private Map<String, Object> serverVars = new HashMap<String, Object>()
private String cacheDirectoryPath
private String baseDownloadUrl
Expand Down Expand Up @@ -95,6 +97,14 @@ class EmbeddedMysqlExtension {
return timeoutSeconds
}

void setTempDir(String tempDir) {
this.tempDir = tempDir
}

String getTempDir() {
return tempDir
}

void setServerCharset(String charset) {
if (charsetValidator.validate(charset))
this.charset = Charset.aCharset(charset, this.charset.getCollate())
Expand Down Expand Up @@ -164,6 +174,7 @@ class EmbeddedMysqlExtension {
.withUser(username, password)
.withCharset(charset)
.withTimeout(timeoutSeconds, TimeUnit.SECONDS)
.withTempDir(tempDir)

if (serverVars)
serverVars.each { k, v -> builder.withServerVariable(k, v) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ class EmbeddedMysqlExtensionTest {
private static final def DEFAULT_VERSION = v5_7_latest
private static final def DEFAULT_PORT = 3306
private static final def DEFAULT_TIMEOUT_SECONDS = 30
private static final def DEFAULT_TEMP_DIR = 'build/mysql-temp/'

private static final def OVERRIDE_USERNAME = "anotherUser"
private static final def OVERRIDE_VERSION = v5_6_latest
private static final def OVERRIDE_TIMEOUT_SECONDS = 60
private static final def OVERRIDE_TEMP_DIR = 'build/mysql-custom-temp'

private static final def PASSWORD = "password"

Expand Down Expand Up @@ -56,6 +58,11 @@ class EmbeddedMysqlExtensionTest {
assertThat(extension.timeoutSeconds).isEqualTo(DEFAULT_TIMEOUT_SECONDS)
}

@Test
void tempDirShouldDefaultToTarget() {
assertThat(extension.tempDir).isEqualTo(DEFAULT_TEMP_DIR)
}

@Test
void shouldSetDatabaseNameFromUrl() {
extension.url = URL
Expand Down Expand Up @@ -99,6 +106,12 @@ class EmbeddedMysqlExtensionTest {
assertThat(extension.timeoutSeconds).isEqualTo(OVERRIDE_TIMEOUT_SECONDS)
}

@Test
void shouldSetTempDir() {
extension.tempDir = OVERRIDE_TEMP_DIR
assertThat(extension.tempDir).isEqualTo(OVERRIDE_TEMP_DIR)
}

@Test
void shouldThrowExceptionIfInvalidVersionSpecified() {
def invalidVersion = "invalid version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class StartStopEmbeddedMysqlTaskTest {
private static final def CHARSET = Charset.LATIN1
private static final def SERVER_VARS = ["explicit_defaults_for_timestamp": true]
private static final def TIMEOUT_SECONDS = 45
private static final def TEMP_DIR = 'build/mysql-target/'

private def project = ProjectBuilder.builder().build()

Expand Down Expand Up @@ -95,6 +96,7 @@ class StartStopEmbeddedMysqlTaskTest {
extension.serverCollate = CHARSET.collate
extension.serverVars = SERVER_VARS
extension.timeoutSeconds = TIMEOUT_SECONDS
extension.tempDir = TEMP_DIR
extension
}

Expand Down