2020-06-03 03:44:04 -04:00
import java.nio.charset.StandardCharsets
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>.
* /
2018-01-10 16:06:58 -05:00
apply from: rootProject . file ( 'gradle/base-information.gradle' )
2015-08-20 14:13:38 -04:00
2010-10-12 16:39:33 -04:00
apply plugin: 'idea'
2013-04-05 16:15:11 -04:00
apply plugin: 'distribution'
2021-06-15 14:43:47 -04:00
//apply plugin: 'java-library-distribution'
2010-10-12 16:39:33 -04:00
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
}
2020-10-15 18:20:30 -04:00
final File documentationDir = mkdir ( "${project.buildDir}/documentation" )
final File projectTemplateStagingDir = mkdir ( "${project.buildDir}/projectTemplate" )
2013-05-17 15:29:33 -04:00
2020-06-03 04:52:16 -04:00
2021-06-15 14:43:47 -04:00
configurations {
core
// testing
envers
agroal
c3p0
hikaricp
proxool
vibur
jcache
jpamodelgen
coreJakarta
// testingJakarta
enversJakarta
jpamodelgenJakarta
}
dependencies {
core project ( ':hibernate-core' )
// testing project( ':hibernate-testing' )
envers project ( ':hibernate-envers' )
agroal project ( ':hibernate-agroal' )
c3p0 project ( ':hibernate-c3p0' )
hikaricp project ( ':hibernate-hikaricp' )
proxool project ( ':hibernate-proxool' )
vibur project ( ':hibernate-vibur' )
jcache project ( ':hibernate-jcache' )
jpamodelgen project ( ':hibernate-jpamodelgen' )
coreJakarta project ( ':hibernate-core-jakarta' )
// testingJakarta project( ':hibernate-testing-jakarta' )
enversJakarta project ( ':hibernate-envers-jakarta' )
jpamodelgenJakarta project ( ':hibernate-jpamodelgen-jakarta' )
}
2013-05-16 19:34:36 -04:00
/ * *
2013-11-22 15:51:56 -05:00
* Assembles all documentation into the { buildDir } / documentation directory .
2013-05-16 19:34:36 -04:00
*
2013-11-22 15:51:56 -05:00
* Depends on building the docs
2013-05-16 19:34:36 -04:00
* /
2021-05-14 18:31:28 -04:00
task assembleDocumentation {
group 'Release'
description 'Assembles all documentation into the {buildDir}/documentation directory'
dependsOn rootProject . project ( 'documentation' ) . tasks . buildDocsForPublishing
2013-05-16 19:34:36 -04:00
doLast {
2014-01-10 14:43:19 -05:00
// copy documentation outputs into target/documentation.
// * this is used in building the dist bundles
// * it is also used as a base to build a staged directory for documentation upload
2016-02-11 16:59:13 -05:00
// Integrations Guide
2013-05-16 19:34:36 -04:00
copy {
2016-08-02 09:45:36 -04:00
from "${rootProject.project( 'documentation' ).buildDir}/asciidoc/integrationguide"
into "${documentationDir}/integrationguide"
2013-05-17 15:29:33 -04:00
}
2016-02-11 16:59:13 -05:00
// Getting-started Guide
copy {
from "${rootProject.project( 'documentation' ).buildDir}/asciidoc/quickstart"
into "${documentationDir}/quickstart"
}
// Topical Guide
2013-11-18 15:48:10 -05:00
copy {
2016-02-11 16:59:13 -05:00
from "${rootProject.project( 'documentation' ).buildDir}/asciidoc/topical"
into "${documentationDir}/topical"
2013-11-18 15:48:10 -05:00
}
2016-02-11 16:59:13 -05:00
// User Guide
copy {
from "${rootProject.project( 'documentation' ).buildDir}/asciidoc/userguide"
into "${documentationDir}/userguide"
}
// Aggregated JavaDoc
2013-05-17 15:29:33 -04:00
copy {
2014-01-10 14:43:19 -05:00
from "${rootProject.project( 'documentation' ).buildDir}/javadocs"
2016-02-11 16:59:13 -05:00
into "${documentationDir}/javadocs"
2013-05-16 19:34:36 -04:00
}
2010-10-12 16:39:33 -04:00
}
}
2021-03-18 16:50:22 -04:00
//task assembleProjectTemplates(type:Copy, dependsOn: project( ":project-template" ).tasks.assembleDist) {
// def templateProject = project( ":project-template" )
// from templateProject.layout.buildDirectory.dir( "distributions" )
// into projectTemplateStagingDir
//}
2020-10-15 18:20:30 -04:00
2013-05-16 19:34:36 -04:00
/ * *
* Upload the documentation to the JBoss doc server
* /
2021-05-14 18:31:28 -04:00
task uploadDocumentation ( type: Exec ) {
group 'Release'
description 'Uploads documentation to the JBoss doc server'
dependsOn assembleDocumentation
2013-05-16 19:34:36 -04:00
2018-04-30 11:38:09 -04:00
final String url = "filemgmt.jboss.org:/docs_htdocs/hibernate/orm/${rootProject.ormVersion.family}" ;
2010-10-12 16:39:33 -04:00
2013-05-16 19:34:36 -04:00
executable 'rsync'
2016-02-11 16:59:13 -05:00
args '-avz' , '--links' , '--protocol=28' , "${documentationDir.absolutePath}/" , url
2010-10-12 16:39:33 -04:00
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 {
logger . lifecycle ( "Uploading documentation [{$url}]..." )
}
}
doLast {
logger . lifecycle ( 'Done uploading documentation' )
}
}
/ * *
* Configuration of the distribution plugin , used to build release bundle as both ZIP and TGZ
* /
2013-04-05 16:15:11 -04:00
distributions {
main {
2021-06-28 16:59:35 -04:00
distributionBaseName = 'hibernate-release'
2013-04-05 16:15:11 -04:00
contents {
2013-05-16 19:34:36 -04:00
from rootProject . file ( 'lgpl.txt' )
from rootProject . file ( 'changelog.txt' )
from rootProject . file ( 'hibernate_logo.gif' )
2013-04-05 16:15:11 -04:00
into ( 'lib/required' ) {
2021-06-15 14:43:47 -04:00
from configurations . core
2013-04-05 16:15:11 -04:00
}
2010-10-12 16:39:33 -04:00
2021-03-18 17:00:32 -04:00
// todo (6.0) - add back
// into( 'project-template' ) {
// // todo : hook in some form of variable replacement - especially for version
// from project( ':project-template' ).files( 'src/main/dist' )
// }
2010-10-12 16:39:33 -04:00
2019-07-25 12:39:32 -04:00
// todo (6.0) - add back spatial
// into( 'lib/spatial' ) {
// from(
// ( parent.project( 'hibernate-spatial' ).configurations.archives.allArtifacts.files.filter{ file -> !file.name.endsWith('-sources.jar') }
// + parent.project( 'hibernate-spatial' ).configurations.runtime )
// - parent.project( 'hibernate-core' ).configurations.runtime
// - parent.project( 'hibernate-core' ).configurations.archives.allArtifacts.files
// )
// }
2016-08-09 21:49:20 -04:00
2013-10-28 10:16:47 -04:00
into ( 'lib/jpa-metamodel-generator' ) {
2021-06-15 14:43:47 -04:00
from ( configurations . jpamodelgen - configurations . core )
2013-10-28 10:16:47 -04:00
}
2013-04-05 16:15:11 -04:00
into ( 'lib/envers' ) {
2021-06-15 14:43:47 -04:00
from ( configurations . envers - configurations . core )
2011-03-18 10:49:00 -04:00
}
2010-10-12 16:39:33 -04:00
2021-06-15 14:43:47 -04:00
// into( 'lib/testing' ) {
// from( configurations.testing - configurations.core )
// }
into ( 'lib/optional' ) {
into ( 'agroal' ) {
from ( configurations . agroal - configurations . core )
}
into ( 'c3p0' ) {
from ( configurations . c3p0 - configurations . core )
}
into ( 'hikaricp' ) {
from ( configurations . hikaricp - configurations . core )
}
into ( 'jcache' ) {
from ( configurations . jcache - configurations . core )
}
into ( 'proxool' ) {
from ( configurations . proxool - configurations . core )
}
into ( 'vibur' ) {
from ( configurations . vibur - configurations . core )
}
}
2013-06-29 12:46:40 -04:00
2021-06-15 14:43:47 -04:00
into ( 'lib/jakarta' ) {
into ( 'required' ) {
from configurations . coreJakarta
}
// into( 'testing' ) {
// from( configurations.testingJakarta - configurations.coreJakarta )
// }
into ( 'envers' ) {
from ( configurations . enversJakarta - configurations . coreJakarta )
}
into ( 'jpa-metamodel-generator' ) {
from ( configurations . jpamodelgenJakarta - configurations . coreJakarta )
2013-04-05 16:15:11 -04:00
}
}
2011-03-18 10:49:00 -04:00
2013-04-05 16:15:11 -04:00
into ( 'documentation' ) {
2013-05-17 15:29:33 -04:00
from documentationDir
2013-04-05 16:15:11 -04:00
}
into ( 'project' ) {
from ( rootProject . projectDir ) {
exclude ( '.git' )
exclude ( '.gitignore' )
exclude ( 'changelog.txt' )
exclude ( 'lgpl.txt' )
exclude ( 'hibernate_logo.gif' )
exclude ( 'tagRelease.sh' )
exclude ( 'gradlew' )
exclude ( 'gradlew.bat' )
exclude ( 'wrapper/*' )
exclude ( '**/.gradle/**' )
exclude ( '**/target/**' )
exclude ( '.idea' )
exclude ( '**/*.ipr' )
exclude ( '**/*.iml' )
exclude ( '**/*.iws' )
exclude ( '**/atlassian-ide-plugin.xml' )
exclude ( '**/.classpath' )
exclude ( '**/.project' )
exclude ( '**/.settings' )
exclude ( '**/.nbattrs' )
2017-10-20 06:48:07 -04:00
exclude ( '**/out/**' )
2018-07-05 09:27:24 -04:00
exclude ( '**/bin/**' )
2018-07-05 09:46:05 -04:00
exclude ( 'build/**' )
exclude ( '*/build/**' )
2013-04-05 16:15:11 -04:00
}
2011-03-18 10:49:00 -04:00
}
2010-10-12 16:39:33 -04:00
}
}
}
2020-10-15 18:20:30 -04:00
distTar . compression = Compression . GZIP
2010-10-12 16:39:33 -04:00
2021-05-18 17:03:34 -04:00
distTar . dependsOn assembleDocumentation
distZip . dependsOn assembleDocumentation
2013-05-16 19:34:36 -04:00
/ * *
* "virtual" task for building both types of dist bundles
* /
2021-05-14 18:31:28 -04:00
task buildBundles {
group 'Release'
description 'Builds all release bundles'
dependsOn distZip
dependsOn distTar
2013-05-16 19:34:36 -04:00
}
2021-05-14 18:31:28 -04:00
task uploadBundlesSourceForge ( type: Exec ) {
group 'Release'
description 'Uploads release bundles to SourceForge'
dependsOn buildBundles
2013-05-16 19:34:36 -04:00
2015-05-27 22:02:27 -04:00
final String url = "frs.sourceforge.net:/home/frs/project/hibernate/hibernate-orm/${version}" ;
2013-05-16 19:34:36 -04:00
executable 'rsync'
args '-vr' , '-e ssh' , "${project.buildDir}/distributions/" , url
doFirst {
2018-04-30 11:38:09 -04:00
if ( rootProject . ormVersion . isSnapshot ) {
2016-06-27 16:29:16 -04:00
logger . error ( "Cannot perform upload of SNAPSHOT bundles to SourceForge" ) ;
throw new RuntimeException ( "Cannot perform upload of SNAPSHOT bundles to SourceForge" )
2013-05-16 19:34:36 -04:00
}
else {
2016-06-27 16:29:16 -04:00
logger . lifecycle ( "Uploading release bundles to SourceForge..." )
2013-05-16 19:34:36 -04:00
}
}
doLast {
2016-06-27 16:29:16 -04:00
logger . lifecycle ( 'Done uploading release bundles to SourceForge' )
2013-05-16 19:34:36 -04:00
}
}
2016-06-27 16:29:16 -04:00
configurations {
bundles {
description = 'Configuration used to group the archives output from the distribution plugin.'
}
}
artifacts {
bundles distTar
bundles distZip
}
2021-05-14 18:31:28 -04:00
task releaseChecks {
group 'Release'
2021-05-18 16:50:10 -04:00
description 'Checks and preparation for release'
2021-05-14 18:31:28 -04:00
}
task changeLogFile {
group 'Release'
description 'Updates the changelog.txt file based on the change-log report from Jira'
2020-04-15 08:20:29 -04:00
2021-05-14 18:31:28 -04:00
dependsOn project . tasks . releaseChecks
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
}
}
2021-05-18 16:50:10 -04:00
task changeToReleaseVersion {
group 'Release'
description 'Updates `gradle/version.properties` file to the specified release-version'
2021-05-14 18:31:28 -04:00
dependsOn project . tasks . releaseChecks
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
2021-05-18 16:50:10 -04:00
task gitPreparationForRelease {
dependsOn changeLogFile
dependsOn changeToReleaseVersion
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}`" )
}
}
task changeToDevelopmentVersion {
group 'Release'
description 'Updates `gradle/version.properties` file to the specified development-version'
dependsOn project . tasks . releaseChecks
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
2021-05-18 16:50:10 -04:00
task gitTasksAfterRelease {
dependsOn changeToDevelopmentVersion
doLast {
logger . lifecycle ( "Performing pre-steps Git commit : `${project.releaseVersion}`" )
executeGitCommand ( 'add' , '.' )
executeGitCommand ( 'commit' , '-m' , "Post-steps for release : `${project.ormVersion.fullName}`" )
2021-05-18 17:03:34 -04:00
if ( project . createTag ) {
2021-05-18 16:50:10 -04:00
logger . lifecycle ( "Tagging release : `${project.releaseTag}`..." )
executeGitCommand ( 'tag' , project . releaseTag )
}
}
}
void updateVersionFile ( String version ) {
logger . lifecycle ( "Updating `gradle/version.properties` version to `${version}`" )
project . ormVersionFile . text = "hibernateVersion=${version}"
}
2021-05-14 18:31:28 -04:00
task publishReleaseArtifacts {
dependsOn releaseChecks
dependsOn uploadDocumentation
dependsOn uploadBundlesSourceForge
2021-05-18 16:50:10 -04:00
mustRunAfter gitPreparationForRelease
2021-05-14 18:31:28 -04:00
}
task release {
group 'Release'
description 'Performs a release on local check-out, including updating changelog and '
2021-05-18 16:50:10 -04:00
dependsOn gitPreparationForRelease
2021-05-14 18:31:28 -04:00
dependsOn publishReleaseArtifacts
2021-05-18 16:50:10 -04:00
finalizedBy gitTasksAfterRelease
2021-05-14 18:31:28 -04:00
}
2020-04-15 08:20:29 -04:00
2020-06-22 12:14:47 -04:00
rootProject . subprojects . each { Project subProject - >
2021-05-14 18:31:28 -04:00
if ( project . name ! = subProject . name ) {
2020-06-22 12:14:47 -04:00
if ( subProject . tasks . findByName ( 'release' ) ) {
2021-05-14 18:31:28 -04:00
project . tasks . publishReleaseArtifacts . dependsOn ( subProject . tasks . release )
subProject . tasks . release . dependsOn ( releaseChecks )
subProject . tasks . release . mustRunAfter ( releaseChecks )
2020-06-22 12:14:47 -04:00
}
}
}
2021-05-14 18:31:28 -04:00
task ciReleaseChecks {
dependsOn releaseChecks
}
2021-05-18 16:50:10 -04:00
task gitTasksAfterCiRelease {
dependsOn gitTasksAfterRelease
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}`..." )
executeGitCommand ( 'push' , '--atomic' , project . gitRemote , project . gitBranch , project . releaseTag )
2020-06-03 05:08:04 -04:00
}
else {
2021-05-18 16:50:10 -04:00
logger . lifecycle ( "Pushing branch to remote `${project.gitRemote}`..." )
2020-06-03 05:08:04 -04:00
executeGitCommand ( 'push' , project . gitRemote , project . gitBranch )
2020-04-15 08:20:29 -04:00
}
}
}
2021-05-18 16:50:10 -04:00
task ciRelease {
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.'
dependsOn ciReleaseChecks
dependsOn release
finalizedBy gitTasksAfterCiRelease
}
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
2021-05-14 18:31:28 -04:00
if ( tg . hasTask ( project . tasks . releaseChecks ) ) {
2021-05-18 17:03:34 -04:00
String releaseVersionLocal
String developmentVersionLocal
def console = tg . hasTask ( project . tasks . ciReleaseChecks )
? null
: System . console ( )
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
logger . lifecycle ( "Checking that the working tree is clean..." )
String uncommittedFiles = executeGitCommand ( 'status' , '--porcelain' )
if ( ! uncommittedFiles . isEmpty ( ) ) {
2021-05-14 18:31:28 -04:00
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
) ;
}
2021-05-18 17:03:34 -04:00
if ( tg . hasTask ( project . tasks . ciReleaseChecks ) ) {
String gitBranchLocal
String gitRemoteLocal
2021-05-14 18:31:28 -04:00
2021-05-18 17:03:34 -04:00
if ( project . hasProperty ( 'gitBranch' ) ) {
gitBranchLocal = project . property ( 'gitBranch' )
}
else {
gitBranchLocal = executeGitCommand ( 'branch' , '--show-current' )
}
2021-05-14 18:31:28 -04:00
2021-05-18 17:03:34 -04:00
if ( project . hasProperty ( 'gitRemote' ) ) {
gitRemoteLocal = project . property ( 'gitRemote' )
}
else {
final String remotes = executeGitCommand ( 'remote' , 'show' )
final List < String > tokens = remotes . tokenize ( )
if ( tokens . size ( ) ! = 1 ) {
throw new GradleException ( "Could not determine `gitRemote` property for `ciRelease` tasks." )
}
gitRemoteLocal = tokens . get ( 0 )
}
2021-05-14 18:31:28 -04:00
2021-05-18 17:03:34 -04:00
project . ext {
gitBranch = gitBranchLocal
gitRemote = gitRemoteLocal
}
2021-05-14 18:31:28 -04:00
2021-05-18 17:03:34 -04:00
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
}
}
}
2021-05-18 17:03:34 -04:00
static String determineReleaseTag ( String releaseVersion ) {
return releaseVersion . endsWith ( '.Final' )
? releaseVersion . replace ( ".Final" , "" )
: releaseVersion ;
2021-05-18 16:50:10 -04:00
}