@ -13,6 +13,8 @@
* SPDX - License - Identifier: Apache - 2.0
* SPDX - License - Identifier: Apache - 2.0
* /
* /
import groovy.transform.Memoized
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.CheckSeverity
import java.text.SimpleDateFormat
import java.text.SimpleDateFormat
@ -637,6 +639,7 @@ def buildTime() {
// Takes the version , and if - SNAPSHOT is part of it replaces SNAPSHOT
// Takes the version , and if - SNAPSHOT is part of it replaces SNAPSHOT
// with the git commit version .
// with the git commit version .
@Memoized
def calculateVersion ( ) {
def calculateVersion ( ) {
String version = rootProject . version
String version = rootProject . version
if ( version . endsWith ( "-SNAPSHOT" ) ) {
if ( version . endsWith ( "-SNAPSHOT" ) ) {
@ -646,25 +649,31 @@ def calculateVersion() {
}
}
def getCheckedOutGitCommitHash ( ) {
def getCheckedOutGitCommitHash ( ) {
def gitFolder = "$projectDir/.git/"
try {
if ( ! file ( gitFolder ) . isDirectory ( ) ) {
def gitFolder = "$projectDir/.git/"
// We are in a submodule . The file ' s contents are ` gitdir: < gitFolder > \ n ` .
if ( ! file ( gitFolder ) . isDirectory ( ) ) {
// Read the file , cut off the front , and trim the whitespace .
// We are in a submodule . The file ' s contents are ` gitdir: < gitFolder > \ n ` .
gitFolder = file ( gitFolder ) . text . substring ( 8 ) . trim ( ) + "/"
// Read the file , cut off the front , and trim the whitespace .
gitFolder = file ( gitFolder ) . text . substring ( 8 ) . trim ( ) + "/"
}
def takeFromHash = 8
/ *
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
* /
def head = new File ( gitFolder + "HEAD" ) . text . split ( ":" ) // . git / HEAD
def isCommit = head . length = = 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
if ( isCommit ) return head [ 0 ] . trim ( ) . take ( takeFromHash ) // e5a7c79edabb
def refHead = new File ( gitFolder + head [ 1 ] . trim ( ) ) // . git /refs/ heads / master
refHead . text . trim ( ) . take takeFromHash
} catch ( Exception e ) {
logger . warn ( 'Could not calculate git commit, using "xxxxxxxx" (run with --info for stacktrace)' )
logger . info ( 'Error retrieving git commit' , e )
return "xxxxxxxx"
}
}
def takeFromHash = 8
/ *
* '.git/HEAD' contains either
* in case of detached head: the currently checked out commit hash
* otherwise: a reference to a file containing the current commit hash
* /
def head = new File ( gitFolder + "HEAD" ) . text . split ( ":" ) // . git / HEAD
def isCommit = head . length = = 1 // e5a7c79edabbf7dd39888442df081b1c9d8e88fd
if ( isCommit ) return head [ 0 ] . trim ( ) . take ( takeFromHash ) // e5a7c79edabb
def refHead = new File ( gitFolder + head [ 1 ] . trim ( ) ) // . git /refs/ heads / master
refHead . text . trim ( ) . take takeFromHash
}
}
tasks . register ( "verifyDistributions" ) {
tasks . register ( "verifyDistributions" ) {