Compare commits
2 Commits
fe46be32c9
...
2019d0e6ad
Author | SHA1 | Date |
---|---|---|
Schalk W. Cronjé | 2019d0e6ad | |
Schalk Cronje | 0e904089c8 |
|
@ -73,7 +73,7 @@ class JRubyPrepareGemsIntegrationSpec extends IntegrationSpecification {
|
||||||
then:
|
then:
|
||||||
// since we need a version range in the setup the
|
// since we need a version range in the setup the
|
||||||
// resolved version here can vary over time
|
// 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"() {
|
void "Check if selenium-webdriver version gets resolved"() {
|
||||||
|
|
|
@ -29,16 +29,18 @@ import groovy.transform.CompileStatic
|
||||||
import org.apache.tools.ant.filters.ReplaceTokens
|
import org.apache.tools.ant.filters.ReplaceTokens
|
||||||
import org.gradle.api.DefaultTask
|
import org.gradle.api.DefaultTask
|
||||||
import org.gradle.api.GradleException
|
import org.gradle.api.GradleException
|
||||||
|
import org.gradle.api.file.CopySpec
|
||||||
import org.gradle.api.file.FileCopyDetails
|
import org.gradle.api.file.FileCopyDetails
|
||||||
import org.gradle.api.file.RelativePath
|
import org.gradle.api.file.RelativePath
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.OutputFile
|
import org.gradle.api.tasks.OutputFile
|
||||||
import org.gradle.api.tasks.TaskAction
|
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
|
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.
|
* performing local manual testing.
|
||||||
*
|
*
|
||||||
* @author Schalk W. Cronjé
|
* @author Schalk W. Cronjé
|
||||||
|
@ -53,6 +55,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
|
||||||
|
|
||||||
GenerateGradleRb() {
|
GenerateGradleRb() {
|
||||||
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
||||||
|
this.projectOperations = ProjectOperations.create(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
void destinationDir(Object dest) {
|
void destinationDir(Object dest) {
|
||||||
|
@ -72,7 +75,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
File getDestinationDir() {
|
File getDestinationDir() {
|
||||||
project.file(destinationDir)
|
projectOperations.file(destinationDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OutputFile
|
@OutputFile
|
||||||
|
@ -86,7 +89,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
File getGemInstallDir() {
|
File getGemInstallDir() {
|
||||||
project.file(this.gemInstallDir)
|
projectOperations.file(this.gemInstallDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TaskAction
|
@TaskAction
|
||||||
|
@ -98,27 +101,27 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
|
||||||
String path = classpathFromConfiguration(jruby.jrubyConfiguration).join(File.pathSeparator)
|
String path = classpathFromConfiguration(jruby.jrubyConfiguration).join(File.pathSeparator)
|
||||||
String gemDir = getGemInstallDir().absolutePath
|
String gemDir = getGemInstallDir().absolutePath
|
||||||
String bootstrapName = getBaseName()
|
String bootstrapName = getBaseName()
|
||||||
|
String bootstrapTemplate = BOOTSTRAP_TEMPLATE
|
||||||
logger.info("GenerateGradleRb - source: ${source}, destination: ${destination}, baseName: ${baseName}")
|
logger.info("GenerateGradleRb - source: ${source}, destination: ${destination}, baseName: ${baseName}")
|
||||||
project.copy {
|
projectOperations.copy { CopySpec cs ->
|
||||||
from(source) {
|
cs.with {
|
||||||
/* In the case of this plugin existing in a zip (i.e. the
|
// In the case of this plugin existing in a zip (i.e. the plugin jar) our `source` will be a ZipTree,
|
||||||
* plugin jar) our `source` will be a ZipTree, so we only want
|
// so we only want to pull in the template itself
|
||||||
* to pull in the template itself
|
from(source).include "**/${bootstrapTemplate}"
|
||||||
*/
|
|
||||||
include "**/${GenerateGradleRb.BOOTSTRAP_TEMPLATE}"
|
|
||||||
}
|
|
||||||
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: '%%',
|
into destination
|
||||||
tokens: [GEMFOLDER: gemDir, JRUBYEXEC_CLASSPATH: path]
|
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]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,4 +155,5 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
|
||||||
private Object destinationDir = project.projectDir
|
private Object destinationDir = project.projectDir
|
||||||
private Object gemInstallDir
|
private Object gemInstallDir
|
||||||
private final JRubyPluginExtension jruby
|
private final JRubyPluginExtension jruby
|
||||||
|
private final ProjectOperations projectOperations
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,16 @@ import org.gradle.api.provider.Provider
|
||||||
import org.gradle.api.tasks.Input
|
import org.gradle.api.tasks.Input
|
||||||
import org.gradle.api.tasks.JavaExec
|
import org.gradle.api.tasks.JavaExec
|
||||||
import org.gradle.api.tasks.Optional
|
import org.gradle.api.tasks.Optional
|
||||||
|
import org.gradle.api.tasks.TaskContainer
|
||||||
import org.gradle.process.JavaExecSpec
|
import org.gradle.process.JavaExecSpec
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
|
import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
|
||||||
import static com.github.jrubygradle.internal.JRubyExecUtils.resolveScript
|
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
|
/** Runs a ruby script using JRuby
|
||||||
*
|
*
|
||||||
|
@ -64,8 +66,10 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
|
|
||||||
JRubyExec() {
|
JRubyExec() {
|
||||||
super()
|
super()
|
||||||
super.setMain MAIN_CLASS
|
super.setMain(MAIN_CLASS)
|
||||||
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
||||||
|
this.projectOperations = ProjectOperations.create(project)
|
||||||
|
this.tasks = project.tasks
|
||||||
|
|
||||||
inputs.property 'jrubyver', { JRubyPluginExtension jruby ->
|
inputs.property 'jrubyver', { JRubyPluginExtension jruby ->
|
||||||
jruby.jrubyVersion
|
jruby.jrubyVersion
|
||||||
|
@ -76,14 +80,20 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
}.curry(this.jruby)
|
}.curry(this.jruby)
|
||||||
|
|
||||||
if (GradleVersion.current() >= GradleVersion.version('4.10')) {
|
if (GradleVersion.current() >= GradleVersion.version('4.10')) {
|
||||||
dependsOn(project.provider({ JRubyPluginExtension jpe ->
|
dependsOn(project.provider({ JRubyPluginExtension jpe, TaskContainer t ->
|
||||||
project.tasks.getByName(jpe.gemPrepareTaskName)
|
t.getByName(jpe.gemPrepareTaskName)
|
||||||
}.curry(this.jruby)))
|
}.curry(this.jruby, this.tasks)))
|
||||||
} else {
|
} else {
|
||||||
project.afterEvaluate({ Task t, JRubyPluginExtension jpe ->
|
project.afterEvaluate({ Task t, JRubyPluginExtension jpe ->
|
||||||
t.dependsOn(jpe.gemPrepareTaskName)
|
t.dependsOn(jpe.gemPrepareTaskName)
|
||||||
}.curry(this, this.jruby))
|
}.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.
|
/** Script to execute.
|
||||||
|
@ -92,7 +102,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
@Optional
|
@Optional
|
||||||
@Input
|
@Input
|
||||||
File getScript() {
|
File getScript() {
|
||||||
resolveScript(project, this.script)
|
resolveScript(projectOperations, this.script)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a list of script arguments
|
/** Returns a list of script arguments
|
||||||
|
@ -176,17 +186,13 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
* @return Provider of GEM working directory.
|
* @return Provider of GEM working directory.
|
||||||
*/
|
*/
|
||||||
Provider<File> getGemWorkDir() {
|
Provider<File> getGemWorkDir() {
|
||||||
Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe ->
|
this.gemWorkDir
|
||||||
((JRubyPrepare) project.tasks.getByName(jpe.gemPrepareTaskName)).outputDir
|
|
||||||
}.curry(jruby) as Callable<File>
|
|
||||||
|
|
||||||
project.provider(resolveGemWorkDir)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** If it is required that a JRubyExec task needs to be executed with a different version of JRuby that the
|
/** 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.
|
* globally configured one, it can be done by setting it here.
|
||||||
*
|
*
|
||||||
* @deprecated Use {@code jruby.getJrubyVersion( )} instead.
|
* @deprecated Use{@code jruby.getJrubyVersion( )} instead.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
|
@ -256,7 +262,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
void exec() {
|
void exec() {
|
||||||
File gemDir = getGemWorkDir().get()
|
File gemDir = getGemWorkDir().get()
|
||||||
setEnvironment prepareJRubyEnvironment(this.environment, this.inheritRubyEnv, gemDir)
|
setEnvironment prepareJRubyEnvironment(this.environment, this.inheritRubyEnv, gemDir)
|
||||||
super.classpath jruby.jrubyConfiguration
|
super.classpath(jruby.jrubyConfiguration)
|
||||||
super.setArgs(getArgs())
|
super.setArgs(getArgs())
|
||||||
super.exec()
|
super.exec()
|
||||||
}
|
}
|
||||||
|
@ -318,5 +324,8 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
|
||||||
private Object script
|
private Object script
|
||||||
private final List<Object> scriptArgs = []
|
private final List<Object> scriptArgs = []
|
||||||
private final List<Object> jrubyArgs = []
|
private final List<Object> jrubyArgs = []
|
||||||
|
private final ProjectOperations projectOperations
|
||||||
|
private final TaskContainer tasks
|
||||||
|
private final Provider<File> gemWorkDir
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ import org.gradle.api.Project
|
||||||
import org.gradle.api.Task
|
import org.gradle.api.Task
|
||||||
import org.gradle.api.artifacts.Configuration
|
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.
|
/** Base plugin for JRuby.
|
||||||
*
|
*
|
||||||
|
@ -62,7 +62,7 @@ class JRubyPlugin implements Plugin<Project> {
|
||||||
JRubyExecDelegate.addToProject(project, PROJECT_JRUBYEXEC)
|
JRubyExecDelegate.addToProject(project, PROJECT_JRUBYEXEC)
|
||||||
|
|
||||||
registerTask(
|
registerTask(
|
||||||
project,
|
project.tasks,
|
||||||
'generateGradleRb',
|
'generateGradleRb',
|
||||||
GenerateGradleRb
|
GenerateGradleRb
|
||||||
).configure(generateGradleRbConfiguration(project))
|
).configure(generateGradleRbConfiguration(project))
|
||||||
|
|
|
@ -29,16 +29,27 @@ import com.github.jrubygradle.internal.JRubyPrepareUtils
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.Task
|
||||||
|
import org.gradle.api.UnknownTaskException
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
import org.gradle.api.artifacts.ConfigurationContainer
|
||||||
import org.gradle.api.artifacts.Dependency
|
import org.gradle.api.artifacts.Dependency
|
||||||
import org.gradle.api.artifacts.ResolutionStrategy
|
import org.gradle.api.artifacts.ResolutionStrategy
|
||||||
|
import org.gradle.api.artifacts.dsl.DependencyHandler
|
||||||
|
import org.gradle.api.artifacts.dsl.RepositoryHandler
|
||||||
|
import org.gradle.api.logging.Logger
|
||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
import org.gradle.api.provider.Provider
|
import org.gradle.api.provider.Provider
|
||||||
import org.ysb33r.grolifant.api.AbstractCombinedProjectTaskExtension
|
import org.gradle.api.provider.ProviderFactory
|
||||||
|
import org.gradle.api.tasks.TaskContainer
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
import org.ysb33r.grolifant.api.v4.AbstractCombinedProjectTaskExtension
|
||||||
|
import org.ysb33r.grolifant.api.v4.TaskProvider
|
||||||
|
|
||||||
import java.util.concurrent.Callable
|
import java.util.concurrent.Callable
|
||||||
|
|
||||||
import static org.ysb33r.grolifant.api.StringUtils.stringize
|
import static com.github.jrubygradle.JRubyPlugin.TASK_GROUP_NAME
|
||||||
|
import static org.ysb33r.grolifant.api.v4.StringUtils.stringize
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class providing the jruby DSL extension to the Gradle build script.
|
* Class providing the jruby DSL extension to the Gradle build script.
|
||||||
|
@ -61,6 +72,13 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
JRubyPluginExtension(Project p) {
|
JRubyPluginExtension(Project p) {
|
||||||
super(p)
|
super(p)
|
||||||
this.jrubyVersion = DEFAULT_JRUBY_VERSION
|
this.jrubyVersion = DEFAULT_JRUBY_VERSION
|
||||||
|
this.repositories = p.repositories
|
||||||
|
this.dependencies = p.dependencies
|
||||||
|
this.configurations = p.configurations
|
||||||
|
this.providers = p.providers
|
||||||
|
this.logger = p.logger
|
||||||
|
this.tasks = p.tasks
|
||||||
|
this.projectOperations = ProjectOperations.create(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Task extension constructor
|
/** Task extension constructor
|
||||||
|
@ -71,6 +89,13 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
*/
|
*/
|
||||||
JRubyPluginExtension(JRubyAwareTask t) {
|
JRubyPluginExtension(JRubyAwareTask t) {
|
||||||
super(t, NAME)
|
super(t, NAME)
|
||||||
|
this.repositories = t.project.repositories
|
||||||
|
this.dependencies = t.project.dependencies
|
||||||
|
this.configurations = t.project.configurations
|
||||||
|
this.providers = t.project.providers
|
||||||
|
this.logger = t.project.logger
|
||||||
|
this.tasks = t.project.tasks
|
||||||
|
this.projectOperations = ProjectOperations.create(t.project)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The default version of jruby that will be used.
|
/** The default version of jruby that will be used.
|
||||||
|
@ -87,7 +112,8 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
|
|
||||||
/** Set a new JRuby version to use.
|
/** Set a new JRuby version to use.
|
||||||
*
|
*
|
||||||
* @param v New version to be used. Can be of anything that be be resolved by {@link StringUtils.stringize ( Object o )}
|
* @param v New version to be used. Can be of anything that be be resolved by
|
||||||
|
* {@link org.ysb33r.grolifant.api.v4.StringUtils#stringize ( Object o )}
|
||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +123,8 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
|
|
||||||
/** Set a new JRuby version to use.
|
/** Set a new JRuby version to use.
|
||||||
*
|
*
|
||||||
* @param v New version to be used. Can be of anything that be be resolved by {@link StringUtils.stringize ( Object o )}
|
* @param v New version to be used. Can be of anything that be be resolved by
|
||||||
|
* {@link org.ysb33r.grolifant.api.v4.StringUtils#stringize ( Object o )}
|
||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
|
@ -153,8 +180,8 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
'It is recommended that you explicitly declare your repositories rather than rely on ' +
|
'It is recommended that you explicitly declare your repositories rather than rely on ' +
|
||||||
'this functionality.'
|
'this functionality.'
|
||||||
)
|
)
|
||||||
project.repositories.jcenter()
|
repositories.jcenter()
|
||||||
((ExtensionAware) (project.repositories)).extensions.getByType(RepositoryHandlerExtension).gems()
|
((ExtensionAware) (repositories)).extensions.getByType(RepositoryHandlerExtension).gems()
|
||||||
} else {
|
} else {
|
||||||
deprecated(
|
deprecated(
|
||||||
'jruby.defaultRepositories are no longer switched on by default - you can safely remove ' +
|
'jruby.defaultRepositories are no longer switched on by default - you can safely remove ' +
|
||||||
|
@ -207,7 +234,7 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
|
|
||||||
List<Dependency> deps = [createDependency(jrubyCompleteDep)]
|
List<Dependency> deps = [createDependency(jrubyCompleteDep)]
|
||||||
|
|
||||||
Configuration configuration = project.configurations.detachedConfiguration(
|
Configuration configuration = configurations.detachedConfiguration(
|
||||||
deps.toArray() as Dependency[]
|
deps.toArray() as Dependency[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -221,16 +248,16 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
/** Sets the GEM configuration.
|
/** Sets the GEM configuration.
|
||||||
*
|
*
|
||||||
* @param c Configuration instance, Character sequence as configuration name, or a {@code Provider<Configuration}.
|
* @param c Configuration instance, Character sequence as configuration name, or a {@code Provider<Configuration}.
|
||||||
*/
|
*/
|
||||||
void setGemConfiguration(final Object c) {
|
void setGemConfiguration(final Object c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case Configuration:
|
case Configuration:
|
||||||
this.gemConfiguration = project.provider({ -> c } as Callable<Configuration>)
|
this.gemConfiguration = providers.provider({ -> c } as Callable<Configuration>)
|
||||||
registerPrepareTask(((Configuration) c).name)
|
registerPrepareTask(((Configuration) c).name)
|
||||||
break
|
break
|
||||||
case CharSequence:
|
case CharSequence:
|
||||||
this.gemConfiguration = project.provider(
|
this.gemConfiguration = project.provider(
|
||||||
{ -> project.configurations.getByName(c.toString()) } as Callable<Configuration>
|
{ -> configurations.getByName(c.toString()) } as Callable<Configuration>
|
||||||
)
|
)
|
||||||
registerPrepareTask(c.toString())
|
registerPrepareTask(c.toString())
|
||||||
break
|
break
|
||||||
|
@ -248,7 +275,7 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
/** Declarative way of setting the GEM configuration.
|
/** Declarative way of setting the GEM configuration.
|
||||||
*
|
*
|
||||||
* @param c Configuration instance, Character sequence as configuration name, or a {@code Provider<Configuration}.
|
* @param c Configuration instance, Character sequence as configuration name, or a {@code Provider<Configuration}.
|
||||||
*/
|
*/
|
||||||
void gemConfiguration(final Object c) {
|
void gemConfiguration(final Object c) {
|
||||||
setGemConfiguration(c)
|
setGemConfiguration(c)
|
||||||
}
|
}
|
||||||
|
@ -306,20 +333,43 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deprecated(String msg) {
|
private void deprecated(String msg) {
|
||||||
project.logger.info("Deprecated feature in ${NAME} extension. ${msg}")
|
logger.info("Deprecated feature in ${NAME} extension. ${msg}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dependency createDependency(final String notation, final Closure configurator = null) {
|
private Dependency createDependency(final String notation, final Closure configurator = null) {
|
||||||
if (configurator) {
|
if (configurator) {
|
||||||
project.dependencies.create(notation, configurator)
|
dependencies.create(notation, configurator)
|
||||||
} else {
|
} else {
|
||||||
project.dependencies.create(notation)
|
dependencies.create(notation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerPrepareTask(final String configurationName) {
|
private void registerPrepareTask(final String configurationName) {
|
||||||
JRubyPrepareUtils.registerPrepareTask(project, configurationName)
|
final String taskName = JRubyPrepareUtils.taskName(configurationName)
|
||||||
this.gemPrepareTaskName = JRubyPrepareUtils.taskName(configurationName)
|
final String gemDir = JRubyPrepareUtils.gemRelativePath(configurationName)
|
||||||
|
|
||||||
|
try {
|
||||||
|
TaskProvider.taskByName(tasks, taskName)
|
||||||
|
} catch (UnknownTaskException e) {
|
||||||
|
TaskProvider<JRubyPrepare> prepare = TaskProvider.registerTask(tasks, taskName, JRubyPrepare)
|
||||||
|
ProjectOperations po = this.projectOperations
|
||||||
|
Action<JRubyPrepare> configurator = new Action<JRubyPrepare>() {
|
||||||
|
void execute(JRubyPrepare jp) {
|
||||||
|
jp.with {
|
||||||
|
group = TASK_GROUP_NAME
|
||||||
|
description = "Prepare the gems/jars from the `${configurationName}` dependencies"
|
||||||
|
dependencies(project.configurations.getByName(configurationName))
|
||||||
|
outputDir = { ->
|
||||||
|
po.buildDirDescendant(gemDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prepare.configure(configurator as Action<? extends Task>)
|
||||||
|
prepare
|
||||||
|
}
|
||||||
|
|
||||||
|
this.gemPrepareTaskName = taskName//JRubyPrepareUtils.taskName(configurationName)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String JRUBY_COMPLETE_DEPENDENCY = 'org.jruby:jruby-complete'
|
private static final String JRUBY_COMPLETE_DEPENDENCY = 'org.jruby:jruby-complete'
|
||||||
|
@ -329,6 +379,12 @@ class JRubyPluginExtension extends AbstractCombinedProjectTaskExtension {
|
||||||
private String gemPrepareTaskName
|
private String gemPrepareTaskName
|
||||||
private boolean taskResolutionStrategiesOnly = false
|
private boolean taskResolutionStrategiesOnly = false
|
||||||
private final List<Action<ResolutionStrategy>> resolutionsStrategies = []
|
private final List<Action<ResolutionStrategy>> resolutionsStrategies = []
|
||||||
|
private final ProjectOperations projectOperations
|
||||||
|
private final RepositoryHandler repositories
|
||||||
|
private final ConfigurationContainer configurations
|
||||||
|
private final DependencyHandler dependencies
|
||||||
|
private final ProviderFactory providers
|
||||||
|
private final TaskContainer tasks
|
||||||
|
private final Logger logger
|
||||||
private boolean defaultRepositoriesCalled = false
|
private boolean defaultRepositoriesCalled = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,9 @@ class JRubyPrepare extends AbstractJRubyPrepare {
|
||||||
JRubyPrepare() {
|
JRubyPrepare() {
|
||||||
super()
|
super()
|
||||||
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
this.jruby = extensions.create(JRubyPluginExtension.NAME, JRubyPluginExtension, this)
|
||||||
|
this.jrubyJarLocation = project.provider({ JRubyPluginExtension jrubyExt ->
|
||||||
|
JRubyExecUtils.jrubyJar(jrubyExt.jrubyConfiguration)
|
||||||
|
}.curry(this.jruby) as Callable<File>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Location of {@code jruby-complete} JAR.
|
/** Location of {@code jruby-complete} JAR.
|
||||||
|
@ -50,9 +53,7 @@ class JRubyPrepare extends AbstractJRubyPrepare {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected Provider<File> getJrubyJarLocation() {
|
protected Provider<File> getJrubyJarLocation() {
|
||||||
project.provider({ JRubyPluginExtension jrubyExt ->
|
this.jrubyJarLocation
|
||||||
JRubyExecUtils.jrubyJar(jrubyExt.jrubyConfiguration)
|
|
||||||
}.curry(this.jruby) as Callable<File>)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Version of JRuby to be used.
|
/** Version of JRuby to be used.
|
||||||
|
@ -67,5 +68,6 @@ class JRubyPrepare extends AbstractJRubyPrepare {
|
||||||
}
|
}
|
||||||
|
|
||||||
private final JRubyPluginExtension jruby
|
private final JRubyPluginExtension jruby
|
||||||
|
private final Provider<File> jrubyJarLocation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,19 +24,24 @@
|
||||||
package com.github.jrubygradle.internal
|
package com.github.jrubygradle.internal
|
||||||
|
|
||||||
import com.github.jrubygradle.JRubyPluginExtension
|
import com.github.jrubygradle.JRubyPluginExtension
|
||||||
|
import com.github.jrubygradle.JRubyPrepare
|
||||||
import com.github.jrubygradle.api.core.JRubyExecSpec
|
import com.github.jrubygradle.api.core.JRubyExecSpec
|
||||||
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
|
import org.gradle.api.plugins.ExtensionContainer
|
||||||
|
import org.gradle.api.tasks.TaskContainer
|
||||||
import org.gradle.process.ExecResult
|
import org.gradle.process.ExecResult
|
||||||
import org.gradle.process.JavaExecSpec
|
import org.gradle.process.JavaExecSpec
|
||||||
import org.ysb33r.grolifant.api.ClosureUtils
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
import org.ysb33r.grolifant.api.v4.ClosureUtils
|
||||||
|
|
||||||
import static com.github.jrubygradle.JRubyExec.MAIN_CLASS
|
import static com.github.jrubygradle.JRubyExec.MAIN_CLASS
|
||||||
import static com.github.jrubygradle.internal.JRubyExecUtils.buildArgs
|
import static com.github.jrubygradle.internal.JRubyExecUtils.buildArgs
|
||||||
import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
|
import static com.github.jrubygradle.internal.JRubyExecUtils.prepareJRubyEnvironment
|
||||||
import static com.github.jrubygradle.internal.JRubyExecUtils.resolveScript
|
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
|
||||||
|
|
||||||
/** Delegate for running JRuby using {@code project.jrubyexec}.
|
/** Delegate for running JRuby using {@code project.jrubyexec}.
|
||||||
*
|
*
|
||||||
|
@ -44,6 +49,7 @@ import static org.ysb33r.grolifant.api.StringUtils.stringize
|
||||||
* @author R Tyler Croy
|
* @author R Tyler Croy
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@CompileStatic
|
||||||
class JRubyExecDelegate {
|
class JRubyExecDelegate {
|
||||||
|
|
||||||
static void addToProject(final Project project, final String name) {
|
static void addToProject(final Project project, final String name) {
|
||||||
|
@ -64,44 +70,54 @@ class JRubyExecDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecResult call(@DelegatesTo(JRubyExecSpec) Closure cfg) {
|
ExecResult call(@DelegatesTo(JRubyExecSpec) Closure cfg) {
|
||||||
project.javaexec { JavaExecSpec javaExecSpec ->
|
projectOperations.javaexec { JavaExecSpec javaExecSpec ->
|
||||||
ExecSpec execSpec = new ExecSpec(project, javaExecSpec)
|
ExecSpec execSpec = new ExecSpec(projectOperations, javaExecSpec)
|
||||||
ClosureUtils.configureItem(execSpec, cfg)
|
ClosureUtils.configureItem(execSpec, cfg)
|
||||||
finaliseJavaExecConfiguration(execSpec, javaExecSpec)
|
finaliseJavaExecConfiguration(execSpec, javaExecSpec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecResult call(Action<JRubyExecSpec> cfg) {
|
ExecResult call(Action<JRubyExecSpec> cfg) {
|
||||||
project.javaexec { JavaExecSpec javaExecSpec ->
|
projectOperations.javaexec { JavaExecSpec javaExecSpec ->
|
||||||
ExecSpec execSpec = new ExecSpec(project, javaExecSpec)
|
ExecSpec execSpec = new ExecSpec(projectOperations, javaExecSpec)
|
||||||
cfg.execute(spec)
|
cfg.execute(execSpec)
|
||||||
finaliseJavaExecConfiguration(execSpec, javaExecSpec)
|
finaliseJavaExecConfiguration(execSpec, javaExecSpec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void finaliseJavaExecConfiguration(ExecSpec execSpec, JavaExecSpec javaExecSpec) {
|
void finaliseJavaExecConfiguration(ExecSpec execSpec, JavaExecSpec javaExecSpec) {
|
||||||
JRubyPluginExtension jruby = project.extensions.getByType(JRubyPluginExtension)
|
JRubyPluginExtension jruby = extensions.getByType(JRubyPluginExtension)
|
||||||
javaExecSpec.with {
|
javaExecSpec.with {
|
||||||
main = MAIN_CLASS
|
main = MAIN_CLASS
|
||||||
classpath = jruby.jrubyConfiguration
|
classpath = jruby.jrubyConfiguration
|
||||||
args = buildArgs([], execSpec.jrubyArgs, execSpec.script, execSpec.scriptArgs)
|
args = buildArgs(
|
||||||
|
[],
|
||||||
|
execSpec.jrubyArgs as List<Object>,
|
||||||
|
execSpec.script,
|
||||||
|
execSpec.scriptArgs as List<Object>
|
||||||
|
)
|
||||||
|
|
||||||
environment = prepareJRubyEnvironment(
|
environment = prepareJRubyEnvironment(
|
||||||
environment,
|
environment,
|
||||||
execSpec.inheritRubyEnv,
|
execSpec.inheritRubyEnv,
|
||||||
project.tasks.getByName(jruby.gemPrepareTaskName).outputDir
|
((JRubyPrepare)tasks.getByName(jruby.gemPrepareTaskName)).outputDir
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private JRubyExecDelegate(Project project) {
|
private JRubyExecDelegate(Project project) {
|
||||||
this.project = project
|
this.projectOperations = ProjectOperations.find(project)
|
||||||
|
this.tasks = project.tasks
|
||||||
|
this.extensions = project.extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Project project
|
private final ProjectOperations projectOperations
|
||||||
|
private final TaskContainer tasks
|
||||||
|
private final ExtensionContainer extensions
|
||||||
|
|
||||||
private static class ExecSpec implements JRubyExecSpec {
|
private static class ExecSpec implements JRubyExecSpec {
|
||||||
ExecSpec(Project project, JavaExecSpec spec) {
|
ExecSpec(ProjectOperations projectOperations, JavaExecSpec spec) {
|
||||||
this.project = project
|
this.projectOperations = projectOperations
|
||||||
this.javaExecSpec = spec
|
this.javaExecSpec = spec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +155,12 @@ class JRubyExecDelegate {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void script(Object scr) {
|
void script(Object scr) {
|
||||||
this.script = resolveScript(project, scr)
|
this.script = resolveScript(projectOperations, scr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void setScript(Object scr) {
|
void setScript(Object scr) {
|
||||||
this.script = resolveScript(project, scr)
|
this.script = resolveScript(projectOperations, scr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -195,6 +211,6 @@ class JRubyExecDelegate {
|
||||||
private final List<String> jrubyArgs = []
|
private final List<String> jrubyArgs = []
|
||||||
private final @Delegate
|
private final @Delegate
|
||||||
JavaExecSpec javaExecSpec
|
JavaExecSpec javaExecSpec
|
||||||
private final Project project
|
private final ProjectOperations projectOperations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,20 +24,17 @@
|
||||||
package com.github.jrubygradle.internal
|
package com.github.jrubygradle.internal
|
||||||
|
|
||||||
import com.github.jrubygradle.JRubyPlugin
|
import com.github.jrubygradle.JRubyPlugin
|
||||||
import com.github.jrubygradle.JRubyPluginExtension
|
|
||||||
import com.github.jrubygradle.api.gems.GemOverwriteAction
|
|
||||||
import com.github.jrubygradle.api.gems.GemUtils
|
|
||||||
import groovy.transform.CompileDynamic
|
import groovy.transform.CompileDynamic
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.InvalidUserDataException
|
import org.gradle.api.InvalidUserDataException
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.ysb33r.grolifant.api.OperatingSystem
|
import org.ysb33r.grolifant.api.OperatingSystem
|
||||||
import org.ysb33r.grolifant.api.StringUtils
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
import org.ysb33r.grolifant.api.v4.StringUtils
|
||||||
|
|
||||||
import java.util.regex.Matcher
|
import java.util.regex.Matcher
|
||||||
|
|
||||||
import static org.ysb33r.grolifant.api.StringUtils.stringize
|
import static org.ysb33r.grolifant.api.v4.StringUtils.stringize
|
||||||
|
|
||||||
/** Utilities for preparation or executing JRuby.
|
/** Utilities for preparation or executing JRuby.
|
||||||
*
|
*
|
||||||
|
@ -120,17 +117,17 @@ class JRubyExecUtils {
|
||||||
|
|
||||||
/** Resolves a script location object.
|
/** Resolves a script location object.
|
||||||
*
|
*
|
||||||
* @paream project Project context for script.
|
* @paream project Project operations for script.
|
||||||
* @param script Script to resolve.
|
* @param script Script to resolve.
|
||||||
* @return Resolved script location. Will be {@code null} if {@code script == null},
|
* @return Resolved script location. Will be {@code null} if {@code script == null},
|
||||||
*/
|
*/
|
||||||
static File resolveScript(Project project, Object script) {
|
static File resolveScript(ProjectOperations projectOperations, Object script) {
|
||||||
if (script) {
|
if (script) {
|
||||||
File intermediate = script instanceof File ? (File) script : new File(stringize(script))
|
File intermediate = script instanceof File ? (File) script : new File(stringize(script))
|
||||||
if (intermediate.absolute) {
|
if (intermediate.absolute) {
|
||||||
intermediate
|
intermediate
|
||||||
} else {
|
} else {
|
||||||
intermediate.parentFile ? project.file(script) : intermediate
|
intermediate.parentFile ? projectOperations.file(script) : intermediate
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
|
@ -217,58 +214,45 @@ class JRubyExecUtils {
|
||||||
return path.absolutePath + File.pathSeparatorChar + originalPath
|
return path.absolutePath + File.pathSeparatorChar + originalPath
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* Update the given configuration on the project with the appropriate versions
|
// * Prepare the Ruby and Java dependencies for the configured configuration
|
||||||
* of JRuby and supplemental dependencies to execute JRuby successfully
|
// *
|
||||||
*/
|
// * This method will determine the appropriate dependency overwrite behavior
|
||||||
static void updateJRubyDependenciesForConfiguration(Project project, String configuration, String version) {
|
// * from the Gradle invocation. In effect, if the --refresh-dependencies flag
|
||||||
Configuration c = project.configurations.findByName(configuration)
|
// * is used, already installed gems will be overwritten.
|
||||||
|
// *
|
||||||
/* Only define this dependency if we don't already have it */
|
// * @param project The associated Gradle project.
|
||||||
if (!(c.dependencies.find { it.name == JRUBY_COMPLETE })) {
|
// * @param gemWorkDir THe GEM unpack/working directory.
|
||||||
project.dependencies.add(configuration, "org.jruby:jruby-complete:${version}")
|
// * @param jruby The associated JRuby project or task extension.
|
||||||
}
|
// * @param gemConfiguration Configuration which contains GEMs for unpacking.
|
||||||
}
|
// * @param overwrite Overwrite mode.
|
||||||
|
// *
|
||||||
/**
|
// * @since 2.0
|
||||||
* Prepare the Ruby and Java dependencies for the configured configuration
|
// */
|
||||||
*
|
// static void prepareDependencies(
|
||||||
* This method will determine the appropriate dependency overwrite behavior
|
// Project project,
|
||||||
* from the Gradle invocation. In effect, if the --refresh-dependencies flag
|
// File gemWorkDir,
|
||||||
* is used, already installed gems will be overwritten.
|
// JRubyPluginExtension jruby,
|
||||||
*
|
// Configuration gemConfiguration,
|
||||||
* @param project The associated Gradle project.
|
// GemOverwriteAction overwrite
|
||||||
* @param gemWorkDir THe GEM unpack/working directory.
|
// ) {
|
||||||
* @param jruby The associated JRuby project or task extension.
|
// File gemDir = gemWorkDir.absoluteFile
|
||||||
* @param gemConfiguration Configuration which contains GEMs for unpacking.
|
//
|
||||||
* @param overwrite Overwrite mode.
|
// gemDir.mkdirs()
|
||||||
*
|
//
|
||||||
* @since 2.0
|
// GemUtils.extractGems(
|
||||||
*/
|
// project,
|
||||||
static void prepareDependencies(
|
// jruby.jrubyConfiguration,
|
||||||
Project project,
|
// gemConfiguration,
|
||||||
File gemWorkDir,
|
// gemDir,
|
||||||
JRubyPluginExtension jruby,
|
// overwrite
|
||||||
Configuration gemConfiguration,
|
// )
|
||||||
GemOverwriteAction overwrite
|
// GemUtils.setupJars(
|
||||||
) {
|
// gemConfiguration,
|
||||||
File gemDir = gemWorkDir.absoluteFile
|
// gemDir,
|
||||||
|
// overwrite
|
||||||
gemDir.mkdirs()
|
// )
|
||||||
|
// }
|
||||||
GemUtils.extractGems(
|
|
||||||
project,
|
|
||||||
jruby.jrubyConfiguration,
|
|
||||||
gemConfiguration,
|
|
||||||
gemDir,
|
|
||||||
overwrite
|
|
||||||
)
|
|
||||||
GemUtils.setupJars(
|
|
||||||
gemConfiguration,
|
|
||||||
gemDir,
|
|
||||||
overwrite
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Prepare en environment which can be used to execute JRuby.
|
/** Prepare en environment which can be used to execute JRuby.
|
||||||
*
|
*
|
||||||
|
|
|
@ -23,17 +23,10 @@
|
||||||
*/
|
*/
|
||||||
package com.github.jrubygradle.internal
|
package com.github.jrubygradle.internal
|
||||||
|
|
||||||
import com.github.jrubygradle.JRubyPrepare
|
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.Action
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.Task
|
|
||||||
import org.gradle.api.UnknownTaskException
|
|
||||||
import org.ysb33r.grolifant.api.TaskProvider
|
|
||||||
|
|
||||||
import static com.github.jrubygradle.JRubyPlugin.DEFAULT_CONFIGURATION
|
import static com.github.jrubygradle.JRubyPlugin.DEFAULT_CONFIGURATION
|
||||||
import static com.github.jrubygradle.JRubyPlugin.DEFAULT_PREPARE_TASK
|
import static com.github.jrubygradle.JRubyPlugin.DEFAULT_PREPARE_TASK
|
||||||
import static com.github.jrubygradle.JRubyPlugin.TASK_GROUP_NAME
|
|
||||||
|
|
||||||
/** Utilities to deal with JRubPrepare tasks
|
/** Utilities to deal with JRubPrepare tasks
|
||||||
*
|
*
|
||||||
|
@ -56,44 +49,11 @@ class JRubyPrepareUtils {
|
||||||
|
|
||||||
/** GEM working (unpack) relative path by convention.
|
/** GEM working (unpack) relative path by convention.
|
||||||
*
|
*
|
||||||
* @param configurationName Name of a GEM configuration.
|
* @param configurationName Name of a GEM configuration.
|
||||||
* @return Associated relative path to project directory.
|
* @return Associated relative path to project directory.
|
||||||
*/
|
*/
|
||||||
static String gemRelativePath(String configurationName) {
|
static String gemRelativePath(String configurationName) {
|
||||||
configurationName == DEFAULT_CONFIGURATION ? '.gems' :
|
configurationName == DEFAULT_CONFIGURATION ? '.gems' :
|
||||||
".gems-${configurationName}"
|
".gems-${configurationName}"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Registers (or creates) a JRUbyPrepare tasks based upon a configuration name
|
|
||||||
*
|
|
||||||
* @param project Associated project
|
|
||||||
* @param configurationName
|
|
||||||
* @return Grolifant {@code TaskProvider}.
|
|
||||||
*/
|
|
||||||
static TaskProvider<JRubyPrepare> registerPrepareTask(
|
|
||||||
final Project project,
|
|
||||||
final String configurationName
|
|
||||||
) {
|
|
||||||
final String taskName = taskName(configurationName)
|
|
||||||
final String gemDir = gemRelativePath(configurationName)
|
|
||||||
|
|
||||||
try {
|
|
||||||
TaskProvider.taskByName(project, taskName)
|
|
||||||
} catch (UnknownTaskException e) {
|
|
||||||
TaskProvider<JRubyPrepare> prepare = TaskProvider.registerTask(project, taskName, JRubyPrepare)
|
|
||||||
Action<JRubyPrepare> configurator = new Action<JRubyPrepare>() {
|
|
||||||
void execute(JRubyPrepare jp) {
|
|
||||||
jp.with {
|
|
||||||
group = TASK_GROUP_NAME
|
|
||||||
description = "Prepare the gems/jars from the `${configurationName}` dependencies"
|
|
||||||
dependencies(project.configurations.getByName(configurationName))
|
|
||||||
outputDir { "${project.buildDir}/${gemDir}" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prepare.configure(configurator as Action<? extends Task>)
|
|
||||||
prepare
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -33,7 +33,6 @@ allprojects {
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -55,8 +54,8 @@ subprojects {
|
||||||
dependencies {
|
dependencies {
|
||||||
compile localGroovy()
|
compile localGroovy()
|
||||||
compile gradleApi()
|
compile gradleApi()
|
||||||
compile 'org.ysb33r.gradle:grolifant:0.12'
|
compile "org.ysb33r.gradle:grolifant50:${grolifantVersion}"
|
||||||
gradleTestRuntime 'org.ysb33r.gradle:grolifant:0.12'
|
gradleTestRuntime "org.ysb33r.gradle:grolifant50:${grolifantVersion}"
|
||||||
}
|
}
|
||||||
|
|
||||||
codenarc {
|
codenarc {
|
||||||
|
@ -79,9 +78,9 @@ subprojects {
|
||||||
gradleTest {
|
gradleTest {
|
||||||
// https://github.com/jruby-gradle/jruby-gradle-plugin/issues/346
|
// https://github.com/jruby-gradle/jruby-gradle-plugin/issues/346
|
||||||
if (JavaVersion.current().java11) {
|
if (JavaVersion.current().java11) {
|
||||||
versions '5.0', '5.4.1', '6.0.1'
|
versions '5.0', '5.4.1', '6.0.1', '6.7'
|
||||||
} else {
|
} else {
|
||||||
versions '4.10.2', '5.3.1', '6.0.1'
|
versions '4.10.2', '5.3.1', '6.0.1', '6.7'
|
||||||
|
|
||||||
if(project.name == 'jruby-gradle-core-plugin' ) {
|
if(project.name == 'jruby-gradle-core-plugin' ) {
|
||||||
versions '4.3'
|
versions '4.3'
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.gradle.api.tasks.InputFiles
|
||||||
import org.gradle.api.tasks.Internal
|
import org.gradle.api.tasks.Internal
|
||||||
import org.gradle.api.tasks.Optional
|
import org.gradle.api.tasks.Optional
|
||||||
import org.gradle.api.tasks.TaskAction
|
import org.gradle.api.tasks.TaskAction
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
|
||||||
import static com.github.jrubygradle.api.gems.GemOverwriteAction.SKIP
|
import static com.github.jrubygradle.api.gems.GemOverwriteAction.SKIP
|
||||||
import static com.github.jrubygradle.api.gems.GemUtils.extractGems
|
import static com.github.jrubygradle.api.gems.GemUtils.extractGems
|
||||||
|
@ -52,6 +53,10 @@ import static com.github.jrubygradle.api.gems.GemUtils.setupJars
|
||||||
abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTask {
|
abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTask {
|
||||||
|
|
||||||
protected AbstractJRubyPrepare() {
|
protected AbstractJRubyPrepare() {
|
||||||
|
this.projectOperations = ProjectOperations.find(project)
|
||||||
|
this.outputDir = {
|
||||||
|
ProjectOperations projectOperations -> projectOperations.buildDirDescendant('.gems')
|
||||||
|
}.curry(this.projectOperations)
|
||||||
outputs.dir({ AbstractJRubyPrepare t -> new File(t.getOutputDir(), 'gems') }.curry(this))
|
outputs.dir({ AbstractJRubyPrepare t -> new File(t.getOutputDir(), 'gems') }.curry(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +64,7 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas
|
||||||
*/
|
*/
|
||||||
@Internal
|
@Internal
|
||||||
File getOutputDir() {
|
File getOutputDir() {
|
||||||
project.file(this.outputDir)
|
projectOperations.file(this.outputDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the output directory
|
/** Sets the output directory
|
||||||
|
@ -84,7 +89,7 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas
|
||||||
*/
|
*/
|
||||||
@InputFiles
|
@InputFiles
|
||||||
FileCollection gemsAsFileCollection() {
|
FileCollection gemsAsFileCollection() {
|
||||||
return GemUtils.getGems(project.files(this.dependencies))
|
return GemUtils.getGems(projectOperations.files(this.dependencies))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
|
@ -99,6 +104,16 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas
|
||||||
this.dependencies.addAll(f.toList())
|
this.dependencies.addAll(f.toList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return Configuration Cache safe project operations service.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
protected ProjectOperations getProjectOperations() {
|
||||||
|
this.projectOperations
|
||||||
|
}
|
||||||
|
|
||||||
/** Location of {@code jruby-complete} JAR.
|
/** Location of {@code jruby-complete} JAR.
|
||||||
*
|
*
|
||||||
* @return Path on local filesystem
|
* @return Path on local filesystem
|
||||||
|
@ -130,6 +145,7 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object outputDir = { -> "${project.buildDir}/.gems" }
|
private Object outputDir
|
||||||
|
private final ProjectOperations projectOperations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.plugins.ExtensionAware
|
import org.gradle.api.plugins.ExtensionAware
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
|
||||||
/** Provides only a repository handler extensiosn for looking up rubygem
|
/** Provides only a repository handler extensiosn for looking up rubygem
|
||||||
* metadata.
|
* metadata.
|
||||||
|
@ -42,6 +43,7 @@ import org.gradle.api.plugins.ExtensionAware
|
||||||
class JRubyCorePlugin implements Plugin<Project> {
|
class JRubyCorePlugin implements Plugin<Project> {
|
||||||
@Override
|
@Override
|
||||||
void apply(Project project) {
|
void apply(Project project) {
|
||||||
|
ProjectOperations.maybeCreateExtension(project)
|
||||||
GemResolverStrategy gemGroups = project.extensions.create(GemResolverStrategy.NAME, GemResolverStrategy)
|
GemResolverStrategy gemGroups = project.extensions.create(GemResolverStrategy.NAME, GemResolverStrategy)
|
||||||
|
|
||||||
((ExtensionAware) project.repositories).extensions.create(
|
((ExtensionAware) project.repositories).extensions.create(
|
||||||
|
|
|
@ -29,11 +29,15 @@ import groovy.transform.CompileDynamic
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.api.artifacts.dsl.RepositoryHandler
|
||||||
import org.gradle.api.artifacts.repositories.ArtifactRepository
|
import org.gradle.api.artifacts.repositories.ArtifactRepository
|
||||||
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
|
import org.gradle.api.artifacts.repositories.IvyArtifactRepository
|
||||||
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
import org.gradle.api.artifacts.repositories.MavenArtifactRepository
|
||||||
|
import org.gradle.api.plugins.ExtensionContainer
|
||||||
import org.gradle.util.GradleVersion
|
import org.gradle.util.GradleVersion
|
||||||
import org.ysb33r.grolifant.api.ClosureUtils
|
import org.ysb33r.grolifant.api.v4.ClosureUtils
|
||||||
|
|
||||||
|
import static org.ysb33r.grolifant.api.v4.UriUtils.urize
|
||||||
|
|
||||||
/** Extension which can be added to {@code project.repositories}.
|
/** Extension which can be added to {@code project.repositories}.
|
||||||
*
|
*
|
||||||
|
@ -51,11 +55,12 @@ class RepositoryHandlerExtension {
|
||||||
* @param project Gradle project.
|
* @param project Gradle project.
|
||||||
*/
|
*/
|
||||||
RepositoryHandlerExtension(final Project project) {
|
RepositoryHandlerExtension(final Project project) {
|
||||||
this.project = project
|
this.extensions = project.extensions
|
||||||
|
this.repositories = project.repositories
|
||||||
this.ivyProxies = new IvyXmlGlobalProxyRegistry(project)
|
this.ivyProxies = new IvyXmlGlobalProxyRegistry(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use {@link https://rubygems.org} and
|
/** Create an artifact repository which will use https://rubygems.org and
|
||||||
* associate group {@code rubygems} with it.
|
* associate group {@code rubygems} with it.
|
||||||
*
|
*
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
|
@ -68,7 +73,7 @@ class RepositoryHandlerExtension {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use {@link https://rubygems.org} and
|
/** Create an artifact repository which will use https://rubygems.org and
|
||||||
* associate group {@code rubygems} with it.
|
* associate group {@code rubygems} with it.
|
||||||
*
|
*
|
||||||
* @param cfg GEM repository configuration
|
* @param cfg GEM repository configuration
|
||||||
|
@ -78,7 +83,7 @@ class RepositoryHandlerExtension {
|
||||||
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
|
bindRepositoryToProxyServer(RUBYGEMS_URI, DEFAULT_GROUP_NAME, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use {@link https://rubygems.org} and
|
/** Create an artifact repository which will use https://rubygems.org and
|
||||||
* associate group {@code rubygems} with it.
|
* associate group {@code rubygems} with it.
|
||||||
*
|
*
|
||||||
* @param cfg GEM repository configuration
|
* @param cfg GEM repository configuration
|
||||||
|
@ -97,7 +102,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(Object uri) {
|
ArtifactRepository gems(Object uri) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, new GemRepositoryConfiguration())
|
bindRepositoryToProxyServer(urize(uri), DEFAULT_GROUP_NAME, new GemRepositoryConfiguration())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use specified URI and
|
/** Create an artifact repository which will use specified URI and
|
||||||
|
@ -110,7 +115,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
|
ArtifactRepository gems(Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
|
bindRepositoryToProxyServer(urize(uri), DEFAULT_GROUP_NAME, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use specified URI and
|
/** Create an artifact repository which will use specified URI and
|
||||||
|
@ -123,7 +128,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(Object uri, Action<GemRepositoryConfiguration> cfg) {
|
ArtifactRepository gems(Object uri, Action<GemRepositoryConfiguration> cfg) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), DEFAULT_GROUP_NAME, cfg)
|
bindRepositoryToProxyServer(urize(uri), DEFAULT_GROUP_NAME, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use specified URI and
|
/** Create an artifact repository which will use specified URI and
|
||||||
|
@ -135,7 +140,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(String group, Object uri) {
|
ArtifactRepository gems(String group, Object uri) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), group, new GemRepositoryConfiguration())
|
bindRepositoryToProxyServer(urize(uri), group, new GemRepositoryConfiguration())
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use specified URI and
|
/** Create an artifact repository which will use specified URI and
|
||||||
|
@ -148,7 +153,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(String group, Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
|
ArtifactRepository gems(String group, Object uri, @DelegatesTo(GemRepositoryConfiguration) Closure cfg) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
|
bindRepositoryToProxyServer(urize(uri), group, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create an artifact repository which will use specified URI and
|
/** Create an artifact repository which will use specified URI and
|
||||||
|
@ -161,7 +166,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Artifact repository.
|
* @return Artifact repository.
|
||||||
*/
|
*/
|
||||||
ArtifactRepository gems(String group, Object uri, Action<GemRepositoryConfiguration> cfg) {
|
ArtifactRepository gems(String group, Object uri, Action<GemRepositoryConfiguration> cfg) {
|
||||||
bindRepositoryToProxyServer(project.uri(uri), group, cfg)
|
bindRepositoryToProxyServer(urize(uri), group, cfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the Maven-GEMs proxy that is supported by the JRuby group.
|
/** Adds the Maven-GEMs proxy that is supported by the JRuby group.
|
||||||
|
@ -184,7 +189,7 @@ class RepositoryHandlerExtension {
|
||||||
* @return Maven repository
|
* @return Maven repository
|
||||||
*/
|
*/
|
||||||
MavenArtifactRepository mavengems(Object uri) {
|
MavenArtifactRepository mavengems(Object uri) {
|
||||||
bindToMavenRepository(project.uri(uri), DEFAULT_GROUP_NAME)
|
bindToMavenRepository(urize(uri), DEFAULT_GROUP_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a remote Maven-GEMs proxy anbd allocate a dedicated group for it.
|
/** Adds a remote Maven-GEMs proxy anbd allocate a dedicated group for it.
|
||||||
|
@ -197,14 +202,14 @@ class RepositoryHandlerExtension {
|
||||||
* @return Maven repository
|
* @return Maven repository
|
||||||
*/
|
*/
|
||||||
MavenArtifactRepository mavengems(String group, Object uri) {
|
MavenArtifactRepository mavengems(String group, Object uri) {
|
||||||
bindToMavenRepository(project.uri(uri), group)
|
bindToMavenRepository(urize(uri), group)
|
||||||
}
|
}
|
||||||
|
|
||||||
private MavenArtifactRepository bindToMavenRepository(
|
private MavenArtifactRepository bindToMavenRepository(
|
||||||
URI serverUri,
|
URI serverUri,
|
||||||
String group
|
String group
|
||||||
) {
|
) {
|
||||||
MavenArtifactRepository repo = project.repositories.maven(new Action<MavenArtifactRepository>() {
|
MavenArtifactRepository repo = repositories.maven(new Action<MavenArtifactRepository>() {
|
||||||
@Override
|
@Override
|
||||||
void execute(MavenArtifactRepository mvn) {
|
void execute(MavenArtifactRepository mvn) {
|
||||||
mvn.url = serverUri
|
mvn.url = serverUri
|
||||||
|
@ -220,7 +225,7 @@ class RepositoryHandlerExtension {
|
||||||
GemRepositoryConfiguration cfg
|
GemRepositoryConfiguration cfg
|
||||||
) {
|
) {
|
||||||
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group, cfg)
|
IvyXmlProxyServer proxy = ivyProxies.registerProxy(serverUri, group, cfg)
|
||||||
project.extensions.getByType(GemResolverStrategy).addGemGroup(group)
|
extensions.getByType(GemResolverStrategy).addGemGroup(group)
|
||||||
restrictToGems(createIvyRepo(serverUri, proxy.bindAddress), group)
|
restrictToGems(createIvyRepo(serverUri, proxy.bindAddress), group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,7 +251,7 @@ class RepositoryHandlerExtension {
|
||||||
|
|
||||||
@CompileDynamic
|
@CompileDynamic
|
||||||
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
|
private IvyArtifactRepository createIvyRepo(URI server, URI bindAddress) {
|
||||||
this.project.repositories.ivy {
|
repositories.ivy {
|
||||||
artifactPattern "${server}/downloads/[artifact]-[revision](-[classifier]).gem"
|
artifactPattern "${server}/downloads/[artifact]-[revision](-[classifier]).gem"
|
||||||
ivyPattern "${bindAddress}/[organisation]/[module]/[revision]/ivy.xml"
|
ivyPattern "${bindAddress}/[organisation]/[module]/[revision]/ivy.xml"
|
||||||
|
|
||||||
|
@ -266,8 +271,9 @@ class RepositoryHandlerExtension {
|
||||||
repo
|
repo
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Project project
|
|
||||||
private final IvyXmlGlobalProxyRegistry ivyProxies
|
private final IvyXmlGlobalProxyRegistry ivyProxies
|
||||||
|
private final ExtensionContainer extensions
|
||||||
|
private final RepositoryHandler repositories
|
||||||
private static final boolean HAS_CONTENT_FEATURE = GradleVersion.current() >= GradleVersion.version('5.1')
|
private static final boolean HAS_CONTENT_FEATURE = GradleVersion.current() >= GradleVersion.version('5.1')
|
||||||
private static final boolean HAS_SECURE_PROTOCOL_FEATURE = GradleVersion.current() >= GradleVersion.version('6.0')
|
private static final boolean HAS_SECURE_PROTOCOL_FEATURE = GradleVersion.current() >= GradleVersion.version('6.0')
|
||||||
private static final URI RUBYGEMS_URI = 'https://rubygems.org'.toURI()
|
private static final URI RUBYGEMS_URI = 'https://rubygems.org'.toURI()
|
||||||
|
|
|
@ -65,7 +65,7 @@ class GemResolverStrategy {
|
||||||
* @param configs Configurations to be excluded
|
* @param configs Configurations to be excluded
|
||||||
*/
|
*/
|
||||||
void excludeConfigurations(Configuration... configs) {
|
void excludeConfigurations(Configuration... configs) {
|
||||||
this.excludedConfigurations.addAll(configs*.name)
|
this.excludedConfigurations.addAll(configs*.name as Iterable<String>)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Exclude a configuration from being resolved using the GEM
|
/** Exclude a configuration from being resolved using the GEM
|
||||||
|
@ -132,7 +132,7 @@ class GemResolverStrategy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Set<Matcher> excludedModules = [].toSet()
|
private final Set<Matcher> excludedModules = [].toSet() as Set<Matcher>
|
||||||
private final Set<String> excludedConfigurations = [].toSet()
|
private final Set<String> excludedConfigurations = [].toSet() as Set<String>
|
||||||
private final Set<String> groups = [RepositoryHandlerExtension.DEFAULT_GROUP_NAME].toSet()
|
private final Set<String> groups = [RepositoryHandlerExtension.DEFAULT_GROUP_NAME].toSet()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
*/
|
*/
|
||||||
package com.github.jrubygradle.api.gems
|
package com.github.jrubygradle.api.gems
|
||||||
|
|
||||||
import groovy.transform.CompileDynamic
|
|
||||||
import groovy.transform.CompileStatic
|
import groovy.transform.CompileStatic
|
||||||
|
import groovy.util.logging.Slf4j
|
||||||
import org.gradle.api.Action
|
import org.gradle.api.Action
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.artifacts.Configuration
|
import org.gradle.api.artifacts.Configuration
|
||||||
|
@ -33,9 +33,9 @@ import org.gradle.api.file.CopySpec
|
||||||
import org.gradle.api.file.DuplicateFileCopyingException
|
import org.gradle.api.file.DuplicateFileCopyingException
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
import org.gradle.process.JavaExecSpec
|
import org.gradle.process.JavaExecSpec
|
||||||
import org.ysb33r.grolifant.api.OperatingSystem
|
import org.ysb33r.grolifant.api.core.OperatingSystem
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
|
|
||||||
import static com.github.jrubygradle.api.gems.GemOverwriteAction.SKIP
|
|
||||||
import static com.github.jrubygradle.api.gems.GemOverwriteAction.FAIL
|
import static com.github.jrubygradle.api.gems.GemOverwriteAction.FAIL
|
||||||
import static com.github.jrubygradle.api.gems.GemOverwriteAction.OVERWRITE
|
import static com.github.jrubygradle.api.gems.GemOverwriteAction.OVERWRITE
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ import static com.github.jrubygradle.api.gems.GemOverwriteAction.OVERWRITE
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
@CompileStatic
|
@CompileStatic
|
||||||
|
@Slf4j
|
||||||
class GemUtils {
|
class GemUtils {
|
||||||
public static final String JRUBY_MAINCLASS = 'org.jruby.Main'
|
public static final String JRUBY_MAINCLASS = 'org.jruby.Main'
|
||||||
public static final String JRUBY_ARCHIVE_NAME = 'jruby-complete'
|
public static final String JRUBY_ARCHIVE_NAME = 'jruby-complete'
|
||||||
|
@ -69,7 +70,10 @@ class GemUtils {
|
||||||
* @param gem Gem file to extract.
|
* @param gem Gem file to extract.
|
||||||
* @param destDir Directory to extract to.
|
* @param destDir Directory to extract to.
|
||||||
* @param overwrite Allow overwrite of an existing gem folder.
|
* @param overwrite Allow overwrite of an existing gem folder.
|
||||||
|
* @deprecated Use the version that takes a {@link ProjectOperations} instead as it will be safe when
|
||||||
|
* configuration cache is active.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
static void extractGem(
|
static void extractGem(
|
||||||
Project project,
|
Project project,
|
||||||
File jRubyClasspath,
|
File jRubyClasspath,
|
||||||
|
@ -77,7 +81,27 @@ class GemUtils {
|
||||||
File destDir,
|
File destDir,
|
||||||
GemOverwriteAction overwrite
|
GemOverwriteAction overwrite
|
||||||
) {
|
) {
|
||||||
|
ProjectOperations po = ProjectOperations.find(project)
|
||||||
|
extractGems(po, jRubyClasspath, po.files(gem), destDir, overwrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extracts a gem to a folder
|
||||||
|
*
|
||||||
|
* @param project {@link ProjectOperations} instance.
|
||||||
|
* @param jRubyClasspath The path to the {@code jruby-complete} jar.
|
||||||
|
* @param gem Gem file to extract.
|
||||||
|
* @param destDir Directory to extract to.
|
||||||
|
* @param overwrite Allow overwrite of an existing gem folder.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
static void extractGem(
|
||||||
|
ProjectOperations project,
|
||||||
|
File jRubyClasspath,
|
||||||
|
File gem,
|
||||||
|
File destDir,
|
||||||
|
GemOverwriteAction overwrite
|
||||||
|
) {
|
||||||
extractGems(project, jRubyClasspath, project.files(gem), destDir, overwrite)
|
extractGems(project, jRubyClasspath, project.files(gem), destDir, overwrite)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,13 +112,36 @@ class GemUtils {
|
||||||
* @param gems GEMs to install.
|
* @param gems GEMs to install.
|
||||||
* @param destDir Directory to extract to.
|
* @param destDir Directory to extract to.
|
||||||
* @param overwrite Allow overwrite of an existing gem folder.
|
* @param overwrite Allow overwrite of an existing gem folder.
|
||||||
|
*
|
||||||
|
* @deprecated Use the version that takes a {@Link ProjectOperations} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
static void extractGems(
|
static void extractGems(
|
||||||
Project project,
|
Project project,
|
||||||
File jRubyClasspath,
|
File jRubyClasspath,
|
||||||
FileCollection gems,
|
FileCollection gems,
|
||||||
File destDir,
|
File destDir,
|
||||||
GemOverwriteAction overwrite
|
GemOverwriteAction overwrite
|
||||||
|
) {
|
||||||
|
extractGems(ProjectOperations.find(project), jRubyClasspath, gems, destDir, overwrite)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extracts and install a collection of GEMs.
|
||||||
|
*
|
||||||
|
* @param project {@link ProjectOperations} instance.
|
||||||
|
* @param jRubyClasspath The path to the {@code jruby-complete} jar.
|
||||||
|
* @param gems GEMs to install.
|
||||||
|
* @param destDir Directory to extract to.
|
||||||
|
* @param overwrite Allow overwrite of an existing gem folder.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
static void extractGems(
|
||||||
|
ProjectOperations project,
|
||||||
|
File jRubyClasspath,
|
||||||
|
FileCollection gems,
|
||||||
|
File destDir,
|
||||||
|
GemOverwriteAction overwrite
|
||||||
) {
|
) {
|
||||||
Set<File> gemsToProcess = []
|
Set<File> gemsToProcess = []
|
||||||
Set<File> deletes = []
|
Set<File> deletes = []
|
||||||
|
@ -107,7 +154,7 @@ class GemUtils {
|
||||||
File extractDirForJava = new File(destDir, "gems/${gemName}-java")
|
File extractDirForJava = new File(destDir, "gems/${gemName}-java")
|
||||||
|
|
||||||
switch (overwrite) {
|
switch (overwrite) {
|
||||||
case SKIP:
|
case GemOverwriteAction.SKIP:
|
||||||
if (extractDir.exists() || extractDirForJava.exists()) {
|
if (extractDir.exists() || extractDirForJava.exists()) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -125,10 +172,10 @@ class GemUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gemsToProcess.size()) {
|
if (gemsToProcess.size()) {
|
||||||
deletes.each { project.delete it }
|
deletes.each { project.delete(it) }
|
||||||
destDir.mkdirs()
|
destDir.mkdirs()
|
||||||
|
|
||||||
project.logger.info("Installing ${gemsToProcess*.name.join(',')}")
|
log.info("Installing ${gemsToProcess*.name.join(',')}")
|
||||||
|
|
||||||
project.javaexec { JavaExecSpec spec ->
|
project.javaexec { JavaExecSpec spec ->
|
||||||
spec.with {
|
spec.with {
|
||||||
|
@ -189,13 +236,40 @@ class GemUtils {
|
||||||
* @param gemConfig Configuration containing GEMs
|
* @param gemConfig Configuration containing GEMs
|
||||||
* @param destDir Directory to extract to
|
* @param destDir Directory to extract to
|
||||||
* @param action Allow overwrite of an existing gem folder
|
* @param action Allow overwrite of an existing gem folder
|
||||||
|
* @deprecated Use the version that takes a {@Link ProjectOperations} instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
static void extractGems(
|
static void extractGems(
|
||||||
Project project,
|
Project project,
|
||||||
Configuration jRubyConfig,
|
Configuration jRubyConfig,
|
||||||
Configuration gemConfig,
|
Configuration gemConfig,
|
||||||
File destDir,
|
File destDir,
|
||||||
GemOverwriteAction action) {
|
GemOverwriteAction action) {
|
||||||
|
extractGems(
|
||||||
|
ProjectOperations.find(project),
|
||||||
|
jRubyConfig,
|
||||||
|
gemConfig,
|
||||||
|
destDir,
|
||||||
|
action
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Extract Gems from a given configuration.
|
||||||
|
*
|
||||||
|
* @param projectOperations Project instance
|
||||||
|
* @param jRubyClasspath Where to find the jruby-complete jar
|
||||||
|
* @param gemConfig Configuration containing GEMs
|
||||||
|
* @param destDir Directory to extract to
|
||||||
|
* @param action Allow overwrite of an existing gem folder
|
||||||
|
*
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
static void extractGems(
|
||||||
|
ProjectOperations projectOperations,
|
||||||
|
Configuration jRubyConfig,
|
||||||
|
Configuration gemConfig,
|
||||||
|
File destDir,
|
||||||
|
GemOverwriteAction action) {
|
||||||
|
|
||||||
Set<File> cp = jRubyConfig.files
|
Set<File> cp = jRubyConfig.files
|
||||||
File jRubyClasspath = cp.find { it.name.startsWith(JRUBY_ARCHIVE_NAME) }
|
File jRubyClasspath = cp.find { it.name.startsWith(JRUBY_ARCHIVE_NAME) }
|
||||||
|
@ -204,7 +278,7 @@ class GemUtils {
|
||||||
"Cannot find ${JRUBY_ARCHIVE_NAME}. Classpath contains ${cp.join(':')}"
|
"Cannot find ${JRUBY_ARCHIVE_NAME}. Classpath contains ${cp.join(':')}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
extractGems(project, jRubyClasspath, project.files(gemConfig.files), destDir, action)
|
extractGems(projectOperations, jRubyClasspath, projectOperations.files(gemConfig.files), destDir, action)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Write a JARs lock file if the content has changed.
|
/** Write a JARs lock file if the content has changed.
|
||||||
|
@ -325,27 +399,47 @@ class GemUtils {
|
||||||
* @param Additional properties to control behaviour
|
* @param Additional properties to control behaviour
|
||||||
* @param dir The source of the GEM files
|
* @param dir The source of the GEM files
|
||||||
* @return Returns a CopySpec which can be attached as a child to another object that implements a CopySpec
|
* @return Returns a CopySpec which can be attached as a child to another object that implements a CopySpec
|
||||||
* @since 0.1.2
|
* @since 0.1.2*
|
||||||
|
* @deprecated Use the version that takes a {@link ProjectOperations}.
|
||||||
*/
|
*/
|
||||||
@CompileDynamic
|
@Deprecated
|
||||||
static CopySpec gemCopySpec(Map properties = [:], Project project, Object dir) {
|
static CopySpec gemCopySpec(Map properties = [:], Project project, Object dir) {
|
||||||
|
gemCopySpec(properties, ProjectOperations.find(project), dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Adds a GEM CopySpec to an archive
|
||||||
|
*
|
||||||
|
* The following are supported as properties:
|
||||||
|
* <ul>
|
||||||
|
* <li>fullGem (boolean) - Copy all of the GEM content, not just a minimal subset</li>
|
||||||
|
* <li>subfolder (Object) - Adds an additional subfolder into the GEM
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param Additional properties to control behaviour
|
||||||
|
* @param dir The source of the GEM files
|
||||||
|
* @return Returns a CopySpec which can be attached as a child to another object that implements a CopySpec
|
||||||
|
* @since 1.0
|
||||||
|
*/
|
||||||
|
static CopySpec gemCopySpec(Map properties = [:], ProjectOperations projectOperations, Object dir) {
|
||||||
boolean fullGem = properties['fullGem']
|
boolean fullGem = properties['fullGem']
|
||||||
String subFolder = properties['subfolder']
|
String subFolder = properties['subfolder']
|
||||||
|
|
||||||
project.copySpec(new Action<CopySpec>() {
|
projectOperations.copySpec(new Action<CopySpec>() {
|
||||||
void execute(CopySpec spec) {
|
void execute(CopySpec spec) {
|
||||||
spec.with {
|
spec.with {
|
||||||
from(dir) {
|
from(dir) { CopySpec cs ->
|
||||||
include EVERYTHING
|
cs.with {
|
||||||
// TODO have some standard which is bin/*, gems/**
|
include EVERYTHING
|
||||||
// specifications/*
|
// TODO have some standard which is bin/*, gems/**
|
||||||
if (!fullGem) {
|
// specifications/*
|
||||||
exclude 'cache/**'
|
if (!fullGem) {
|
||||||
exclude 'gems/*/test/**'
|
exclude 'cache/**'
|
||||||
exclude 'gems/*/tests/**'
|
exclude 'gems/*/test/**'
|
||||||
exclude 'gems/*/spec/**'
|
exclude 'gems/*/tests/**'
|
||||||
exclude 'gems/*/specs/**'
|
exclude 'gems/*/spec/**'
|
||||||
exclude 'build_info'
|
exclude 'gems/*/specs/**'
|
||||||
|
exclude 'build_info'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (subFolder) {
|
if (subFolder) {
|
||||||
|
@ -356,6 +450,7 @@ class GemUtils {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
static CopySpec jarCopySpec(Project project, Object dir) {
|
static CopySpec jarCopySpec(Project project, Object dir) {
|
||||||
project.copySpec { CopySpec spec ->
|
project.copySpec { CopySpec spec ->
|
||||||
spec.with {
|
spec.with {
|
||||||
|
@ -364,6 +459,14 @@ class GemUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static CopySpec jarCopySpec(ProjectOperations projectOperations, Object dir) {
|
||||||
|
projectOperations.copySpec { CopySpec spec ->
|
||||||
|
spec.with {
|
||||||
|
from(dir) { include EVERYTHING }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static final String GEM = 'gem'
|
private static final String GEM = 'gem'
|
||||||
private static final String GEM_EXTENSION = '.gem'
|
private static final String GEM_EXTENSION = '.gem'
|
||||||
private static final String EVERYTHING = '**'
|
private static final String EVERYTHING = '**'
|
||||||
|
|
|
@ -28,6 +28,7 @@ import com.github.jrubygradle.api.gems.GemUtils
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.file.DuplicateFileCopyingException
|
import org.gradle.api.file.DuplicateFileCopyingException
|
||||||
import org.gradle.testfixtures.ProjectBuilder
|
import org.gradle.testfixtures.ProjectBuilder
|
||||||
|
import org.ysb33r.grolifant.api.core.ProjectOperations
|
||||||
import spock.lang.Specification
|
import spock.lang.Specification
|
||||||
|
|
||||||
import static com.github.jrubygradle.api.gems.GemOverwriteAction.FAIL
|
import static com.github.jrubygradle.api.gems.GemOverwriteAction.FAIL
|
||||||
|
@ -46,6 +47,7 @@ class GemUtilsSpec extends Specification {
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
project = ProjectBuilder.builder().build()
|
project = ProjectBuilder.builder().build()
|
||||||
|
ProjectOperations.maybeCreateExtension(project)
|
||||||
src = project.file('src')
|
src = project.file('src')
|
||||||
dest = project.file('dest')
|
dest = project.file('dest')
|
||||||
fakeGem = new File(src, 'gems/mygem-1.0')
|
fakeGem = new File(src, 'gems/mygem-1.0')
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
version=2.0.0
|
version=2.1.0-alpha.1
|
||||||
group=com.github.jruby-gradle
|
group=com.github.jruby-gradle
|
||||||
copyrightYear=2014-2020
|
copyrightYear=2014-2020
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ releaseBuild=false
|
||||||
targetCompatibility=1.8
|
targetCompatibility=1.8
|
||||||
sourceCompatibility=1.8
|
sourceCompatibility=1.8
|
||||||
|
|
||||||
|
grolifantVersion=1.0.0-alpha.1
|
||||||
jrubyVersion=9.2.9.0
|
jrubyVersion=9.2.9.0
|
||||||
jettyVersion=9.2.12.v20150709
|
jettyVersion=9.2.12.v20150709
|
||||||
bcprovVersion=1.46
|
bcprovVersion=1.46
|
||||||
|
|
|
@ -227,7 +227,7 @@ class JRubyJarTestKitSpec extends IntegrationSpecification {
|
||||||
|
|
||||||
private BuildResult build(String taskName, String... additionalTasks) {
|
private BuildResult build(String taskName, String... additionalTasks) {
|
||||||
writeBuildFile()
|
writeBuildFile()
|
||||||
List<String> tasks = ['-i', taskName]
|
List<String> tasks = ['-i', '-s', taskName]
|
||||||
tasks.addAll(additionalTasks)
|
tasks.addAll(additionalTasks)
|
||||||
gradleRunner(tasks).build()
|
gradleRunner(tasks).build()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue