1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.maven.plugins.jenkins.helper;
17
18 import java.util.ArrayList;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.lang.StringUtils;
23 import org.kuali.maven.plugins.jenkins.context.ProcessResult;
24
25 public abstract class ExecutableHelper {
26
27 ProcessHelper helper = new ProcessHelper();
28
29 public abstract String getExecutable();
30
31 public List<String> buildArgumentListFromMap(Map<String, String> options) {
32 List<String> list = new ArrayList<String>();
33 for (String key : options.keySet()) {
34 String value = options.get(key);
35 list.add(key.startsWith("-") ? key : "-" + key);
36 if (!StringUtils.isBlank(value)) {
37 list.add(options.get(key));
38 }
39 }
40 return list;
41 }
42
43 public ProcessResult execute(Map<String, String> options, List<String> args, String input) {
44 String[] arr = {};
45 List<String> list = buildArgumentListFromMap(options);
46 list.addAll(args);
47 String[] sArgs = list.toArray(arr);
48 return helper.execute(getExecutable(), sArgs, input);
49 }
50 }