Skip to content

Commit 2019d0e

Browse files
authored
Merge pull request #411 from ysb33r/gradle7
Prepare for Gradle's configuration cache
2 parents fe46be3 + 0e90408 commit 2019d0e

File tree

18 files changed

+389
-229
lines changed

18 files changed

+389
-229
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
7373
then:
7474
// since we need a version range in the setup the
7575
// resolved version here can vary over time
76-
new File(projectDir, "gems/rack-1.6.12").exists()
76+
new File(projectDir, "gems/rack-1.6.13").exists()
7777
}
7878

7979
void "Check if selenium-webdriver version gets resolved"() {

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,18 @@ import groovy.transform.CompileStatic
2929
import org.apache.tools.ant.filters.ReplaceTokens
3030
import org.gradle.api.DefaultTask
3131
import org.gradle.api.GradleException
32+
import org.gradle.api.file.CopySpec
3233
import org.gradle.api.file.FileCopyDetails
3334
import org.gradle.api.file.RelativePath
3435
import org.gradle.api.tasks.Input
3536
import org.gradle.api.tasks.OutputFile
3637
import org.gradle.api.tasks.TaskAction
37-
import org.ysb33r.grolifant.api.StringUtils
38+
import org.ysb33r.grolifant.api.core.ProjectOperations
39+
import org.ysb33r.grolifant.api.v4.StringUtils
3840

3941
import static com.github.jrubygradle.internal.JRubyExecUtils.classpathFromConfiguration
4042

41-
/** Generate a LOAD_PATH Ruby file whichi is loadable by Ruby scripts when
43+
/** Generate a LOAD_PATH Ruby file which is loadable by Ruby scripts when
4244
* performing local manual testing.
4345
*
4446
* @author Schalk W. Cronjé
@@ -53,6 +55,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
5355

5456
GenerateGradleRb() {
5557
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
58+
this.projectOperations = ProjectOperations.create(project)
5659
}
5760

5861
void destinationDir(Object dest) {
@@ -72,7 +75,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
7275
}
7376

7477
File getDestinationDir() {
75-
project.file(destinationDir)
78+
projectOperations.file(destinationDir)
7679
}
7780

7881
@OutputFile
@@ -86,7 +89,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
8689
}
8790

8891
File getGemInstallDir() {
89-
project.file(this.gemInstallDir)
92+
projectOperations.file(this.gemInstallDir)
9093
}
9194

9295
@TaskAction
@@ -98,27 +101,27 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
98101
String path = classpathFromConfiguration(jruby.jrubyConfiguration).join(File.pathSeparator)
99102
String gemDir = getGemInstallDir().absolutePath
100103
String bootstrapName = getBaseName()
104+
String bootstrapTemplate = BOOTSTRAP_TEMPLATE
101105
logger.info("GenerateGradleRb - source: ${source}, destination: ${destination}, baseName: ${baseName}")
102-
project.copy {
103-
from(source) {
104-
/* In the case of this plugin existing in a zip (i.e. the
105-
* plugin jar) our `source` will be a ZipTree, so we only want
106-
* to pull in the template itself
107-
*/
108-
include "**/${GenerateGradleRb.BOOTSTRAP_TEMPLATE}"
106+
projectOperations.copy { CopySpec cs ->
107+
cs.with {
108+
// In the case of this plugin existing in a zip (i.e. the plugin jar) our `source` will be a ZipTree,
109+
// so we only want to pull in the template itself
110+
from(source).include "**/${bootstrapTemplate}"
111+
112+
into destination
113+
fileMode = 0755
114+
includeEmptyDirs = false
115+
rename bootstrapTemplate, bootstrapName
116+
// Flatten the file into the destination directory so we don't copy
117+
// the file into: ${destination}/META-INF/gradle-plugins/gradle.rb
118+
eachFile { FileCopyDetails details ->
119+
details.relativePath = new RelativePath(true, [details.name] as String[])
120+
}
121+
122+
filter ReplaceTokens, beginToken: '%%', endToken: '%%',
123+
tokens: [GEMFOLDER: gemDir, JRUBYEXEC_CLASSPATH: path]
109124
}
110-
into destination
111-
fileMode = 0755
112-
includeEmptyDirs = false
113-
rename BOOTSTRAP_TEMPLATE, bootstrapName
114-
// Flatten the file into the destination directory so we don't copy
115-
// the file into: ${destination}/META-INF/gradle-plugins/gradle.rb
116-
eachFile { FileCopyDetails details ->
117-
details.relativePath = new RelativePath(true, [details.name] as String[])
118-
}
119-
120-
filter ReplaceTokens, beginToken: '%%', endToken: '%%',
121-
tokens: [GEMFOLDER: gemDir, JRUBYEXEC_CLASSPATH: path]
122125
}
123126
}
124127

@@ -152,4 +155,5 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
152155
private Object destinationDir = project.projectDir
153156
private Object gemInstallDir
154157
private final JRubyPluginExtension jruby
158+
private final ProjectOperations projectOperations
155159
}

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ import org.gradle.api.provider.Provider
3333
import org.gradle.api.tasks.Input
3434
import org.gradle.api.tasks.JavaExec
3535
import org.gradle.api.tasks.Optional
36+
import org.gradle.api.tasks.TaskContainer
3637
import org.gradle.process.JavaExecSpec
3738
import org.gradle.util.GradleVersion
39+
import org.ysb33r.grolifant.api.core.ProjectOperations
3840

3941
import java.util.concurrent.Callable
4042

4143
import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
4244
import static com.github.jrubygradle.internal.JRubyExecUtils.resolveScript
43-
import static org.ysb33r.grolifant.api.StringUtils.stringize
45+
import static org.ysb33r.grolifant.api.v4.StringUtils.stringize
4446

4547
/** Runs a ruby script using JRuby
4648
*
@@ -64,8 +66,10 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
6466

6567
JRubyExec() {
6668
super()
67-
super.setMain MAIN_CLASS
69+
super.setMain(MAIN_CLASS)
6870
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
71+
this.projectOperations = ProjectOperations.create(project)
72+
this.tasks = project.tasks
6973

7074
inputs.property 'jrubyver', { JRubyPluginExtension jruby ->
7175
jruby.jrubyVersion
@@ -76,14 +80,20 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
7680
}.curry(this.jruby)
7781

7882
if (GradleVersion.current() >= GradleVersion.version('4.10')) {
79-
dependsOn(project.provider({ JRubyPluginExtension jpe ->
80-
project.tasks.getByName(jpe.gemPrepareTaskName)
81-
}.curry(this.jruby)))
83+
dependsOn(project.provider({ JRubyPluginExtension jpe, TaskContainer t ->
84+
t.getByName(jpe.gemPrepareTaskName)
85+
}.curry(this.jruby, this.tasks)))
8286
} else {
8387
project.afterEvaluate({ Task t, JRubyPluginExtension jpe ->
8488
t.dependsOn(jpe.gemPrepareTaskName)
8589
}.curry(this, this.jruby))
8690
}
91+
92+
Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe, TaskContainer t ->
93+
((JRubyPrepare) t.getByName(jpe.gemPrepareTaskName)).outputDir
94+
}.curry(jruby, tasks) as Callable<File>
95+
96+
this.gemWorkDir = project.provider(resolveGemWorkDir)
8797
}
8898

8999
/** Script to execute.
@@ -92,7 +102,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
92102
@Optional
93103
@Input
94104
File getScript() {
95-
resolveScript(project, this.script)
105+
resolveScript(projectOperations, this.script)
96106
}
97107

98108
/** Returns a list of script arguments
@@ -176,17 +186,13 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
176186
* @return Provider of GEM working directory.
177187
*/
178188
Provider<File> getGemWorkDir() {
179-
Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe ->
180-
((JRubyPrepare) project.tasks.getByName(jpe.gemPrepareTaskName)).outputDir
181-
}.curry(jruby) as Callable<File>
182-
183-
project.provider(resolveGemWorkDir)
189+
this.gemWorkDir
184190
}
185191

186192
/** If it is required that a JRubyExec task needs to be executed with a different version of JRuby that the
187193
* globally configured one, it can be done by setting it here.
188194
*
189-
* @deprecated Use {@code jruby.getJrubyVersion( )} instead.
195+
* @deprecated Use{@code jruby.getJrubyVersion( )} instead.
190196
*
191197
*/
192198
@Deprecated
@@ -256,7 +262,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
256262
void exec() {
257263
File gemDir = getGemWorkDir().get()
258264
setEnvironment prepareJRubyEnvironment(this.environment, this.inheritRubyEnv, gemDir)
259-
super.classpath jruby.jrubyConfiguration
265+
super.classpath(jruby.jrubyConfiguration)
260266
super.setArgs(getArgs())
261267
super.exec()
262268
}
@@ -318,5 +324,8 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
318324
private Object script
319325
private final List<Object> scriptArgs = []
320326
private final List<Object> jrubyArgs = []
327+
private final ProjectOperations projectOperations
328+
private final TaskContainer tasks
329+
private final Provider<File> gemWorkDir
321330

322331
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import org.gradle.api.Project
3232
import org.gradle.api.Task
3333
import org.gradle.api.artifacts.Configuration
3434

35-
import static org.ysb33r.grolifant.api.TaskProvider.registerTask
35+
import static org.ysb33r.grolifant.api.v4.TaskProvider.registerTask
3636

3737
/** Base plugin for JRuby.
3838
*
@@ -62,7 +62,7 @@ class JRubyPlugin implements Plugin<Project> {
6262
JRubyExecDelegate.addToProject(project, PROJECT_JRUBYEXEC)
6363

6464
registerTask(
65-
project,
65+
project.tasks,
6666
'generateGradleRb',
6767
GenerateGradleRb
6868
).configure(generateGradleRbConfiguration(project))

0 commit comments

Comments
 (0)