Skip to content

Commit

Permalink
Merge pull request #411 from ysb33r/gradle7
Browse files Browse the repository at this point in the history
Prepare for Gradle's configuration cache
  • Loading branch information
ysb33r authored Oct 30, 2020
2 parents fe46be3 + 0e90408 commit 2019d0e
Show file tree
Hide file tree
Showing 18 changed files with 389 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
then:
// since we need a version range in the setup the
// resolved version here can vary over time
new File(projectDir, "gems/rack-1.6.12").exists()
new File(projectDir, "gems/rack-1.6.13").exists()
}

void "Check if selenium-webdriver version gets resolved"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@ import groovy.transform.CompileStatic
import org.apache.tools.ant.filters.ReplaceTokens
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.file.CopySpec
import org.gradle.api.file.FileCopyDetails
import org.gradle.api.file.RelativePath
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.ysb33r.grolifant.api.StringUtils
import org.ysb33r.grolifant.api.core.ProjectOperations
import org.ysb33r.grolifant.api.v4.StringUtils

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

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

GenerateGradleRb() {
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
this.projectOperations = ProjectOperations.create(project)
}

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

File getDestinationDir() {
project.file(destinationDir)
projectOperations.file(destinationDir)
}

@OutputFile
Expand All @@ -86,7 +89,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
}

File getGemInstallDir() {
project.file(this.gemInstallDir)
projectOperations.file(this.gemInstallDir)
}

@TaskAction
Expand All @@ -98,27 +101,27 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
String path = classpathFromConfiguration(jruby.jrubyConfiguration).join(File.pathSeparator)
String gemDir = getGemInstallDir().absolutePath
String bootstrapName = getBaseName()
String bootstrapTemplate = BOOTSTRAP_TEMPLATE
logger.info("GenerateGradleRb - source: ${source}, destination: ${destination}, baseName: ${baseName}")
project.copy {
from(source) {
/* In the case of this plugin existing in a zip (i.e. the
* plugin jar) our `source` will be a ZipTree, so we only want
* to pull in the template itself
*/
include "**/${GenerateGradleRb.BOOTSTRAP_TEMPLATE}"
projectOperations.copy { CopySpec cs ->
cs.with {
// In the case of this plugin existing in a zip (i.e. the plugin jar) our `source` will be a ZipTree,
// so we only want to pull in the template itself
from(source).include "**/${bootstrapTemplate}"

into destination
fileMode = 0755
includeEmptyDirs = false
rename bootstrapTemplate, bootstrapName
// Flatten the file into the destination directory so we don't copy
// the file into: ${destination}/META-INF/gradle-plugins/gradle.rb
eachFile { FileCopyDetails details ->
details.relativePath = new RelativePath(true, [details.name] as String[])
}

filter ReplaceTokens, beginToken: '%%', endToken: '%%',
tokens: [GEMFOLDER: gemDir, JRUBYEXEC_CLASSPATH: path]
}
into destination
fileMode = 0755
includeEmptyDirs = false
rename BOOTSTRAP_TEMPLATE, bootstrapName
// Flatten the file into the destination directory so we don't copy
// the file into: ${destination}/META-INF/gradle-plugins/gradle.rb
eachFile { FileCopyDetails details ->
details.relativePath = new RelativePath(true, [details.name] as String[])
}

filter ReplaceTokens, beginToken: '%%', endToken: '%%',
tokens: [GEMFOLDER: gemDir, JRUBYEXEC_CLASSPATH: path]
}
}

Expand Down Expand Up @@ -152,4 +155,5 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
private Object destinationDir = project.projectDir
private Object gemInstallDir
private final JRubyPluginExtension jruby
private final ProjectOperations projectOperations
}
35 changes: 22 additions & 13 deletions base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@ import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.JavaExec
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskContainer
import org.gradle.process.JavaExecSpec
import org.gradle.util.GradleVersion
import org.ysb33r.grolifant.api.core.ProjectOperations

import java.util.concurrent.Callable

import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
import static com.github.jrubygradle.internal.JRubyExecUtils.resolveScript
import static org.ysb33r.grolifant.api.StringUtils.stringize
import static org.ysb33r.grolifant.api.v4.StringUtils.stringize

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

JRubyExec() {
super()
super.setMain MAIN_CLASS
super.setMain(MAIN_CLASS)
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
this.projectOperations = ProjectOperations.create(project)
this.tasks = project.tasks

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

if (GradleVersion.current() >= GradleVersion.version('4.10')) {
dependsOn(project.provider({ JRubyPluginExtension jpe ->
project.tasks.getByName(jpe.gemPrepareTaskName)
}.curry(this.jruby)))
dependsOn(project.provider({ JRubyPluginExtension jpe, TaskContainer t ->
t.getByName(jpe.gemPrepareTaskName)
}.curry(this.jruby, this.tasks)))
} else {
project.afterEvaluate({ Task t, JRubyPluginExtension jpe ->
t.dependsOn(jpe.gemPrepareTaskName)
}.curry(this, this.jruby))
}

Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe, TaskContainer t ->
((JRubyPrepare) t.getByName(jpe.gemPrepareTaskName)).outputDir
}.curry(jruby, tasks) as Callable<File>

this.gemWorkDir = project.provider(resolveGemWorkDir)
}

/** Script to execute.
Expand All @@ -92,7 +102,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
@Optional
@Input
File getScript() {
resolveScript(project, this.script)
resolveScript(projectOperations, this.script)
}

/** Returns a list of script arguments
Expand Down Expand Up @@ -176,17 +186,13 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
* @return Provider of GEM working directory.
*/
Provider<File> getGemWorkDir() {
Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe ->
((JRubyPrepare) project.tasks.getByName(jpe.gemPrepareTaskName)).outputDir
}.curry(jruby) as Callable<File>

project.provider(resolveGemWorkDir)
this.gemWorkDir
}

/** If it is required that a JRubyExec task needs to be executed with a different version of JRuby that the
* globally configured one, it can be done by setting it here.
*
* @deprecated Use {@code jruby.getJrubyVersion( )} instead.
* @deprecated Use{@code jruby.getJrubyVersion( )} instead.
*
*/
@Deprecated
Expand Down Expand Up @@ -256,7 +262,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
void exec() {
File gemDir = getGemWorkDir().get()
setEnvironment prepareJRubyEnvironment(this.environment, this.inheritRubyEnv, gemDir)
super.classpath jruby.jrubyConfiguration
super.classpath(jruby.jrubyConfiguration)
super.setArgs(getArgs())
super.exec()
}
Expand Down Expand Up @@ -318,5 +324,8 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
private Object script
private final List<Object> scriptArgs = []
private final List<Object> jrubyArgs = []
private final ProjectOperations projectOperations
private final TaskContainer tasks
private final Provider<File> gemWorkDir

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.Configuration

import static org.ysb33r.grolifant.api.TaskProvider.registerTask
import static org.ysb33r.grolifant.api.v4.TaskProvider.registerTask

/** Base plugin for JRuby.
*
Expand Down Expand Up @@ -62,7 +62,7 @@ class JRubyPlugin implements Plugin<Project> {
JRubyExecDelegate.addToProject(project, PROJECT_JRUBYEXEC)

registerTask(
project,
project.tasks,
'generateGradleRb',
GenerateGradleRb
).configure(generateGradleRbConfiguration(project))
Expand Down
Loading

0 comments on commit 2019d0e

Please sign in to comment.