-
Notifications
You must be signed in to change notification settings - Fork 40
/
plugin-tasks.gradle
241 lines (208 loc) · 7.97 KB
/
plugin-tasks.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
/*
* Copyright 2022 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import groovy.xml.MarkupBuilder
processResources {
from("src/main/resource-templates") {
duplicatesStrategy(DuplicatesStrategy.INCLUDE)
filesMatching('plugin.xml') {
expand project.pluginDesc
}
filesMatching('plugin.properties') {
expand project.pluginDesc
}
filesMatching('version.properties') {
expand project.pluginDesc
}
}
}
project.ext.color = [
ANSI_BOLD_WHITE: "\u001B[0;1m",
ANSI_RESET : "\u001B[0m",
ANSI_RED : "\u001B[31m",
ANSI_GREEN : "\u001B[32m",
ANSI_YELLOW : "\u001B[33m",
ANSI_WHITE : "\u001B[37m"
]
project.ext.symbols = [
CHECK_MARK : "\u2714",
NEUTRAL_FACE: "\u0CA0_\u0CA0",
X_MARK : "\u2718"
]
tasks.withType(JavaCompile) {
options.deprecation = true
options.encoding = 'utf-8'
options.warnings = true
options.compilerArgs << "-Xlint:all"
options.compilerArgs << "-Xlint:-serial"
}
tasks.withType(Jar) { jarTask ->
preserveFileTimestamps = false
reproducibleFileOrder = true
['MD5', 'SHA1', 'SHA-256'].each { algo ->
jarTask.outputs.files("${jarTask.archiveFile.get()}.${algo}")
jarTask.doLast {
ant.checksum file: jarTask.archiveFile.get(), format: 'MD5SUM', algorithm: algo
}
}
manifest {
attributes(
'Go-Version': project.pluginDesc.goCdVersion,
'Plugin-Revision': project.pluginDesc.version,
'Implementation-Title': project.name,
'Implementation-Version': project.version,
'Source-Compatibility': project.java.sourceCompatibility,
'Target-Compatibility': project.java.targetCompatibility
)
}
}
tasks.withType(Test) {
maxParallelForks = 1
testLogging {
def previousFailed = false
exceptionFormat 'full'
beforeSuite { suite ->
if (suite.name.startsWith("Test Run") || suite.name.startsWith("Gradle Worker")) return
if (suite.parent != null && suite.className != null) {
println(project.color.ANSI_BOLD_WHITE + suite.name + project.color.ANSI_RESET)
}
}
beforeTest {
if (previousFailed) {
System.err.println("")
}
}
afterTest { descriptor, result ->
previousFailed = false
def executionTime = (result.endTime - result.startTime) / 1000
println(" ${resultIndicator(result)}$project.color.ANSI_RESET $descriptor.name $project.color.ANSI_YELLOW($executionTime seconds)$project.color.ANSI_RESET")
if (result.failedTestCount > 0) {
previousFailed = true
println('')
println(result.exception)
}
}
afterSuite { desc, result ->
if (desc.parent != null && desc.className != null) {
println("")
}
if (!desc.parent) { // will match the outermost suite
def failStyle = project.color.ANSI_RED
def skipStyle = project.color.ANSI_YELLOW
def summaryStyle = summaryStyle(result)
if (result.failedTestCount > 0) {
failStyle = project.color.ANSI_RED
}
if (result.skippedTestCount > 0) {
skipStyle = project.color.ANSI_YELLOW
}
println("--------------------------------------------------------------------------")
println("Results: $summaryStyle$result.resultType$project.color.ANSI_RESET ($result.testCount tests, $project.color.ANSI_GREEN$result.successfulTestCount passed$project.color.ANSI_RESET, $failStyle$result.failedTestCount failed$project.color.ANSI_RESET, $skipStyle$result.skippedTestCount skipped$project.color.ANSI_RESET)")
println("--------------------------------------------------------------------------")
}
}
}
}
private String summaryStyle(result) {
def summaryStyle = project.color.ANSI_WHITE
switch (result.resultType) {
case TestResult.ResultType.SUCCESS:
summaryStyle = project.color.ANSI_GREEN
break
case TestResult.ResultType.FAILURE:
summaryStyle = project.color.ANSI_RED
break
}
summaryStyle
}
private String resultIndicator(result) {
def indicator = project.color.ANSI_WHITE
if (result.failedTestCount > 0) {
indicator = project.color.ANSI_RED + project.symbols.X_MARK
} else if (result.skippedTestCount > 0) {
indicator = project.color.ANSI_YELLOW + project.symbols.NEUTRAL_FACE
} else {
indicator = project.color.ANSI_GREEN + project.symbols.CHECK_MARK
}
indicator
}
task previewGithubRelease() {
doLast {
def prerelease = !"No".equalsIgnoreCase(System.getenv('PRERELEASE'))
def lastTag = project.git.getLastTag(prerelease)
def targetCommitish = project.git.gitRevision()
def assets = subprojects.findAll { it.name != "common" }
.collect { it.jar.outputs.files.files }
.flatten()
def tagName = "${project.fullVersion}${prerelease ? '-exp' : ''}"
def releaseName = "${prerelease ? 'Experimental: ' : ''}${project.fullVersion}"
def changelogHeader = lastTag ? "Changelog ${lastTag}..${project.fullVersion}" : "Changelog"
def changes = project.git.getCommitsSinceLastTag(lastTag).replaceAll("\"", "").stripIndent().trim()
def previewFile = file("${project.buildDir}/preview.html")
if (!previewFile.exists()) {
previewFile.createNewFile()
}
def html = new MarkupBuilder(new FileWriter(previewFile))
html.html {
body {
div {
h1(project.pluginDesc.repo)
h3(releaseName)
div {
b("Tag: ")
span(tagName)
}
div {
b("Commit: ")
span(targetCommitish.substring(0, 7))
}
div {
h4("Assets")
assets.each { div(it.getName() + " - " + project.git.readableFileSize(it.length())) }
}
div {
h4(changelogHeader)
p {
changes.split("\n").each { div(it) }
}
}
}
}
}
def output_preview = file("$rootProject.buildDir/preview.html")
if (output_preview.exists()) {
output_preview.append(previewFile.text)
} else {
output_preview.write(previewFile.text)
}
}
}
task deploy() {
dependsOn assemble
description 'Run ./gradlew deploy -Pserver_path=~/gocd to deploy plugin'
doLast {
if (project.hasProperty('server_path')) {
def server_path = "$server_path"
project.copy {
from "$project.buildDir/libs/"
include "*.jar"
into server_path
}
} else {
throw new GradleScriptException('Run ./gradlew deploy -Pserver_path=~/gocd to deploy plugin', null)
}
}
}
previewGithubRelease.dependsOn assemble