forked from BladeRunnerJS/brjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
325 lines (267 loc) · 10.5 KB
/
build.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
apply from: 'wrapper.gradle'
def projectBuildVersion = org.bladerunnerjs.BuildVersionCalculator.calculateVersion(project)
def projectBuildMajorVersion = org.bladerunnerjs.BuildVersionCalculator.calculateMajorVersion(project)
def projectVersionIsDirty = org.bladerunnerjs.BuildVersionCalculator.isVersionDirty(project)
def projectBuildDate = org.bladerunnerjs.BuildVersionCalculator.calculateBuildDate(project)
def projectBuildHostname = org.bladerunnerjs.BuildVersionCalculator.calculateBuildHostname(project)
def projectCurrentBranch = org.bladerunnerjs.BuildVersionCalculator.calculateCurrentBranch(project)
logger.info "Build version calculated as: ${projectBuildVersion}"
logger.info "Build date is: ${projectBuildDate}"
logger.info "Build hostname is: ${projectBuildHostname}"
logger.info "Build branch is: ${projectCurrentBranch}"
def overrideBuildVersionPropertyName = "overrideBuildVersion"
if (project.hasProperty(overrideBuildVersionPropertyName)) {
logger.info "Project has property ${overrideBuildVersionPropertyName} set, overriding calculated build version"
projectBuildVersion = project.property(overrideBuildVersionPropertyName)
}
def overrideMajorVersionPropertyName = "overrideBuildMajorVersion"
if (project.hasProperty(overrideMajorVersionPropertyName)) {
logger.info "Project has property ${overrideMajorVersionPropertyName} set, overriding calculated build version"
projectBuildMajorVersion = project.property(overrideMajorVersionPropertyName)
}
[ "JAVA8_HOME", "JAVA7_HOME" ].each { envName ->
def property = System.getenv()[envName]
if (property == null)
{
throw new GradleException("The environment variable '${envName} must be set for the build to work correctly, please make sure it is set. Refer to README.md for info on the dev environment setup.")
}
}
ext {
RELEASE_BRANCH = "master"
}
allprojects {
ext {
buildVersion = projectBuildVersion
buildDate = projectBuildDate
buildHostname = projectBuildHostname
}
def projectContainingSharedLogic = project
while (projectContainingSharedLogic != null) {
def dependenciesFile = projectContainingSharedLogic.file('dependencies.gradle')
if (dependenciesFile.isFile()) {
apply from: dependenciesFile
break
}
projectContainingSharedLogic = projectContainingSharedLogic.parent
}
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'base'
repositories {
mavenCentral()
maven { url "http://bladerunnerjs.github.io/brjs-build-dependencies/repo" }
}
buildscript {
repositories {
mavenCentral()
}
}
tasks.withType(Copy) {
fileMode = 0755
includeEmptyDirs = false
}
tasks.withType(Sync) {
fileMode = 0755
includeEmptyDirs = false
}
tasks.withType(Zip) {
fileMode = 0755
includeEmptyDirs = false
}
}
subprojects { p ->
version = buildVersion
group = 'org.bladerunnerjs'
afterEvaluate { project ->
if (project.plugins.hasPlugin(JavaPlugin)) {
if(project.name == 'brjs-core'
|| project.name == 'brjs-core-tests'
|| project.name == 'brjs-plugins') {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
else if(project.name == 'brjs-servlet') {
sourceCompatibility = '1.6'
targetCompatibility = '1.6'
}
else {
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
}
project.tasks.withType(Test) { testTask ->
test {
testLogging {
events 'skipped', 'failed'
exceptionFormat 'full'
info {
displayGranularity = 0
}
}
}
}
project.tasks.withType(JavaCompile) {
options.compilerArgs += ['-Xlint:all,-path']
options.encoding = 'UTF-8'
}
}
}
}
task runAllJavaTests << { throw new GradleException("runAllJavaTests has been renamed to testJava") }
task testJava {
description "Runs 'test' for all Java projects."
}
subprojects {
afterEvaluate { project ->
project.tasks.withType(Test) { testTask ->
testJava.dependsOn testTask
}
}
}
task cleanJava {
description "Runs clean for all Java projects."
}
subprojects {
afterEvaluate { project ->
if (project.plugins.hasPlugin(JavaPlugin.class)) {
cleanJava.dependsOn project.clean
}
}
}
task build {
description "Builds and tests the distribution. Runs 'build' on all subprojects."
}
def parentBuildTask = build
subprojects {
afterEvaluate { subProject ->
parentBuildTask.dependsOn subProject.getTasksByName('build',false)
}
}
def getProperty = { project, property ->
if (!project.hasProperty(property)) {
throw new GradleException("${property} property must be set")
}
return project.property(property)
}
/* Automated release stuff */
def getGitHubToken = { project ->
return getProperty(project,"githubToken")
}
def getReleaseNoteJson = { project, tagVersion ->
def releaseDataFile = file("releases/${tagVersion}.json")
def releaseDataText = releaseDataFile.text
releaseDataText = releaseDataText.replaceAll("@tagVersion@", tagVersion)
releaseDataText = releaseDataText.replaceAll("@buildVersion@", buildVersion)
def releaseNoteJson = new groovy.json.JsonSlurper().parseText( releaseDataText )
return releaseNoteJson
}
import org.bladerunnerjs.github.*
task generateReleaseNotes, {
def assembledReleaseNotesFile = file("${buildDir}/release-note.txt")
inputs.property "projectBuildVersion", projectBuildVersion
outputs.file assembledReleaseNotesFile
doFirst {
def gitHubToken = getGitHubToken(project)
def githubApi = new GitHubAPIBridge(project, "BladeRunnerJS", "brjs", gitHubToken)
def tagVersion = projectBuildMajorVersion
def releaseNoteFile = file("releases/${tagVersion}.md")
def milestoneJson = getReleaseNoteJson(project,tagVersion).milestone
def milestones = milestoneJson.split(",").collect { it.trim() }
def milestoneIds = githubApi.getMilestoneIds(milestones)
def includeIssueLabels = ["bug", "feature", "enhancement", "experience", "breaking-change", "java-api", "js-api", " CaplinSupport"]
def issueIncludeLabelsString = includeIssueLabels.join(", ").replaceAll(/^(.*),(.*)$/,'$1 or$2'); /* regex replaces the last ',' with 'or' */
def excludeIssueLabels = ["invalid", "duplicate", "wont-fix", "wontfix", "ignore-release-note"]
List<Issue> issues = new ArrayList<Issue>();
milestoneIds.each { milestoneId ->
issues.addAll( githubApi.getClosedIssuesForMilestone(milestoneId) )
}
List<Issue> releaseNoteIssues = new LinkedList<Issue>()
issues.each {
if (it.labels.intersect(includeIssueLabels) && !it.labels.intersect(excludeIssueLabels)) {
releaseNoteIssues.add(it)
}
}
def appendToReleaseNotes = []
appendToReleaseNotes << ""
appendToReleaseNotes << "<br/>"
appendToReleaseNotes << "-------------"
appendToReleaseNotes << "### API Documentation"
appendToReleaseNotes << ""
appendToReleaseNotes << "- [@tagVersion@ JavaScript API](http://apidocs.bladerunnerjs.org/@tagVersion@/js/)"
appendToReleaseNotes << "- [@tagVersion@ Java Model API](http://apidocs.bladerunnerjs.org/@tagVersion@/java/)"
appendToReleaseNotes << ""
appendToReleaseNotes << "**Travis Build Status for @tagVersion@:** [![Build Status](https://travis-ci.org/BladeRunnerJS/brjs.svg?branch=@tagVersion@)](https://travis-ci.org/BladeRunnerJS/brjs)"
appendToReleaseNotes << ""
appendToReleaseNotes << "### Closed Issues"
appendToReleaseNotes << "The following issues labelled ${issueIncludeLabelsString} have been closed:"
appendToReleaseNotes << ""
releaseNoteIssues.each {
appendToReleaseNotes << "- ${it.toString()}"
}
appendToReleaseNotes << ""
appendToReleaseNotes << "<sup>${issues.size} issues closed; ${releaseNoteIssues.size} labelled ${issueIncludeLabelsString} from ${milestoneIds.size} milestones: "
milestoneIds.each { milestoneId ->
if (milestoneId != milestoneIds.first()) {
appendToReleaseNotes << "; "
}
def milestoneUrl = "${githubApi.getMilestoneUrl(milestoneId)}&state=closed"
appendToReleaseNotes << "<a href=\"${milestoneUrl}\">${milestoneUrl}</a>"
}
appendToReleaseNotes << "</sub>"
appendToReleaseNotes << ""
appendToReleaseNotes << "### Found an Issue?"
appendToReleaseNotes << "- [https://github.com/BladeRunnerJS/brjs/issues](https://github.com/BladeRunnerJS/brjs/issues) for any existing issues"
appendToReleaseNotes << "- [https://github.com/BladeRunnerJS/brjs/issues/new](https://github.com/BladeRunnerJS/brjs/issues/new) to raise a new issues."
appendToReleaseNotes << ""
appendToReleaseNotes << ""
appendToReleaseNotes << '<sub>Parts of this release note have been auto-generated. If you notice any problems with it <a href="https://github.com/BladeRunnerJS/brjs/issues/new">tell us</a></sub>'
appendToReleaseNotes << ""
appendToReleaseNotes << ""
assembledReleaseNotesFile.parentFile.mkdirs()
assembledReleaseNotesFile.createNewFile()
assembledReleaseNotesFile.text = releaseNoteFile.text + "\n" + appendToReleaseNotes.join("\n")
ant.replace(file: assembledReleaseNotesFile) {
replacefilter(token:"@tagVersion@", value:tagVersion)
replacefilter(token:"@buildVersion@", value:buildVersion)
}
}
}
generateReleaseNotes.shouldRunAfter ':brjs-sdk:distZip'
task githubRelease, dependsOn:[generateReleaseNotes, ':brjs-sdk:distZip', build], {
doLast {
def cutlassSdkProject = project(':brjs-sdk')
def brjsZipPattern = "**/BladeRunnerJS-${projectBuildVersion}.zip"
def brjsZip = fileTree(dir:cutlassSdkProject.buildDir, include:brjsZipPattern).singleFile
if (!projectCurrentBranch.equals(RELEASE_BRANCH))
{
throw new GradleException("BladeRunnerJS ${projectBuildVersion} can only be released from '${RELEASE_BRANCH}' branch, you are currently on '${projectCurrentBranch}'.")
}
if (projectVersionIsDirty)
{
throw new GradleException("Project version is dirty, this version (${projectBuildVersion}) cannot be released.")
}
def gitHubToken = getGitHubToken(project)
def githubApi = new GitHubAPIBridge(project, "BladeRunnerJS", "brjs", gitHubToken)
def tagVersion = projectBuildMajorVersion
def releaseNoteFile = generateReleaseNotes.outputs.files.singleFile
def releaseJson = getReleaseNoteJson(project,tagVersion)
Release release = githubApi.createReleaseForTag(tagVersion, releaseJson, releaseNoteFile.text)
githubApi.uploadAssetForRelease(brjsZip, release)
}
}
if (org.bladerunnerjs.OSCalculator.isWin32())
{
configurations {
curlDep
}
dependencies {
curlDep dependency('curl-win32')
}
task downloadCurl, type:Copy, dependsOn:configurations.curlDep, {
from { configurations.curlDep.collect { zipTree(it) } }
into "${buildDir}/curl"
}
githubRelease.doFirst {
GitHubAPIBridge.CURL_PATH = fileTree(dir:downloadCurl.outputs.files.singleFile, include:"**/curl.exe").singleFile.path
}
githubRelease.dependsOn downloadCurl
}