Skip to content

Commit

Permalink
Revert "Fix configuration cache for focus task and add a test for it"
Browse files Browse the repository at this point in the history
This reverts commit 23a8b15.
  • Loading branch information
Mexator committed Sep 10, 2024
1 parent b470222 commit 0e04149
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
package com.dropbox.focus

import java.io.Serializable
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault(because = "Not worth caching")
public abstract class CreateFocusSettingsTask : DefaultTask() {

@get:Input
protected abstract val projectDeps: SetProperty<DependentProjectInfo>

@get:Input
protected abstract val projectPath: Property<String>

@get:OutputFile
public abstract val settingsFile: RegularFileProperty

@get:OutputFile
public abstract val modulesToDirMapFile: RegularFileProperty

/**
* Project info required for focus.settings.gradle generation.
*/
protected data class DependentProjectInfo(
public val path: String,
public val projectDir: String,
): Serializable

init {
outputs.upToDateWhen { false }
}

@TaskAction
public fun createFocusSettings() {
val dependencies = projectDeps.get().sortedBy { it.path }
val dependencies = project.collectDependencies().sortedBy { it.path }

// generate CSV mapping from module name to its absolute path
modulesToDirMapFile.get().asFile.writer().use { writer ->
Expand All @@ -55,7 +37,7 @@ public abstract class CreateFocusSettingsTask : DefaultTask() {
}

settingsFile.get().asFile.writer().use { writer ->
writer.write("// ${projectPath.get()} specific settings\n")
writer.write("// ${project.path} specific settings\n")
writer.appendLine("//")
writer.appendLine("// This file is autogenerated by the focus task. Changes will be overwritten.")
writer.appendLine()
Expand All @@ -78,12 +60,11 @@ public abstract class CreateFocusSettingsTask : DefaultTask() {
}
}

private fun Project.collectDependencies(): Set<DependentProjectInfo> {
val result = mutableSetOf<DependentProjectInfo>()
private fun Project.collectDependencies(): Set<Project> {
val result = mutableSetOf<Project>()
fun addDependent(project: Project) {
val configuredProject = this.evaluationDependsOn(project.path)
val dep = DependentProjectInfo(project.path, project.projectDir.absolutePath)
if (result.add(dep)) {
if (result.add(configuredProject)) {
configuredProject.configurations.forEach { config ->
config.dependencies
.filterIsInstance<ProjectDependency>()
Expand All @@ -102,10 +83,7 @@ public abstract class CreateFocusSettingsTask : DefaultTask() {
group = FOCUS_TASK_GROUP
settingsFile.set(subExtension.focusSettingsFile)
modulesToDirMapFile.set(subExtension.moduleToDirMapFile)
projectPath.set(project.path)
// Collecting dependencies info in the configuration phase.
// Gradle disallows accessing project in execution phase.
projectDeps.set(project.collectDependencies())
notCompatibleWithConfigurationCache("This reads configurations from the project at action-time.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,7 @@ class FocusPluginTest {
}

@Test
fun configurationCache_focus() {
val fixtureRoot = File("src/test/projects/configuration-cache-compatible")

gradleRunner
.withArguments("--configuration-cache", "focus")
.withProjectDir(fixtureRoot)
.build()

val result = gradleRunner
.withArguments("--configuration-cache", "focus")
.withProjectDir(fixtureRoot)
.build()

assertThat(result.output).contains("Reusing configuration cache.")
}

@Test
fun configurationCache_clear() {
fun configurationCache() {
val fixtureRoot = File("src/test/projects/configuration-cache-compatible")

gradleRunner
Expand Down

0 comments on commit 0e04149

Please sign in to comment.