Skip to content

Commit c87e1a6

Browse files
committed
Add debug support
1 parent 6bba6f3 commit c87e1a6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/CommonsExecWebServerFactoryBean.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class CommonsExecWebServerFactoryBean
6060

6161
private CommonsExecWebServer webServer;
6262

63+
private Integer debugPort;
64+
65+
private boolean suspend = true;
66+
6367
CommonsExecWebServerFactoryBean() {
6468
Class<?> jarDetector = ClassUtils.resolveClassName(this.mainClass, null);
6569
this.classpath.entries(new ResourceClasspathEntry(
@@ -103,13 +107,39 @@ public CommonsExecWebServerFactoryBean systemProperties(Consumer<Map<String, Str
103107
return this;
104108
}
105109

110+
/**
111+
* If set, will start up in debug mode listening on the specified port.
112+
* @param debugPort the port to listen on or null (default) to disable debug mode.
113+
* @return
114+
*/
115+
public CommonsExecWebServerFactoryBean debugPort(Integer debugPort) {
116+
this.debugPort = debugPort;
117+
return this;
118+
}
119+
120+
/**
121+
* If {@link #debugPort(Integer)} is set, then this determines if the server should be
122+
* suspended or not.
123+
* @param suspend true if should suspend, else false.
124+
* @return
125+
*/
126+
public CommonsExecWebServerFactoryBean suspend(boolean suspend) {
127+
this.suspend = suspend;
128+
return this;
129+
}
130+
106131
@Override
107132
public boolean isEagerInit() {
108133
return true;
109134
}
110135

111136
private CommonsExecWebServer build() {
112137
CommandLine commandLine = new CommandLine(this.executable);
138+
if (this.debugPort != null) {
139+
String s = (this.suspend) ? "y" : "n";
140+
commandLine.addArgument(
141+
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=" + s + ",address=*:" + this.debugPort);
142+
}
113143
commandLine.addArguments(createSystemPropertyArgs(), false);
114144
commandLine.addArgument("-classpath", false);
115145
commandLine.addArgument(this.classpath.build(), false);

0 commit comments

Comments
 (0)