Merge pull request #9916 from bjornlindstrom:gh-9713
* pr/9916: Polish "Fix handling of empty/null arguments" Fix handling of empty/null arguments
This commit is contained in:
commit
3da9406435
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.maven;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.codehaus.plexus.util.cli.CommandLineUtils;
|
import org.codehaus.plexus.util.cli.CommandLineUtils;
|
||||||
|
|
||||||
|
|
@ -31,14 +32,16 @@ class RunArguments {
|
||||||
|
|
||||||
private static final String[] NO_ARGS = {};
|
private static final String[] NO_ARGS = {};
|
||||||
|
|
||||||
private final LinkedList<String> args;
|
private final LinkedList<String> args = new LinkedList<>();
|
||||||
|
|
||||||
RunArguments(String arguments) {
|
RunArguments(String arguments) {
|
||||||
this(parseArgs(arguments));
|
this(parseArgs(arguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
RunArguments(String[] args) {
|
RunArguments(String[] args) {
|
||||||
this.args = new LinkedList<>(Arrays.asList(args));
|
if (args != null) {
|
||||||
|
Arrays.stream(args).filter(Objects::nonNull).forEach(this.args::add);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<String> getArgs() {
|
public LinkedList<String> getArgs() {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2016 the original author or authors.
|
* Copyright 2012-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -34,6 +34,27 @@ public class RunArgumentsTests {
|
||||||
assertThat(args.length).isEqualTo(0);
|
assertThat(args.length).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseNullArray() {
|
||||||
|
String[] args = new RunArguments((String[]) null).asArray();
|
||||||
|
assertThat(args).isNotNull();
|
||||||
|
assertThat(args.length).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseArrayContainingNullValue() {
|
||||||
|
String[] args = new RunArguments(new String[]{"foo", null, "bar"}).asArray();
|
||||||
|
assertThat(args).isNotNull();
|
||||||
|
assertThat(args).containsOnly("foo", "bar");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseArrayContainingEmptyValue() {
|
||||||
|
String[] args = new RunArguments(new String[]{"foo", "", "bar"}).asArray();
|
||||||
|
assertThat(args).isNotNull();
|
||||||
|
assertThat(args).containsOnly("foo", "", "bar");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parseEmpty() {
|
public void parseEmpty() {
|
||||||
String[] args = parseArgs(" ");
|
String[] args = parseArgs(" ");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue