Skip to content

Commit

Permalink
Change ValidatePlugins::enableStricterValidation to true
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierSegoviaCordoba committed Oct 12, 2024
1 parent 8276e98 commit cd5d980
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 52 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Changed

- `ValidatePlugins::enableStricterValidation` to `true`

### Deprecated

### Fixed
Expand Down
11 changes: 7 additions & 4 deletions hubdle-gradle-plugin/api/hubdle-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,14 @@ public final class com/javiersc/hubdle/project/extensions/config/documentation/a
public final synthetic fun execute (Ljava/lang/Object;)V
}

public abstract class com/javiersc/hubdle/project/extensions/config/documentation/changelog/AddChangelogItemTask : org/gradle/api/DefaultTask {
public class com/javiersc/hubdle/project/extensions/config/documentation/changelog/AddChangelogItemTask : org/gradle/api/DefaultTask {
public static final field Companion Lcom/javiersc/hubdle/project/extensions/config/documentation/changelog/AddChangelogItemTask$Companion;
public static final field NAME Ljava/lang/String;
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun <init> (Ljava/io/File;Lorg/gradle/api/model/ObjectFactory;Lorg/gradle/api/file/ProjectLayout;)V
public final fun getAdded ()Lorg/gradle/api/provider/Property;
public final fun getChanged ()Lorg/gradle/api/provider/Property;
public final fun getChangelogFileInput ()Lorg/gradle/api/file/RegularFileProperty;
public final fun getChangelogFileOutput ()Lorg/gradle/api/file/RegularFileProperty;
public final fun getDeprecated ()Lorg/gradle/api/provider/Property;
public final fun getFixed ()Lorg/gradle/api/provider/Property;
public final fun getRemoved ()Lorg/gradle/api/provider/Property;
Expand Down Expand Up @@ -377,8 +379,9 @@ public final class com/javiersc/hubdle/project/extensions/config/documentation/c
public abstract class com/javiersc/hubdle/project/extensions/config/documentation/changelog/MergeChangelogTask : org/gradle/api/DefaultTask {
public static final field Companion Lcom/javiersc/hubdle/project/extensions/config/documentation/changelog/MergeChangelogTask$Companion;
public static final field NAME Ljava/lang/String;
public fun <init> ()V
public final fun getChangelogFile ()Ljava/io/File;
public fun <init> (Lorg/gradle/api/model/ObjectFactory;Lorg/gradle/api/file/ProjectLayout;)V
public final fun getChangelogFileInput ()Lorg/gradle/api/file/RegularFileProperty;
public final fun getChangelogFileOutput ()Lorg/gradle/api/file/RegularFileProperty;
public final fun run ()V
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevCommit
import org.eclipse.jgit.storage.file.FileRepositoryBuilder
import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.options.Option
import org.gradle.kotlin.dsl.property

public abstract class AddChangelogItemTask @Inject constructor(objects: ObjectFactory) :
DefaultTask() {
@CacheableTask
public open class AddChangelogItemTask
@Inject
constructor(rootDir: File, objects: ObjectFactory, layout: ProjectLayout) : DefaultTask() {

@Input
@Option(option = "added", description = "Add an item to the `added` section")
Expand Down Expand Up @@ -80,6 +89,18 @@ public abstract class AddChangelogItemTask @Inject constructor(objects: ObjectFa
public val renovateCommitTable: Property<Boolean> =
objects.property<Boolean>().convention(false)

@get:Internal
internal val rootDir: RegularFileProperty = objects.fileProperty().convention { rootDir }

@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
public val changelogFileInput: RegularFileProperty =
objects.fileProperty().convention(layout.projectDirectory.file("CHANGELOG.md"))

@OutputFile
public val changelogFileOutput: RegularFileProperty =
objects.fileProperty().convention(layout.projectDirectory.file("CHANGELOG.md"))

init {
group = "changelog"
}
Expand All @@ -101,50 +122,56 @@ public abstract class AddChangelogItemTask @Inject constructor(objects: ObjectFa
}
}

private val Project.changelog: String
get() = changelogFile.readText()

private fun AddChangelogItemTask.setupSection(header: String, item: String?) {
if (item.isNotNullNorEmpty()) {
with(project) {
val updatedChangelog = changelog.addChanges(header, listOf(item))
changelogFile.writeText(updatedChangelog.toString())
}
val updatedChangelog: Changelog =
changelogFileInput.get().asFile.readText().addChanges(header, listOf(item))
changelogFileOutput.get().asFile.writeText(updatedChangelog.toString())
}
}

private fun AddChangelogItemTask.setupRenovate(): Unit =
with(project) {
val dependenciesFromPullRequest: List<String> =
dependenciesFromRenovatePullRequestBody(renovate.orNull, renovatePath.orNull)
private fun AddChangelogItemTask.setupRenovate() {
val rootDir: File = rootDir.get().asFile

val dependenciesFromCommit: List<String> =
if (renovateCommitTable.get()) dependenciesFromRenovateCommit() else emptyList()
val dependenciesFromPullRequest: List<String> =
dependenciesFromRenovatePullRequestBody(rootDir, renovate.orNull, renovatePath.orNull)

val updatedLabel = "### Updated"
val dependenciesFromCommit: List<String> =
if (renovateCommitTable.get()) dependenciesFromRenovateCommit(rootDir) else emptyList()

when {
dependenciesFromPullRequest.isNotEmpty() -> {
logger.lifecycle(updatedLabel)
for (dependencyFromPullRequest in dependenciesFromPullRequest) {
logger.lifecycle("- $dependencyFromPullRequest")
}
val updatedLabel = "### Updated"

val updatedChangelog =
changelog.addChanges(updatedLabel, dependenciesFromPullRequest)
changelogFile.writeText(updatedChangelog.toString())
when {
dependenciesFromPullRequest.isNotEmpty() -> {
logger.lifecycle(updatedLabel)
for (dependencyFromPullRequest in dependenciesFromPullRequest) {
logger.lifecycle("- $dependencyFromPullRequest")
}
dependenciesFromCommit.isNotEmpty() -> {
logger.lifecycle(updatedLabel)
for (dependencyFromCommit in dependenciesFromCommit) {
logger.lifecycle("- $dependencyFromCommit")
}

val updatedChangelog = changelog.addChanges(updatedLabel, dependenciesFromCommit)
changelogFile.writeText(updatedChangelog.toString())
val updatedChangelog: Changelog =
changelogFileInput
.get()
.asFile
.readText()
.addChanges(updatedLabel, dependenciesFromPullRequest)
changelogFileOutput.get().asFile.writeText(updatedChangelog.toString())
}
dependenciesFromCommit.isNotEmpty() -> {
logger.lifecycle(updatedLabel)
for (dependencyFromCommit in dependenciesFromCommit) {
logger.lifecycle("- $dependencyFromCommit")
}

val updatedChangelog: Changelog =
changelogFileInput
.get()
.asFile
.readText()
.addChanges(updatedLabel, dependenciesFromCommit)
changelogFileOutput.get().asFile.writeText(updatedChangelog.toString())
}
}
}

private fun String.addChanges(header: String, changes: List<String>): Changelog =
buildList<String> {
Expand Down Expand Up @@ -187,7 +214,8 @@ private fun String.addChanges(header: String, changes: List<String>): Changelog
.joinToString("\n")
.run(Changelog.Companion::fromString)

private fun Project.dependenciesFromRenovatePullRequestBody(
private fun dependenciesFromRenovatePullRequestBody(
rootDir: File,
body: String?,
path: String?,
): List<String> {
Expand Down Expand Up @@ -219,8 +247,8 @@ private fun Project.dependenciesFromRenovatePullRequestBody(
.toList()
}

private fun Project.dependenciesFromRenovateCommit(): List<String> {
val gitFolder = File("${rootProject.rootDir}").walkTopDown().first { it.name == ".git" }
private fun dependenciesFromRenovateCommit(rootDir: File): List<String> {
val gitFolder = rootDir.walkTopDown().first { it.name == ".git" }

val repository: Repository =
FileRepositoryBuilder().setGitDir(gitFolder).readEnvironment().findGitDir().build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction

@CacheableTask
public abstract class GenerateChangelogHtmlTask
@Inject
constructor(objects: ObjectFactory, layout: ProjectLayout) : DefaultTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ constructor(project: Project) : HubdleConfigurableExtension(project) {
task.finalizedBy(ApplyFormatChangelogTask.NAME)
}

tasks.register<AddChangelogItemTask>(AddChangelogItemTask.NAME).configure { task ->
task.enabled = isTagPrefixProject
task.finalizedBy(ApplyFormatChangelogTask.NAME)
}
tasks
.register<AddChangelogItemTask>(AddChangelogItemTask.NAME, rootDir)
.configure { task ->
task.enabled = isTagPrefixProject
task.finalizedBy(ApplyFormatChangelogTask.NAME)
}

val generateChangelogHtmlTask: TaskProvider<GenerateChangelogHtmlTask> =
tasks.register<GenerateChangelogHtmlTask>(GenerateChangelogHtmlTask.NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,42 @@
package com.javiersc.hubdle.project.extensions.config.documentation.changelog

import com.javiersc.hubdle.project.extensions.config.documentation.changelog._internal.Changelog
import com.javiersc.hubdle.project.extensions.config.documentation.changelog._internal.changelogFile
import com.javiersc.hubdle.project.extensions.config.documentation.changelog._internal.fromFile
import com.javiersc.hubdle.project.extensions.config.documentation.changelog._internal.merged
import java.io.File
import javax.inject.Inject
import org.gradle.api.DefaultTask
import org.gradle.api.file.ProjectLayout
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity
import org.gradle.api.tasks.TaskAction

public abstract class MergeChangelogTask : DefaultTask() {
@CacheableTask
public abstract class MergeChangelogTask
@Inject
constructor(objects: ObjectFactory, layout: ProjectLayout) : DefaultTask() {

@InputFile public val changelogFile: File = project.changelogFile
@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
public val changelogFileInput: RegularFileProperty =
objects.fileProperty().convention(layout.projectDirectory.file("CHANGELOG.md"))

@OutputFile
public val changelogFileOutput: RegularFileProperty =
objects.fileProperty().convention(layout.projectDirectory.file("CHANGELOG.md"))

init {
group = "changelog"
}

@TaskAction
public fun run() {
val changelog: Changelog = Changelog.fromFile(changelogFile)
changelogFile.writeText(changelog.merged().toString())
val changelog: Changelog = Changelog.fromFile(changelogFileInput.get().asFile)
changelogFileOutput.get().asFile.writeText(changelog.merged().toString())
}

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.file.FileSystemOperations
import org.gradle.api.file.ProjectLayout
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.register

@CacheableTask
public abstract class BuildSiteTask
@Inject
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.provider.Property
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.TaskAction
import org.gradle.kotlin.dsl.register

@CacheableTask
public abstract class CheckIsSemverTask : DefaultTask() {

@get:Input public abstract val hasPublishToMavenLocalTest: Property<Boolean>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.withType
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
import org.gradle.plugin.devel.tasks.PluginUnderTestMetadata
import org.gradle.plugin.devel.tasks.ValidatePlugins

public open class HubdleGradlePluginFeatureExtension @Inject constructor(project: Project) :
HubdleConfigurableExtension(project), HubdleGradleDependencies {
Expand Down Expand Up @@ -143,6 +144,10 @@ public open class HubdleGradlePluginFeatureExtension @Inject constructor(project
applicablePlugin(scope = Scope.CurrentProject, pluginId = PluginId.JavaGradlePlugin)

lazyConfigurable {
tasks.withType<ValidatePlugins>().configureEach { validatePlugins ->
validatePlugins.enableStricterValidation.set(true)
}

val dependencies = pluginUnderTestDependencies.get()
val externalDependencies = pluginUnderTestExternalDependencies.get()
val projects = pluginUnderTestProjects.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import org.gradle.api.Project
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.register
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault
public open class FixChecksTask : DefaultTask(), HubdleTask {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import org.gradle.api.plugins.BasePlugin.ASSEMBLE_TASK_NAME
import org.gradle.api.plugins.BasePlugin.BUILD_GROUP
import org.gradle.api.tasks.TaskProvider
import org.gradle.kotlin.dsl.register
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault
public open class GenerateTask : DefaultTask(), HubdleTask {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.withType
import org.gradle.language.base.plugins.LifecycleBasePlugin.CHECK_TASK_NAME
import org.gradle.language.base.plugins.LifecycleBasePlugin.VERIFICATION_GROUP
import org.gradle.work.DisableCachingByDefault

@DisableCachingByDefault
public open class TestsTask : DefaultTask(), HubdleTask {

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class AddChangelogItemTest : GradleTestKitTest() {
withArgumentsFromTXT()
build()
projectDir.testChangelog()
testConfigurationCache(expectTaskOutcome = TaskOutcome.SUCCESS)
testConfigurationCache(expectTaskOutcome = TaskOutcome.UP_TO_DATE)
}
}

Expand Down Expand Up @@ -73,7 +73,7 @@ internal class AddChangelogItemTest : GradleTestKitTest() {
withArgumentsFromTXT()
build()
projectDir.testChangelog()
testConfigurationCache(expectTaskOutcome = TaskOutcome.SUCCESS)
testConfigurationCache(expectTaskOutcome = TaskOutcome.UP_TO_DATE)
}
}

Expand Down

0 comments on commit cd5d980

Please sign in to comment.