forked from jMonkeyEngine/jmonkeyengine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.gradle
168 lines (150 loc) · 4.63 KB
/
version.gradle
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
Version Info Examples
=====================
Nightly Build Snapshot
* git tag:
* Full Version: 3.1-5124
* POM Version: 3.1.0-SNAPSHOT
* NBM Revision: 5124
* NBM UC Suffix: nightly/3.1/plugins
Nightly Build Snapshot (PBRIsComing branch)
* git tag:
* Full Version: 3.1-PBRIsComing-5124
* POM Version: 3.1.0-PBRIsComing-SNAPSHOT
* NBM Revision: 5124
* NBM UC Suffix: PBRIsComing-nightly/3.1/plugins
Alpha1 Release
* git tag: v3.1.0-alpha1
* Full Version: 3.1-alpha1
* POM Version: 3.1.0-alpha1
* NBM Revision: 0
* NBM UC Suffix: stable/3.1/plugins
Final Release
* git tag: v3.1.0
* Full Version: 3.1
* POM Version: 3.1.0
* NBM Revision: 0
* NBM UC Suffix: stable/3.1/plugins
*/
import java.text.SimpleDateFormat
import org.ajoberstar.grgit.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.ajoberstar:gradle-git:1.2.0'
}
}
ext {
jmeRevision = 0
jmeGitHash = ""
jmeGitTag = ""
jmeShortGitHash = ""
jmeBuildDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date())
jmeBranchName = "unknown"
jmeFullVersion = "${jmeVersion}-UNKNOWN"
jmePomVersion = "unknown"
}
def getReleaseInfo(String tag) {
if (tag == null) {
// not a tagged commit
return null;
}
if (!tag.startsWith("v")) {
// syntax error
return null;
}
tag = tag.substring(1)
String[] parts = tag.split("-", 2);
String mainVersion;
boolean prerelease;
String releaseName = null;
if (parts.length == 2) {
// prerelease
prerelease = true;
mainVersion = parts[0];
releaseName = parts[1];
if (releaseName.size() == 0) {
// syntax error
return null;
}
} else if (parts.length == 1) {
// final release
prerelease = false;
mainVersion = parts[0];
} else {
// error
return null;
}
if (mainVersion.size() == 0) {
// syntax error
return null;
}
parts = mainVersion.split("\\.");
if (parts.size() != 3) {
// syntax error
return null;
}
String baseVersion = parts[0] + "." + parts[1];
return [
"tag" : tag,
"baseVersion" : baseVersion,
"mainVersion" : mainVersion,
"prerelease" : prerelease,
"releaseName" : releaseName,
"releaseSuffix": (prerelease ? "-${releaseName}": "")
]
}
task configureVersionInfo {
try {
def grgit = Grgit.open(project.file('.'))
def head = grgit.head()
jmeRevision = grgit.log(includes: [head]).size()
jmeGitHash = head.id
jmeShortGitHash = head.abbreviatedId
jmeBranchName = grgit.branch.current.name
jmeGitTag = grgit.tag.list().find { it.commit == head }
if (jmeGitTag != null) {
jmeGitTag = jmeGitTag.name
} else {
if (System.env.APPVEYOR_REPO_TAG == "true") {
jmeGitTag = System.env.APPVEYOR_REPO_TAG_NAME
} else {
jmeGitTag = System.env.TRAVIS_TAG
}
}
def releaseInfo = getReleaseInfo(jmeGitTag)
if (releaseInfo != null) {
jmeFullVersion = "${releaseInfo.baseVersion}${releaseInfo.releaseSuffix}"
jmePomVersion = "${releaseInfo.mainVersion}${releaseInfo.releaseSuffix}"
} else {
// SNAPSHOT
jmeFullVersion = jmeMainVersion
jmePomVersion = jmeVersion
if (System.env.TRAVIS_BRANCH != null) {
jmeBranchName = System.env.TRAVIS_BRANCH
} else if (System.env.APPVEYOR_REPO_BRANCH != null) {
jmeBranchName = System.env.APPVEYOR_REPO_BRANCH
}
if (System.env.TRAVIS_PULL_REQUEST != null &&
System.env.TRAVIS_PULL_REQUEST != "false") {
jmeBranchName += "-pr-" + System.env.TRAVIS_PULL_REQUEST
} else if (System.env.APPVEYOR_PULL_REQUEST_NUMBER != null) {
jmeBranchName += "-pr-" + System.env.APPVEYOR_PULL_REQUEST_NUMBER
}
if (jmeBranchName != "master") {
jmeFullVersion += "-${jmeBranchName}"
jmePomVersion += "-${jmeBranchName}"
}
jmeFullVersion += "-${jmeRevision}"
jmePomVersion += "-SNAPSHOT"
}
logger.warn("Full Version: ${jmeFullVersion}")
logger.warn("POM Version: ${jmePomVersion}")
} catch (ex) {
// Failed to get repo info
logger.warn("Failed to get repository info: " + ex.message + ". " + \
"Only partial build info will be generated.")
}
}