Skip to content

Commit

Permalink
Following documentation on config cache https://docs.gradle.org/curre…
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Jan 23, 2023
1 parent 54eee41 commit 294b917
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion dependency-guard/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ testing {
useJUnitJupiter()
dependencies {
// gradleTest test suite depends on the production code in tests
implementation(project)
implementation(project(project.path))
implementation(libs.truth)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ public class DependencyGuardPlugin : Plugin<Project> {
internal companion object {
internal const val DEPENDENCY_GUARD_TASK_GROUP = "Dependency Guard"

internal const val DEPENDENCY_GUARD_EXTENSION_NAME = "dependencyGuard"

internal const val DEPENDENCY_GUARD_TASK_NAME = "dependencyGuard"

internal const val DEPENDENCY_GUARD_BASELINE_TASK_NAME = "dependencyGuardBaseline"
}

override fun apply(target: Project) {
val extension = target.extensions.create(
DEPENDENCY_GUARD_TASK_NAME,
DEPENDENCY_GUARD_EXTENSION_NAME,
DependencyGuardPluginExtension::class.java,
target.objects
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ internal object ConfigurationValidators {
}.toString()
throw GradleException(message)
}
return
}
val configurationNames = monitoredConfigurations.map { it.configurationName }
require(configurationNames.isNotEmpty() && configurationNames[0].isNotBlank()) {
StringBuilder().apply {
appendLine("Error: No configurations provided to Dependency Guard Plugin.")
appendLine("Here are some valid configurations you could use.")
appendLine("")
val availableConfigNames = availableConfigurations
.filter { isClasspathConfig(it) }
} else {
val configurationNames = monitoredConfigurations.map { it.configurationName }
require(configurationNames.isNotEmpty() && configurationNames[0].isNotBlank()) {
StringBuilder().apply {
appendLine("Error: No configurations provided to Dependency Guard Plugin.")
appendLine("Here are some valid configurations you could use.")
appendLine("")
val availableConfigNames = availableConfigurations
.filter { isClasspathConfig(it) }

appendLine("dependencyGuard {")
availableConfigNames.forEach {
appendLine(""" configuration("$it")""")
}
appendLine("}")
}.toString()
appendLine("dependencyGuard {")
availableConfigNames.forEach {
appendLine(""" configuration("$it")""")
}
appendLine("}")
}.toString()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ internal val Project.projectConfigurations: ConfigurationContainer
configurations
}

internal fun ConfigurationContainer.getResolvedComponentResult(name: String): ResolvedComponentResult = this
internal fun ConfigurationContainer.getResolvedComponentResult(name: String): Provider<ResolvedComponentResult> = this
.getByName(name)
.incoming
.resolutionResult
.root
.rootComponent
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.MapProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction

Expand Down Expand Up @@ -57,7 +58,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() {
abstract val projectPath: Property<String>

@get:Input
abstract val monitoredConfigurationsMap: MapProperty<DependencyGuardConfiguration, ResolvedComponentResult>
abstract val monitoredConfigurationsMap: MapProperty<DependencyGuardConfiguration, Provider<ResolvedComponentResult>>

@get:Input
abstract val buildDirectory: DirectoryProperty
Expand All @@ -70,7 +71,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() {
internal fun execute() {
val dependencyGuardConfigurations = monitoredConfigurationsMap.get()

val reports = dependencyGuardConfigurations.map { generateReportForConfiguration(it.key, it.value) }
val reports = dependencyGuardConfigurations.map { generateReportForConfiguration(it.key, it.value.get()) }

// Throw Error if any Disallowed Dependencies are Found
val reportsWithDisallowedDependencies = reports.filter { it.disallowed.isNotEmpty() }
Expand Down Expand Up @@ -184,7 +185,7 @@ internal abstract class DependencyGuardListTask : DefaultTask() {
private fun resolveMonitoredConfigurationsMap(
project: Project,
monitoredConfigurations: Collection<DependencyGuardConfiguration>,
): Map<DependencyGuardConfiguration, ResolvedComponentResult> {
): Map<DependencyGuardConfiguration, Provider<ResolvedComponentResult>> {
val configurationContainer = project.projectConfigurations

return monitoredConfigurations.associateWith {
Expand Down

0 comments on commit 294b917

Please sign in to comment.