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

Configuration cache 7.4.2 #58

Closed
wants to merge 15 commits into from
Closed
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
10 changes: 0 additions & 10 deletions dependencies/classpath.tree.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@

------------------------------------------------------------
Root project 'dependency-guard-root'
------------------------------------------------------------

classpath
+--- org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10
| +--- org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.6.10
| | +--- org.jetbrains.kotlin:kotlin-native-utils:1.6.10
Expand Down Expand Up @@ -405,7 +399,3 @@ classpath
| +--- org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32 -> 1.5.0 (*)
| \--- org.ow2.asm:asm:9.1
\--- com.dropbox.dependency-guard:dependency-guard -> project :dependency-guard

(*) - dependencies omitted (listed previously)

A web-based, searchable dependency report is available by adding the --scan option.
8 changes: 0 additions & 8 deletions dependency-guard/api/dependency-guard.api
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,3 @@ public class com/dropbox/gradle/plugins/dependencyguard/DependencyGuardPluginExt
public final fun configuration (Ljava/lang/String;Lorg/gradle/api/Action;)V
}

public abstract class com/dropbox/gradle/plugins/dependencyguard/internal/list/DependencyGuardListTask : org/gradle/api/DefaultTask {
public fun <init> ()V
public abstract fun getAvailableConfigurations ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getForRootProject ()Lorg/gradle/api/provider/Property;
public abstract fun getMonitoredConfigurations ()Lorg/gradle/api/provider/ListProperty;
public abstract fun getShouldBaseline ()Lorg/gradle/api/provider/Property;
}

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.dropbox.gradle.plugins.dependencyguard

import com.dropbox.gradle.plugins.dependencyguard.fixture.Builder.build
import com.dropbox.gradle.plugins.dependencyguard.fixture.Builder.buildAndFail
import com.dropbox.gradle.plugins.dependencyguard.fixture.ConfiguredProject
import com.dropbox.gradle.plugins.dependencyguard.fixture.FullProject
import com.dropbox.gradle.plugins.dependencyguard.fixture.SimpleProject
import com.dropbox.gradle.plugins.dependencyguard.util.exists
import com.dropbox.gradle.plugins.dependencyguard.util.readLines
import com.dropbox.gradle.plugins.dependencyguard.util.readText
import com.dropbox.gradle.plugins.dependencyguard.util.assertFileExistsWithContentEqual
import com.dropbox.gradle.plugins.dependencyguard.util.replaceText
import com.google.common.truth.Truth.assertThat
import org.gradle.testkit.runner.BuildResult
import org.gradle.util.GradleVersion
import org.junit.jupiter.api.Test

class PluginTest {
Expand All @@ -19,48 +19,234 @@ class PluginTest {
args = arrayOf(":lib:dependencyGuard")
)

validateBuild(project, result)
// verify baseline
assertThat(result.output)
.contains("Dependency Guard baseline created for :lib for configuration compileClasspath.")
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "simple/list_before_update.txt",
)
// verify tree baseline
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.tree.txt",
contentFile = "simple/tree_before_update.txt",
)
// verify configuration-cache related stuff
assertThat(result.output)
.contains("Calculating task graph as no configuration cache is available for tasks: :lib:dependencyGuard")
assertThat(result.output)
.contains("Configuration cache entry stored.")
}

@Test
fun `doesn't fall over when configuration cache is used`(): Unit = SimpleProject().use { project ->
fun `guard with no dependencies changes`(): Unit = SimpleProject().use { project ->
// create baseline
build(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

// check with no dependencies changes
val result = build(
project = project,
// Gradle 7.4 is the minimum version for which this feature is relevant
gradleVersion = GradleVersion.version("7.4"),
args = arrayOf(":lib:dependencyGuard", "--configuration-cache")
args = arrayOf(":lib:dependencyGuard")
)

validateBuild(project, result)
assertThat(result.output)
.contains("No Dependency Changes Found in :lib for configuration \"compileClasspath\"")

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "simple/list_before_update.txt",
)

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.tree.txt",
contentFile = "simple/tree_before_update.txt",
)
}

@Test
fun `guard after dependencies tree changes`(): Unit = SimpleProject().use { project ->
// create baseline
build(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

project.lib.resolve("build.gradle").replaceText(
oldValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.4'",
newValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.5'",
)

// check after dependencies changes
val result = buildAndFail(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

assertThat(result.output).contains("Dependency Tree comparison to baseline does not match.")
assertThat(result.output).contains(
"""
***** DEPENDENCY CHANGE DETECTED *****
-\--- io.reactivex.rxjava3:rxjava:3.1.4
- \--- org.reactivestreams:reactive-streams:1.0.3
+\--- io.reactivex.rxjava3:rxjava:3.1.5
+ \--- org.reactivestreams:reactive-streams:1.0.4
""".trimIndent()
)

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "simple/list_before_update.txt",
)

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.tree.txt",
contentFile = "simple/tree_before_update.txt",
)
}

@Test
fun `guard after dependencies list changes`(): Unit = SimpleProject(tree = false).use { project ->
// create baseline
build(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

project.lib.resolve("build.gradle").replaceText(
oldValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.4'",
newValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.5'",
)

// check after dependencies changes
val result = buildAndFail(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

// verify configuration-cache related stuff
assertThat(result.output)
.contains("Calculating task graph as no configuration cache is available for tasks: :lib:dependencyGuard")
.contains(
"""
> Dependencies Changed in :lib for configuration compileClasspath
- io.reactivex.rxjava3:rxjava:3.1.4
+ io.reactivex.rxjava3:rxjava:3.1.5
- org.reactivestreams:reactive-streams:1.0.3
+ org.reactivestreams:reactive-streams:1.0.4

If this is intentional, re-baseline using ./gradlew :lib:dependencyGuardBaseline
""".trimIndent()
)

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "simple/list_before_update.txt",
)
}

@Test
fun `baseline after dependencies changes`(): Unit = SimpleProject().use { project ->
// create baseline
build(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

project.lib.resolve("build.gradle").replaceText(
oldValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.4'",
newValue = "implementation 'io.reactivex.rxjava3:rxjava:3.1.5'",
)

// check after dependencies changes
val result = build(
project = project,
args = arrayOf(":lib:dependencyGuardBaseline")
)

assertThat(result.output)
.contains("problems were found storing the configuration cache")
// There is also the implicit test that the build succeeded, despite these problems.
.contains("Dependency Guard baseline created for :lib for configuration compileClasspath")

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "simple/list_after_update.txt",
)

project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.tree.txt",
contentFile = "simple/tree_after_update.txt",
)
}

private fun validateBuild(project: SimpleProject, result: BuildResult) {
@Test
fun `can generate full report baseline`(): Unit = FullProject().use { project ->
val result = build(
project = project,
args = arrayOf("dependencyGuard")
)

// verify baseline
assertThat(result.output)
.contains("Dependency Guard baseline created for :lib for configuration compileClasspath.")
assertThat(result.output).contains("Dependency Guard baseline created for : for configuration classpath.")
assertThat(result.output).contains("Dependency Guard baseline created for :lib for configuration compileClasspath.")
assertThat(result.output).contains("Dependency Guard baseline created for :lib for configuration testCompileClasspath.")
assertThat(result.output).contains("Dependency Guard Tree baseline created for : for configuration classpath.")
assertThat(result.output).contains("Dependency Guard Tree baseline created for :lib for configuration compileClasspath.")
assertThat(result.output).contains("Dependency Guard Tree baseline created for :lib for configuration testCompileClasspath.")

val baseline = project.projectFile("lib/dependencies/compileClasspath.txt")
assertThat(baseline.exists()).isTrue()
project.assertFileExistsWithContentEqual(
filename = "dependencies/classpath.txt",
contentFile = "full/root_list.txt",
)
project.assertFileExistsWithContentEqual(
filename = "dependencies/classpath.tree.txt",
contentFile = "full/root_tree.txt",
)
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.txt",
contentFile = "full/lib_compile_list.txt",
)
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/compileClasspath.tree.txt",
contentFile = "full/lib_compile_tree.txt",
)
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/testCompileClasspath.txt",
contentFile = "full/lib_test_compile_list.txt",
)
project.assertFileExistsWithContentEqual(
filename = "lib/dependencies/testCompileClasspath.tree.txt",
contentFile = "full/lib_test_compile_tree.txt",
)

val lines = baseline.readLines()
assertThat(lines).hasSize(1)
assertThat(lines.single()).isEqualTo("commons-io:commons-io:2.11.0")
// verify configuration cache is supported
assertThat(result.output).contains("Calculating task graph as no configuration cache is available for tasks: dependencyGuard")
assertThat(result.output).contains("Configuration cache entry stored.")
}

// verify tree baseline
val treeBaseline = project.projectFile("lib/dependencies/compileClasspath.tree.txt")
assertThat(treeBaseline.exists()).isTrue()
assertThat(treeBaseline.readText()).contains(
"""
compileClasspath - Compile classpath for source set 'main'.
\--- commons-io:commons-io:2.11.0
""".trimIndent()
@Test
fun `prints error when no configuration found`(): Unit = ConfiguredProject(
configurations = emptyList(),
).use { project ->
val result = buildAndFail(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

assertThat(result.output).contains("Error: No configurations provided to Dependency Guard Plugin.")
}

@Test
fun `prints error when wrong configuration found`(): Unit = ConfiguredProject(
configurations = listOf(
"compileClasspath",
"releaseCompileClasspath",
),
).use { project ->
val result = buildAndFail(
project = project,
args = arrayOf(":lib:dependencyGuard")
)

assertThat(result.output).contains("Configuration with name releaseCompileClasspath was not found for :lib")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Builder {
withPluginClasspath()
withGradleVersion(gradleVersion.version)
withProjectDir(projectDir.toFile())
withArguments(args.toList() + "-s")
withArguments(args.toList() + "-s" + "--configuration-cache")
// Ensure this value is true when `--debug-jvm` is passed to Gradle, and false otherwise
withDebug(getRuntimeMXBean().inputArguments.toString().indexOf("-agentlib:jdwp") > 0)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.dropbox.gradle.plugins.dependencyguard.fixture

import com.dropbox.gradle.plugins.dependencyguard.util.createDirectories
import com.dropbox.gradle.plugins.dependencyguard.util.writeText
import java.nio.file.Path

class ConfiguredProject(
private val configurations: List<String>,
) : AbstractProject() {

private val gradlePropertiesFile = projectDir.resolve("gradle.properties")
private val settingsFile = projectDir.resolve("settings.gradle")
private val rootBuildFile = projectDir.resolve("build.gradle")

// Generate java library project named 'lib'
val lib = minimalLibrary("lib")

init {
gradlePropertiesFile.writeText(
"""
org.gradle.jvmargs=-Dfile.encoding=UTF-8
""".trimIndent()
)

settingsFile.writeText(
"""
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
}
}

rootProject.name = 'project-under-test'

// Don't forget to add all your modules here!
include ':lib'
""".trimIndent()
)
}

private fun minimalLibrary(name: String): Path {
val lib = projectDir.resolve(name).createDirectories()

lib.resolve("build.gradle").writeText(
"""
plugins {
id 'java-library'
id 'com.dropbox.dependency-guard'
}

dependencies {
implementation 'io.reactivex.rxjava3:rxjava:3.1.4'
}

dependencyGuard {
${
configurations.map {
"""
configuration('$it') {
tree = true
}
""".trimIndent()
}
}
}
""".trimIndent()
)

return lib
}
}
Loading