Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Uses Provider<ResolvedComponentResult> as input to Task #70

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## Version 0.4.1 ([All Changes](https://github.com/dropbox/dependency-guard/compare/0.4.0...0.4.1))

_2023-01-23_

* Fixes [#67](https://github.com/dropbox/dependency-guard/issues/67): Configuration Cache by [@handstandsam](https://github.com/handstandsam) in [#70](https://github.com/dropbox/dependency-guard/pull/70)
* Compatibility: **Requires Gradle 7.4 or Higher** in order to support Configuration Cache.

## Version 0.4.0 ([All Changes](https://github.com/dropbox/dependency-guard/compare/0.3.2...0.4.0))

_2023-01-17_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class GradleVersionArgumentsProvider : ArgumentsProvider {

override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> = Stream
.of(
ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.3.3"), withConfigurationCache = false),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test fails for 7.3 because resolutionRoot is not available in this version.

ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.4.2"), withConfigurationCache = false),
ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.4.2"), withConfigurationCache = true),
ParameterizedPluginArgs(gradleVersion = GradleVersion.version("7.5.1"), withConfigurationCache = false),
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,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not required in this diff, but is zero risk and slightly more explicit.

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 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were using the return at the end of the if block, but if/else reads better IMO as this is an exahaustive if/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 @@ -4,6 +4,7 @@ import com.dropbox.gradle.plugins.dependencyguard.DependencyGuardPlugin
import org.gradle.api.Project
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.artifacts.result.ResolvedComponentResult
import org.gradle.api.provider.Provider

internal fun Project.isRootProject(): Boolean = this == rootProject

Expand All @@ -19,8 +20,8 @@ internal val Project.projectConfigurations: ConfigurationContainer
configurations
}

internal fun ConfigurationContainer.getResolvedComponentResult(name: String): ResolvedComponentResult = this
internal fun ConfigurationContainer.getResolvedComponentResult(name: String): Provider<ResolvedComponentResult> = this
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using recommended pattern in Config Cache Documentation: https://docs.gradle.org/current/userguide/configuration_cache.html
Screen Shot 2023-01-23 at 10 17 39 AM

.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>>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using recommended pattern in Config Cache Documentation: https://docs.gradle.org/current/userguide/configuration_cache.html
Screen Shot 2023-01-23 at 10 17 39 AM


@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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.result.ResolvedComponentResult
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