-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding
dropdb
goal. README update. Cleanup.
- Loading branch information
Nathan Green
committed
Mar 14, 2014
1 parent
5dc6a7a
commit 3e483c0
Showing
7 changed files
with
205 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
secrets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.github.adrianboimvaser.it</groupId> | ||
<artifactId>initdb</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<description>Integration test for initdb goal.</description> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>@project.groupId@</groupId> | ||
<artifactId>@project.artifactId@</artifactId> | ||
<version>@project.version@</version> | ||
<configuration> | ||
<pgsqlHome>@project.build.directory@/pgsql</pgsqlHome> | ||
<dataDir>${project.build.directory}/data</dataDir> | ||
<username>postgres</username> | ||
<passwordFile>password.txt</passwordFile> | ||
<encoding>UTF8</encoding> | ||
<locale>sv_SE</locale> | ||
<databaseName>createanddrop</databaseName> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>initdb</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>initdb</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>start-postgresql</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>createdb</id> | ||
<phase>pre-integration-test</phase> | ||
<goals> | ||
<goal>createdb</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>dropdb</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>dropdb</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>dropdb2</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>dropdb</goal> | ||
</goals> | ||
<configuration> | ||
<if-exists>true</if-exists> | ||
<noPassword>true</noPassword> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>stop-postgresql</id> | ||
<phase>post-integration-test</phase> | ||
<goals> | ||
<goal>stop</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
File touchFile = new File(basedir, "target/data/postgresql.conf"); | ||
assert touchFile.isFile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/com/github/adrianboimvaser/postgresql/plugin/DropdbMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.github.adrianboimvaser.postgresql.plugin; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
@Mojo(name = "dropdb") | ||
public class DropdbMojo extends PgsqlMojo { | ||
|
||
@Parameter | ||
protected String username; | ||
|
||
@Parameter(required = true) | ||
protected String databaseName; | ||
|
||
@Parameter | ||
protected String host; | ||
|
||
@Parameter | ||
protected Integer port; | ||
|
||
/** If specified, no error will be reported when dropping a non-existent database */ | ||
@Parameter(alias = "if-exists", property = "if-exists", defaultValue = "false") | ||
protected boolean ifExists; | ||
|
||
/** If specified, password prompts are disabled (may result in an error) */ | ||
@Parameter(alias = "no-password", property = "no-password", defaultValue = "false") | ||
protected boolean noPassword; | ||
|
||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
if (skip) { | ||
getLog().debug("Skipped."); | ||
return; | ||
} | ||
|
||
final List<String> cmd = createCommand(); | ||
if (getLog().isDebugEnabled()) { | ||
getLog().debug(cmd.toString()); | ||
} | ||
|
||
final ProcessBuilder processBuilder = new ProcessBuilder(cmd); | ||
String message = ""; | ||
Exception cause = null; | ||
int returnValue = Integer.MIN_VALUE; | ||
try { | ||
Process process = processBuilder.start(); | ||
logOutput(process); | ||
returnValue = process.waitFor(); | ||
message = "dropdb returned " + returnValue; | ||
getLog().debug(message); | ||
} catch (IOException|InterruptedException e) { | ||
message = e.getLocalizedMessage(); | ||
cause = e; | ||
getLog().error(e); | ||
} | ||
if (returnValue != 0 && failOnError) { | ||
throw new MojoExecutionException(message, cause); | ||
} | ||
} | ||
|
||
private List<String> createCommand() throws MojoExecutionException { | ||
List<String> cmd = new ArrayList<String>(); | ||
cmd.add(getCommandPath("dropdb")); | ||
|
||
if (host != null) { | ||
cmd.add("-h"); | ||
cmd.add(host); | ||
} | ||
|
||
if (port != null) { | ||
cmd.add("-p"); | ||
cmd.add(port.toString()); | ||
} | ||
|
||
if (username != null) { | ||
cmd.add("-U"); | ||
cmd.add(username); | ||
} | ||
|
||
if (ifExists) { | ||
cmd.add("--if-exists"); | ||
} | ||
|
||
if (noPassword) { | ||
cmd.add("--no-password"); | ||
} | ||
|
||
cmd.add(databaseName); | ||
return cmd; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters