forked from apache/geronimo-yoko
-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
268 lines (235 loc) · 8.7 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
/*
* Copyright 2024 IBM Corporation and others.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
import groovy.time.TimeDuration
import groovy.time.TimeCategory
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.1.0'
}
}
plugins {
id "biz.aQute.bnd.builder" version "6.3.1" apply false
}
ext {
testCount = 0
successfulTestCount = 0
failedTestCount = 0
skippedTestCount = 0
time = new TimeDuration(0,0,0,0)
testsResults = []
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
/**
* Compute a hash no longer than <code>length</code> for the git repository.
* @param length
* @return the hash as a string
*/
def getGitHash(length) {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', "--short=$length", 'HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}
/* Standard configuration for each subproject */
subprojects { sp ->
apply plugin: 'java-library'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
maven { url "https://repository.apache.org/snapshots" }
maven { url "https://repo.maven.apache.org/maven2" }
}
configurations {
// declare a test library configuration
testLib
testImplementation.extendsFrom testLib
}
// additional configuration for projects that have bnd.bnd files
if (sp.file("bnd.bnd").exists()) {
apply plugin: 'biz.aQute.bnd.builder'
// to extend the project with a new property, use project.ext.<new property name>
project.ext.symbolicName = project.name.replaceFirst("^yoko-", symbolicNamePrefix)
version = '1.5.0.' + getGitHash(10)
}
// standardise the test deps here
dependencies {
testLib 'junit:junit:4.12'
testLib 'org.mockito:mockito-core:2.22.0'
testLib 'org.mockito:mockito-junit-jupiter:2.22.0'
testLib "org.hamcrest:hamcrest:2.1"
testLib "org.junit.jupiter:junit-jupiter:5.9.0"
testLib "org.junit.platform:junit-platform-runner:1.8.2"
testLib "org.junit-pioneer:junit-pioneer:1.9.1"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.9.0"
testRuntimeOnly "org.junit.vintage:junit-vintage-engine:5.9.0"
}
if (JavaVersion.current() < JavaVersion.VERSION_11) {
throw new GradleException("This build must be run with java 11 or higher")
}
// ensure tests run under $buildDir somewhere
test {
jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED'
jvmArgs '--add-opens=java.base/java.io=ALL-UNNAMED'
jvmArgs '--add-opens=java.base/java.util=ALL-UNNAMED'
jvmArgs '--add-opens=java.rmi/java.rmi=ALL-UNNAMED'
useJUnitPlatform()
workingDir = "$buildDir/testWorkingDir"
doFirst {workingDir.mkdirs()}
testLogging {
// set options for log level LIFECYCLE
events "skipped", "failed", "passed", "standardOut"
showExceptions true
exceptionFormat "full"
showCauses true
showStackTraces true
// set options for log level DEBUG and INFO
debug {
events "skipped", "failed", "started", "passed", "standardOut", "standardError"
exceptionFormat "full"
}
info.events = debug.events
info.exceptionFormat = debug.exceptionFormat
ignoreFailures = true // Always try to run all tests for all modules
afterTest { desc, result ->
def totalTime = result.endTime - result.startTime
println """"Test elapsed time","$desc.name",$totalTime"""
}
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
def timeTaken = TimeCategory.minus(new Date(result.endTime), new Date(result.startTime))
String summary = "${desc.name}" +
"\n" +
"Results: ${result.resultType} " +
"(" +
"${result.testCount} tests, " +
"${result.successfulTestCount} successes, " +
"${result.failedTestCount} failures, " +
"${result.skippedTestCount} skipped" +
") " +
"in ${timeTaken}" +
"\n"
rootProject.testCount += result.testCount
rootProject.successfulTestCount += result.successfulTestCount
rootProject.failedTestCount += result.failedTestCount
rootProject.skippedTestCount += result.skippedTestCount
rootProject.time += timeTaken
// Add reports in `testsResults`, keep failed suites at the end
if (result.resultType == TestResult.ResultType.SUCCESS) {
rootProject.testsResults.add(0, summary)
} else {
rootProject.testsResults += summary
}
def output = "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
def startItem = '| ', endItem = ' |'
def repeatLength = startItem.length() + output.length() + endItem.length()
println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength))
}
def totalTime = result.endTime - result.startTime
println """"Suite elapsed time","$desc.name",$totalTime"""
}
}
}
}
gradle.buildFinished {
String overallSummary = "Total Summary" +
"\n" +
"Results: ${(failedTestCount == 0) ? "SUCCESS": "FAILURE"} " +
"(" +
"${rootProject.testCount} tests, " +
"${rootProject.successfulTestCount} successes, " +
"${rootProject.failedTestCount} failures, " +
"${rootProject.skippedTestCount} skipped" +
") " +
"in ${rootProject.time}" +
"\n"
rootProject.testsResults.add(overallSummary)
def allResults = rootProject.testsResults
if (!allResults.isEmpty()) {
printResults rootProject.testsResults
}
}
private static void printResults(allResults) {
println "\n \n Build Summary:"
// Max line length has to take lines from all items into account
def maxLength = allResults*.readLines().flatten().collect { it.length() }.max()
println ",${"${"-" * maxLength}"}." // Top border
println allResults.collect {
it.readLines().collect { // Add left and right border to each _line_
"|" + it + " " * (maxLength - it.length()) + "|"
}.join("\n")
}.join("\n+${"${"-" * maxLength}"}+\n") // Add separator between entries
println "`${"${"-" * maxLength}"}'" // Print bottom border
}
/* Standard configuration for subprojects with shippable outputs */
configure([
project(':yoko-osgi'),
project(':yoko-util'),
project(':yoko-spec-corba'),
project(':yoko-rmi-spec'),
project(':yoko-rmi-impl'),
project(':yoko-core'),
project(':testify'),
]) {
apply plugin: 'maven-publish'
publishing {
publications {
maven(MavenPublication) {
artifact jar
pom.withXml {
def rootNode = asNode()
// // specify packaging type as bundle (default is pom)
// def packaging = root.packaging[0] ?:
// root.appendNode('packaging')
// packaging.setValue('bundle')
def depsNode = rootNode.dependencies[0] ?:
rootNode.appendNode('dependencies')
// declare compile scope dependencies in the pom.xml
// as compile dependencies
configurations.implementation.allDependencies.each {
def depNode = depsNode.appendNode('dependency')
depNode.appendNode('groupId', it.group)
depNode.appendNode('artifactId', it.name)
depNode.appendNode('version', it.version)
depNode.appendNode('scope', 'compile')
}
}
}
}
}
jar {
dependsOn "generatePomFileForMavenPublication"
// generate the maven dependency metadata
into("/META-INF/maven/$project.group/$project.name") {
from 'build/publications/maven'
rename "pom-default.xml", "pom.xml"
}
}
publish.dependsOn build
// generated tasks need to be expressed as strings
// because they don't exist yet when these lines are executed
publish.dependsOn "publishMavenPublicationToMavenLocal"
publish.dependsOn "publishToMavenLocal"
}