Skip to content

Commit 9387364

Browse files
committed
Make JRubyExec compatible with Gradle 4.2 - 4.9 (#366)
1 parent 9387814 commit 9387364

File tree

15 files changed

+79
-407
lines changed

15 files changed

+79
-407
lines changed

base-plugin/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ ext {
3030
dependencies {
3131

3232
compile project(':jruby-gradle-core-plugin')
33-
// compile "org.eclipse.jetty:jetty-server:${jettyVersion}"
34-
// compile "org.eclipse.jetty:jetty-webapp:${jettyVersion}"
3533
runtime('de.saumya.mojo:rubygems:0.2.3@war') {
3634
// we just want the war file on the classloader for the application
3735
// to find it and use the war-file from filesystem

base-plugin/src/gradleTest/jrubyExec/build.gradle

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import com.github.jrubygradle.JRubyExec
22

33
apply plugin : 'com.github.jruby-gradle.base'
44

5+
configurations {
6+
jrubyExec
7+
}
8+
59
dependencies {
610
jrubyExec ':credit_card_validator:1.1.0@gem'
711
}
812

9-
jruby {
10-
defaultRepositories = false
11-
}
1213

1314
task requiresGems( type : JRubyExec ) {
15+
jruby {
16+
gemConfiguration 'jrubyExec'
17+
}
18+
1419
script 'scripts/requiresGem.rb'
1520
}
1621

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

Lines changed: 1 addition & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -155,144 +155,4 @@ class JRubyExecExtensionIntegrationSpec extends IntegrationSpecification {
155155
private String getBcprovVer() {
156156
testProperties.bcprovVersion
157157
}
158-
}
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-
*/
158+
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
3333
@IgnoreIf({ IntegrationSpecification.OFFLINE })
3434
void "Check if rack version gets resolved"() {
3535
setup:
36-
//withDefaultRepositories()
37-
3836
withPreamble """repositories.ruby.gems()
3937
jrubyPrepare.outputDir = '${pathAsUriStr(projectDir)}'.toURI()
4038
"""
@@ -50,7 +48,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
5048
then:
5149
// since we need a version range in the setup the
5250
// resolved version here can vary over time
53-
new File(projectDir, "gems/rack-1.5.5").exists()
51+
new File(projectDir, "gems/rack-1.6.11").exists()
5452
}
5553

5654
@IgnoreIf({ IntegrationSpecification.OFFLINE })

base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package com.github.jrubygradle
33
import com.github.jrubygradle.api.core.JRubyAwareTask
44
import com.github.jrubygradle.api.core.JRubyExecSpec
55
import com.github.jrubygradle.internal.JRubyExecUtils
6+
import org.gradle.api.Task
67
import org.gradle.api.artifacts.Configuration
78
import org.gradle.api.provider.Provider
89
import org.gradle.api.tasks.Input
910
import org.gradle.api.tasks.JavaExec
1011
import org.gradle.api.tasks.Optional
1112
import org.gradle.process.JavaExecSpec
13+
import org.gradle.util.GradleVersion
1214

1315
import java.util.concurrent.Callable
1416

@@ -45,9 +47,15 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
4547
jruby.gemConfiguration
4648
}
4749

48-
dependsOn(project.provider({ JRubyPluginExtension jpe ->
49-
project.tasks.getByName(jpe.gemPrepareTaskName)
50-
}.curry(this.jruby)))
50+
if (GradleVersion.current() >= GradleVersion.version('4.10')) {
51+
dependsOn(project.provider({ JRubyPluginExtension jpe ->
52+
project.tasks.getByName(jpe.gemPrepareTaskName)
53+
}.curry(this.jruby)))
54+
} else {
55+
project.afterEvaluate({ Task t, JRubyPluginExtension jpe ->
56+
t.dependsOn(jpe.gemPrepareTaskName)
57+
}.curry(this, this.jruby))
58+
}
5159
}
5260

5361
/** Script to execute.

base-plugin/src/main/groovy/com/github/jrubygradle/JRubyPluginExtension.groovy

Lines changed: 2 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,15 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
114114
setJrubyVersion(newDefaultVersion)
115115
}
116116

117-
/** Set this to false if you do not want the default set of repositories to be loaded.
118-
*
119-
* @since 0.1.1
120-
*/
121-
122117
/** Legacy method for setting default repositories.
123118
*
124119
* @deprecated Default repositories are no longer set by default. People
125120
* who still need to use this feature must explicitly call this method, but
126121
* are encouraged to migrate to using the {@code repositories} block instead.
127122
*
128123
* @param value {@code true} to enabled default repositories
124+
*
125+
* @since 0.1.1
129126
*/
130127
@Deprecated
131128
void setDefaultRepositories(boolean value) {
@@ -148,31 +145,6 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
148145
}
149146
}
150147

151-
// /** Resolves the currently configured Jars installation directory.
152-
// *
153-
// * @return Install directory as an absolute path
154-
// * @since 0.1.16
155-
// */
156-
// @Deprecated
157-
// File getJarInstallDir() {
158-
// project.file(this.jarInstallDir).absoluteFile
159-
// }
160-
//
161-
// /** Sets the jar installation directory. Anything that can be passed to {@code project.file} can be
162-
// * passed here as well.
163-
// *
164-
// * @param dir Directory (String, GString, File, Closure etc.)
165-
// * @return The passed object.
166-
// * @deprecated Setting a custom jarInstallDir can cause dependencies to
167-
// * overlap and unexpected behavior. Please use Configurations instead.
168-
// *
169-
// * @since 0.1.16
170-
// */
171-
// @Deprecated
172-
// Object setJarInstallDir(Object dir) {
173-
// this.jarInstallDir = dir
174-
// }
175-
176148
/** Clears the current list of resolution strategies.
177149
*
178150
* If done on a task it will break the link to any global reoslution strategies.
@@ -294,19 +266,6 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
294266
}
295267
}
296268

297-
// /**
298-
// * Register a callback to be invoked when defaultVersion is updated
299-
// *
300-
// * NOTE: This is primarily meant for JRuby/Gradle plugin developers
301-
// *
302-
// * @param callback
303-
// * @since 1.1.0
304-
// */
305-
// @Incubating
306-
// void registerDefaultVersionCallback(Closure callback) {
307-
// defaultVersionCallbacks.add(callback)
308-
// }
309-
310269
/** Return all of the resolution strategies that are related to this extension.
311270
*
312271
* @return List of resolution strategy actions to perform.
@@ -339,22 +298,6 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
339298
}
340299
}
341300

342-
// /** Directory for jrubyPrepare to install GEM dependencies into */
343-
// @Deprecated
344-
// private Object gemInstallDir
345-
//
346-
// /** Directory for jrubyPrepare to install JAR dependencies into */
347-
// @Deprecated
348-
// private Object jarInstallDir
349-
350-
// /** List of callbacks to invoke when jruby.defaultVersion is modified */
351-
// private final List<Closure> defaultVersionCallbacks = []
352-
//
353-
// /** List of callbacks to invoke when jruby.execVersion is modified */
354-
// private final List<Closure> execVersionCallbacks = []
355-
//
356-
// private Boolean isExecVersionModified = false
357-
358301
private void registerPrepareTask(final String configurationName) {
359302
JRubyPrepareUtils.registerPrepareTask(project, configurationName)
360303
this.gemPrepareTaskName = JRubyPrepareUtils.taskName(configurationName)

0 commit comments

Comments
 (0)