提交 0dd7f1c1 编写于 作者: K kohsuke

added a convenience method for adding complex property list

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@13208 71c3de6d-444a-0410-be80-ed276b4c234a
上级 929bed57
......@@ -7,8 +7,12 @@ import java.util.List;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;
import java.io.Serializable;
import java.io.StringReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
/**
* Used to build up arguments for a process invocation.
......@@ -62,9 +66,9 @@ public class ArgumentListBuilder implements Serializable {
}
/**
* Adds key value pairs as "-Dkey=value -Dkey=value"...
* Adds key value pairs as "-Dkey=value -Dkey=value ..."
*
* <tt>-D</tt> portion is configurable.
* <tt>-D</tt> portion is configurable as the 'prefix' parameter.
* @since 1.114
*/
public ArgumentListBuilder addKeyValuePairs(String prefix, Map<String,String> props) {
......@@ -73,6 +77,37 @@ public class ArgumentListBuilder implements Serializable {
return this;
}
/**
* Adds key value pairs as "-Dkey=value -Dkey=value ..." by parsing a given string using {@link Properties}.
*
* @param prefix
* The '-D' portion of the example.
* @param properties
* The persisted form of {@link Properties}. For example, "abc=def\nghi=jkl". Can be null, in which
* case this method becomes no-op.
* @param vr
* {@link VariableResolver} to be performed on the values.
* @since 1.262
*/
public ArgumentListBuilder addKeyValuePairsFromPropertyString(String prefix, String properties, VariableResolver vr) throws IOException {
if(properties==null) return this;
Properties p = new Properties();
try {
p.load(new StringReader(properties));
} catch (NoSuchMethodError e) {
// load(Reader) method is only available on JDK6.
// this fall back version doesn't work correctly with non-ASCII characters,
// but there's no other easy ways out it seems.
p.load(new ByteArrayInputStream(properties.getBytes()));
}
for (Entry<Object,Object> entry : p.entrySet()) {
args.add(prefix + entry.getKey() + "=" + Util.replaceMacro(entry.getValue().toString(),vr));
}
return this;
}
public String[] toCommandArray() {
return args.toArray(new String[args.size()]);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册