From a005617c16ba08ba875809df31cd2086c20a88b2 Mon Sep 17 00:00:00 2001 From: daz Date: Mon, 12 Feb 2024 19:02:07 -0700 Subject: [PATCH] Fix for older versions of Gradle --- .../AbstractDependencyExtractorPlugin.kt | 7 ++++--- .../extractor/DependencyExtractor.kt | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/src/main/kotlin/org/gradle/dependencygraph/AbstractDependencyExtractorPlugin.kt b/plugin/src/main/kotlin/org/gradle/dependencygraph/AbstractDependencyExtractorPlugin.kt index fba417c..843302f 100644 --- a/plugin/src/main/kotlin/org/gradle/dependencygraph/AbstractDependencyExtractorPlugin.kt +++ b/plugin/src/main/kotlin/org/gradle/dependencygraph/AbstractDependencyExtractorPlugin.kt @@ -89,9 +89,10 @@ abstract class AbstractDependencyExtractorPlugin : Plugin { extractorServiceProvider: Provider ) { gradle.buildFinished { - extractorServiceProvider.get().close() - gradle.buildOperationListenerManager - .removeListener(extractorServiceProvider.get()) + val extractorService = extractorServiceProvider.get() + extractorService.handleBuildCompletion(it.failure) + extractorService.close() + gradle.buildOperationListenerManager.removeListener(extractorService) } } } diff --git a/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt b/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt index e5578ab..d1d5c63 100644 --- a/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt +++ b/plugin/src/main/kotlin/org/gradle/dependencygraph/extractor/DependencyExtractor.kt @@ -38,8 +38,8 @@ abstract class DependencyExtractor : private val pluginParameters = PluginParameters() private var settingsEvaluated = false - private var buildWorkCompleted = false - private var buildWorkFailure = false + private var buildCompleted = false + private var buildFailed = false private val resolvedConfigurations = Collections.synchronizedList(mutableListOf()) @@ -88,7 +88,7 @@ abstract class DependencyExtractor : EvaluateSettingsBuildOperationType.Result>(buildOperation, finishEvent) { details, _ -> extractSettings(details) } if (buildOperation.metadata == BuildOperationCategory.RUN_WORK) { - handleRunWorkCompleted(finishEvent) + handleBuildCompletion(finishEvent.failure) } } @@ -349,10 +349,10 @@ abstract class DependencyExtractor : ) } - private fun handleRunWorkCompleted(finishEvent: OperationFinishEvent) { - buildWorkCompleted = true - if (finishEvent.failure != null) { - buildWorkFailure = true + fun handleBuildCompletion(failure: Throwable?) { + buildCompleted = true + if (failure != null) { + buildFailed = true } } @@ -373,8 +373,8 @@ abstract class DependencyExtractor : ) return } - // We use the absence of Settings Evaluated to determine if the build was loaded from the configuration-cache - if (!buildWorkCompleted || buildWorkFailure) { + // Do not write an incomplete graph when build didn't complete successfully + if (!buildCompleted || buildFailed) { LOGGER.lifecycle( "Gradle Build did not complete successfully: Dependency Graph file will not be generated." )