Skip to content

Commit

Permalink
LocateDependenciesTask can be up to date.
Browse files Browse the repository at this point in the history
  • Loading branch information
autonomousapps committed Oct 18, 2021
1 parent 34f08f6 commit 92910c8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ charset = utf-8
# end_of_line = lf
indent_size = 2
indent_style = space
# insert_final_newline = false
max_line_length = 100
insert_final_newline = true
max_line_length = 120
# tab_width = 4
ij_continuation_indent_size = 2
# ij_formatter_off_tag = @formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ internal class ConfigurationsToDependenciesTransformer(

companion object {
private val DEFAULT_CONFS = listOf(
// Main configurations
"api",
"implementation",
// Deprecated, removed in Gradle 7
"compile",
"compileOnly",
"compileOnly",
//"compileOnlyApi", // TODO
"runtimeOnly",

// Test configurations
"testRuntimeOnly",
"testImplementation",
"testCompileOnly"
"testCompileOnly",
)
private val DEFAULT_PROC_CONFS = listOf("kapt", "annotationProcessor")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal fun ComponentIdentifier.resolvedVersion(): String? = when (this) {
* [ComponentIdentifier.toIdentifier].
*/
internal fun DependencySet.toIdentifiers(
metadataSink: MutableMap<String, Boolean>
metadataSink: MutableMap<String, Boolean> = mutableMapOf()
): Set<String> = mapNotNullToSet {
it.toIdentifier(metadataSink)
}
Expand Down
21 changes: 9 additions & 12 deletions src/main/kotlin/com/autonomousapps/subplugin/ProjectPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,25 +370,22 @@ internal class ProjectPlugin(private val project: Project) {
* Subproject tasks are registered here. This function is called in a loop, once for each Android
* variant or Java source set.
*/
private fun <T : ClassAnalysisTask> Project.analyzeDependencies(
dependencyAnalyzer: DependencyAnalyzer<T>
) {
private fun <T : ClassAnalysisTask> Project.analyzeDependencies(dependencyAnalyzer: DependencyAnalyzer<T>) {
val flavorName: String? = dependencyAnalyzer.flavorName
val variantName = dependencyAnalyzer.variantName
val buildType = dependencyAnalyzer.buildType
val variantTaskName = dependencyAnalyzer.variantNameCapitalized
val outputPaths = OutputPaths(this, variantName)

// Produces a report of all declared dependencies and the configurations on which they are
// declared
val locateDependencies =
tasks.register<LocateDependenciesTask>("locateDependencies$variantTaskName") {
this@register.flavorName.set(flavorName)
this@register.variantName.set(variantName)
this@register.buildType.set(buildType)
// Produces a report of all declared dependencies and the configurations on which they are declared
val locateDependencies = tasks.register<LocateDependenciesTask>("locateDependencies$variantTaskName") {
this@register.flavorName.set(flavorName)
this@register.variantName.set(variantName)
this@register.buildType.set(buildType)
this@register.configurations = this@analyzeDependencies.configurations

output.set(outputPaths.locationsPath)
}
output.set(outputPaths.locationsPath)
}

// Produces a report that lists all direct and transitive dependencies, their artifacts
val artifactsReportTask =
Expand Down
29 changes: 14 additions & 15 deletions src/main/kotlin/com/autonomousapps/tasks/LocateDependenciesTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@ package com.autonomousapps.tasks
import com.autonomousapps.TASK_GROUP_DEP_INTERNAL
import com.autonomousapps.internal.ConfigurationsToDependenciesTransformer
import com.autonomousapps.internal.utils.getAndDelete
import com.autonomousapps.internal.utils.toIdentifiers
import com.autonomousapps.internal.utils.toJson
import org.gradle.api.DefaultTask
import org.gradle.api.artifacts.ConfigurationContainer
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.*

abstract class LocateDependenciesTask : DefaultTask() {

init {
group = TASK_GROUP_DEP_INTERNAL
description =
"Produces a report of all dependencies and the configurations on which they are declared"

// This task can never be up to date because we do not yet know a way to model having the
// configurations themselves (not the files they resolve to!) as an input
// TODO May no longer be necessary now that an input is the resolved dependencies
outputs.upToDateWhen { false }
description = "Produces a report of all dependencies and the configurations on which they are declared"
}

@get:Optional
Expand All @@ -36,9 +29,15 @@ abstract class LocateDependenciesTask : DefaultTask() {
@get:Input
abstract val variantName: Property<String>

// For up to date correctness
// @get:Classpath
// abstract val compileClasspathArtifacts: ConfigurableFileCollection
@get:Internal
lateinit var configurations: ConfigurationContainer

@Input
fun getDeclaredDependencies(): Map<String, Set<String>> {
return configurations.asMap.map { (name, conf) ->
name to conf.dependencies.toIdentifiers()
}.toMap()
}

/*
* Outputs
Expand All @@ -54,7 +53,7 @@ abstract class LocateDependenciesTask : DefaultTask() {
flavorName = flavorName.orNull,
buildType = buildType.orNull,
variantName = variantName.get(),
configurations = project.configurations
configurations = configurations
).locations()

outputFile.writeText(locations.toJson())
Expand Down

0 comments on commit 92910c8

Please sign in to comment.