Skip to content
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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
with the `additionalCodeGenerators` property and `CodeGeneratorBinding`.
See [the migrations guide](https://rbusarow.github.io/ModuleCheck/migrations#code-generator-binding)

### 💥 Breaking Changes

- The base `:moduleCheck` task will now automatically hook into the root project's `:check` task, if
one exists. [@RBusarow](https://github.com/RBusarow) ([#611](https://github.com/rbusarow/ModuleCheck/pull/611))

### 🚀 Features

- Added support
Expand Down Expand Up @@ -38,7 +43,8 @@
./gradlew moduleCheckAuto
```
- Tasks are no longer generated for most individual rules. Instead, rules should be toggled via
the [Gradle DSL](https://rbusarow.github.io/ModuleCheck/docs/next/configuration) and can be invoked
the [Gradle DSL](https://rbusarow.github.io/ModuleCheck/docs/next/configuration) and can be
invoked
through `./gradlew modulecheck` or `./gradlew moduleCheckAuto`.

### 📐 New Rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import modulecheck.rule.FindingFactory
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider
import org.gradle.language.base.plugins.LifecycleBasePlugin

class ModuleCheckPlugin : Plugin<Project> {

Expand Down Expand Up @@ -89,6 +90,12 @@ class ModuleCheckPlugin : Plugin<Project> {
includeAuto = true,
disableConfigCache = disableConfigCache
)

target.tasks
.matching { it.name == LifecycleBasePlugin.CHECK_TASK_NAME }
.configureEach {
it.dependsOn("moduleCheck")
}
}

private fun Project.registerTasks(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,17 @@ abstract class BasePluginTest : ProjectTest() {
tasks.last().outcome shouldBe TaskOutcome.SUCCESS
}

fun shouldSucceed(vararg tasks: String, stacktrace: Boolean = true): BuildResult {
fun shouldSucceed(
vararg tasks: String,
stacktrace: Boolean = true,
assertions: BuildResult.() -> Unit = {}
): BuildResult {
val result = build(*tasks, stacktrace = stacktrace)

result.tasks.last().outcome shouldBe TaskOutcome.SUCCESS

result.assertions()

return result
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2021-2022 Rick Busarow
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package modulecheck.gradle

import modulecheck.utils.child
import modulecheck.utils.createSafely
import org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.junit.jupiter.api.Test

class TaskLifecycleTest : BasePluginTest() {

@Test
fun `the modulecheck task should be invoked for the base plugin check task`() {

kotlinProject(":") {
buildFile {
"""
plugins {
id("com.rickbusarow.module-check")
base
}
"""
}

projectDir.child("settings.gradle.kts").createSafely()
}

shouldSucceed("check") {

task(":moduleCheck")!!.outcome shouldBe SUCCESS

tasks shouldBe listOf(
task(":moduleCheck"),
task(":check")
)
}
}

@Test
fun `the modulecheck task should be invoked for a late, manually created check task`() {

kotlinProject(":") {
buildFile {
"""
plugins {
id("com.rickbusarow.module-check")
}

afterEvaluate {
task("check")
}
"""
}

projectDir.child("settings.gradle.kts").createSafely()
}

shouldSucceed("check") {

task(":moduleCheck")!!.outcome shouldBe SUCCESS

tasks shouldBe listOf(
task(":moduleCheck"),
task(":check")
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package modulecheck.testing
import hermit.test.junit.HermitJUnit5
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.runBlocking
import modulecheck.utils.child
import modulecheck.utils.remove
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.TestInfo
Expand All @@ -32,18 +33,20 @@ abstract class BaseTest : HermitJUnit5(), FancyShould {
// so use the FqName and trim the package name to get qualified nested names
.let { it.canonicalName.removePrefix(it.packageName + ".") }
.split(".")
.joinToString("/")
.joinToString(File.separator)
.replace("[^a-zA-Z\\d/]".toRegex(), "_")

val testName = testInfo.testMethod.get().name
.replace("[^a-zA-Z0-9]".toRegex(), "_")
.replace("[^a-zA-Z\\d]".toRegex(), "_")
.replace("_{2,}".toRegex(), "_")
.removeSuffix("_")

File("build/tests/$className/$testName").absoluteFile
File("build")
.child("tests", className, testName)
.absoluteFile
}

private var testInfo: TestInfo by Delegates.notNull()
var testInfo: TestInfo by Delegates.notNull()

fun File.relativePath() = path.removePrefix(testProjectDir.path)

Expand Down
8 changes: 7 additions & 1 deletion website/src/pages/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
with the `additionalCodeGenerators` property and `CodeGeneratorBinding`.
See [the migrations guide](/migrations#code-generator-binding)

#### 💥 Breaking Changes

- The base `:moduleCheck` task will now automatically hook into the root project's `:check` task, if
one exists. [@RBusarow](https://github.com/RBusarow) ([#611](https://github.com/rbusarow/ModuleCheck/pull/611))

#### 🚀 Features

- Added support
Expand Down Expand Up @@ -38,7 +43,8 @@
./gradlew moduleCheckAuto
```
- Tasks are no longer generated for most individual rules. Instead, rules should be toggled via
the [Gradle DSL](/docs/next/configuration) and can be invoked
the [Gradle DSL](/docs/next/configuration) and can be
invoked
through `./gradlew modulecheck` or `./gradlew moduleCheckAuto`.

#### 📐 New Rules
Expand Down