From 05cb65e52a9633bf0919487b920d59abbbda6e78 Mon Sep 17 00:00:00 2001 From: aboyko Date: Thu, 16 Jan 2025 15:40:04 -0500 Subject: [PATCH] Move launch settings from program args to system props --- ...stractBootLaunchConfigurationDelegate.java | 20 +++++---- .../BootLaunchConfigurationDelegate.java | 41 +++++++++---------- ...oolsClientLaunchConfigurationDelegate.java | 6 +-- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/AbstractBootLaunchConfigurationDelegate.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/AbstractBootLaunchConfigurationDelegate.java index a2c57ef7f..0cf59da14 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/AbstractBootLaunchConfigurationDelegate.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/AbstractBootLaunchConfigurationDelegate.java @@ -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 args, Properties props) { + protected void addPropertiesArguments(List 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(); } diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java index f22509a79..360d4194f 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/BootLaunchConfigurationDelegate.java @@ -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 args = new ArrayList<>(); if (useThinWrapper(conf)) { + ArrayList 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 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 enabled = getEnabledJmxFeatures(conf); if (!enabled.isEmpty()) { diff --git a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/devtools/BootDevtoolsClientLaunchConfigurationDelegate.java b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/devtools/BootDevtoolsClientLaunchConfigurationDelegate.java index 438c187f0..0c0e507b2 100644 --- a/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/devtools/BootDevtoolsClientLaunchConfigurationDelegate.java +++ b/eclipse-extensions/org.springframework.ide.eclipse.boot.launch/src/org/springframework/ide/eclipse/boot/launch/devtools/BootDevtoolsClientLaunchConfigurationDelegate.java @@ -69,14 +69,14 @@ public class BootDevtoolsClientLaunchConfigurationDelegate extends AbstractBootL public String getProgramArguments(ILaunchConfiguration conf) throws CoreException { Properties props = getApplicationProperties(conf); ArrayList 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);