Skip to content

Commit ce44d67

Browse files
committed
Cleaned up and restructured base-plugin (#366).
- `JRubyPluginExtension` - `JRubyExec` - Split out `GemUtils.OverwriteAction` into its own class `GemOverwriteAction`. - Moved `GemUtils` to `core-plugin`. - Removed `RubygemsServlet`. - Reworked `GemVersion` to be more Ivy-like rather than Maven-like. - Reworked `JRubyPrepare` & `JRubyExec`. - Extract common `JRubyPrepare` code to `AbstractJRubyPrepare`. - Cleaned up `JRubyExec` to no longer depend on `JRubyExecTraits`. - Cleaned up `JRubyExecDelegate` to no longer depend on `JRubyExecTraits`. - In `JRubyPlugin`, register tasks instead of creating them if Gradle supports lazy-creation. - Removed last usages of `jar-dependencies`. - Cleaned up integration tests and unit tests
1 parent a4df54b commit ce44d67

File tree

42 files changed

+2138
-1911
lines changed

Some content is hidden

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

42 files changed

+2138
-1911
lines changed

base-plugin/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ ext {
2929

3030
dependencies {
3131

32-
compile project(":jruby-gradle-core-plugin")
33-
compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
34-
compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
32+
compile project(':jruby-gradle-core-plugin')
33+
// compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
34+
// compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
3535
runtime('de.saumya.mojo:rubygems:0.2.3@war') {
3636
// we just want the war file on the classloader for the application
3737
// to find it and use the war-file from filesystem
@@ -42,10 +42,12 @@ dependencies {
4242

4343
testCompile(spockVersion) {
4444
exclude module: 'groovy-all'
45+
exclude group: 'org.codehaus.groovy'
4546
}
4647

4748
integrationTestCompile(spockVersion) {
4849
exclude module: 'groovy-all'
50+
exclude group: 'org.codehaus.groovy'
4951
}
5052

5153
// NOTE: This is used by JRubyPrepareGemsIntegrationSpec

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyExecExtensionIntegrationSpec.groovy

Lines changed: 145 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
5454

5555
void "Running a script that requires a jar"() {
5656
setup:
57-
def leadingDir = 'jrubyExec/jars/org/bouncycastle/'
57+
def leadingDir = '.gems/jars/org/bouncycastle/'
5858
def artifactPath = "${BCPROV_NAME}/${bcprovVer}/${BCPROV_NAME}-${bcprovVer}"
5959
def withPattern = ~/.*\["file:.+${leadingDir}${artifactPath}\.jar"\].*/
6060

@@ -86,24 +86,6 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
8686
result.output =~ /Not valid/
8787
}
8888

89-
void "Running a script that requires a gem, a separate jRuby, a separate configuration and a custom gemWorkDir"() {
90-
setup:
91-
final String customGemDir = 'customGemDir'
92-
useScript(REQUIRES_GEM)
93-
createJRubyExecProject withCreditCardValidator(), """
94-
script '${REQUIRES_GEM}'
95-
jrubyArgs '-T1'
96-
gemWorkDir { new File(project.buildDir, '${customGemDir}' ) }
97-
"""
98-
99-
when:
100-
BuildResult result = build()
101-
102-
then:
103-
result.output =~ /Not valid/
104-
new File(projectDir, "build/${customGemDir}").exists()
105-
}
106-
10789
void "Running a script that requires environment variables"() {
10890
// This tests that the passthrough invocation
10991
// happens for overloaded versions of environment
@@ -131,7 +113,7 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
131113
}
132114

133115
private BuildResult build() {
134-
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
116+
gradleRunner(DEFAULT_TASK_NAME, '-i', '-s').build()
135117
}
136118

137119
@SuppressWarnings('BuilderMethodWithSideEffects')
@@ -152,14 +134,16 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
152134
${jrubyexecConfig}
153135
}
154136
}
137+
138+
dependsOn jrubyPrepare
155139
}
156140
"""
157141
}
158142

159143
private String withJarToUse(String jarFormat) {
160144
"""
161145
dependencies {
162-
jrubyExec ${jarFormat}
146+
gems ${jarFormat}
163147
}
164148
"""
165149
}
@@ -172,3 +156,143 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
172156
testProperties.bcprovVersion
173157
}
174158
}
159+
160+
/*
161+
class JRubyExecDelegateSpec extends Specification {
162+
static final String ABS_FILE_PREFIX = System.getProperty('os.name').toLowerCase().startsWith('windows') ? 'C:' : ''
163+
164+
Project project
165+
JRubyExecDelegate jred
166+
167+
void setup() {
168+
project = ProjectBuilder.builder().build()
169+
project.apply plugin: 'com.github.jruby-gradle.base'
170+
jred = JRubyExecDelegate.createJRubyExecDelegate(project)
171+
}
172+
173+
void "When just passing script, scriptArgs, jrubyArgs, expect local properties to be updated"() {
174+
given:
175+
def xplatformFileName = project.file('path/to/file')
176+
xplatformFileName.parentFile.mkdirs()
177+
xplatformFileName.text = ''
178+
def cl = {
179+
script 'path/to/file'
180+
jrubyArgs 'c', 'd', '-S'
181+
scriptArgs '-x'
182+
scriptArgs '-y', '-z'
183+
jrubyArgs 'a', 'b'
184+
gemWorkDir 'path/to/file'
185+
}
186+
jred.configure(cl)
187+
188+
expect:
189+
jred.passthrough.size() == 0
190+
jred.script == xplatformFileName
191+
jred._convertScriptArgs() == ['-x', '-y', '-z']
192+
jred._convertJrubyArgs() == ['c', 'd', '-S', 'a', 'b']
193+
jred.buildArgs() == ['-rjars/setup', 'c', 'd', '-S', 'a', 'b', xplatformFileName.toString(), '-x', '-y', '-z']
194+
jred._convertGemWorkDir(project) == project.file('path/to/file')
195+
}
196+
197+
void "When passing absolute file and absolute file, expect check for existence to be executed"() {
198+
given:
199+
def cl = {
200+
script ABS_FILE_PREFIX + '/path/to/file'
201+
jrubyArgs 'c', 'd', '-S'
202+
scriptArgs '-x'
203+
scriptArgs '-y', '-z'
204+
jrubyArgs 'a', 'b'
205+
}
206+
cl.delegate = jred
207+
cl.call()
208+
when:
209+
jred.buildArgs()
210+
211+
then:
212+
thrown(InvalidUserDataException)
213+
}
214+
215+
void "When just passing arbitrary javaexec, expect them to be stored"() {
216+
given:
217+
def cl = {
218+
environment 'XYZ', '123'
219+
executable '/path/to/file'
220+
jvmArgs '-x'
221+
jvmArgs '-y', '-z'
222+
}
223+
cl.delegate = jred
224+
cl.call()
225+
226+
expect:
227+
jred.valuesAt(0) == ['XYZ', '123']
228+
jred.valuesAt(1) == '/path/to/file'
229+
jred.valuesAt(2) == '-x'
230+
jred.valuesAt(3) == ['-y', '-z']
231+
jred.keyAt(0) == 'environment'
232+
jred.keyAt(1) == 'executable'
233+
jred.keyAt(2) == 'jvmArgs'
234+
jred.keyAt(3) == 'jvmArgs'
235+
236+
}
237+
238+
void "When using a conditional, expect specific calls to be passed"() {
239+
given:
240+
def cl = {
241+
if (condition == 1) {
242+
jvmArgs '-x'
243+
} else {
244+
jvmArgs '-y'
245+
}
246+
}
247+
cl.delegate = jred
248+
cl.call()
249+
250+
expect:
251+
jred.valuesAt(0) == parameter
252+
253+
where:
254+
condition | parameter
255+
1 | '-x'
256+
5 | '-y'
257+
258+
}
259+
260+
void "Prevent main from being called"() {
261+
when:
262+
def cl = {
263+
main 'some.class'
264+
}
265+
cl.delegate = jred
266+
cl.call()
267+
268+
then:
269+
thrown(UnsupportedOperationException)
270+
}
271+
272+
void "Prevent args from being called"() {
273+
when:
274+
def cl = {
275+
args '-x', '-y'
276+
}
277+
cl.delegate = jred
278+
cl.call()
279+
280+
then:
281+
thrown(UnsupportedOperationException)
282+
}
283+
284+
void "Prevent setArgs from being called"() {
285+
when:
286+
def cl = {
287+
setArgs '-x', '-y'
288+
}
289+
cl.delegate = jred
290+
cl.call()
291+
292+
then:
293+
thrown(UnsupportedOperationException)
294+
}
295+
296+
}
297+
298+
*/

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyExecIntegrationSpec.groovy

Lines changed: 9 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import static com.github.jrubygradle.internal.JRubyExecUtils.DEFAULT_JRUBYEXEC_C
1010

1111
class JRubyExecIntegrationSpec extends IntegrationSpecification {
1212
static final String DEFAULT_TASK_NAME = 'RubyWax'
13+
static final String DEFAULT_JRUBYEXEC_CONFIG = JRubyPlugin.DEFAULT_CONFIGURATION
1314

1415
String jrubyExecConfig
1516
String preamble
@@ -34,13 +35,13 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
3435

3536
withJRubyExecConfig """
3637
configuration '${configName}'
37-
jrubyVersion '${altVersion}'
38+
jruby.jrubyVersion '${altVersion}'
3839
"""
3940

4041
withAdditionalContent """
4142
task validateVersion {
4243
doLast {
43-
assert jruby.execVersion != '${altVersion}'
44+
assert jruby.jrubyVersion != '${altVersion}'
4445
}
4546
}
4647
@@ -74,8 +75,8 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
7475
"""
7576
withDependencies "${altConfiguration} ${withCreditCardValidator()}"
7677
withJRubyExecConfig """
77-
jrubyVersion '${altVersion}'
78-
configuration '${altConfiguration}'
78+
jruby.jrubyVersion '${altVersion}'
79+
jruby.gemConfiguration '${altConfiguration}'
7980
"""
8081

8182
when:
@@ -109,34 +110,15 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
109110
result.output =~ /Not valid/
110111
}
111112

112-
// Embedded server has never worked well - ignoring for now
113-
@PendingFeature
114-
@IgnoreIf({ IntegrationSpecification.OFFLINE })
115-
void "Running a script that requires a gem using default embedded rubygems-servlets maven repo"() {
116-
setup:
117-
String version = '0.1.1'
118-
useScript(REQUIRE_THE_A_GEM)
119-
withPreamble 'repositories { rubygems() }'
120-
withDependencies "jrubyExec 'rubygems:a:${version}'"
121-
withJRubyExecConfig 'setEnvironment [:]'
122-
123-
when:
124-
BuildResult result = build()
125-
126-
then:
127-
// note this test has some error output not sure where this comes from. but the actual test passes
128-
result.output =~ /loaded 'a' gem with version ${version}/
129-
}
130-
131113
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/77')
132114
void "Running rspec from a script should not cause a gemWorkDir failure"() {
133115
setup:
134-
withPreamble "jruby.execVersion '${olderJRubyVersion}'"
116+
withPreamble "jruby.jrubyVersion '${olderJRubyVersion}'"
135117

136118
withDependencies """
137-
jrubyExec ${findDependency('', 'rspec', 'gem')}
138-
jrubyExec ${findDependency('', 'rspec-core', 'gem')}
139-
jrubyExec ${findDependency('', 'rspec-support', 'gem')}
119+
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec', 'gem')}
120+
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec-core', 'gem')}
121+
${DEFAULT_JRUBYEXEC_CONFIG} ${findDependency('', 'rspec-support', 'gem')}
140122
"""
141123

142124
withJRubyExecConfig """
@@ -154,25 +136,6 @@ class JRubyExecIntegrationSpec extends IntegrationSpecification {
154136
result.output =~ /No examples found./
155137
}
156138

157-
@Issue('https://github.com/jruby-gradle/jruby-gradle-plugin/issues/73')
158-
void "Running a script that has a custom gemdir"() {
159-
setup:
160-
String customGemDir = 'customGemDir'
161-
useScript(REQUIRES_GEM)
162-
withDependencies "${DEFAULT_JRUBYEXEC_CONFIG} ${withCreditCardValidator()}"
163-
withJRubyExecConfig """
164-
setEnvironment [:]
165-
gemWorkDir '${customGemDir}'
166-
"""
167-
168-
when:
169-
BuildResult result = build()
170-
171-
then:
172-
result.output =~ /Not valid/
173-
new File(projectDir, customGemDir).exists()
174-
}
175-
176139
@Override
177140
void useScript(final String name, final String relativePath = null) {
178141
super.useScript(name, relativePath)

base-plugin/src/integTest/groovy/com/github/jrubygradle/JRubyGenerateGradleRbIntegrationSpec.groovy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ class JRubyGenerateGradleRbIntegrationSpec extends IntegrationSpecification {
1919
2020
${projectWithLocalRepo}
2121
22-
task ${DEFAULT_TASK_NAME} (type: GenerateGradleRb)
22+
task ${DEFAULT_TASK_NAME} (type: GenerateGradleRb) {
23+
gemInstallDir 'build/gems'
24+
}
2325
"""
2426

2527
def expected = new File(projectDir, 'gradle.rb')
2628

2729
when: "The load path file is generated "
28-
gradleRunner(DEFAULT_TASK_NAME, '-i').build()
30+
gradleRunner(DEFAULT_TASK_NAME, '-i', '-s').build()
2931

3032
then: "Expect to be in the configured destinationDir and be called gradle.rb"
3133
expected.exists()

0 commit comments

Comments
 (0)