Skip to content

Commit 988253a

Browse files
authored
Merge pull request #3648 from ireneGonzalezRuiz/iglezruiz/cargo-migration
Cargo migration & Upgrade Gradle to version 9.0.0
2 parents cedec71 + bef2db8 commit 988253a

File tree

19 files changed

+196
-837
lines changed

19 files changed

+196
-837
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ clients, as well as various other management functions.
1616

1717
The authentication service is `uaa`. It's a plain Spring MVC webapp.
1818
Deploy as normal in Tomcat or your container of choice, or execute
19-
`./gradlew run` to run it directly from `uaa` directory in the source
19+
`./gradlew run` (or `./gradlew bootRun`) to run it directly from `uaa` directory in the source
2020
tree. When running with Gradle, it listens on port 8080 and the URL is
2121
`http://localhost:8080/uaa`
2222

@@ -90,7 +90,7 @@ UAA will log to a file called `uaa.log` which can be found using the following c
9090

9191
which you should find under something like:-
9292

93-
$TMPDIR/cargo/conf/logs/
93+
scripts/boot/tomcat/logs/
9494

9595
### Demo of command line usage on a local server
9696

@@ -109,16 +109,17 @@ For complex requests it is more convenient to interact with UAA using
109109

110110
### Running as a Spring Boot Application
111111

112-
Two separate Gradle tasks can be used to run the Spring Boot application
112+
Three separate Gradle tasks can be used to run the Spring Boot application
113113

114+
- `./gradlew run` — alias that kills any running UAA and starts the application (recommended)
114115
- `./gradlew bootRun` — the built-in Spring Boot Gradle task
115116
- `./gradlew bootWarRun` — use a `JavaExec` Gradle task to launch the runnable .war file
116117
- Manual run, as show below, to be run after `./gradlew assemble`
117118
- Using ./scripts/boot/boot-with-tls.sh — runs http/8080 and https/8443
118119

119120
```text
120-
java -DCLOUDFOUNDRY_CONFIG_PATH=`pwd`/scripts/cargo \
121-
-DSECRETS_DIR=`pwd`/scripts/cargo \
121+
java -DCLOUDFOUNDRY_CONFIG_PATH=`pwd`/scripts/boot \
122+
-DSECRETS_DIR=`pwd`/scripts/boot \
122123
-Djava.security.egd=file:/dev/./urandom \
123124
-Dmetrics.perRequestMetrics=true \
124125
-Dserver.servlet.context-path=/uaa \
@@ -135,7 +136,7 @@ java -DCLOUDFOUNDRY_CONFIG_PATH=`pwd`/scripts/cargo \
135136
```
136137

137138
Running Spring Boot standalone allows us to run the integration tests against it using the
138-
`./gradlew -Dcargo.tests.run=false integrationTest` with the system property preventing Gradle from starting up Apache Tomcat.
139+
`./gradlew integrationTest` with the system property preventing Gradle from starting up Apache Tomcat.
139140

140141
### Debugging local server
141142

@@ -158,9 +159,10 @@ or
158159
```sh
159160
./gradlew -Dspring.profiles.active=hsqldb,debugs run
160161
```
162+
Note: You can also use `bootRun` instead of `run` for these commands.
161163

162164
## Running a local UAA server with different databases
163-
`./gradlew run` runs the UAA server with hsqldb database by default.
165+
`./gradlew run` (or `./gradlew bootRun`) runs the UAA server with hsqldb database by default.
164166

165167
### MySql
166168
1. Start the mysql server (e.g. a mysql docker container)

build.gradle

Lines changed: 53 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ buildscript {
1010
mavenCentral()
1111
gradlePluginPortal()
1212
maven {
13-
url("https://plugins.gradle.org/m2/")
13+
url = uri("https://plugins.gradle.org/m2/")
1414
}
1515
}
1616

1717
dependencies {
18-
classpath(libraries.cargoGradlePlugin)
19-
classpath(libraries.springDependencyMangementGradlePlugin)
18+
classpath(libraries.springDependencyManagementGradlePlugin)
2019
classpath(libraries.springBootGradlePlugin)
2120
classpath(libraries.gradleJcocoPlugin)
2221
classpath(libraries.sonarqubePlugin)
@@ -27,9 +26,6 @@ apply(from: "dependencies.gradle")
2726

2827
def applicationPort = project.hasProperty('port') ? project.getProperty('port').toInteger() : 8080
2928

30-
apply(plugin: "com.bmuschko.cargo")
31-
apply(plugin: "war")
32-
3329
allprojects {
3430
apply(plugin: "io.spring.dependency-management")
3531
apply(plugin: "org.barfuin.gradle.jacocolog")
@@ -44,25 +40,12 @@ allprojects {
4440
repositories {
4541
mavenCentral()
4642
maven {
47-
url("https://build.shibboleth.net/nexus/content/repositories/releases/")
43+
url = uri("https://build.shibboleth.net/nexus/content/repositories/releases/")
4844
}
49-
maven { url("https://repository.mulesoft.org/releases/") }
45+
maven { url = uri("https://repository.mulesoft.org/releases/") }
5046
}
51-
52-
//set this property to false to run integration tests against an already
53-
//running server on http://localhost:8080/uaa
54-
ext.runCargoTests = Boolean.valueOf(System.getProperty("cargo.tests.run", "true"))
5547
}
5648

57-
configurations {
58-
mockitoAgent
59-
}
60-
dependencies {
61-
testImplementation(libraries.mockito)
62-
mockitoAgent(libraries.mockito) {
63-
transitive = false
64-
}
65-
}
6649

6750
subprojects {
6851
apply(plugin: "java")
@@ -71,7 +54,7 @@ subprojects {
7154
targetCompatibility = JavaVersion.VERSION_21
7255
}
7356

74-
configurations.all {
57+
configurations.configureEach {
7558
exclude(group: "org.hamcrest", module: "hamcrest-all")
7659
exclude(group: "org.hamcrest", module: "hamcrest-core")
7760
exclude(group: "org.hamcrest", module: "hamcrest-library")
@@ -128,37 +111,38 @@ subprojects {
128111
jvmArgs += ["-Xmx1024m",
129112
"-XX:+StartAttachListener",
130113
"-XX:+HeapDumpOnOutOfMemoryError",
131-
"-XX:HeapDumpPath=/var/log/uaa-tests.hprof",
132-
"-javaagent:${parent.configurations.mockitoAgent.asPath}"
114+
"-XX:HeapDumpPath=/var/log/uaa-tests.hprof"
133115
]
134116

135117
testLogging {
136118
events("failed")
137-
exceptionFormat("full")
119+
exceptionFormat = "full"
138120
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
139121
//showStandardStreams = true
140122
}
141123
}
142124

143-
task integrationTest(type: Test) {
144-
if (runCargoTests) {
145-
dependsOn rootProject.cargoStartLocal
146-
}
125+
tasks.register('integrationTest', Test) {
147126
useJUnitPlatform()
148127

128+
// Enable JaCoCo for integration tests
129+
jacoco {
130+
enabled = true
131+
}
132+
149133
testLogging {
150134
events("failed")
151-
exceptionFormat("full")
135+
exceptionFormat = "full"
152136
// Uncomment the following line to see all standard output from tests (there's a ton of it!)
153137
//showStandardStreams = true
154138
}
155139
}
156140

157-
task generateDocs() {}
141+
tasks.register('generateDocs') {}
158142

159-
task allDeps(type: DependencyReportTask) {}
143+
tasks.register('allDeps', DependencyReportTask) {}
160144

161-
task writeNewPom() {
145+
tasks.register('writeNewPom') {
162146
doLast {
163147
pom {
164148
project {
@@ -185,81 +169,6 @@ subprojects {
185169
}
186170
}
187171

188-
cargo {
189-
containerId = "tomcat10x"
190-
port = applicationPort
191-
192-
if (JavaVersion.current() < JavaVersion.VERSION_21) {
193-
throw new GradleException("This build must be run with Java version [ " + JavaVersion.VERSION_21 + " ] or greater. Your Java version is [ " + JavaVersion.current() + " ]")
194-
}
195-
196-
deployable {
197-
file = file("uaa/build/libs/cloudfoundry-identity-uaa-" + version + ".war")
198-
context = "uaa"
199-
}
200-
201-
local {
202-
configHomeDir = file(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
203-
startStopTimeout = Integer.parseInt(System.getProperty("startStopTimeout", "540000"))
204-
rmiPort = applicationPort + 10
205-
206-
jvmArgs = ""
207-
jvmArgs = String.format("%s -DCLOUDFOUNDRY_CONFIG_PATH='%s'", jvmArgs, file("scripts/cargo").getAbsolutePath())
208-
jvmArgs = String.format("%s -Dlogging.config='%s'", jvmArgs, file("scripts/cargo/log4j2.properties").getAbsolutePath())
209-
jvmArgs = String.format("%s -Dstatsd.enabled=true", jvmArgs)
210-
211-
String activeSpringProfiles = System.getProperty("spring.profiles.active", "").split(',');
212-
if (activeSpringProfiles.contains("debugs") || Boolean.valueOf(System.getProperty("xdebugs"))) {
213-
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005", jvmArgs)
214-
} else if (activeSpringProfiles.contains("debug") || Boolean.valueOf(System.getProperty("xdebug"))) {
215-
jvmArgs = String.format("%s -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005", jvmArgs)
216-
}
217-
String tlsDebug = System.getProperty("javax.net.debug");
218-
if (tlsDebug?.trim()) {
219-
jvmArgs = String.format("%s -Djavax.net.debug=%s", jvmArgs, tlsDebug)
220-
}
221-
222-
if (Boolean.valueOf(System.getProperty("xcoveragerun"))) {
223-
copy {
224-
from(zipTree(configurations.getByName('jacocoAgent')
225-
.findAll { 'runtimeClasspath' }.get(0))
226-
.matching { include 'jacocoagent.jar' }.singleFile)
227-
into(layout.buildDirectory.dir("jacoco"))
228-
}
229-
230-
String jacocoBuildPath = layout.buildDirectory.dir("jacoco").get().asFile.path
231-
jvmArgs = String.format(
232-
"%s -javaagent:%s/jacocoagent.jar=destfile=%s/cargo.exec",
233-
jvmArgs, jacocoBuildPath, jacocoBuildPath)
234-
}
235-
236-
outputFile = file("uaa/build/reports/tests/uaa-server.log")
237-
configFile {
238-
files = files("scripts/cargo/tomcat-conf/context.xml")
239-
toDir = "conf"
240-
}
241-
242-
systemProperties {
243-
property("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("scripts/cargo").getAbsolutePath()))
244-
property("spring.profiles.active", System.getProperty("spring.profiles.active", "hsqldb"))
245-
property("metrics.perRequestMetrics", System.getProperty("metrics.perRequestMetrics", "true"))
246-
property("smtp.host", "localhost")
247-
property("smtp.port", 2525)
248-
property("java.security.egd", "file:/dev/./urandom")
249-
}
250-
251-
containerProperties {
252-
property('cargo.tomcat.ajp.port', applicationPort + 20)
253-
}
254-
255-
installer {
256-
installUrl = "https://repo1.maven.org/maven2/org/apache/tomcat/tomcat/" + tomcatCargoVersion + "/tomcat-" + tomcatCargoVersion + ".tar.gz"
257-
downloadDir = layout.buildDirectory.dir("download").get().asFile
258-
extractDir = layout.buildDirectory.dir("extract").get().asFile
259-
}
260-
}
261-
}
262-
263172
sonarqube {
264173
properties {
265174
property "sonar.projectKey", "cloudfoundry-identity-parent"
@@ -277,19 +186,8 @@ project.gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
277186
}
278187
}
279188

280-
//task declarations
281-
tasks.register('killUaa', Exec) {
282-
workingDir './'
283-
executable = 'scripts/kill_uaa.sh'
284-
}
285-
286-
tasks.register('run') {
287-
dependsOn killUaa
288-
dependsOn cargoRunLocal
289-
}
290-
291189
tasks.register('manifests', Copy) {
292-
dependsOn assemble
190+
dependsOn subprojects.assemble
293191
from("uaa/src/test/resources/sample-manifests") {
294192
include("**/*.yml")
295193
filter(ReplaceTokens,
@@ -303,39 +201,33 @@ tasks.register('manifests', Copy) {
303201
into("build/sample-manifests")
304202
}
305203

306-
tasks.register('cleanCargoConfDir') {
307-
delete(Path.of(System.getProperty("java.io.tmpdir"), "cargo", "uaa-${applicationPort}"))
308-
try {
309-
Files.createDirectory(Path.of(System.getProperty("java.io.tmpdir"), "uaa-${applicationPort}"))
310-
} catch (ignored) {
311-
}
312-
}
313-
314204
tasks.register('integrationTest', Test) {
315-
if (runCargoTests) {
316-
dependsOn killUaa
317-
}
318205
dependsOn subprojects.integrationTest
319-
if (runCargoTests) {
320-
finalizedBy cargoStopLocal
321-
}
322206
}
323207

324-
// Jacoco report from cargo run
325-
// - To record coverage of cargo run, execute the task with
326-
// `-Dxcoveragerun=true` option, then use this task to generate report from it.
327-
// - e.g. To generate coverage report of integration test:
328-
// 1) ./gradlew integrationTest -Dxcoveragerun=true
329-
// 2) ./bin/kill_uaa.sh
330-
// 3) ./gradlew jacocoCargoReport
331-
// 4) See the Gradle console output for the test coverage summary.
332-
// 5) See `build/reports/jacoco/jacocoCargoReport` for the full report.
333-
task jacocoCargoReport(type: JacocoReport) {
208+
// Jacoco coverage reports:
209+
//
210+
// For unit test coverage (recommended):
211+
// ./gradlew test jacocoTestReport
212+
// Reports in each module: <module>/build/reports/jacoco/test/html/index.html
213+
//
214+
// For aggregated coverage across all modules:
215+
// ./gradlew test jacocoAggregatedReport
216+
// Report: build/reports/jacoco/jacocoAggregatedReport/html/index.html
217+
//
218+
// Note: Integration test coverage (jacocoIntegrationReport) requires running
219+
// integration tests which need special setup (UAA server, database, LDAP).
220+
// Use ./run-integration-tests.sh for that purpose.
221+
tasks.register('jacocoCargoReport', JacocoReport) {
334222
def javaProjects = subprojects.findAll {
335223
it.pluginManager.hasPlugin('java')
336224
}
337225

338-
executionData(fileTree(layout.buildDirectory).include("jacoco/cargo.exec"))
226+
// Collect execution data from all subprojects' integration tests
227+
executionData(fileTree(layout.buildDirectory).include("jacoco/*.exec"))
228+
javaProjects.each { subproject ->
229+
executionData.from(fileTree(subproject.layout.buildDirectory).include("jacoco/integrationTest.exec"))
230+
}
339231

340232
FileTree sourceTree = files().asFileTree
341233
FileTree classTree = files().asFileTree
@@ -347,13 +239,6 @@ task jacocoCargoReport(type: JacocoReport) {
347239
additionalClassDirs = classTree
348240
}
349241

350-
// task dependencies
351-
assemble.dependsOn(subprojects.assemble)
352-
test.dependsOn(subprojects.test)
353-
test.mustRunAfter(integrationTest)
354-
cargoStartLocal.dependsOn(assemble)
355-
cargoRunLocal.dependsOn(cleanCargoConfDir, assemble)
356-
357242
tasks.register('cleanBootTomcatDir') {
358243
String tomcatBase = file("scripts/boot/tomcat/").getAbsolutePath()
359244
delete(java.nio.file.Path.of(tomcatBase))
@@ -363,16 +248,29 @@ tasks.register('cleanBootTomcatDir') {
363248

364249
tasks.register('bootWarRun', JavaExec) {
365250
dependsOn cleanBootTomcatDir
366-
dependsOn assemble
251+
dependsOn subprojects.assemble
367252
classpath = files(file("uaa/build/libs/cloudfoundry-identity-uaa-0.0.0.war"))
368253
systemProperty("server.tomcat.basedir", file("scripts/boot/tomcat/").getAbsolutePath())
369-
systemProperty("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("scripts/cargo").getAbsolutePath()))
254+
systemProperty("SECRETS_DIR", System.getProperty("SECRETS_DIR", file("scripts/boot").getAbsolutePath()))
370255
systemProperty("spring.profiles.active", System.getProperty("spring.profiles.active", "hsqldb"))
371256
systemProperty("metrics.perRequestMetrics", System.getProperty("metrics.perRequestMetrics", "true"))
372257
systemProperty("smtp.host", "localhost")
373258
systemProperty("smtp.port", 2525)
374259
systemProperty("java.security.egd", "file:/dev/./urandom")
375-
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("scripts/cargo").getAbsolutePath())
260+
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("scripts/boot").getAbsolutePath())
376261
systemProperty("server.servlet.context-path", "/uaa")
377262
systemProperty("statsd.enabled", "true")
263+
systemProperty("logging.config", file("scripts/boot/log4j2.properties").getAbsolutePath())
264+
}
265+
266+
tasks.register('killUaa', Exec) {
267+
workingDir './'
268+
executable = 'scripts/kill_uaa.sh'
269+
}
270+
271+
tasks.register('run') {
272+
dependsOn killUaa
273+
dependsOn ':cloudfoundry-identity-uaa:bootRun'
274+
description = "Kills any running UAA and starts the application"
275+
group = "application"
378276
}

0 commit comments

Comments
 (0)