Fixed invalid system props tokenizing

This commit is contained in:
Marcin Grzejszczak
2017-11-20 11:15:03 +01:00
parent 1c786e25e9
commit 663ba13468
2 changed files with 10 additions and 4 deletions

View File

@@ -106,10 +106,16 @@ public class ProjectBuilder {
*/
private String[] substituteSystemProps(String... commands) {
boolean containsSystemProps = this.properties.getMaven().getSystemProperties().contains("-D");
String[] splitSystemProps = StringUtils.tokenizeToStringArray(this.properties.getMaven()
String[] splitSystemProps = StringUtils.delimitedListToStringArray(this.properties.getMaven()
.getSystemProperties(), "-D");
// first element might be empty even though the second one contains values
if (splitSystemProps.length > 1) {
splitSystemProps = StringUtils.isEmpty(splitSystemProps[0]) ?
Arrays.copyOfRange(splitSystemProps, 1, splitSystemProps.length) :
splitSystemProps;
}
String[] systemPropsWithPrefix = containsSystemProps ? Arrays.stream(splitSystemProps)
.map(s -> "-D" + s)
.map(s -> "-D" + s.trim())
.collect(Collectors.toList())
.toArray(new String[splitSystemProps.length]) : splitSystemProps;
final AtomicInteger index = new AtomicInteger(-1);

View File

@@ -133,14 +133,14 @@ public class ProjectBuilderTests {
public void should_successfully_execute_a_deploy_command_with_sys_props_placeholder() throws Exception {
ReleaserProperties properties = new ReleaserProperties();
properties.getMaven().setDeployCommand("echo \"{{systemProps}}\"");
properties.getMaven().setSystemProperties("hello world");
properties.getMaven().setSystemProperties("-Dhello=hello-world");
properties.setWorkingDir(tmpFile("/builder/resolved").getPath());
ProjectBuilder builder = new ProjectBuilder(properties, executor(properties));
builder.deploy();
then(asString(tmpFile("/builder/resolved/resolved.log")))
.contains("hello world");
.contains("-Dhello=hello-world");
}
@Test