Skip to content

Commit 6a25ff1

Browse files
committed
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.
1 parent ad08006 commit 6a25ff1

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/CustomSessionConfiguration.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ public interface CustomSessionConfiguration extends SessionCustomization {
8383
*/
8484
public CustomSessionConfiguration setConfigIniValue(String key, String value);
8585

86+
/**
87+
* Sets the given system property for all subsequently executed sessions. If the
88+
* value is null, the property will not be set in subsequent runs anymore.
89+
*
90+
* @param key the system property key
91+
* @param value the value to set for the key or {@code null} to remove the key
92+
*
93+
* @return this
94+
*/
95+
public CustomSessionConfiguration setSystemProperty(String key, String value);
96+
8697
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationDummy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,9 @@ public CustomSessionConfiguration setConfigIniValue(String key, String value) {
6868
return this;
6969
}
7070

71+
@Override
72+
public CustomSessionConfiguration setSystemProperty(String key, String value) {
73+
return this;
74+
}
75+
7176
}

runtime/tests/org.eclipse.core.tests.harness/src/org/eclipse/core/tests/harness/session/customization/CustomSessionConfigurationImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class CustomSessionConfigurationImpl implements CustomSessionConfiguratio
5353
private final Collection<BundleReference> bundleReferences = new LinkedHashSet<>();
5454
private Path configurationDirectory;
5555
private final Map<String, String> configIniValues = new HashMap<>();
56+
private final Map<String, String> systemProperties = new HashMap<>();
5657
private boolean readOnly = false;
5758
private boolean cascaded = false;
5859
private boolean firstExecutedSession = true;
@@ -154,6 +155,16 @@ public CustomSessionConfiguration setConfigIniValue(String key, String value) {
154155
return this;
155156
}
156157

158+
@Override
159+
public CustomSessionConfiguration setSystemProperty(String key, String value) {
160+
if (value == null) {
161+
systemProperties.remove(key);
162+
} else {
163+
systemProperties.put(key, value);
164+
}
165+
return this;
166+
}
167+
157168
@Override
158169
public CustomSessionConfiguration setConfigurationDirectory(Path configurationDirectory) {
159170
Objects.requireNonNull(configurationDirectory);
@@ -189,6 +200,7 @@ public void prepareSession(Setup setup) throws IOException {
189200
if (cascaded) {
190201
createOrRefreshConfigIni();
191202
}
203+
setup.setSystemProperties(systemProperties);
192204
}
193205

194206
@Override

0 commit comments

Comments
 (0)