Skip to content

Commit

Permalink
Merge pull request #92 from unbroken-dome/fix/gradle-5.2-compat
Browse files Browse the repository at this point in the history
Gradle compatibility: ConfigurableFileCollection factory method
  • Loading branch information
tkrullmann authored Oct 6, 2020
2 parents 547f229 + 1243935 commit e0e635a
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import groovy.lang.Closure
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Provider
import org.gradle.api.resources.TextResource
import org.gradle.util.GradleVersion
import org.slf4j.LoggerFactory
import org.unbrokendome.gradle.plugins.helm.util.GRADLE_VERSION_5_3
import org.unbrokendome.gradle.plugins.helm.util.mapProperty
import java.util.concurrent.Callable

Expand Down Expand Up @@ -72,11 +75,15 @@ internal data class HelmValueOptionsHolder(
override val valueFiles: ConfigurableFileCollection
) : ConfigurableHelmValueOptions {

constructor(objects: ObjectFactory)
: this(
constructor(objects: ObjectFactory, layout: ProjectLayout) : this(
values = objects.mapProperty(),
fileValues = objects.mapProperty(),
valueFiles = objects.fileCollection()
valueFiles = if (GradleVersion.current() >= GRADLE_VERSION_5_3) {
objects.fileCollection()
} else {
@Suppress("DEPRECATION")
layout.configurableFiles()
}
)
}

Expand Down Expand Up @@ -120,17 +127,17 @@ internal object HelmValueOptionsApplier : HelmOptionsApplier {

private fun buildFileValuesArg(options: HelmValueOptions): String =
options.fileValues.getOrElse(emptyMap())
.entries
.joinToString(separator = ",") { (key, value) ->
val valueRepresentation = when (val resolvedValue = resolveValue(value)) {
is FileCollection -> resolvedValue.singleFile
is TextResource -> resolvedValue.asFile()
else -> resolvedValue
}

"$key=$valueRepresentation"
.entries
.joinToString(separator = ",") { (key, value) ->
val valueRepresentation = when (val resolvedValue = resolveValue(value)) {
is FileCollection -> resolvedValue.singleFile
is TextResource -> resolvedValue.asFile()
else -> resolvedValue
}

"$key=$valueRepresentation"
}

private fun resolveValue(value: Any?): Any? =
when (value) {
is Provider<*> -> resolveValue(value.orNull)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ 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.util.GradleVersion
import org.unbrokendome.gradle.plugins.helm.command.ConfigurableHelmInstallFromRepositoryOptions
import org.unbrokendome.gradle.plugins.helm.command.ConfigurableHelmValueOptions
import org.unbrokendome.gradle.plugins.helm.command.HelmExecProviderSupport
import org.unbrokendome.gradle.plugins.helm.command.HelmInstallFromRepositoryOptionsApplier
import org.unbrokendome.gradle.plugins.helm.command.HelmInstallationOptionsApplier
import org.unbrokendome.gradle.plugins.helm.command.HelmValueOptionsApplier
import org.unbrokendome.gradle.plugins.helm.util.GRADLE_VERSION_5_3
import org.unbrokendome.gradle.plugins.helm.util.mapProperty
import org.unbrokendome.gradle.plugins.helm.util.property
import java.io.File
Expand Down Expand Up @@ -206,7 +208,12 @@ abstract class AbstractHelmInstallationCommandTask :
*/
@get:InputFiles
final override val valueFiles: ConfigurableFileCollection =
project.objects.fileCollection()
if (GradleVersion.current() >= GRADLE_VERSION_5_3) {
project.objects.fileCollection()
} else {
@Suppress("DEPRECATION")
project.layout.configurableFiles()
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.SkipWhenEmpty
import org.gradle.api.tasks.TaskAction
import org.gradle.util.GFileUtils
import org.gradle.util.GradleVersion
import org.unbrokendome.gradle.plugins.helm.command.ConfigurableHelmValueOptions
import org.unbrokendome.gradle.plugins.helm.command.HelmExecProviderSupport
import org.unbrokendome.gradle.plugins.helm.command.HelmValueOptionsApplier
import org.unbrokendome.gradle.plugins.helm.util.GRADLE_VERSION_5_3
import org.unbrokendome.gradle.plugins.helm.util.ifPresent
import org.unbrokendome.gradle.plugins.helm.util.mapProperty
import org.unbrokendome.gradle.plugins.helm.util.property
Expand Down Expand Up @@ -81,7 +83,12 @@ open class HelmLint : AbstractHelmCommandTask(), ConfigurableHelmValueOptions {
*/
@get:InputFiles
final override val valueFiles: ConfigurableFileCollection =
project.objects.fileCollection()
if (GradleVersion.current() >= GRADLE_VERSION_5_3) {
project.objects.fileCollection()
} else {
@Suppress("DEPRECATION")
project.layout.configurableFiles()
}


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package org.unbrokendome.gradle.plugins.helm.dsl

import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.util.GradleVersion
import org.unbrokendome.gradle.plugins.helm.util.GRADLE_VERSION_5_3
import org.unbrokendome.gradle.plugins.helm.util.mapProperty
import org.unbrokendome.gradle.plugins.helm.util.property
import javax.inject.Inject
Expand Down Expand Up @@ -70,7 +73,10 @@ private interface LintingInternal : Linting, Hierarchical<Linting>
* Default implementation of [Linting].
*/
private open class DefaultLinting
@Inject constructor(objectFactory: ObjectFactory) : LintingInternal {
@Inject constructor(
objectFactory: ObjectFactory,
projectLayout: ProjectLayout
) : LintingInternal {

final override val enabled: Property<Boolean> =
objectFactory.property<Boolean>()
Expand All @@ -86,7 +92,13 @@ private open class DefaultLinting
objectFactory.mapProperty()

final override val valueFiles: ConfigurableFileCollection =
objectFactory.fileCollection()
if (GradleVersion.current() >= GRADLE_VERSION_5_3) {
objectFactory.fileCollection()
} else {
@Suppress("DEPRECATION")
projectLayout.configurableFiles()
}


final override fun setParent(parent: Linting) {
enabled.set(parent.enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.gradle.api.Task
import org.gradle.api.file.Directory
import org.gradle.api.file.FileCollection
import org.gradle.api.file.RegularFile
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtensionContainer
import org.gradle.api.provider.ListProperty
Expand Down Expand Up @@ -434,24 +433,23 @@ internal interface HelmReleaseInternal {


private abstract class AbstractHelmRelease(
objects: ObjectFactory,
private val name: String,
protected val project: Project
) : Named, HelmReleaseProperties,
ConfigurableHelmInstallFromRepositoryOptions by HelmInstallFromRepositoryOptionsHolder(objects),
ConfigurableHelmValueOptions by HelmValueOptionsHolder(objects) {
ConfigurableHelmInstallFromRepositoryOptions by HelmInstallFromRepositoryOptionsHolder(project.objects),
ConfigurableHelmValueOptions by HelmValueOptionsHolder(project.objects, project.layout) {

override fun getName(): String =
name


final override val releaseName: Property<String> =
objects.property<String>()
project.objects.property<String>()
.convention(name)


final override val chart: Property<ChartReference> =
objects.property()
project.objects.property()


final override fun from(notation: Any) {
Expand Down Expand Up @@ -497,18 +495,18 @@ private abstract class AbstractHelmRelease(


final override val replace: Property<Boolean> =
objects.property<Boolean>()
project.objects.property<Boolean>()
.convention(false)


final override val keepHistoryOnUninstall: Property<Boolean> =
objects.property<Boolean>()
project.objects.property<Boolean>()
.convention(false)


@Suppress("OverridingDeprecatedMember")
final override val dependsOn: SetProperty<String> =
objects.setProperty()
project.objects.setProperty()


final override val installDependsOn: MutableSet<Any> = mutableSetOf()
Expand All @@ -521,10 +519,9 @@ private abstract class AbstractHelmRelease(

private open class DefaultHelmRelease
@Inject constructor(
objects: ObjectFactory,
name: String,
project: Project
) : AbstractHelmRelease(objects, name, project), HelmRelease, HelmReleaseInternal {
) : AbstractHelmRelease(name, project), HelmRelease, HelmReleaseInternal {

private val targetSpecificActions = mutableMapOf<String, Action<HelmRelease.TargetSpecific>>()
private val targetSpecificCache: MutableMap<String, HelmReleaseProperties> = ConcurrentHashMap()
Expand All @@ -534,7 +531,7 @@ private open class DefaultHelmRelease


override val valuesDirs: ListProperty<File> =
objects.listProperty()
project.objects.listProperty()


override fun valuesDirs(directories: Iterable<Any>) {
Expand Down Expand Up @@ -592,7 +589,7 @@ private open class DefaultHelmRelease

logger.info("Constructing target-specific release \"{}\" for target \"{}\"", this.name, target.name)

return TargetSpecific(project.objects, name, project, target).also { targetSpecific ->
return TargetSpecific(name, project, target).also { targetSpecific ->

// Call setFrom(HelmInstallFromRepositoryOptions) to assign all the options properties that only exist
// on HelmRelease, but not on HelmReleaseTarget
Expand Down Expand Up @@ -646,11 +643,10 @@ private open class DefaultHelmRelease


private class TargetSpecific(
objects: ObjectFactory,
name: String,
project: Project,
override val target: HelmReleaseTarget
) : AbstractHelmRelease(objects, name, project), HelmRelease.TargetSpecific
) : AbstractHelmRelease(name, project), HelmRelease.TargetSpecific
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.gradle.api.Named
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.Project
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.ProjectLayout
import org.gradle.api.model.ObjectFactory
import org.gradle.api.plugins.ExtensionAware
import org.gradle.api.plugins.ExtensionContainer
Expand Down Expand Up @@ -84,10 +85,11 @@ private open class DefaultHelmReleaseTarget
@Inject constructor(
private val name: String,
private val globalSelectTagsExpression: TagExpression,
objects: ObjectFactory
objects: ObjectFactory,
layout: ProjectLayout
) : HelmReleaseTarget, HelmReleaseTargetInternal,
ConfigurableHelmInstallationOptions by HelmInstallationOptionsHolder(objects),
ConfigurableHelmValueOptions by HelmValueOptionsHolder(objects) {
ConfigurableHelmValueOptions by HelmValueOptionsHolder(objects, layout) {

private var localSelectTagsExpression: TagExpression =
TagExpression.alwaysMatch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.unbrokendome.gradle.plugins.helm.util
import org.gradle.util.GradleVersion


internal val GRADLE_VERSION_5_3 = GradleVersion.version("5.3")
internal val GRADLE_VERSION_5_6 = GradleVersion.version("5.6")
internal val GRADLE_VERSION_6_0 = GradleVersion.version("6.0")
internal val GRADLE_VERSION_6_2 = GradleVersion.version("6.2")

0 comments on commit e0e635a

Please sign in to comment.