Add appending capabilities to the SimpleCommandLineArgsProvider
Adds the ability to add a list of command line arguments to the existing ones. Resolves #279
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cloud.task.batch.partition;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -22,7 +23,8 @@ import org.springframework.cloud.task.repository.TaskExecution;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Returns any command line arguments used with the {@link TaskExecution} provided.
|
||||
* Returns any command line arguments used with the {@link TaskExecution} provided
|
||||
* appended with any additional arguments configured.
|
||||
*
|
||||
* @author Michael Minella
|
||||
* @since 1.1.0
|
||||
@@ -31,14 +33,38 @@ public class SimpleCommandLineArgsProvider implements CommandLineArgsProvider {
|
||||
|
||||
private final TaskExecution taskExecution;
|
||||
|
||||
private List<String> appendedArgs;
|
||||
|
||||
public SimpleCommandLineArgsProvider(TaskExecution taskExecution) {
|
||||
Assert.notNull(taskExecution, "A taskExecution is required");
|
||||
|
||||
this.taskExecution = taskExecution;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional command line args to be appended.
|
||||
*
|
||||
* @param appendedArgs list of arguments
|
||||
* @since 1.2
|
||||
*/
|
||||
public void setAppendedArgs(List<String> appendedArgs) {
|
||||
this.appendedArgs = appendedArgs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getCommandLineArgs(ExecutionContext executionContext) {
|
||||
return this.taskExecution.getArguments();
|
||||
|
||||
int listSize = this.taskExecution.getArguments().size() +
|
||||
(this.appendedArgs != null ? this.appendedArgs.size() : 0);
|
||||
|
||||
List<String> args = new ArrayList<>(listSize);
|
||||
|
||||
args.addAll(this.taskExecution.getArguments());
|
||||
|
||||
if(this.appendedArgs != null) {
|
||||
args.addAll(this.appendedArgs);
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user