Skip to content

Commit

Permalink
Merge pull request #419 from lptr/lptr/fix-validation-warnings-2.0
Browse files Browse the repository at this point in the history
Fix task property annotation problems for 2.0
  • Loading branch information
ysb33r authored Feb 8, 2021
2 parents 553702e + e07ddf8 commit c737ee0
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,6 +72,7 @@ class GenerateGradleRb extends DefaultTask implements JRubyAwareTask {
this.gemInstallDir = dir
}

@Internal
File getDestinationDir() {
project.file(destinationDir)
}
Expand All @@ -85,18 +87,24 @@ 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')
void generate() {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -175,6 +177,7 @@ class JRubyExec extends JavaExec implements JRubyAwareTask, JRubyExecSpec {
*
* @return Provider of GEM working directory.
*/
@LocalState
Provider<File> getGemWorkDir() {
Callable<File> resolveGemWorkDir = { JRubyPluginExtension jpe ->
((JRubyPrepare) project.tasks.getByName(jpe.gemPrepareTaskName)).outputDir
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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))
}

Expand All @@ -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())
}
Expand All @@ -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
Expand Down

0 comments on commit c737ee0

Please sign in to comment.