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'
2010-10-12 16:39:33 -04:00
2012-02-15 17:31:29 -05:00
idea . module {
2010-10-12 16:39:33 -04:00
}
2016-02-11 14:40:10 -05:00
final File documentationDir = mkdir ( "${project.buildDir}/documentation" ) ;
2013-05-17 15:29:33 -04:00
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
* /
2016-02-11 16:59:13 -05:00
task assembleDocumentation ( type: Task , dependsOn: [ rootProject . project ( 'documentation' ) . tasks . buildDocsForPublishing ] ) {
2013-11-22 15:51:56 -05:00
description = 'Assembles all documentation into the {buildDir}/documentation directory'
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
}
}
2013-05-16 19:34:36 -04:00
/ * *
* Upload the documentation to the JBoss doc server
* /
2016-02-11 14:40:10 -05:00
task uploadDocumentation ( type: Exec , dependsOn: assembleDocumentation ) {
2013-05-16 19:34:36 -04:00
description = "Uploads documentation to the JBoss doc server"
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 {
baseName = 'hibernate-release'
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' ) {
from parent . project ( 'hibernate-core' ) . configurations . provided . files { dep - > dep . name = = 'jta' }
from parent . project ( 'hibernate-core' ) . configurations . runtime
from parent . project ( 'hibernate-core' ) . configurations . archives . allArtifacts . files . filter { file - > ! file . name . endsWith ( '-sources.jar' ) }
// for now,
from parent . project ( 'hibernate-core' ) . configurations . provided . files { dep - > dep . name = = 'javassist' }
}
2010-10-12 16:39:33 -04:00
2016-05-06 13:28:31 -04:00
// into( 'lib/jpa' ) {
// from parent.project( 'hibernate-entitymanager' ).configurations.archives.allArtifacts.files.filter{ file -> !file.name.endsWith('-sources.jar') }
// }
2010-10-12 16:39:33 -04:00
2016-08-09 21:49:20 -04:00
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
)
}
2013-10-28 10:16:47 -04:00
into ( 'lib/jpa-metamodel-generator' ) {
2013-11-12 10:07:00 -05:00
from parent . project ( 'hibernate-jpamodelgen' ) . configurations . archives . allArtifacts . files . filter { file - > ! file . name . endsWith ( '-sources.jar' ) }
2013-10-28 10:16:47 -04:00
}
2013-04-05 16:15:11 -04:00
into ( 'lib/envers' ) {
from (
( parent . project ( 'hibernate-envers' ) . configurations . archives . allArtifacts . files . filter { file - > ! file . name . endsWith ( '-sources.jar' ) }
+ parent . project ( 'hibernate-envers' ) . configurations . runtime )
2011-03-18 10:49:00 -04:00
- parent . project ( 'hibernate-core' ) . configurations . runtime
2012-03-26 03:12:10 -04:00
- parent . project ( 'hibernate-core' ) . configurations . archives . allArtifacts . files
2011-03-18 10:49:00 -04:00
)
}
2010-10-12 16:39:33 -04:00
2013-06-29 12:46:40 -04:00
into ( 'lib/osgi' ) {
from (
( parent . project ( 'hibernate-osgi' ) . configurations . archives . allArtifacts . files . filter { file - > ! file . name . endsWith ( '-sources.jar' ) }
+ parent . project ( 'hibernate-osgi' ) . configurations . runtime )
- parent . project ( 'hibernate-core' ) . configurations . runtime
- parent . project ( 'hibernate-core' ) . configurations . archives . allArtifacts . files
)
2015-08-20 02:12:46 -04:00
from (
2018-06-26 14:05:24 -04:00
parent . project ( 'hibernate-osgi' ) . extensions . karaf . features . outputFile
2015-08-20 02:12:46 -04:00
)
2013-06-29 12:46:40 -04:00
}
2013-04-05 16:15:11 -04:00
// todo : this closure is problematic as it does not write into the hibernate-release-$project.version directory
// due to http://issues.gradle.org/browse/GRADLE-1450
2018-07-11 04:15:03 -04:00
[ 'hibernate-agroal' , 'hibernate-c3p0' , 'hibernate-ehcache' , 'hibernate-hikaricp' , 'hibernate-jcache' , 'hibernate-proxool' , 'hibernate-vibur' ] . each { feature - >
2018-01-10 16:06:58 -05:00
final String shortName = feature . substring ( 'hibernate-' . length ( ) )
2013-04-05 16:15:11 -04:00
// WORKAROUND http://issues.gradle.org/browse/GRADLE-1450
// into('lib/optional/' + shortName) {
owner . into ( 'lib/optional/' + shortName ) {
from (
( parent . project ( feature ) . configurations . archives . allArtifacts . files . filter { file - > ! file . name . endsWith ( '-sources.jar' ) }
+ parent . project ( feature ) . configurations . runtime )
- parent . project ( 'hibernate-core' ) . configurations . runtime
- parent . project ( 'hibernate-core' ) . configurations . archives . allArtifacts . files
)
}
}
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
}
}
}
2013-11-22 15:51:56 -05:00
distZip . dependsOn assembleDocumentation
distTar . dependsOn assembleDocumentation
2013-04-05 17:53:29 -04:00
distTar {
compression = Compression . GZIP
}
2010-10-12 16:39:33 -04:00
2013-05-16 19:34:36 -04:00
/ * *
* "virtual" task for building both types of dist bundles
* /
task buildBundles ( type: Task , dependsOn: [ distZip , distTar ] ) {
description = "Builds all release bundles"
}
2015-08-20 14:13:38 -04:00
task uploadBundlesSourceForge ( type: Exec , dependsOn: buildBundles ) {
2013-05-16 19:34:36 -04:00
description = "Uploads release bundles to SourceForge"
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
}
2018-01-31 09:33:39 -05:00
task release ( dependsOn: [ uploadDocumentation , uploadBundlesSourceForge ] )
2013-05-16 19:34:36 -04:00
2020-04-15 08:20:29 -04:00
def gitRemote = 'origin'
if ( project . hasProperty ( 'gitRemote' ) ) {
gitRemote = project . property ( 'gitRemote' )
}
task updateChangeLogFile {
group = "Release"
description = "Updates the changelog.txt file and push the changes to github"
doFirst {
ChangeLogFile . update ( ormVersion . fullName ) ;
executeGitCommand (
"git add ." ,
"An error occurred during the execution of git add for the changelog.txt and the release version changes."
)
executeGitCommand (
"git commit -m \"${project.ormVersion.fullName}\"" ,
"An error occurred during the execution of git commit for the changelog.txt and the release version changes."
)
executeGitCommand (
"git push ${gitRemote}" ,
"An error occurred during the execution git push for the changelog.txt and the release version changes."
)
}
}
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."
doLast {
if ( ! project . hasProperty ( 'developmentVersion' ) ) {
throw new GradleException (
"When the releaseVersion parameter is specified, the parameter developmentVersion is required as well."
)
}
if ( ! project . hasProperty ( 'noTag' ) ) {
String tag = project . ormVersion . fullName
// the release is tagged and the tag is pushed to github
if ( tag . endsWith ( ".Final" ) ) {
tag = tag . replace ( ".Final" , "" )
}
executeGitCommand (
"git tag ${tag}" ,
"An error occurred during the execution of git tag"
)
executeGitCommand (
"git push ${gitRemote} ${tag}" ,
"An error occurred during the execution of git push od the tag"
)
// the hibernate version is changed to the development one and the changes are pushed to github
project . ormVersionFile . text = "hibernateVersion=${project.property( 'developmentVersion' )}"
executeGitCommand (
"git add ." ,
"An error occurred during the execution of git add for the development version change."
)
executeGitCommand (
2020-06-03 04:16:19 -04:00
"git commit -m \"${project.property( 'developmentVersion' )}\"" ,
2020-04-15 08:20:29 -04:00
"An error occurred during the execution of git commit for the development version change."
)
executeGitCommand (
"git push ${gitRemote}" ,
"An error occurred during the execution git push for the development version change."
)
}
}
}
ciRelease . dependsOn updateChangeLogFile , release
release . mustRunAfter updateChangeLogFile
2020-06-03 03:44:04 -04:00
static void executeGitCommand ( String command , String errorMessage ) {
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 ) {
throw new GradleException ( errorMessage + "\n\nstdout:\n" + stdout + "\n\nstderr:\n" + stderr )
}
}
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 )
def releseNotes = new JsonSlurper ( ) . parse ( apiUrl )
def releaseDate = new Date ( ) . format ( 'MMMM dd, YYYY' )
def versionId = releseNotes . issues . get ( 0 ) . fields . fixVersions . get ( 0 ) . id
ReleaseNote releaseNotes = new ReleaseNote ( releaseVersion , releaseDate , versionId )
def issuetype
releseNotes . issues . each {
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
}
}
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 ( )
}
}
}