From d86ae16e5e4021fe7bc71c243d3d5c0c0105693a Mon Sep 17 00:00:00 2001 From: "Klare, Heiko" Date: Fri, 12 Dec 2025 10:02:02 +0100 Subject: [PATCH] Allow to set system property in session tests The setup used in JUnit 3 ConfigurationSessionTestSuites allows to set/change system properties for executed sessions. This capability is currently missing in the JUnit 5 SessionTestExection and the respective CustomSessionConfiguration. This change adds it. --- .../harness/session/CustomSessionConfiguration.java | 11 +++++++++++ .../CustomSessionConfigurationDummy.java | 5 +++++ .../CustomSessionConfigurationImpl.java | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java index 3a918accf50..544116153ab 100644 --- a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java +++ b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java @@ -83,4 +83,15 @@ public interface CustomSessionConfiguration extends SessionCustomization { */ public CustomSessionConfiguration setConfigIniValue(String key, String value); + /** + * Sets the given system property for all subsequently executed sessions. If the + * value is null, the property will not be set in subsequent runs anymore. + * + * @param key the system property key + * @param value the value to set for the key or {@code null} to remove the key + * + * @return this + */ + public CustomSessionConfiguration setSystemProperty(String key, String value); + } diff --git a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java index 095d42421f6..6cf258aa0fd 100644 --- a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java +++ b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java @@ -68,4 +68,9 @@ public CustomSessionConfiguration setConfigIniValue(String key, String value) { return this; } + @Override + public CustomSessionConfiguration setSystemProperty(String key, String value) { + return this; + } + } diff --git a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java index 09b56296a1b..d96bcae43c1 100644 --- a/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java +++ b/runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java @@ -53,6 +53,7 @@ public class CustomSessionConfigurationImpl implements CustomSessionConfiguratio private final Collection bundleReferences = new LinkedHashSet<>(); private Path configurationDirectory; private final Map configIniValues = new HashMap<>(); + private final Map systemProperties = new HashMap<>(); private boolean readOnly = false; private boolean cascaded = false; private boolean firstExecutedSession = true; @@ -154,6 +155,16 @@ public CustomSessionConfiguration setConfigIniValue(String key, String value) { return this; } + @Override + public CustomSessionConfiguration setSystemProperty(String key, String value) { + if (value == null) { + systemProperties.remove(key); + } else { + systemProperties.put(key, value); + } + return this; + } + @Override public CustomSessionConfiguration setConfigurationDirectory(Path configurationDirectory) { Objects.requireNonNull(configurationDirectory); @@ -189,6 +200,7 @@ public void prepareSession(Setup setup) throws IOException { if (cascaded) { createOrRefreshConfigIni(); } + setup.setSystemProperties(systemProperties); } @Override