Skip to content

Commit 85b9ac8

Browse files
treilhesHannesWell
authored andcommitted
Ignore null values in system-props/env-variables for test launch-configs
Fixes #1832
1 parent 70cf76f commit 85b9ac8

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

org.eclipse.m2e.jdt.tests/src/org/eclipse/m2e/jdt/tests/UnitTestLaunchConfigConfigurationTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,30 @@ public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectT
5656
private static final String SUREFIRE_ARGS_SET = """
5757
<configuration>
5858
<argLine>
59-
--argLineItem=surefireArgLineValue
59+
--argLineItem=surefireArgLineValue --undefinedArgLineItem=${undefinedProperty}
6060
</argLine>
6161
<systemPropertyVariables>
6262
<surefireProp1>surefireProp1Value</surefireProp1>
63+
<surefireEmptyProp>${undefinedProperty}</surefireEmptyProp>
6364
</systemPropertyVariables>
6465
<environmentVariables>
6566
<surefireEnvironmentVariables1>surefireEnvironmentVariables1Value</surefireEnvironmentVariables1>
67+
<surefireEmptyEnvironmentVariables1>${undefinedProperty}</surefireEmptyEnvironmentVariables1>
6668
</environmentVariables>
6769
</configuration>
6870
""";
6971
private static final String FAILSAFE_ARGS_SET = """
7072
<configuration>
7173
<argLine>
72-
--argLineItem=failsafeArgLineValue
74+
--argLineItem=failsafeArgLineValue --undefinedArgLineItem=${undefinedProperty}
7375
</argLine>
7476
<systemPropertyVariables>
7577
<failsafeProp1>failsafeProp1Value</failsafeProp1>
78+
<failsafeEmptyProp>${undefiniedProperty}</failsafeEmptyProp>
7679
</systemPropertyVariables>
7780
<environmentVariables>
7881
<failsafeEnvironmentVariables1>failsafeEnvironmentVariables1Value</failsafeEnvironmentVariables1>
82+
<failsafeEmptyEnvironmentVariables1>${undefinedProperty}</failsafeEmptyEnvironmentVariables1>
7983
</environmentVariables>
8084
</configuration>
8185
""";
@@ -144,6 +148,10 @@ public void test_configuration_must_be_updated_with_surefire_config()
144148

145149
// check systemPropertyVariables
146150
assertTrue(argLine.contains("-DsurefireProp1=surefireProp1Value"));
151+
152+
// check systemPropertyVariables with null value aren't set
153+
assertTrue(!argLine.contains("-DsurefireEmptyProp="));
154+
147155
}
148156

149157
@Test
@@ -193,6 +201,9 @@ public void test_configuration_must_be_updated_with_failsafe_config()
193201

194202
// check systemPropertyVariables
195203
assertTrue(argLine.contains("-DfailsafeProp1=failsafeProp1Value"));
204+
205+
// check systemPropertyVariables with null value aren't set
206+
assertTrue(!argLine.contains("-DfailsafeEmptyProp="));
196207
}
197208

198209
@Test

org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/UnitTestSupport.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Set;
2929
import java.util.StringJoiner;
3030
import java.util.regex.Pattern;
31+
import java.util.stream.Collectors;
3132

3233
import org.slf4j.Logger;
3334
import org.slf4j.LoggerFactory;
@@ -278,7 +279,9 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
278279
launchArguments.add(args.argLine());
279280
}
280281
if(args.systemPropertyVariables() != null) {
281-
args.systemPropertyVariables().forEach((key, value) -> launchArguments.add("-D" + key + "=" + value));
282+
args.systemPropertyVariables().entrySet().stream() //
283+
.filter(e -> e.getKey() != null && e.getValue() != null)
284+
.forEach(e -> launchArguments.add("-D" + e.getKey() + "=" + e.getValue()));
282285
}
283286
copy.setAttribute(LAUNCH_CONFIG_VM_ARGUMENTS, launchArguments.toString());
284287

@@ -294,7 +297,10 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
294297
}
295298

296299
if(args.environmentVariables() != null) {
297-
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, args.environmentVariables());
300+
Map<String, String> filteredMap = args.environmentVariables().entrySet().stream()
301+
.filter(entry -> entry.getKey() != null && entry.getValue() != null)
302+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
303+
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, filteredMap);
298304
}
299305

300306
copy.doSave();

0 commit comments

Comments
 (0)