diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt index 84f855d..3690ce4 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt @@ -32,6 +32,7 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.UnknownDomainObjectException import org.gradle.api.logging.Logger +import org.gradle.api.tasks.TaskProvider import java.io.File /** @@ -232,7 +233,7 @@ abstract class AffectedModuleDetector { } /** - * Call this method to configure the given task to execute only if the owner project + * Call this method to configure the given provided task to execute only if the owner project * is affected by current changes * * Can be called during the configuration or execution phase @@ -247,6 +248,24 @@ abstract class AffectedModuleDetector { } } + /** + * Call this method to configure the given task to execute only if the owner project + * is affected by current changes + * + * Can be called during the configuration or execution phase + */ + @Throws(GradleException::class) + @JvmStatic + fun configureTaskGuard(taskProvider: TaskProvider) { + taskProvider.configure { task -> + task.onlyIf { + getOrThrow( + task.project + ).shouldInclude(task.project) + } + } + } + /** * Call this method to determine if the project was affected in this change * @@ -340,7 +359,11 @@ class AffectedModuleDetectorImpl constructor( injectedGitClient ?: GitClientImpl( rootProject.projectDir, logger, - commitShaProvider = CommitShaProvider.fromString(config.compareFrom, config.specifiedBranch, config.specifiedRawCommitSha), + commitShaProvider = CommitShaProvider.fromString( + config.compareFrom, + config.specifiedBranch, + config.specifiedRawCommitSha + ), ignoredFiles = config.ignoredFiles ) }