Skip to content

Commit

Permalink
plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandy committed Jan 20, 2018
1 parent 53ed4c0 commit 65315e4
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Ignore Play! working directory #
bin/
/db
.eclipse
/eclipse
.settings
.classpath
.project
/lib/
/logs/
/modules
Expand Down
1 change: 1 addition & 0 deletions app/play.plugins
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
299: plugin.EmbeddedPostgresqlPlugin
42 changes: 42 additions & 0 deletions app/plugin/EmbeddedPostgresqlPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package plugin;

import java.io.IOException;

import de.flapdoodle.embed.process.distribution.GenericVersion;
import de.flapdoodle.embed.process.distribution.IVersion;
import play.Logger;
import play.Play;
import play.PlayPlugin;
import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres;

public class EmbeddedPostgresqlPlugin extends PlayPlugin {

private final IVersion PG_VERSION = new GenericVersion("9.3.20-1");
private final EmbeddedPostgres postgres = new EmbeddedPostgres(this.PG_VERSION);
private String url;

@Override
public void onLoad() {
Logger.info("onLoad: %s", getClass());
if (Play.runingInTestMode()) {
try {
this.url = this.postgres.start("localhost", 9876, "test", "test", "test");
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
Logger.info("EmbeddedPostgresqlPlugin is disabled");
Play.pluginCollection.disablePlugin(this);
}
}

@Override
public void onConfigurationRead() {
Logger.info("onConfigurationRead: %s", getClass());
if (Play.runingInTestMode()) {
Play.configuration.setProperty("db", "");
Play.configuration.setProperty("db.url", this.url);
}
}

}
49 changes: 49 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>

<project name="pep" default="build" basedir=".">

<target name="check" unless="play.path">
<fail message="Please specify Play framework path using -Dplay.path=/path/to/framework/home" />
</target>

<path id="project.classpath">
<pathelement path="${play.path}/framework/classes"/>
<fileset dir="${play.path}/framework/lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${play.path}/framework">
<include name="*.jar"/>
</fileset>
<fileset dir="lib">
<include name="*.jar"/>
</fileset>
</path>

<target name="build" depends="compile">
<mkdir dir="lib" />
<copy todir="tmp/classes">
<fileset dir="src">
<include name="**/*.properties"/>
<include name="**/*.xml"/>
<include name="**/play.plugins"/>
<include name="**/play.static"/>
</fileset>
</copy>
<jar destfile="lib/play-pep.jar" basedir="tmp/classes">
<manifest>
<section name="Play-module">
<attribute name="Specification-Title" value="pep"/>
</section>
</manifest>
</jar>
<delete dir="tmp" />
</target>

<target name="compile" depends="check">
<mkdir dir="tmp/classes" />
<javac srcdir="src" destdir="tmp/classes" target="1.5" debug="true">
<classpath refid="project.classpath" />
</javac>
</target>

</project>
35 changes: 35 additions & 0 deletions commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Here you can create play commands that are specific to the module, and extend existing commands

MODULE = 'play-empedded-postgres'

# Commands that are specific to your module

COMMANDS = ['play-empedded-postgres:hello']

def execute(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")

if command == "play-empedded-postgres:hello":
print "~ Hello"


# This will be executed before any command (new, run...)
def before(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")


# This will be executed after any command (new, run...)
def after(**kargs):
command = kargs.get("command")
app = kargs.get("app")
args = kargs.get("args")
env = kargs.get("env")

if command == "new":
pass
5 changes: 5 additions & 0 deletions conf/dependencies.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
self: com.github.aleksandy -> play-embedded-postgres 1.5

require:
- play
- ru.yandex.qatools.embed -> postgresql-embedded 2.6

0 comments on commit 65315e4

Please # to comment.