forked from researchgate/gradle-release
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - use build service, not task listener for Gradle 8.3 compatibility
See researchgate#346
- Loading branch information
Showing
2 changed files
with
58 additions
and
15 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/groovy/net/researchgate/release/CleanupBuildService.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.researchgate.release | ||
|
||
import org.gradle.api.Project | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.services.BuildService | ||
import org.gradle.api.services.BuildServiceParameters | ||
import org.gradle.tooling.events.FinishEvent | ||
import org.gradle.tooling.events.OperationCompletionListener | ||
import org.gradle.tooling.events.task.TaskFailureResult | ||
import org.gradle.tooling.events.task.TaskFinishEvent | ||
import org.slf4j.LoggerFactory | ||
|
||
abstract class CleanupBuildService implements BuildService<Params>, OperationCompletionListener { | ||
|
||
interface Params extends BuildServiceParameters { | ||
Property<BaseScmAdapter> getScmAdapter() | ||
Property<ReleaseExtension> getExtension() | ||
Property<Project> getProject() | ||
} | ||
|
||
@Override | ||
void onFinish(FinishEvent finishEvent) { | ||
if (finishEvent instanceof TaskFinishEvent) { | ||
def result = finishEvent.result | ||
if (result instanceof TaskFailureResult) { | ||
def extension = parameters.extension.get() | ||
def scmAdapter = parameters.scmAdapter.get() | ||
def project = parameters.project.get() | ||
def log = project.logger ?: LoggerFactory.getLogger(this.getClass()) | ||
|
||
if (finishEvent.descriptor.name == "release") { | ||
if (scmAdapter && extension.revertOnFail && project.file(extension.versionPropertyFile)?.exists()) { | ||
log.error('Release process failed, reverting back any changes made by Release Plugin.') | ||
scmAdapter.revert() | ||
} else { | ||
log.error('Release process failed, please remember to revert any uncommitted changes made by the Release Plugin.') | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters