From 627ed6e944928ee1f9f6d7b7e6cd45bce7ddb9d0 Mon Sep 17 00:00:00 2001 From: Emily Ploszaj Date: Fri, 7 Jun 2024 13:29:42 -0500 Subject: [PATCH] Be more explicit about API diffing source --- .../com/google/gradle/plugins/ChangelogPlugin.kt | 3 +++ .../com/google/gradle/tasks/WarnVersionBumpTask.kt | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/src/main/java/com/google/gradle/plugins/ChangelogPlugin.kt b/plugins/src/main/java/com/google/gradle/plugins/ChangelogPlugin.kt index b30367e0..7a79c3a0 100644 --- a/plugins/src/main/java/com/google/gradle/plugins/ChangelogPlugin.kt +++ b/plugins/src/main/java/com/google/gradle/plugins/ChangelogPlugin.kt @@ -97,6 +97,9 @@ abstract class ChangelogPlugin : Plugin { } tasks.register("warnVersionBump") { + if (export.isPresent) { + export.set(apiPlugin.exportFile) + } changesFile.set(fileChanges) } diff --git a/plugins/src/main/java/com/google/gradle/tasks/WarnVersionBumpTask.kt b/plugins/src/main/java/com/google/gradle/tasks/WarnVersionBumpTask.kt index c1880d26..1b281828 100644 --- a/plugins/src/main/java/com/google/gradle/tasks/WarnVersionBumpTask.kt +++ b/plugins/src/main/java/com/google/gradle/tasks/WarnVersionBumpTask.kt @@ -17,13 +17,11 @@ package com.google.gradle.tasks import com.google.gradle.types.LinesChanged -import com.google.gradle.types.VersionType import com.google.gradle.types.VersionType.* -import com.google.gradle.util.SkipTask import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.StopExecutionException +import org.gradle.api.tasks.Optional import org.gradle.api.tasks.TaskAction import org.gradle.api.tasks.TaskExecutionException @@ -38,6 +36,8 @@ import org.gradle.api.tasks.TaskExecutionException * @throws TaskExecutionException if changes cause an minor or major API bump */ abstract class WarnVersionBumpTask : DefaultTask() { + @get:[Optional InputFile] abstract val export: RegularFileProperty + @get:InputFile abstract val changesFile: RegularFileProperty @TaskAction @@ -45,7 +45,11 @@ abstract class WarnVersionBumpTask : DefaultTask() { val diff = LinesChanged.fromFile(changesFile.asFile.get()) if (diff.bump == MAJOR || diff.bump == MINOR) { - throw TaskExecutionException(this, Exception("Changes are ${diff.bump}, higher than PATCH. If this is intended, add a changelog entry. Otherwise, revert the changes.")) + if (export.isPresent) { + throw TaskExecutionException(this, Exception("Based on exported API, changes are ${diff.bump}, higher than PATCH. If this is intended, add a changelog entry. Otherwise, revert the changes.")) + } else { + throw TaskExecutionException(this, Exception("Based on last release API, changes are ${diff.bump}, higher than PATCH. If this is intended, add a changelog entry. Otherwise, revert the changes. To compare local changes, run exportApi on a commit first.")) + } } } }