Skip to content

Commit 2a12d71

Browse files
committed
Create a sub-project that uses the plugin for testing. Reproduces #438
1 parent 4cec0fd commit 2a12d71

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

activejdbc-gradle-plugin/build.gradle

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import org.apache.tools.ant.taskdefs.condition.Os
2+
13
group 'org.javalite'
24
version '1.4.12-SNAPSHOT'
35

46
apply plugin: 'groovy'
7+
apply plugin: 'maven'
58

69
sourceCompatibility = 1.7
710

@@ -46,8 +49,6 @@ task moveJars(type: Copy, dependsOn: ['docJar', 'sourceJar']) {
4649
exclude jar.archivePath.name
4750
}
4851

49-
build.dependsOn << [moveJars, moveClasses]
50-
5152
clean {
5253
delete 'target'
5354
}
@@ -57,3 +58,39 @@ artifacts {
5758
archives docJar
5859
archives sourceJar
5960
}
61+
62+
build.dependsOn << ['testPluginSubproject', 'moveJars', 'moveClasses']
63+
64+
task testDaemonBuild1(type: TestProjectBuild) {
65+
useDaemon = true
66+
}
67+
68+
task testDaemonBuild2(type: TestProjectBuild) {
69+
useDaemon = true
70+
}
71+
72+
task testNormalBuild1(type: TestProjectBuild) {}
73+
task testNormalBuild2(type: TestProjectBuild) {}
74+
75+
task testPluginSubproject(dependsOn: ['test', 'install', 'testDaemonBuild1', 'testDaemonBuild2', 'testNormalBuild1', 'testNormalBuild2'])
76+
77+
class TestProjectBuild extends Exec {
78+
79+
boolean useDaemon = false
80+
81+
TestProjectBuild() {
82+
workingDir = 'test-project'
83+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
84+
executable = '../gradlew.bat'
85+
} else {
86+
executable = '../gradlew'
87+
}
88+
}
89+
90+
@Override
91+
protected void exec() {
92+
def daemonArg = (useDaemon) ? '--daemon' : '--no-daemon'
93+
setArgs([daemonArg, '--stacktrace', "-Pplugin.project.jar=${project.jar.archivePath}", "-Pparent.version=${project.version}", 'clean', 'test'])
94+
super.exec()
95+
}
96+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
buildscript {
2+
repositories {
3+
mavenCentral()
4+
mavenLocal()
5+
}
6+
dependencies {
7+
classpath "org.javalite:activejdbc-gradle-plugin:${property('parent.version')}"
8+
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
9+
classpath "com.h2database:h2:1.4.187"
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'org.javalite.activejdbc'
15+
apply plugin: 'org.flywaydb.flyway'
16+
17+
repositories {
18+
mavenCentral()
19+
}
20+
21+
dependencies {
22+
compile 'org.javalite:activejdbc:1.4.11'
23+
compile "com.h2database:h2:1.4.187"
24+
testCompile 'junit:junit:4.12'
25+
}
26+
27+
sourceCompatibility = 1.7
28+
29+
task cleanDb(type: Delete) {
30+
delete 'build/testdb.*'
31+
}
32+
33+
flyway {
34+
url = 'jdbc:h2:file:./build/testdb'
35+
}
36+
37+
test {
38+
dependsOn << 'cleanDb'
39+
dependsOn << 'flywayMigrate'
40+
testLogging.events 'passed', 'skipped', 'failed'
41+
testLogging.exceptionFormat = 'full'
42+
testLogging.showStandardStreams = true
43+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.javalite.activejdbc.gradle.plugin.test;
2+
3+
import org.javalite.activejdbc.Base;
4+
import org.javalite.activejdbc.Model;
5+
6+
public class Example extends Model {
7+
8+
public Example() { }
9+
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
create table EXAMPLES (
2+
ID int not null auto_increment,
3+
NAME text
4+
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.javalite.activejdbc.gradle.plugin.test;
2+
3+
import org.javalite.activejdbc.Base;
4+
import org.junit.After;
5+
import org.junit.Before;
6+
import org.junit.Test;
7+
8+
import java.lang.SafeVarargs;
9+
import java.util.Arrays;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class ExampleTest {
14+
15+
@Test
16+
public void testOk() {
17+
Base.open("org.h2.Driver", "jdbc:h2:file:./build/testdb", null, null);
18+
for (String name : Arrays.asList("foo", "bar", "baz")) {
19+
Example e = new Example();
20+
e.set("name", name);
21+
e.saveIt();
22+
}
23+
assertEquals(3, Example.findAll().size());
24+
Base.close();
25+
}
26+
27+
}

0 commit comments

Comments
 (0)