Skip to content

Commit

Permalink
Merge remote branch 'fork/override-socket'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Dec 4, 2014
2 parents 9381060 + 2c0a197 commit 262760d
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 14 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>${maven.version}</version>
</requireMavenVersion>
<requireSameVersions>
<dependencies>
<dependency>org.apache.maven:*</dependency>
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/jcabi/mysql/maven/plugin/AbstractMysqlMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ abstract class AbstractMysqlMojo extends AbstractMojo {
)
private transient File data;

/**
* Override location of MySQL socket file. Defaults to
* (data dir)/mysql.socket.
*/
@Parameter(
required = false
)
private transient File socket;

/**
* Shall we always delete an existing database or reuse it?
*/
Expand Down Expand Up @@ -209,6 +218,14 @@ public File dataDir() {
return this.data;
}

/**
* Get MySQL socket location.
* @return Overridden socket location (null for default)
*/
public File socketFile() {
return this.socket;
}

/**
* If true, always delete existing database files and create a new instance
* from scratch. If false, try to reuse existing files.
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/com/jcabi/mysql/maven/plugin/Instances.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,21 @@ public final class Instances {
* @param dist Path to MySQL distribution
* @param target Where to keep temp data
* @param deldir If existing DB should be deleted
* @param socket Alternative socket location for mysql (may be null)
* @throws IOException If fails to start
* @checkstyle ParameterNumberCheck (10 lines)
*/
public void start(@NotNull final Config config, @NotNull final File dist,
@NotNull final File target, final boolean deldir) throws IOException {
@NotNull final File target, final boolean deldir, final File socket)
throws IOException {
this.setClean(target, deldir);
synchronized (this.processes) {
if (this.processes.containsKey(config.port())) {
throw new IllegalArgumentException(
String.format("port %d is already busy", config.port())
);
}
final Process proc = this.process(config, dist, target);
final Process proc = this.process(config, dist, target, socket);
this.processes.put(config.port(), proc);
Runtime.getRuntime().addShutdownHook(
new Thread(
Expand Down Expand Up @@ -167,15 +169,21 @@ public boolean reusedExistingDatabase() {
* @param config Instance configuration
* @param dist Path to MySQL distribution
* @param target Where to keep temp data
* @param socketfile Alternative socket location for mysql (may be null)
* @return Process started
* @throws IOException If fails to start
* @checkstyle ParameterNumberCheck (10 lines)
*/
private Process process(@NotNull final Config config,
final File dist, final File target)
final File dist, final File target, final File socketfile)
throws IOException {
final File temp = this.prepareFolders(target);
final File socket = new File(target, "mysql.sock");
final File socket;
if (socketfile == null) {
socket = new File(target, "mysql.sock");
} else {
socket = socketfile;
}
final ProcessBuilder builder = this.builder(
dist,
"bin/mysqld",
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jcabi/mysql/maven/plugin/RunMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public void run(final Instances instances) throws MojoFailureException {
config,
this.distDir(),
this.dataDir(),
this.clear()
this.clear(),
this.socketFile()
);
} catch (final IOException ex) {
throw new MojoFailureException(
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/jcabi/mysql/maven/plugin/StartMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public void run(final Instances instances) throws MojoFailureException {
this.config(),
this.distDir(),
this.dataDir(),
this.clear()
this.clear(),
this.socketFile()
);
} catch (final IOException ex) {
throw new MojoFailureException(
Expand Down
24 changes: 16 additions & 8 deletions src/test/java/com/jcabi/mysql/maven/plugin/InstancesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void startsAndStops() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
true
true,
null
);
Class.forName(InstancesTest.DRIVER).newInstance();
try {
Expand Down Expand Up @@ -157,7 +158,8 @@ public void useOptions() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
true
true,
null
);
Class.forName(InstancesTest.DRIVER).newInstance();
try {
Expand Down Expand Up @@ -212,7 +214,8 @@ public void canUseCustomDbUserName() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
true
true,
null
);
Class.forName(InstancesTest.DRIVER).newInstance();
try {
Expand Down Expand Up @@ -266,7 +269,8 @@ public void canUseCustomDbPassword() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
true
true,
null
);
Class.forName(InstancesTest.DRIVER).newInstance();
try {
Expand Down Expand Up @@ -317,7 +321,8 @@ public void canUseCustomDbDbName() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
true
true,
null
);
Class.forName(InstancesTest.DRIVER).newInstance();
try {
Expand Down Expand Up @@ -367,7 +372,8 @@ public void willCreateDatabaseEvenWithoutClear() throws Exception {
),
new File(InstancesTest.DIST),
Files.createTempDir(),
false
false,
null
);
MatcherAssert.assertThat(
"Instance reusedExistingDatabase should be false.",
Expand Down Expand Up @@ -422,7 +428,8 @@ public void canReuseExistingDatabse() throws Exception {
),
new File(InstancesTest.DIST),
target,
true
true,
null
);
MatcherAssert.assertThat(
"Instance reusedExistingDatabase should be false.",
Expand Down Expand Up @@ -483,7 +490,8 @@ private void checkExistingDatabase(final File target) throws Exception {
),
new File(InstancesTest.DIST),
target,
false
false,
null
);
MatcherAssert.assertThat(
"Instance reusedExistingDatabase should be true.",
Expand Down

0 comments on commit 262760d

Please sign in to comment.