2020-06-03 03:44:04 -04:00
import java.nio.charset.StandardCharsets
2021-09-27 08:09:29 -04:00
import java.util.function.Function
2020-06-03 03:44:04 -04:00
2020-04-15 08:20:29 -04:00
import groovy.json.JsonSlurper
2015-05-19 00:23:35 -04:00
/ *
* Hibernate , Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License ( LGPL ) , version 2.1 or later .
* See the lgpl . txt file in the root directory or < http: //www.gnu.org/licenses/lgpl-2.1.html>.
* /
2022-03-15 21:10:17 -04:00
apply from: rootProject . file ( 'gradle/module.gradle' )
2015-08-20 14:13:38 -04:00
2022-04-07 09:48:17 -04:00
apply plugin: 'org.hibernate.orm.build.doc-pub'
2023-08-07 21:05:47 -04:00
apply plugin: 'org.hibernate.orm.build.jdks'
2010-10-12 16:39:33 -04:00
apply plugin: 'idea'
2020-06-03 04:52:16 -04:00
2012-02-15 17:31:29 -05:00
idea . module {
2010-10-12 16:39:33 -04:00
}
2021-10-29 16:55:50 -04:00
// skip building this when `build` task is run from root, as many of our CI jobs do
tasks . build . dependsOn . clear ( )
2021-05-14 18:31:28 -04:00
2023-08-08 19:11:13 -04:00
def stageIntegrationGuideTask = tasks . register ( "stageIntegrationGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group "documentation"
2023-08-08 19:11:13 -04:00
description "Stages the Integration Guide as part of preparing for release"
dependsOn ":documentation:renderIntegrationGuides"
2013-05-16 19:34:36 -04:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/integrationguide" ) }
into layout . buildDirectory . dir ( "documentation/integrationguide" )
2021-09-27 08:09:29 -04:00
}
2023-08-08 19:11:13 -04:00
def stageQuickstartTask = tasks . register ( "stageQuickstart" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the Getting Started Guide as part of preparing for release"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:renderGettingStartedGuides'
2021-09-27 08:09:29 -04:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/quickstart" ) }
into layout . buildDirectory . dir ( "documentation/quickstart" )
2021-09-27 08:09:29 -04:00
}
2021-07-19 11:38:41 -04:00
2023-08-08 19:11:13 -04:00
def stageTopicalGuideTask = tasks . register ( "stageTopicalGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the Topical Guide as part of preparing for release"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:renderTopicalGuides'
2021-09-27 08:09:29 -04:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/topical" ) }
into layout . buildDirectory . dir ( "documentation/topical" )
2021-09-27 08:09:29 -04:00
}
2023-08-08 19:11:13 -04:00
def stageIntroductionGuideTask = tasks . register ( "stageIntroductionGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the Introduction Guide as part of preparing for release"
dependsOn ':documentation:renderIntroductionGuides'
2023-02-21 08:36:00 -05:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/introduction" ) }
into layout . buildDirectory . dir ( "documentation/introduction" )
2023-02-21 08:36:00 -05:00
}
2023-08-08 19:11:13 -04:00
def stageQueryGuideTasks = tasks . register ( "stageQueryGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the Query Language Guide as part of preparing for release"
dependsOn ':documentation:renderQueryLanguageGuides'
2023-08-08 19:11:13 -04:00
description "Stages the Query Language Guide as part of preparing for release"
dependsOn ':documentation:renderQueryLanguageGuides'
2023-05-27 15:01:52 -04:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/querylanguage" ) }
into layout . buildDirectory . dir ( "documentation/querylanguage" )
2023-05-27 15:01:52 -04:00
}
2021-09-27 08:09:29 -04:00
2023-08-08 19:11:13 -04:00
def stageUserGuideTask = tasks . register ( "stageUserGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the User Guide as part of preparing for release"
dependsOn ':documentation:renderUserGuides'
2023-08-08 19:11:13 -04:00
description "Stages the User Guide as part of preparing for release"
dependsOn ':documentation:renderUserGuides'
2021-07-19 11:38:41 -04:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/userguide" ) }
into layout . buildDirectory . dir ( "documentation/userguide" )
2021-09-27 08:09:29 -04:00
}
2021-07-19 11:38:41 -04:00
2022-03-08 22:16:53 -05:00
2023-08-08 19:11:13 -04:00
def stageMigrationGuideTask = tasks . register ( "stageMigrationGuide" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the Migration Guide as part of preparing for release"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:renderMigrationGuide'
2022-03-08 22:16:53 -05:00
2023-08-08 19:11:13 -04:00
from project . provider { project ( ":documentation" ) . layout . buildDirectory . dir ( "asciidoc/migration-guide" ) }
into layout . buildDirectory . dir ( "documentation/migration-guide" )
2023-04-01 10:33:34 -04:00
}
tasks . named ( "publishMigrationGuide" ) . configure {
dependsOn stageMigrationGuide
2022-03-31 12:01:06 -04:00
}
2023-08-08 19:11:13 -04:00
def stageIncubationReportTask = tasks . register ( "stageIncubationReport" , Copy ) { task - >
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages ORM @Incubating report"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:generateIncubationReport'
2023-08-08 19:11:13 -04:00
2022-03-31 12:01:06 -04:00
tasks . stageOrmReports . dependsOn task
2023-08-08 19:11:13 -04:00
from project ( ":documentation" ) . tasks . generateIncubationReport
into layout . buildDirectory . dir ( "documentation/incubating" )
2022-03-31 12:01:06 -04:00
}
2023-08-08 19:11:13 -04:00
def stageInternalsReportTask = tasks . register ( "stageInternalsReport" , Copy ) { task - >
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the @Internal report"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:generateInternalsReport'
2023-08-08 19:11:13 -04:00
from project ( ":documentation" ) . tasks . generateInternalsReport
into layout . buildDirectory . dir ( "documentation/internals" )
2022-03-31 12:01:06 -04:00
}
2023-08-08 19:11:13 -04:00
def stageDeprecationReportTask = tasks . register ( "stageDeprecationReport" , Copy ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the @Deprecated/@Remove report"
2022-12-22 17:55:02 -05:00
dependsOn ':documentation:generateDeprecationReport'
2023-08-08 19:11:13 -04:00
from project ( ":documentation" ) . tasks . generateDeprecationReport
into layout . buildDirectory . dir ( "documentation/deprecated" )
2022-12-22 17:55:02 -05:00
}
2023-08-08 19:11:13 -04:00
def stageLoggingReportTask = tasks . register ( "stageLoggingReport" , Copy ) { task - >
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the logging report"
2022-03-31 12:01:06 -04:00
dependsOn ':documentation:renderLoggingReport'
2023-08-08 19:11:13 -04:00
from project ( ":documentation" ) . tasks . renderLoggingReport
into layout . buildDirectory . dir ( "documentation/logging" )
2022-03-31 12:01:06 -04:00
}
2023-08-08 19:11:13 -04:00
def stageDialectReportTask = tasks . register ( "stageDialectReport" , Copy ) { task - >
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages the supported Dialects report"
2023-05-03 10:55:45 -04:00
dependsOn ':documentation:renderDialectReport'
2023-08-08 19:11:13 -04:00
from project ( ":documentation" ) . tasks . renderDialectReport
2023-05-03 10:55:45 -04:00
into "${buildDir}/documentation/dialect"
}
2023-08-08 19:11:13 -04:00
def stageOrmReportsTask = tasks . register ( "stageOrmReports" ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2023-08-08 19:11:13 -04:00
description "Stages all ORM reports as part of preparing for release"
dependsOn ':documentation:generateReports'
dependsOn stageIncubationReportTask
dependsOn stageInternalsReportTask
dependsOn stageDeprecationReportTask
dependsOn stageLoggingReportTask
dependsOn stageDialectReportTask
}
2023-08-10 17:15:57 -04:00
def stageJavadocsTask = tasks . register ( "stageJavadocs" , Copy ) {
group 'documentation'
description "Stages the aggregated Javadocs"
2023-08-31 10:43:54 -04:00
dependsOn ':documentation:javadoc'
2023-08-10 17:15:57 -04:00
2023-08-31 10:43:54 -04:00
from project ( ":documentation" ) . tasks . javadoc
2023-08-10 17:15:57 -04:00
into "${buildDir}/documentation/javadocs"
}
2023-05-03 10:55:45 -04:00
2021-09-27 08:09:29 -04:00
/ * *
* Assembles all documentation into the { buildDir } / documentation directory .
*
* Depends on building the docs
* /
2023-08-08 19:11:13 -04:00
def assembleDocumentationTask = tasks . register ( "assembleDocumentation" ) {
2023-08-10 17:15:57 -04:00
group 'documentation'
2021-09-27 08:09:29 -04:00
description 'Assembles all documentation into the {buildDir}/documentation directory'
dependsOn ':documentation:buildDocsForPublishing'
2023-08-10 17:15:57 -04:00
dependsOn stageJavadocsTask
2023-08-08 19:11:13 -04:00
dependsOn stageQuickstartTask
dependsOn stageIntroductionGuideTask
dependsOn stageUserGuideTask
dependsOn stageQueryGuideTasks
dependsOn stageIntegrationGuideTask
dependsOn stageTopicalGuideTask
dependsOn stageMigrationGuideTask
dependsOn stageOrmReportsTask
}
tasks . named ( "uploadDocumentation" ) {
2023-08-10 17:15:57 -04:00
group = "documentation"
description = "Uploads assembled documentation to the doc server"
2023-08-08 19:11:13 -04:00
dependsOn assembleDocumentationTask
2013-05-16 19:34:36 -04:00
doFirst {
2018-04-30 11:38:09 -04:00
if ( rootProject . ormVersion . isSnapshot ) {
2013-05-16 19:34:36 -04:00
logger . error ( "Cannot perform upload of SNAPSHOT documentation" ) ;
throw new RuntimeException ( "Cannot perform upload of SNAPSHOT documentation" ) ;
}
else {
2022-05-06 12:34:35 -04:00
logger . lifecycle ( "Uploading documentation ..." )
2013-05-16 19:34:36 -04:00
}
}
doLast {
logger . lifecycle ( 'Done uploading documentation' )
}
}
2023-08-08 19:11:13 -04:00
def releaseChecksTask = tasks . register ( "releaseChecks" ) {
2021-05-14 18:31:28 -04:00
group 'Release'
2021-05-18 16:50:10 -04:00
description 'Checks and preparation for release'
2023-10-04 13:32:11 -04:00
doFirst {
logger . lifecycle ( "Checking that the working tree is clean..." )
String uncommittedFiles = executeGitCommand ( 'status' , '--porcelain' )
if ( ! uncommittedFiles . isEmpty ( ) ) {
throw new GradleException (
"Cannot release because there are uncommitted or untracked files in the working tree.\n" +
"Commit or stash your changes first.\n" +
"Uncommitted files:\n " +
uncommittedFiles
) ;
}
String gitBranchLocal
String gitRemoteLocal
2024-06-14 11:39:17 -04:00
if ( project . hasProperty ( 'gitBranch' ) & & ! project . property ( 'gitBranch' ) . isEmpty ( ) ) {
2023-10-04 13:32:11 -04:00
gitBranchLocal = project . property ( 'gitBranch' )
}
else {
2023-10-04 15:28:08 -04:00
gitBranchLocal = executeGitCommand ( 'branch' , '--show-current' ) . trim ( )
2023-10-04 13:32:11 -04:00
}
2024-06-14 11:42:02 -04:00
if ( project . hasProperty ( 'gitRemote' ) & & ! project . property ( 'gitRemote' ) . isEmpty ( ) ) {
2023-10-04 13:32:11 -04:00
gitRemoteLocal = project . property ( 'gitRemote' )
}
else {
2023-10-04 15:28:08 -04:00
final String remotes = executeGitCommand ( 'remote' , 'show' ) . trim ( )
2023-10-04 13:32:11 -04:00
final List < String > tokens = remotes . tokenize ( )
if ( tokens . size ( ) ! = 1 ) {
throw new GradleException ( "Could not determine `gitRemote` property for `releaseChecks` tasks." )
}
gitRemoteLocal = tokens . get ( 0 )
}
project . ext {
gitBranch = gitBranchLocal
gitRemote = gitRemoteLocal
}
logger . lifecycle ( "Switching to branch '${project.gitBranch}'..." )
executeGitCommand ( 'checkout' , project . gitBranch )
logger . lifecycle ( "Checking that all commits are pushed..." )
String diffWithUpstream = executeGitCommand ( 'diff' , '@{u}' )
if ( ! diffWithUpstream . isEmpty ( ) ) {
throw new GradleException (
"Cannot perform `ciRelease` tasks because there are un-pushed local commits .\n" +
"Push your commits first."
) ;
}
}
2021-05-14 18:31:28 -04:00
}
2023-10-04 15:28:08 -04:00
def preVerifyReleaseTask = tasks . register ( "preVerifyRelease" ) {
2022-05-16 06:11:48 -04:00
group 'Release'
description 'Pre-verifies a release job execution (Run locally before a CI release)'
2023-08-08 19:11:13 -04:00
dependsOn tasks . clean
dependsOn assembleDocumentationTask
2022-05-16 06:11:48 -04:00
}
2023-08-08 19:11:13 -04:00
def changeLogFileTask = tasks . register ( "changeLogFile" ) {
2021-05-14 18:31:28 -04:00
group 'Release'
description 'Updates the changelog.txt file based on the change-log report from Jira'
2023-08-08 19:11:13 -04:00
dependsOn releaseChecksTask
2020-06-03 05:48:45 -04:00
2020-06-22 05:31:36 -04:00
doFirst {
2021-05-18 16:50:10 -04:00
logger . lifecycle ( "Appending version `${project.releaseVersion}` to changelog..." )
2020-04-15 08:20:29 -04:00
ChangeLogFile . update ( ormVersion . fullName ) ;
2020-06-22 05:31:36 -04:00
}
}
2023-08-08 19:11:13 -04:00
def changeToReleaseVersionTask = tasks . register ( "changeToReleaseVersion" ) {
2021-05-18 16:50:10 -04:00
group 'Release'
description 'Updates `gradle/version.properties` file to the specified release-version'
2021-05-14 18:31:28 -04:00
2023-08-08 19:11:13 -04:00
dependsOn releaseChecksTask
2021-05-14 18:31:28 -04:00
doFirst {
2021-05-18 16:50:10 -04:00
logger . lifecycle ( "Updating version-file to release-version : `${project.releaseVersion}`" )
updateVersionFile ( project . releaseVersion )
}
}
2020-04-15 08:20:29 -04:00
2023-08-08 19:11:13 -04:00
def gitPreparationForReleaseTask = tasks . register ( 'gitPreparationForRelease' ) {
2023-10-04 13:32:11 -04:00
dependsOn releaseChecksTask
2023-08-08 19:11:13 -04:00
dependsOn changeLogFileTask
dependsOn changeToReleaseVersionTask
2021-05-18 16:50:10 -04:00
doLast {
logger . lifecycle ( "Performing pre-steps Git commit : `${project.releaseVersion}`" )
2020-06-03 04:19:12 -04:00
executeGitCommand ( 'add' , '.' )
2021-05-18 16:50:10 -04:00
executeGitCommand ( 'commit' , '-m' , "Pre-steps for release : `${project.ormVersion.fullName}`" )
}
}
2023-08-08 19:11:13 -04:00
def changeToDevelopmentVersionTask = tasks . register ( 'changeToDevelopmentVersion' ) {
2021-05-18 16:50:10 -04:00
group 'Release'
description 'Updates `gradle/version.properties` file to the specified development-version'
2023-08-08 19:11:13 -04:00
dependsOn releaseChecksTask
2021-05-18 16:50:10 -04:00
doFirst {
logger . lifecycle ( "Updating version-file to development-version : `${project.developmentVersion}`" )
updateVersionFile ( project . developmentVersion )
2020-04-15 08:20:29 -04:00
}
}
2021-05-14 18:31:28 -04:00
2023-10-04 17:02:22 -04:00
def releasePreparePostGitTask = tasks . register ( 'gitTasksAfterRelease' ) {
2023-08-08 19:11:13 -04:00
dependsOn changeToDevelopmentVersionTask
2021-05-18 16:50:10 -04:00
doLast {
2021-05-18 17:03:34 -04:00
if ( project . createTag ) {
2023-08-08 19:11:13 -04:00
logger . lifecycle ( "Tagging release : `${project.releaseTag}`..." )
2022-04-13 11:08:38 -04:00
executeGitCommand ( 'tag' , '-a' , project . releaseTag , '-m' , "Release $project.ormVersion.fullName" )
2021-05-18 16:50:10 -04:00
}
2024-04-18 06:42:37 -04:00
logger . lifecycle ( "Performing post-steps Git commit : `${project.releaseVersion}`" )
executeGitCommand ( 'add' , '.' )
executeGitCommand ( 'commit' , '-m' , "Post-steps for release : `${project.ormVersion.fullName}`" )
2021-05-18 16:50:10 -04:00
}
}
void updateVersionFile ( String version ) {
logger . lifecycle ( "Updating `gradle/version.properties` version to `${version}`" )
project . ormVersionFile . text = "hibernateVersion=${version}"
}
2023-08-08 19:11:13 -04:00
def publishReleaseArtifactsTask = tasks . register ( 'publishReleaseArtifacts' ) {
mustRunAfter gitPreparationForReleaseTask
2021-05-18 16:50:10 -04:00
2023-08-08 19:11:13 -04:00
dependsOn uploadDocumentation
dependsOn uploadDocumentationDescriptor
2021-05-14 18:31:28 -04:00
}
2023-10-04 17:02:22 -04:00
def releasePerformPostGitTask = tasks . register ( 'gitTasksAfterReleasePerform' ) {
2021-05-14 18:31:28 -04:00
2020-04-15 08:20:29 -04:00
doLast {
2021-05-18 16:50:10 -04:00
if ( project . createTag ) {
logger . lifecycle ( "Pushing branch and tag to remote `${project.gitRemote}`..." )
2023-08-08 19:11:13 -04:00
executeGitCommand ( 'push' , '--atomic' , project . gitRemote , project . gitBranch , project . releaseTag )
2020-06-03 05:08:04 -04:00
}
else {
2023-08-08 19:11:13 -04:00
logger . lifecycle ( "Pushing branch to remote `${project.gitRemote}`..." )
executeGitCommand ( 'push' , project . gitRemote , project . gitBranch )
2020-04-15 08:20:29 -04:00
}
}
}
2021-05-18 16:50:10 -04:00
2023-10-04 17:02:22 -04:00
def releasePrepareTask = tasks . register ( 'releasePrepare' ) {
group 'Release'
description 'Performs release preparations on local check-out, including updating changelog'
dependsOn gitPreparationForReleaseTask
finalizedBy releasePreparePostGitTask
}
def releasePerformTask = tasks . register ( 'releasePerform' ) {
group 'Release'
description 'Performs a release on local check-out, including updating changelog and '
dependsOn publishReleaseArtifactsTask
finalizedBy releasePerformPostGitTask
}
def releaseTask = tasks . register ( 'release' ) {
group 'Release'
description 'Performs a release on local check-out, including updating changelog and '
dependsOn releasePrepareTask
dependsOn releasePerformTask
}
2023-08-08 19:11:13 -04:00
def ciReleaseTask = tasks . register ( 'ciRelease' ) {
2021-05-18 16:50:10 -04:00
group 'Release'
description 'Performs a release: the hibernate version is set and the changelog.txt file updated, the changes are pushed to github, then the release is performed, tagged and the hibernate version is set to the development one.'
2023-08-08 19:11:13 -04:00
dependsOn releaseTask
2021-05-18 16:50:10 -04:00
}
2020-04-15 08:20:29 -04:00
2020-06-03 04:52:16 -04:00
static String executeGitCommand ( Object . . . subcommand ) {
2020-06-03 04:19:12 -04:00
List < Object > command = [ 'git' ]
Collections . addAll ( command , subcommand )
2020-04-15 08:20:29 -04:00
def proc = command . execute ( )
2020-06-03 03:44:04 -04:00
def code = proc . waitFor ( )
def stdout = inputStreamToString ( proc . getInputStream ( ) )
def stderr = inputStreamToString ( proc . getErrorStream ( ) )
if ( code ! = 0 ) {
2020-06-03 04:19:12 -04:00
throw new GradleException ( "An error occurred while executing " + command + "\n\nstdout:\n" + stdout + "\n\nstderr:\n" + stderr )
2020-06-03 03:44:04 -04:00
}
2020-06-03 04:52:16 -04:00
return stdout
2020-06-03 03:44:04 -04:00
}
static String inputStreamToString ( InputStream inputStream ) {
inputStream . withCloseable { ins - >
new BufferedInputStream ( ins ) . withCloseable { bis - >
new ByteArrayOutputStream ( ) . withCloseable { buf - >
int result = bis . read ( ) ;
while ( result ! = - 1 ) {
buf . write ( ( byte ) result ) ;
result = bis . read ( ) ;
}
return buf . toString ( StandardCharsets . UTF_8 . name ( ) ) ;
}
}
2020-04-15 08:20:29 -04:00
}
}
class ChangeLogFile {
// Get the Release Notes from Jira and add them to the Hibernate changelog.txt file
static void update ( String releaseVersion ) {
def text = ""
File changelog = new File ( "changelog.txt" )
def newReleaseNoteBlock = getNewReleaseNoteBlock ( releaseVersion )
changelog . eachLine {
line - >
if ( line . startsWith ( "Note:" ) ) {
text + = line + System . lineSeparator ( ) + System . lineSeparator ( ) + newReleaseNoteBlock
}
else {
text + = line + System . lineSeparator ( )
}
}
changelog . text = text
}
// Get the Release Notes from Jira
static String getNewReleaseNoteBlock ( String releaseVersion ) {
def restReleaseVersion ;
if ( releaseVersion . endsWith ( ".Final" ) ) {
restReleaseVersion = releaseVersion . replace ( ".Final" , "" )
}
else {
restReleaseVersion = releaseVersion
}
def apiString = "https://hibernate.atlassian.net/rest/api/2/search/?jql=project=HHH%20AND%20fixVersion=${restReleaseVersion}%20order%20by%20issuetype%20ASC"
def apiUrl = new URL ( apiString )
2020-10-02 04:42:36 -04:00
def jsonReleaseNotes = new JsonSlurper ( ) . parse ( apiUrl )
2020-04-15 08:20:29 -04:00
def releaseDate = new Date ( ) . format ( 'MMMM dd, YYYY' )
2020-10-02 04:42:36 -04:00
def versionId = getVersionId ( jsonReleaseNotes , restReleaseVersion )
2020-04-15 08:20:29 -04:00
ReleaseNote releaseNotes = new ReleaseNote ( releaseVersion , releaseDate , versionId )
def issuetype
2020-10-02 04:42:36 -04:00
jsonReleaseNotes . issues . each {
2020-04-15 08:20:29 -04:00
issue - >
if ( issuetype ! = issue . fields . issuetype . name ) {
issuetype = issue . fields . issuetype . name
releaseNotes . addEmptyLine ( ) ;
releaseNotes . addLine ( "** ${issue.fields.issuetype.name}" )
}
releaseNotes . addLine ( " * [" + issue . key + "] - " + issue . fields . summary )
}
releaseNotes . addEmptyLine ( )
return releaseNotes . notes
}
2020-10-02 04:42:36 -04:00
private static getVersionId ( jsonReleaseNotes , String restReleaseVersion ) {
def fixVersions = jsonReleaseNotes . issues . get ( 0 ) . fields . fixVersions
for ( def fixVersion : fixVersions ) {
if ( fixVersion . name . equals ( restReleaseVersion ) ) {
return fixVersion . id
}
}
throw new GradleException ( "Unable to determine the version id of the current release." )
}
2020-04-15 08:20:29 -04:00
}
class ReleaseNote {
String notes ;
String notesHeaderSeparator = "------------------------------------------------------------------------------------------------------------------------"
ReleaseNote ( String releaseVersion , String releaseDate , String versionId ) {
notes = "Changes in ${releaseVersion} (${releaseDate})" + System . lineSeparator ( )
addHeaderSeparator ( )
addEmptyLine ( )
addLine ( "https://hibernate.atlassian.net/projects/HHH/versions/${versionId}" )
}
void addLine ( String text ) {
notes + = text + System . lineSeparator ( )
}
void addHeaderSeparator ( ) {
addLine ( notesHeaderSeparator )
}
void addEmptyLine ( ) {
notes + = System . lineSeparator ( )
}
void addEmptyLines ( int numberOfLines ) {
for ( i in 1 . . numberOfLines ) {
notes + = System . lineSeparator ( )
}
}
}
2013-05-16 19:34:36 -04:00
2021-05-14 18:31:28 -04:00
gradle . getTaskGraph ( ) . whenReady { tg - >
2021-05-18 17:03:34 -04:00
2023-10-04 17:19:49 -04:00
if ( ( tg . hasTask ( project . tasks . releasePrepare ) | | tg . hasTask ( project . tasks . releasePerform ) )
2022-03-15 13:15:56 -04:00
& & ! project . getGradle ( ) . getStartParameter ( ) . isDryRun ( ) ) {
2021-05-18 17:03:34 -04:00
String releaseVersionLocal
String developmentVersionLocal
2023-10-04 17:02:22 -04:00
def console = tg . hasTask ( project . tasks . release ) & & ! tg . hasTask ( project . tasks . ciRelease )
? System . console ( )
: null
2021-05-18 17:03:34 -04:00
if ( project . hasProperty ( 'releaseVersion' ) ) {
releaseVersionLocal = project . property ( 'releaseVersion' )
}
else {
if ( console ) {
// prompt for `releaseVersion`
releaseVersionLocal = console . readLine ( '> Enter the release version: ' )
}
else {
throw new GradleException (
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
)
}
2021-05-14 18:31:28 -04:00
}
2021-05-18 17:03:34 -04:00
if ( project . hasProperty ( 'developmentVersion' ) ) {
developmentVersionLocal = project . property ( 'developmentVersion' )
}
else {
if ( console ) {
// prompt for `developmentVersion`
developmentVersionLocal = console . readLine ( '> Enter the next development version: ' )
}
else {
throw new GradleException (
"`release`-related tasks require the following properties: 'releaseVersion', 'developmentVersion'"
)
}
}
assert releaseVersionLocal ! = null & & developmentVersionLocal ! = null ;
2021-05-14 18:31:28 -04:00
// set up information for the release-related tasks
project . ext {
2021-05-18 17:03:34 -04:00
releaseVersion = releaseVersionLocal ;
developmentVersion = developmentVersionLocal ;
createTag = ! project . hasProperty ( 'noTag' )
releaseTag = project . createTag ? determineReleaseTag ( releaseVersionLocal ) : ''
2021-05-14 18:31:28 -04:00
}
}
}
2021-05-18 17:03:34 -04:00
static String determineReleaseTag ( String releaseVersion ) {
return releaseVersion . endsWith ( '.Final' )
? releaseVersion . replace ( ".Final" , "" )
: releaseVersion ;
2022-12-22 17:55:02 -05:00
}