From 1eb84da335f810a99d9128f46606fa32ca6dc1e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Fri, 29 Jan 2021 18:22:59 +0100 Subject: [PATCH 1/2] Enable strict validation --- build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build.gradle b/build.gradle index a1420692..a942b7ac 100644 --- a/build.gradle +++ b/build.gradle @@ -107,6 +107,11 @@ subprojects { ideReport.enabled = true ideReport.destination = file( "${project.codenarc.reportsDir}/${reportName}.ide.txt") } + + tasks.withType(ValidateTaskProperties) { validateTaskProperties -> + validateTaskProperties.failOnWarning = true + validateTaskProperties.enableStricterValidation = true + } } idea { From e07ddf817dbf5beff5efa264b31b82aa3d55c8a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=B3r=C3=A1nt=20Pint=C3=A9r?= Date: Mon, 8 Feb 2021 11:23:08 +0100 Subject: [PATCH 2/2] Fix problems with task properties --- .../jrubygradle/GenerateGradleRb.groovy | 10 ++++++++- .../com/github/jrubygradle/JRubyExec.groovy | 17 ++++++++++++-- .../api/core/AbstractJRubyPrepare.groovy | 22 ++++++++++++++++--- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/base-plugin/src/main/groovy/com/github/jrubygradle/GenerateGradleRb.groovy b/base-plugin/src/main/groovy/com/github/jrubygradle/GenerateGradleRb.groovy index b54a2dd8..170eb2be 100644 --- a/base-plugin/src/main/groovy/com/github/jrubygradle/GenerateGradleRb.groovy +++ b/base-plugin/src/main/groovy/com/github/jrubygradle/GenerateGradleRb.groovy @@ -32,6 +32,7 @@ import org.gradle.api.GradleException import org.gradle.api.file.FileCopyDetails import org.gradle.api.file.RelativePath import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.ysb33r.grolifant.api.StringUtils @@ -71,6 +72,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask { this.gemInstallDir = dir } + @Internal File getDestinationDir() { project.file(destinationDir) } @@ -85,10 +87,16 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask { StringUtils.stringize(baseName) } + @Internal File getGemInstallDir() { project.file(this.gemInstallDir) } + @Input + protected String getGemInstallDirPath() { + getGemInstallDir().absolutePath + } + @TaskAction @CompileDynamic @SuppressWarnings('DuplicateStringLiteral') @@ -96,7 +104,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask { Object source = getSourceFromResource() File destination = destinationFile().parentFile String path = classpathFromConfiguration(jruby.jrubyConfiguration).join(File.pathSeparator) - String gemDir = getGemInstallDir().absolutePath + String gemDir = getGemInstallDirPath() String bootstrapName = getBaseName() logger.info("GenerateGradleRb - source: ${source}, destination: ${destination}, baseName: ${baseName}") project.copy { diff --git a/base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy b/base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy index dd5be03c..abb142e3 100644 --- a/base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy +++ b/base-plugin/src/main/groovy/com/github/jrubygradle/JRubyExec.groovy @@ -29,9 +29,12 @@ import com.github.jrubygradle.internal.JRubyExecUtils import groovy.transform.CompileStatic import org.gradle.api.Task import org.gradle.api.artifacts.Configuration +import org.gradle.api.model.ReplacedBy import org.gradle.api.provider.Provider import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Internal import org.gradle.api.tasks.JavaExec +import org.gradle.api.tasks.LocalState import org.gradle.api.tasks.Optional import org.gradle.process.JavaExecSpec import org.gradle.util.GradleVersion @@ -89,8 +92,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec { /** Script to execute. * @return The path to the script (or {@code null} if not set) */ - @Optional - @Input + @Internal File getScript() { resolveScript(project, this.script) } @@ -175,6 +177,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec { * * @return Provider of GEM working directory. */ + @LocalState Provider getGemWorkDir() { Callable resolveGemWorkDir = { JRubyPluginExtension jpe -> ((JRubyPrepare) project.tasks.getByName(jpe.gemPrepareTaskName)).outputDir @@ -190,6 +193,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec { * */ @Deprecated + @ReplacedBy('jruby.jrubyVersion') String getJrubyVersion() { deprecated('Use jruby.getJrubyVersion() rather getJrubyVersion()') jruby.jrubyVersion @@ -306,6 +310,15 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec { throw notAllowed(USE_JVM_ARGS) } + /** Capture the path of the script as an input. + * @return the path of the script to execute. + */ + @Optional + @Input + protected String getScriptPath() { + getScript()?.path + } + private static UnsupportedOperationException notAllowed(final String msg) { return new UnsupportedOperationException(msg) } diff --git a/core-plugin/src/main/groovy/com/github/jrubygradle/api/core/AbstractJRubyPrepare.groovy b/core-plugin/src/main/groovy/com/github/jrubygradle/api/core/AbstractJRubyPrepare.groovy index 495b31ba..39124a8b 100644 --- a/core-plugin/src/main/groovy/com/github/jrubygradle/api/core/AbstractJRubyPrepare.groovy +++ b/core-plugin/src/main/groovy/com/github/jrubygradle/api/core/AbstractJRubyPrepare.groovy @@ -34,11 +34,13 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.PathSensitive import org.gradle.api.tasks.TaskAction 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.setupJars +import static org.gradle.api.tasks.PathSensitivity.ABSOLUTE /** Abstract base class for building custom tasks for preparing GEMs. * @@ -81,9 +83,24 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas /** All GEMs that have been supplied as dependencies. * * @return Collection of GEMs. + * + * @see #getGemsAsFileCollection() + * @deprecated Use {@link #getGemsAsFileCollection()} instead. */ - @InputFiles + @Deprecated FileCollection gemsAsFileCollection() { + gemsAsFileCollection + } + + /** All GEMs that have been supplied as dependencies. + * + * @return Collection of GEMs. + * + * @since 2.1.0 + */ + @InputFiles + @PathSensitive(ABSOLUTE) + FileCollection getGemsAsFileCollection() { return GemUtils.getGems(project.files(this.dependencies)) } @@ -94,7 +111,6 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas * * @param f One or more of file, directory, configuration or list of gems. */ - @Optional void dependencies(Object... f) { this.dependencies.addAll(f.toList()) } @@ -121,7 +137,7 @@ abstract class AbstractJRubyPrepare extends DefaultTask implements JRubyAwareTas void exec() { File out = getOutputDir() File jrubyJar = jrubyJarLocation.get() - extractGems(project, jrubyJar, gemsAsFileCollection(), out, SKIP) + extractGems(project, jrubyJar, gemsAsFileCollection, out, SKIP) dependencies.findAll { it instanceof Configuration