Skip to content

Commit

Permalink
Fixes #3, Root Project Task Suggestion.
Browse files Browse the repository at this point in the history
  • Loading branch information
handstandsam committed Apr 25, 2022
1 parent 4311d2f commit 6b291f1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
package com.dropbox.gradle.plugins.dependencyguard.internal

import com.dropbox.gradle.plugins.dependencyguard.DependencyGuardPlugin
import org.gradle.api.Project

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

internal fun getQualifiedBaselineTaskForProjectPath(path: String): String {
val separator = if (path == ":") "" else ":"
return "${path}${separator}${DependencyGuardPlugin.DEPENDENCY_GUARD_BASELINE_TASK_NAME}"
}

internal fun Project.qualifiedBaselineTaskName(): String = getQualifiedBaselineTaskForProjectPath(this.path)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyGuardReport
import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyGuardReportType
import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyVisitor
import com.dropbox.gradle.plugins.dependencyguard.internal.isRootProject
import com.dropbox.gradle.plugins.dependencyguard.internal.qualifiedBaselineTaskName
import com.dropbox.gradle.plugins.dependencyguard.internal.utils.ColorTerminal
import com.dropbox.gradle.plugins.dependencyguard.internal.utils.OutputFileUtils
import org.gradle.api.DefaultTask
Expand Down Expand Up @@ -148,7 +149,7 @@ internal open class DependencyGuardListTask : DefaultTask() {
}
appendLine()
appendLine("$type comparison to baseline does not match.")
appendLine("If this is a desired change, you can re-baseline using ./gradlew ${project.path}:dependencyGuardBaseline")
appendLine("If this is a desired change, you can re-baseline using ./gradlew ${project.qualifiedBaselineTaskName()}")
}.toString()
throw GradleException(errorMessage)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dropbox.gradle.plugins.dependencyguard.internal.utils

import com.dropbox.gradle.plugins.dependencyguard.internal.DependencyGuardReportType
import com.dropbox.gradle.plugins.dependencyguard.internal.qualifiedBaselineTaskName
import java.io.File
import org.gradle.api.GradleException
import org.gradle.api.Project
Expand Down Expand Up @@ -63,7 +64,7 @@ internal class DependencyGuardTreeDiffer(
StringBuilder().apply {
appendLine(failureMessage)
appendLine("Dependency Tree comparison to baseline does not match.")
appendLine("If this is a desired change, you can re-baseline using ./gradlew ${project.path}:dependencyGuardBaseline")
appendLine("If this is a desired change, you can re-baseline using ./gradlew ${project.qualifiedBaselineTaskName()}")
}.toString()
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dropbox.gradle.plugins.dependencyguard.internal

import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test

class ProjectExtTest {

@Test
fun `not root project qualified baseline task`() {
assertThat(getQualifiedBaselineTaskForProjectPath(":sample:app"))
.isEqualTo(":sample:app:dependencyGuardBaseline")
}

@Test
fun `root project qualified baseline task`() {
assertThat(getQualifiedBaselineTaskForProjectPath(":"))
.isEqualTo(":dependencyGuardBaseline")
}
}

0 comments on commit 6b291f1

Please sign in to comment.