Move launch settings from program args to system props

This commit is contained in:
aboyko
2025-01-16 15:40:04 -05:00
parent 02cd877742
commit 05cb65e52a
3 changed files with 36 additions and 31 deletions

View File

@@ -63,6 +63,9 @@ public abstract class AbstractBootLaunchConfigurationDelegate extends AdvancedJa
private static final String BOOT_MAVEN_CLASS_PATH_PROVIDER = "org.springframework.ide.eclipse.boot.launch.BootMavenClassPathProvider";
private static final String BUILDSHIP_CLASS_PATH_PROVIDER = "org.eclipse.buildship.core.classpathprovider";
protected static final String PROGRAM_ARG_PREFIX = "--";
protected static final String SYSTEM_PROP_PREFIX = "-D";
/**
* Spring boot properties are stored as launch confiuration properties with
* an extra prefix added to property name to avoid name clashes with
@@ -253,28 +256,31 @@ public abstract class AbstractBootLaunchConfigurationDelegate extends AdvancedJa
}
@SuppressWarnings("rawtypes")
protected void addPropertiesArguments(ArrayList<String> args, Properties props) {
protected void addPropertiesArguments(List<String> args, Properties props, String prefix) {
for (Map.Entry e : props.entrySet()) {
String name = (String) e.getKey();
String value = (String) e.getValue();
//spring boot doesn't like empty option keys/values so skip those.
if (!name.isEmpty()) {
args.add(propertyAssignmentArgument(name, value));
args.add(propertyAssignmentArgument(name, value, prefix));
}
}
}
protected String propertyAssignmentArgument(String name, String value) {
protected String propertyAssignmentArgument(String name, String value, String prefix) {
if (name.contains("=")) {
//spring boot has no handling of escape sequences like '\='
//so we cannot represent keys containing '='.
throw new IllegalArgumentException("property name shouldn't contain '=':"+name);
}
if (value.isEmpty()) {
return "--"+name;
} else {
return "--"+name + "=" +value;
StringBuilder sb = new StringBuilder();
sb.append(prefix);
sb.append(name);
if (!value.isEmpty()) {
sb.append('=');
sb.append(value);
}
return sb.toString();
}

View File

@@ -172,34 +172,17 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura
@Override
public String getProgramArguments(ILaunchConfiguration conf) throws CoreException {
Properties props = getApplicationProperties(conf);
String profile = getProfile(conf);
boolean debugOutput = getEnableDebugOutput(conf);
boolean enableAnsiConsole = supportsAnsiConsoleOutput() && getEnableAnsiConsoleOutput(conf);
if ((props==null || props.isEmpty()) && !debugOutput && !hasText(profile) && !enableAnsiConsole && !useThinWrapper(conf)) {
//shortcut for case where no boot-specific customizations are specified.
return super.getProgramArguments(conf);
}
ArrayList<String> args = new ArrayList<>();
if (useThinWrapper(conf)) {
ArrayList<String> args = new ArrayList<>();
String realMain = super.getMainTypeName(conf);
//--thin.main=com.example.SampleApplication
// --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)
args.add("--thin.main="+realMain);
args.add("--thin.archive="+getThinArchive(conf));
args.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getProgramArguments(conf))));
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);
}
if (debugOutput) {
args.add("--debug");
}
if (hasText(profile)) {
args.add(propertyAssignmentArgument("spring.profiles.active", profile));
}
if (enableAnsiConsole) {
args.add(propertyAssignmentArgument("spring.output.ansi.enabled", "always"));
}
addPropertiesArguments(args, props);
args.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getProgramArguments(conf))));
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);
return super.getProgramArguments(conf);
}
private String getThinArchive(ILaunchConfiguration conf) throws CoreException {
@@ -228,6 +211,22 @@ public class BootLaunchConfigurationDelegate extends AbstractBootLaunchConfigura
try {
List<String> vmArgs = new ArrayList<>();
vmArgs.addAll(Arrays.asList(DebugPlugin.parseArguments(super.getVMArguments(conf))));
Properties props = getApplicationProperties(conf);
String profile = getProfile(conf);
boolean debugOutput = getEnableDebugOutput(conf);
boolean enableAnsiConsole = supportsAnsiConsoleOutput() && getEnableAnsiConsoleOutput(conf);
if (debugOutput) {
vmArgs.add("-Ddebug");
}
if (hasText(profile)) {
vmArgs.add(propertyAssignmentArgument("spring.profiles.active", profile, SYSTEM_PROP_PREFIX));
}
if (enableAnsiConsole) {
vmArgs.add(propertyAssignmentArgument("spring.output.ansi.enabled", "always", SYSTEM_PROP_PREFIX));
}
addPropertiesArguments(vmArgs, props, SYSTEM_PROP_PREFIX);
// VM args for JMX connection
EnumSet<JmxBeanSupport.Feature> enabled = getEnabledJmxFeatures(conf);
if (!enabled.isEmpty()) {

View File

@@ -69,14 +69,14 @@ public class BootDevtoolsClientLaunchConfigurationDelegate extends AbstractBootL
public String getProgramArguments(ILaunchConfiguration conf) throws CoreException {
Properties props = getApplicationProperties(conf);
ArrayList<String> args = new ArrayList<>();
addPropertiesArguments(args, props);
addPropertiesArguments(args, props, PROGRAM_ARG_PREFIX);
String secret = getSecret(conf);
if (StringUtil.hasText(secret)) {
args.add(propertyAssignmentArgument(REMOTE_SECRET, secret));
args.add(propertyAssignmentArgument(REMOTE_SECRET, secret, PROGRAM_ARG_PREFIX));
}
Integer debugPort = localDebugPort.get();
if (debugPort!=null) {
args.add(propertyAssignmentArgument(DEBUG_PORT, ""+debugPort));
args.add(propertyAssignmentArgument(DEBUG_PORT, ""+debugPort, PROGRAM_ARG_PREFIX));
}
args.add(getRemoteUrl(conf));
return DebugPlugin.renderArguments(args.toArray(new String[args.size()]), null);