Skip to content

Commit 05cb65e

Browse files
committed
Move launch settings from program args to system props
1 parent 02cd877 commit 05cb65e

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/AbstractBootLaunchConfigurationDelegate.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public abstract class AbstractBootLaunchConfigurationDelegate extends AdvancedJa
6363
private static final String BOOT_MAVEN_CLASS_PATH_PROVIDER = "org.springframework.ide.eclipse.boot.launch.BootMavenClassPathProvider";
6464
private static final String BUILDSHIP_CLASS_PATH_PROVIDER = "org.eclipse.buildship.core.classpathprovider";
6565

66+
protected static final String PROGRAM_ARG_PREFIX = "--";
67+
protected static final String SYSTEM_PROP_PREFIX = "-D";
68+
6669
/**
6770
* Spring boot properties are stored as launch confiuration properties with
6871
* an extra prefix added to property name to avoid name clashes with
@@ -253,28 +256,31 @@ public static Properties getApplicationProperties(ILaunchConfiguration conf) {
253256
}
254257

255258
@SuppressWarnings("rawtypes")
256-
protected void addPropertiesArguments(ArrayList<String> args, Properties props) {
259+
protected void addPropertiesArguments(List<String> args, Properties props, String prefix) {
257260
for (Map.Entry e : props.entrySet()) {
258261
String name = (String) e.getKey();
259262
String value = (String) e.getValue();
260263
//spring boot doesn't like empty option keys/values so skip those.
261264
if (!name.isEmpty()) {
262-
args.add(propertyAssignmentArgument(name, value));
265+
args.add(propertyAssignmentArgument(name, value, prefix));
263266
}
264267
}
265268
}
266269

267-
protected String propertyAssignmentArgument(String name, String value) {
270+
protected String propertyAssignmentArgument(String name, String value, String prefix) {
268271
if (name.contains("=")) {
269272
//spring boot has no handling of escape sequences like '\='
270273
//so we cannot represent keys containing '='.
271274
throw new IllegalArgumentException("property name shouldn't contain '=':"+name);
272275
}
273-
if (value.isEmpty()) {
274-
return "--"+name;
275-
} else {
276-
return "--"+name + "=" +value;
276+
StringBuilder sb = new StringBuilder();
277+
sb.append(prefix);
278+
sb.append(name);
279+
if (!value.isEmpty()) {
280+
sb.append('=');
281+
sb.append(value);
277282
}
283+
return sb.toString();
278284
}
279285

280286

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,34 +172,17 @@ public void launch(ILaunchConfiguration conf, String mode,
172172

173173
@Override
174174
public String getProgramArguments(ILaunchConfiguration conf) throws CoreException {
175-
Properties props = getApplicationProperties(conf);
176-
String profile = getProfile(conf);
177-
boolean debugOutput = getEnableDebugOutput(conf);
178-
boolean enableAnsiConsole = supportsAnsiConsoleOutput() && getEnableAnsiConsoleOutput(conf);
179-
if ((props==null || props.isEmpty()) && !debugOutput && !hasText(profile) && !enableAnsiConsole && !useThinWrapper(conf)) {
180-
//shortcut for case where no boot-specific customizations are specified.
181-
return super.getProgramArguments(conf);
182-
}
183-
ArrayList<String> args = new ArrayList<>();
184175
if (useThinWrapper(conf)) {
176+
ArrayList<String> args = new ArrayList<>();
185177
String realMain = super.getMainTypeName(conf);
186178
//--thin.main=com.example.SampleApplication
187179
// --thin.archive=target/classes - the first one is the main class of the boot app, as already configured in the boot launch config, the second one points to the compiled classes (the entry that was on the regular classpath before without the maven dependencies)
188180
args.add("--thin.main="+realMain);
189181
args.add("--thin.archive="+getThinArchive(conf));
182+
args.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getProgramArguments(conf))));
183+
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);
190184
}
191-
if (debugOutput) {
192-
args.add("--debug");
193-
}
194-
if (hasText(profile)) {
195-
args.add(propertyAssignmentArgument("spring.profiles.active", profile));
196-
}
197-
if (enableAnsiConsole) {
198-
args.add(propertyAssignmentArgument("spring.output.ansi.enabled", "always"));
199-
}
200-
addPropertiesArguments(args, props);
201-
args.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getProgramArguments(conf))));
202-
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);
185+
return super.getProgramArguments(conf);
203186
}
204187

205188
private String getThinArchive(ILaunchConfiguration conf) throws CoreException {
@@ -228,6 +211,22 @@ public String getVMArguments(ILaunchConfiguration conf)
228211
try {
229212
List<String> vmArgs = new ArrayList<>();
230213
vmArgs.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getVMArguments(conf))));
214+
215+
Properties props = getApplicationProperties(conf);
216+
String profile = getProfile(conf);
217+
boolean debugOutput = getEnableDebugOutput(conf);
218+
boolean enableAnsiConsole = supportsAnsiConsoleOutput() && getEnableAnsiConsoleOutput(conf);
219+
if (debugOutput) {
220+
vmArgs.add("-Ddebug");
221+
}
222+
if (hasText(profile)) {
223+
vmArgs.add(propertyAssignmentArgument("spring.profiles.active", profile, SYSTEM_PROP_PREFIX));
224+
}
225+
if (enableAnsiConsole) {
226+
vmArgs.add(propertyAssignmentArgument("spring.output.ansi.enabled", "always", SYSTEM_PROP_PREFIX));
227+
}
228+
addPropertiesArguments(vmArgs, props, SYSTEM_PROP_PREFIX);
229+
231230
// VM args for JMX connection
232231
EnumSet<JmxBeanSupport.Feature> enabled = getEnabledJmxFeatures(conf);
233232
if (!enabled.isEmpty()) {

eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/devtools/BootDevtoolsClientLaunchConfigurationDelegate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ public String getMainTypeName(ILaunchConfiguration configuration) throws CoreExc
6969
public String getProgramArguments(ILaunchConfiguration conf) throws CoreException {
7070
Properties props = getApplicationProperties(conf);
7171
ArrayList<String> args = new ArrayList<>();
72-
addPropertiesArguments(args, props);
72+
addPropertiesArguments(args, props, PROGRAM_ARG_PREFIX);
7373
String secret = getSecret(conf);
7474
if (StringUtil.hasText(secret)) {
75-
args.add(propertyAssignmentArgument(REMOTE_SECRET, secret));
75+
args.add(propertyAssignmentArgument(REMOTE_SECRET, secret, PROGRAM_ARG_PREFIX));
7676
}
7777
Integer debugPort = localDebugPort.get();
7878
if (debugPort!=null) {
79-
args.add(propertyAssignmentArgument(DEBUG_PORT, ""+debugPort));
79+
args.add(propertyAssignmentArgument(DEBUG_PORT, ""+debugPort, PROGRAM_ARG_PREFIX));
8080
}
8181
args.add(getRemoteUrl(conf));
8282
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);

0 commit comments

Comments
 (0)