-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
83 lines (71 loc) · 2.68 KB
/
build.gradle
File metadata and controls
83 lines (71 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.owasp:dependency-check-gradle:5.2.2'
}
}
plugins {
id 'java-library'
id 'base'
id 'idea'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}
apply from: "$rootDir/gradle/Release.gradle"
apply from: "$rootDir/gradle/DockerSupport.gradle"
def currentJvm = org.gradle.internal.jvm.Jvm.current()
private String getGitRevision() {
def gitOutput = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', '--short', 'HEAD'
standardOutput = gitOutput
}
return gitOutput.toString().replace("\n", "")
}
/**
* Returns difference between number of commits from repo root to current head and to a specified commit.
* If the current HEAD is directly inherited from from the tag then returned number represents number of commits since tag.
* Otherwise the returned value has no special meaning.
*/
private Integer getCountOfCommitsSinceTag(tag) {
def gitOutput = new ByteArrayOutputStream()
try {
exec {
commandLine 'git', 'rev-list', '--count', tag
standardOutput = gitOutput
errorOutput = new ByteArrayOutputStream()
}
} catch (Exception ignore) {
logger.warn("WARN: Failed to find git tag: " + project.version)
return null;
}
def commitsFromRootToTag = gitOutput.toString()
gitOutput.reset()
exec {
commandLine 'git', 'rev-list', '--count', 'HEAD'
standardOutput = gitOutput
}
def commitsFromRootToHead = gitOutput.toString()
return Integer.parseInt(commitsFromRootToHead.replace("\n", "")) - Integer.parseInt(commitsFromRootToTag.replace("\n", ""))
}
private String getBuildTimestamp() {
def gitOutput = new ByteArrayOutputStream()
exec {
workingDir project.rootDir
commandLine 'git', 'log', '-1', '--date=iso8601', '--pretty=format:%cd'
standardOutput = gitOutput
}
return gitOutput.toString()
}
ext.revision = getGitRevision()
ext.commitsAfterTag = getCountOfCommitsSinceTag(project.version) // Note: project version is expected to match existing tag name
ext.commitTimestamp = getBuildTimestamp()
println '======================================================================'
println 'Current JVM ' + currentJvm
println 'Project version ' + project.version
println 'Revision ' + ext.revision
println 'Commits after tag: ' + ext.commitsAfterTag
println 'Commit timestamp: ' + ext.commitTimestamp
println 'Repository user: ' + findProperty("ARTIFACTORY_USER");
println '======================================================================'