Skip to content

Commit

Permalink
fix for #1832, null values in systemPropertyVariables aren't propagated
Browse files Browse the repository at this point in the history
  • Loading branch information
treilhes committed Oct 11, 2024
1 parent 894ebef commit 19a6a90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,30 @@ public class UnitTestLaunchConfigConfigurationTest extends AbstractMavenProjectT
private static final String SUREFIRE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=surefireArgLineValue
--argLineItem=surefireArgLineValue --undefinedArgLineItem=${undefinedProperty}
</argLine>
<systemPropertyVariables>
<surefireProp1>surefireProp1Value</surefireProp1>
<surefireEmptyProp>${undefinedProperty}</surefireEmptyProp>
</systemPropertyVariables>
<environmentVariables>
<surefireEnvironmentVariables1>surefireEnvironmentVariables1Value</surefireEnvironmentVariables1>
<surefireEmptyEnvironmentVariables1>${undefinedProperty}</surefireEmptyEnvironmentVariables1>
</environmentVariables>
</configuration>
""";
private static final String FAILSAFE_ARGS_SET = """
<configuration>
<argLine>
--argLineItem=failsafeArgLineValue
--argLineItem=failsafeArgLineValue --undefinedArgLineItem=${undefinedProperty}
</argLine>
<systemPropertyVariables>
<failsafeProp1>failsafeProp1Value</failsafeProp1>
<failsafeEmptyProp>${undefiniedProperty}</failsafeEmptyProp>
</systemPropertyVariables>
<environmentVariables>
<failsafeEnvironmentVariables1>failsafeEnvironmentVariables1Value</failsafeEnvironmentVariables1>
<failsafeEmptyEnvironmentVariables1>${undefinedProperty}</failsafeEmptyEnvironmentVariables1>
</environmentVariables>
</configuration>
""";
Expand Down Expand Up @@ -144,6 +148,10 @@ public void test_configuration_must_be_updated_with_surefire_config()

// check systemPropertyVariables
assertTrue(argLine.contains("-DsurefireProp1=surefireProp1Value"));

// check systemPropertyVariables with null value aren't set
assertTrue(!argLine.contains("-DsurefireEmptyProp="));

}

@Test
Expand Down Expand Up @@ -193,6 +201,9 @@ public void test_configuration_must_be_updated_with_failsafe_config()

// check systemPropertyVariables
assertTrue(argLine.contains("-DfailsafeProp1=failsafeProp1Value"));

// check systemPropertyVariables with null value aren't set
assertTrue(!argLine.contains("-DfailsafeEmptyProp="));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -279,7 +280,9 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
launchArguments.add(args.argLine());
}
if(args.systemPropertyVariables() != null) {
args.systemPropertyVariables().forEach((key, value) -> launchArguments.add("-D" + key + "=" + value));
args.systemPropertyVariables().entrySet().stream().filter(e -> e.getKey() != null)
.filter(e -> e.getValue() != null)
.forEach(e -> launchArguments.add("-D" + e.getKey() + "=" + e.getValue()));
}
copy.setAttribute(LAUNCH_CONFIG_VM_ARGUMENTS, launchArguments.toString());

Expand All @@ -295,7 +298,10 @@ private void defineConfigurationValues(IProject project, ILaunchConfiguration co
}

if(args.environmentVariables() != null) {
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, args.environmentVariables());
Map<String, String> filteredMap = args.environmentVariables().entrySet().stream()
.filter(entry -> entry.getKey() != null && entry.getValue() != null)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
copy.setAttribute(LAUNCH_CONFIG_ENVIRONMENT_VARIABLES, filteredMap);
}

copy.doSave();
Expand Down

0 comments on commit 19a6a90

Please sign in to comment.