View Javadoc

1   /**
2    * Copyright 2011-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }