Skip to content

Commit e28db13

Browse files
authored
Merge pull request #347 from ysb33r/restructure-build
Restructure build
2 parents 4db1cf2 + 1aca432 commit e28db13

File tree

116 files changed

+2035
-1898
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+2035
-1898
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ build/
33
.ruby-*
44
.gradle/
55
*.iml
6+
*.ipr
7+
*.iws
68
.idea
79
.awestruct/
810
out/
11+
.testconfig

HACKING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ Please do not commit the config file back with DEBUG turned on.
1212

1313
=== Running single test suites
1414

15-
If you only want to run the unittests in say `JRubyPlugin` then you can do `./gradlew test -Dtest.single=JRubyPlugin`.
16-
In a similar manner for integration tests one can do `./gradlew integrationTest -Dtest.single=JRubyIntegrationSpec`.
15+
If you only want to run the unittests in say `JRubyPlugin` then you can do `./gradlew test --tests JRubyPlugin`.
16+
In a similar manner for integration tests one can do `./gradlew integrationTest --tests JRubyIntegrationSpec`.
1717

18-
== Release HOWTO
18+
=== Running tests in IntelliJ
1919

20-
*TBC*
20+
Go to `File` -> `Settings` -> `Build, Execution, Deployment` -> `Gradle` -> `Runner`, then check `Delete build/run actions to Gradle` and select `Platform Test Runner`.
21+
22+
On a Mac use `IntelliJ IDEA` -> `Preferences` instead of `File/Settings`.
File renamed without changes.

base-plugin/build.gradle

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
2+
// --- Could be in a separate gradle file
3+
configurations {
4+
testJRubyPrepare
5+
}
6+
7+
ext {
8+
flatRepoDir = file("${buildDir}/tmp/integrationTest/flatRepo")
9+
10+
jrubyClassPathFromConfiguration = { Configuration cfg ->
11+
def f = cfg.files.find { it.name.startsWith('jruby-complete-') }
12+
return f?.absolutePath
13+
}
14+
}
15+
16+
project.afterEvaluate {
17+
test {
18+
systemProperties TEST_JRUBY_CLASSPATH: "${jrubyClassPathFromConfiguration(configurations.testJRubyPrepare)}"
19+
}
20+
}
21+
22+
// --- up to here
23+
24+
ext {
25+
olderJRubyVersion = '9.0.1.0'
26+
slimVersion = '2.0.2'
27+
leafyVersion = '0.4.0'
28+
}
29+
30+
dependencies {
31+
32+
compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
33+
compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
34+
runtime('de.saumya.mojo:rubygems:0.2.3@war') {
35+
// we just want the war file on the classloader for the application
36+
// to find it and use the war-file from filesystem
37+
exclude group: 'org.sonatype.nexus.plugins', module: 'nexus-ruby-tools'
38+
}
39+
40+
testJRubyPrepare "org.jruby:jruby-complete:${jrubyVersion}"
41+
42+
testCompile(spockVersion) {
43+
exclude module: 'groovy-all'
44+
}
45+
46+
integrationTestCompile(spockVersion) {
47+
exclude module: 'groovy-all'
48+
}
49+
50+
// NOTE: This is used by JRubyPrepareGemsIntegrationSpec
51+
integrationTestGems "rubygems:slim:${slimVersion}"
52+
53+
// NOTE: This is used by JRubyPrepareJarsIntegrationSpec
54+
integrationTestGems "rubygems:leafy-complete:${leafyVersion}"
55+
56+
// NOTE: If you change this, you will also need to update JRubyExecIntegrationSpec & JRubyExecExtensionIntegrationSpec
57+
integrationTestGems 'rubygems:credit_card_validator:1.1.0'
58+
59+
// NOTE: If you change this, you will also need to update JRubyExecIntegrationSpec
60+
integrationTestGems 'rubygems:rspec:3.1.0'
61+
62+
// NOTE: This should always be an older older version.
63+
// It is used by JRubyExecIntegrationSpec
64+
integrationTestGems "org.jruby:jruby-complete:${olderJRubyVersion}"
65+
66+
// NOTE: older jruby versions needs this for exec to work properly
67+
integrationTestGems "rubygems:jar-dependencies:0.1.15"
68+
69+
// This is used by JRubyExecExtensionIntegrationSpec
70+
integrationTestGems "org.bouncycastle:bcprov-jdk15on:${bcprovVersion}"
71+
72+
gradleTest "org.jruby:jruby-complete:${jrubyVersion}"
73+
gradleTest 'rubygems:credit_card_validator:1.1.0'
74+
gradleTest 'org.bouncycastle:bcprov-jdk15on:1.50'
75+
}
76+
77+
generateTestConfig {
78+
testProperties mavenrepo: file('src/integTest/mavenrepo').absolutePath,
79+
flatrepo: flatRepoDir.absolutePath,
80+
bcprovVersion: bcprovVersion,
81+
olderJRubyVersion: olderJRubyVersion,
82+
slimVersion: slimVersion,
83+
leafyVersion: leafyVersion
84+
}
85+
86+
task copyIntegrationTestJRuby(type: Copy) {
87+
from({ configurations.testJRubyPrepare.files })
88+
into new File(buildDir, 'tmp/integrationTest/flatRepo')
89+
}
90+
91+
integrationTest {
92+
if (gradle.startParameter.isOffline()) {
93+
systemProperties 'TESTS_ARE_OFFLINE': '1'
94+
}
95+
dependsOn copyIntegrationTestJRuby
96+
}
97+
98+
task installGroovyDoc(type: Copy) {
99+
from({ new File(buildDir, 'docs/groovydoc') }) {
100+
include '**'
101+
}
102+
into { new File(project.properties.jrubyGradleWebsiteInstallDir, "docs/api/${archivesBaseName}/${version}") }
103+
onlyIf { project.hasProperty('jrubyGradleWebsiteInstallDir') }
104+
}
105+
106+
107+
publishing {
108+
publications {
109+
maven(MavenPublication) {
110+
// groupId project.group
111+
// artifactId project.archivesBaseName
112+
// version project.version
113+
114+
artifact sourcesJar {
115+
classifier "sources"
116+
}
117+
118+
from components.java
119+
}
120+
}
121+
}
122+
123+
bintray {
124+
user = project.bintrayUser
125+
key = project.bintrayKey
126+
publish = true
127+
dryRun = false
128+
publications = ['maven']
129+
130+
pkg {
131+
userOrg = 'jruby-gradle'
132+
repo = 'plugins'
133+
name = 'jruby-gradle-plugin'
134+
labels = ['jruby']
135+
136+
version {
137+
name = project.version
138+
vcsTag = "v${project.version}"
139+
attributes = ['gradle-plugin': 'com.github.jruby-gradle.base:com.github.jruby-gradle:jruby-gradle-plugin']
140+
desc = 'The purpose of plugin is to encapsulate useful Gradle functionality for JRuby projects.'
141+
142+
}
143+
}
144+
}
145+
bintrayUpload.dependsOn assemble
146+
147+
gradleTest.mustRunAfter integrationTest
148+
// vim: ft=groovy
149+
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
package com.github.jrubygradle
2+
3+
import com.github.jrubygradle.testhelper.IntegrationSpecification
4+
import org.gradle.testkit.runner.BuildResult
5+
import spock.lang.Shared
6+
7+
/**
8+
* @author Schalk W. Cronjé
9+
*/
10+
class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
11+
12+
static final String DEFAULT_TASK_NAME = 'inlineJRubyExec'
13+
static final String BCPROV_NAME = 'bcprov-jdk15on'
14+
15+
void "Run a script with minimum parameters"() {
16+
setup:
17+
useScript(HELLO_WORLD, 'src')
18+
createJRubyExecProject """
19+
script 'src/${HELLO_WORLD}'
20+
"""
21+
22+
23+
when: "I call jrubyexec with only a script name"
24+
BuildResult result = build()
25+
26+
then: "I expect the Ruby script to be executed"
27+
result.output =~ /Hello, World/
28+
}
29+
30+
void "Run an inline script"() {
31+
setup:
32+
createJRubyExecProject """
33+
jrubyArgs '-e', "puts 'Hello, World'"
34+
"""
35+
36+
when: "I call jrubyexec with only script text"
37+
BuildResult result = build()
38+
39+
then: "I expect the Ruby script to be executed"
40+
result.output =~ /Hello, World/
41+
}
42+
43+
void "Run a script with no subpath and arguments"() {
44+
useScript(HELLO_NAME)
45+
createJRubyExecProject """
46+
script '${HELLO_NAME}'
47+
scriptArgs 'Stan'
48+
"""
49+
50+
when:
51+
BuildResult result = build()
52+
53+
then: "only the appropriate parameters should be passed"
54+
result.output =~ /Hello, Stan/
55+
}
56+
57+
void "Running a script that requires a jar"() {
58+
setup:
59+
def leadingDir = 'jrubyExec/jars/org/bouncycastle/'
60+
def artifactPath = "${BCPROV_NAME}/${bcprovVer}/${BCPROV_NAME}-${bcprovVer}"
61+
def withPattern = ~/.*\["file:.+${leadingDir}${artifactPath}\.jar"\].*/
62+
63+
def jarToUse = findDependency('org.bouncycastle', BCPROV_NAME, 'jar')
64+
createJRubyExecProject withJarToUse(jarToUse), '''
65+
jrubyArgs '-e'
66+
jrubyArgs 'print $CLASSPATH'
67+
'''
68+
69+
when:
70+
BuildResult result = build()
71+
72+
then:
73+
result.output.readLines().any { it.matches withPattern }
74+
}
75+
76+
void "Running a script that requires a gem, a separate jRuby and a separate configuration"() {
77+
setup:
78+
useScript(REQUIRES_GEM)
79+
createJRubyExecProject withCreditCardValidator(), """
80+
script '${REQUIRES_GEM}'
81+
jrubyArgs '-T1'
82+
"""
83+
84+
when:
85+
BuildResult result = build()
86+
87+
then:
88+
result.output =~ /Not valid/
89+
}
90+
91+
void "Running a script that requires a gem, a separate jRuby, a separate configuration and a custom gemWorkDir"() {
92+
setup:
93+
final String customGemDir = 'customGemDir'
94+
useScript(REQUIRES_GEM)
95+
createJRubyExecProject withCreditCardValidator(), """
96+
script '${REQUIRES_GEM}'
97+
jrubyArgs '-T1'
98+
gemWorkDir { new File(project.buildDir, '${customGemDir}' ) }
99+
"""
100+
101+
when:
102+
BuildResult result = build()
103+
104+
then:
105+
result.output =~ /Not valid/
106+
new File(projectDir, "build/${customGemDir}").exists()
107+
}
108+
109+
void "Running a script that requires environment variables"() {
110+
// This tests that the passthrough invocation
111+
// happens for overloaded versions of environment
112+
// and that the environment variables are passed
113+
// on to the script
114+
setup:
115+
final String envVarName = 'TEST_ENV_VAR'
116+
final String envVarValue = 'Test Value'
117+
118+
useScript(ENV_VARS)
119+
createJRubyExecProject """
120+
environment '${envVarName}', '${envVarValue}'
121+
environment TEST_A: 'A123', TEST_B: 'B123'
122+
script '${ENV_VARS}'
123+
"""
124+
125+
when:
126+
BuildResult result = build()
127+
String outputBuffer = result.output
128+
129+
then:
130+
outputBuffer =~ /TEST_ENV_VAR=Test Value/
131+
outputBuffer =~ /TEST_A=A123/
132+
outputBuffer =~ /TEST_B=B123/
133+
}
134+
135+
private BuildResult build() {
136+
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
137+
}
138+
139+
private void createJRubyExecProject(String jrubyexecConfig) {
140+
createJRubyExecProject('', jrubyexecConfig)
141+
}
142+
143+
private void createJRubyExecProject(String preamble, String jrubyexecConfig) {
144+
buildFile.text = """
145+
${projectWithLocalRepo}
146+
147+
${preamble}
148+
149+
task ${DEFAULT_TASK_NAME} {
150+
doLast {
151+
jrubyexec {
152+
${jrubyexecConfig}
153+
}
154+
}
155+
}
156+
"""
157+
}
158+
159+
private String withJarToUse(String jarFormat) {
160+
String dependencies = """
161+
dependencies {
162+
jrubyExec ${jarFormat}
163+
}
164+
"""
165+
}
166+
167+
private String withCreditCardValidator() {
168+
withJarToUse(findDependency('', 'credit_card_validator', 'gem'))
169+
}
170+
171+
private String getBcprovVer() {
172+
testProperties.bcprovVersion
173+
}
174+
175+
176+
}

0 commit comments

Comments
 (0)