Skip to content

Commit 10d737e

Browse files
committed
Add debug mode with -Pdebug and -Pdebugs
1 parent d09b969 commit 10d737e

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,24 +142,23 @@ Running Spring Boot standalone allows us to run the integration tests against it
142142

143143
To load JDWP agent for UAA jvm debugging, start the server as follows:
144144
```sh
145-
./gradlew run -Dxdebug=true
146-
```
147-
or
148-
```sh
149-
./gradlew -Dspring.profiles.active=hsqldb,debug run
145+
./gradlew run -Pdebug
150146
```
147+
151148
You can then attach your debugger to port 5005 of the jvm process.
152149

153150
To suspend the server start-up until the debugger is attached (useful for
154151
debugging start-up code), start the server as follows:
155152
```sh
156-
./gradlew run -Dxdebugs=true
157-
```
158-
or
159-
```sh
160-
./gradlew -Dspring.profiles.active=hsqldb,debugs run
153+
./gradlew run -Pdebugs
161154
```
155+
162156
Note: You can also use `bootRun` instead of `run` for these commands.
157+
To change the port that the debug command listens on, set the `debugPort` property, as follows:
158+
159+
```bash
160+
./gradlew run -Pdebug -PdebugPort=5006
161+
```
163162

164163
## Running a local UAA server with different databases
165164
`./gradlew run` (or `./gradlew bootRun`) runs the UAA server with hsqldb database by default.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,6 @@ tasks.register('killUaa', Exec) {
244244
tasks.register('run') {
245245
dependsOn killUaa
246246
dependsOn ':cloudfoundry-identity-uaa:bootRun'
247-
description = "Kills any running UAA and starts the application"
247+
description = "Kills any running UAA and starts the application. Use -Pdebug to enable debug mode (starts immediately) or -Pdebugs to enable debug mode with suspend (waits for debugger). Default port 5005, configurable with -PdebugPort=<port>"
248248
group = "application"
249249
}

scripts/debug_uaa.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ export ORG_GRADLE_PROJECT_port=${PORT:-8080}
44
echo "PORT: ${ORG_GRADLE_PROJECT_port}"
55

66
if [ "${1:-}" == "-h" ]; then
7-
echo USAGE: $0 [-h] [-s] [args]
7+
echo "USAGE: $0 [-h] [-s] [-r] [-PdebugPort=<port>] [args]"
88
echo "Run UAA in debug mode"
99
echo " -h: help"
1010
echo " -s: suspend startup for debugging"
1111
echo " -r: run UAA without debug mode"
12+
echo " -PdebugPort=<port>: set debug port, default 5005"
1213
exit 0
1314
fi
1415

15-
DEBUG_FLAG="-Dxdebug=true"
16+
debug_flag="-Pdebug"
1617
if [ "${1:-}" == "-s" ]; then
17-
DEBUG_FLAG="-Dxdebugs=true"
18+
debug_flag="-Pdebugs"
1819
shift
1920
elif [ "${1:-}" == "-r" ]; then
20-
DEBUG_FLAG=""
21+
debug_flag=""
2122
shift
2223
fi
2324

2425
cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd
25-
## scripts/kill_uaa.sh && \
26-
./gradlew run ${DEBUG_FLAG} "${@}"
26+
./gradlew run ${debug_flag} "${@}"

uaa/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,16 @@ bootRun {
306306
systemProperty("CLOUDFOUNDRY_CONFIG_PATH", file("../scripts/boot").getAbsolutePath())
307307
systemProperty("server.servlet.context-path", "/uaa")
308308
systemProperty("statsd.enabled", "true")
309+
310+
// Enable debug mode if -Pdebug or -Pdebugs flag is provided
311+
if (project.hasProperty('debug') || project.hasProperty('debugs')) {
312+
def debugPort = project.findProperty('debugPort') ?: '5005'
313+
// debugs = suspend and wait for debugger, debug = start immediately
314+
def suspend = project.hasProperty('debugs') ? 'y' : 'n'
315+
jvmArgs += [
316+
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=${suspend},address=*:${debugPort}"
317+
]
318+
def mode = suspend == 'y' ? 'Suspended debug' : 'Debug'
319+
logger.lifecycle("${mode} mode enabled. Listening on port ${debugPort}")
320+
}
309321
}

0 commit comments

Comments
 (0)