-
Notifications
You must be signed in to change notification settings - Fork 828
/
build.gradle
347 lines (295 loc) · 12.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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
import org.apache.tools.ant.filters.ReplaceTokens
import java.nio.file.Files
import java.nio.file.Path
buildscript {
apply(from: "dependencies.gradle")
repositories {
mavenCentral()
gradlePluginPortal()
maven {
url("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath(libraries.cargoGradlePlugin)
classpath(libraries.springDependencyMangementGradlePlugin)
classpath(libraries.springBootGradlePlugin)
classpath(libraries.testRetryPlugin)
classpath(libraries.gradleJcocoPlugin)
classpath(libraries.sonarqubePlugin)
}
}
apply(from: "dependencies.gradle")
def applicationPort = project.hasProperty('port') ? project.getProperty('port').toInteger() : 8080
apply(plugin: "com.bmuschko.cargo")
apply(plugin: "war")
allprojects {
apply(plugin: "io.spring.dependency-management")
apply(plugin: "org.gradle.test-retry")
apply(plugin: "org.barfuin.gradle.jacocolog")
apply(plugin: "org.sonarqube")
dependencyManagement {
imports {
mavenBom(libraries.springBootBom)
}
}
repositories {
mavenCentral()
maven {
url("https://build.shibboleth.net/nexus/content/repositories/releases/")
}
maven { url("https://repository.mulesoft.org/releases/") }
}
}
subprojects {
apply(plugin: "java")
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
configurations.all {
exclude(group: "org.hamcrest", module: "hamcrest-all")
exclude(group: "org.hamcrest", module: "hamcrest-core")
exclude(group: "org.hamcrest", module: "hamcrest-library")
exclude(group: "org.springframework.boot", module: "spring-boot-starter-logging")
exclude(group: "org.apache.directory.server", module: "apacheds-core")
exclude(group: "org.apache.directory.server", module: "apacheds-protocol-ldap")
exclude(group: "org.skyscreamer", module: "jsonassert")
exclude(group: "com.vaadin.external.google", module: "android-json")
exclude(group: "com.unboundid.components", module: "json")
// Exclude opensaml-security-api and non-FIPS bouncycastle libs, and use Shadow library for FIPS compliance
exclude(group: "org.bouncycastle", module: "bcpkix-jdk15on")
exclude(group: "org.bouncycastle", module: "bcprov-jdk15on")
exclude(group: "org.bouncycastle", module: "bcutil-jdk15on")
exclude(group: "org.bouncycastle", module: "bcprov-jdk18on")
exclude(group: "org.bouncycastle", module: "bcpkix-jdk18on")
exclude(group: "org.bouncycastle", module: "bcutil-jdk18on")
resolutionStrategy {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
if (details.requested.group == 'org.opensaml' && details.requested.name.startsWith("opensaml-")) {
details.useVersion "${versions.opensaml}"
details.because 'Spring Security 5.8.x allows OpenSAML 3 or 4. OpenSAML 3 has reached its end-of-life. Spring Security 6 drops support for 3, using 4.'
}
}
}
}
dependencies {
testImplementation(libraries.springBootStarterTest)
testImplementation(libraries.hamcrest)
testImplementation(libraries.junit5JupiterApi)
testImplementation(libraries.junit5JupiterParams)
testRuntimeOnly(libraries.junit5JupiterEngine)
testRuntimeOnly(libraries.junitVintageEngine)
testImplementation(libraries.unboundIdLdapSdk)
testRuntimeOnly(libraries.jacocoAgent)
compileOnly("org.projectlombok:lombok")
annotationProcessor("org.projectlombok:lombok")
}
[compileJava, compileTestJava]*.options*.compilerArgs = ["-Xlint:none", "-nowarn"]
test {
// when failFast = true AND retry is on, there is a serious issue:
// gradle might stop the test run due to the failFast but still concludes with BUILD SUCCESSFUL (if the retry is successful)
failFast = false
useJUnitPlatform()
jvmArgs += ["-Xmx1024m", "-XX:+StartAttachListener", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=/var/log/uaa-tests.hprof"]
retry {
def failOnPassedAfterRetrySystemProperty = Boolean.parseBoolean(
System.getProperty("failOnPassedAfterRetry", "false"));
if (!failOnPassedAfterRetrySystemProperty) {
logger.warn("retry: Flaky tests will not make the test run fail because failOnPassedAfterRetry is false.")
}
// Configure the retry extension
failOnPassedAfterRetry = failOnPassedAfterRetrySystemProperty
maxFailures = Integer.parseInt(System.getProperty("maxFailures", "3"))
maxRetries = Integer.parseInt(System.getProperty("maxRetries", "1"))
}
testLogging {
events("failed")
exceptionFormat("full")
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
//showStandardStreams = true
}
}
task integrationTest(type: Test) {
dependsOn rootProject.cargoStartLocal
useJUnitPlatform()
testLogging {
events("failed")
exceptionFormat("full")
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
//showStandardStreams = true
}
}
task generateDocs() {}
task allDeps(type: DependencyReportTask) {}
task writeNewPom() {
doLast {
pom {
project {
licenses {
license {
name("The Apache Software License, Version 2.0")
url("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution("repo")
}
}
}
}.writeTo("./pom.xml")
}
}
repositories {
mavenCentral()
maven {
url("https://jitpack.io")
}
maven {
url("https://repo.maven.apache.org/maven2")
}
}
}
cargo {
containerId = "tomcat9x"
port = applicationPort
if (JavaVersion.current() < JavaVersion.VERSION_17) {
throw new GradleException("This build must be run with Java version [ " + JavaVersion.VERSION_17 + " ] or greater. Your Java version is [ " + JavaVersion.current() + " ]")
}
deployable {
file = file("samples/api/build/libs/cloudfoundry-identity-api-" + version + ".war")
context = "api"
}
deployable {
file = file("samples/app/build/libs/cloudfoundry-identity-app-" + version + ".war")
context = "app"
}
deployable {
file = file("uaa/build/libs/cloudfoundry-identity-uaa-" + version + ".war")
context = "uaa"
}
local {
configHomeDir = file(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
startStopTimeout = Integer.parseInt(System.getProperty("startStopTimeout", "540000"))
rmiPort = applicationPort + 10
jvmArgs = ""
jvmArgs = String.format("%s -DCLOUDFOUNDRY_CONFIG_PATH='%s'", jvmArgs, file("scripts/cargo").getAbsolutePath())
jvmArgs = String.format("%s -Dlogging.config='%s'", jvmArgs, file("scripts/cargo/log4j2.properties").getAbsolutePath())
jvmArgs = String.format("%s -Dstatsd.enabled=true", jvmArgs)
String activeSpringProfiles = System.getProperty("spring.profiles.active", "").split(',');
if (activeSpringProfiles.contains("debugs") || Boolean.valueOf(System.getProperty("xdebugs"))) {
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", jvmArgs)
} else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", jvmArgs)
}
if (Boolean.valueOf(System.getProperty("xcoveragerun"))) {
copy {
from(zipTree(configurations.getByName('jacocoAgent')
.findAll { 'runtimeClasspath' }.get(0))
.matching { include 'jacocoagent.jar' }.singleFile)
into(layout.buildDirectory.dir("jacoco"))
}
String jacocoBuildPath = layout.buildDirectory.dir("jacoco").get().asFile.path
jvmArgs = String.format(
"%s -javaagent:%s/jacocoagent.jar=destfile=%s/cargo.exec",
jvmArgs, jacocoBuildPath, jacocoBuildPath)
}
outputFile = file("uaa/build/reports/tests/uaa-server.log")
configFile {
files = files("scripts/cargo/tomcat-conf/context.xml")
toDir = "conf"
}
systemProperties {
property("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("scripts/cargo").getAbsolutePath()))
property("spring.profiles.active", System.getProperty("spring.profiles.active", "default"))
property("metrics.perRequestMetrics", System.getProperty("metrics.perRequestMetrics", "true"))
property("smtp.host", "localhost")
property("smtp.port", 2525)
property("java.security.egd", "file:/dev/./urandom")
}
containerProperties {
property('cargo.tomcat.ajp.port', applicationPort + 20)
}
installer {
installUrl = "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/" + tomcatCargoVersion + "/tomcat-" + tomcatCargoVersion + ".tar.gz"
downloadDir = layout.buildDirectory.dir("download").get().asFile
extractDir = layout.buildDirectory.dir("extract").get().asFile
}
}
}
sonarqube {
properties {
property "sonar.projectKey", "cloudfoundry-identity-parent"
property "sonar.organization", "cloudfoundry-1"
property "sonar.host.url", "https://sonarcloud.io"
property "sonar.exclusions", "samples/**/*.*,**/*Test.java,**/*Tests.java,**/*IT.java"
property "sonar.java.source", JavaVersion.current()
}
}
project.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
project.allprojects.collect({ it.tasks.withType(Test) }).flatten().each {
it.systemProperty("spring.profiles.active", System.getProperty("spring.profiles.active", "default"))
it.systemProperty("testId", System.getProperty("testId", ""))
}
}
//task declarations
tasks.register('killUaa', Exec) {
workingDir './'
executable = 'scripts/kill_uaa.sh'
}
tasks.register('run') {
dependsOn killUaa
dependsOn cargoRunLocal
}
tasks.register('manifests', Copy) {
dependsOn assemble
from("uaa/src/test/resources/sample-manifests") {
include("**/*.yml")
filter(ReplaceTokens,
tokens: [
version : version,
app : System.getProperty("app", "myuaa"),
appdomain: System.getProperty("app-domain", "bosh-lite.com"),
]
)
}
into("build/sample-manifests")
}
tasks.register('cleanCargoConfDir') {
delete(Path.of(System.getProperty("java.io.tmpdir"), "cargo", "uaa-${applicationPort}"))
try {
Files.createDirectory(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
} catch (ignored) {
}
}
tasks.register('integrationTest', Test) {
dependsOn killUaa
dependsOn subprojects.integrationTest
finalizedBy cargoStopLocal
}
// Jacoco report from cargo run
// - To record coverage of cargo run, execute the task with
// `-Dxcoveragerun=true` option, then use this task to generate report from it.
// - e.g. To generate coverage report of integration test:
// 1) ./gradlew integrationTest -Dxcoveragerun=true
// 2) ./bin/kill_uaa.sh
// 3) ./gradlew jacocoCargoReport
// 4) See the Gradle console output for the test coverage summary.
// 5) See `build/reports/jacoco/jacocoCargoReport` for the full report.
task jacocoCargoReport(type: JacocoReport) {
def javaProjects = subprojects.findAll {
it.pluginManager.hasPlugin('java')
}
executionData(fileTree(layout.buildDirectory).include("jacoco/cargo.exec"))
FileTree sourceTree = files().asFileTree
FileTree classTree = files().asFileTree
javaProjects.each {
sourceTree += it.sourceSets.main.allJava
classTree += it.sourceSets.main.output.asFileTree
}
additionalSourceDirs = sourceTree
additionalClassDirs = classTree
}
// task dependencies
assemble.dependsOn(subprojects.assemble)
test.dependsOn(subprojects.test)
test.mustRunAfter(integrationTest)
cargoStartLocal.dependsOn(assemble)
cargoRunLocal.dependsOn(cleanCargoConfDir, assemble)