提交 149ab92a 编写于 作者: K Kohsuke Kawaguchi

made this method reusable from elsewhere

上级 51116f9d
......@@ -57,6 +57,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.io.PrintStream;
import java.io.InputStreamReader;
......@@ -81,6 +82,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.SimpleTimeZone;
import java.util.StringTokenizer;
......@@ -1162,6 +1164,24 @@ public class Util {
return s==null ? s : s.intern();
}
/**
* Loads a key/value pair string as {@link Properties}
* @since 1.392
*/
@IgnoreJRERequirement
public static Properties loadProperties(String properties) throws IOException {
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()));
}
return p;
}
public static final FastDateFormat XS_DATETIME_FORMATTER = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss'Z'",new SimpleTimeZone(0,"GMT"));
// Note: RFC822 dates must not be localized!
......
......@@ -35,13 +35,9 @@ import java.util.Properties;
import java.util.Map.Entry;
import java.io.Serializable;
import java.io.File;
import java.io.StringReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Set;
import org.jvnet.animal_sniffer.IgnoreJRERequirement;
/**
* Used to build up arguments for a process invocation.
*
......@@ -194,7 +190,7 @@ public class ArgumentListBuilder implements Serializable {
public ArgumentListBuilder addKeyValuePairsFromPropertyString(String prefix, String properties, VariableResolver vr) throws IOException {
if(properties==null) return this;
for (Entry<Object,Object> entry : load(properties).entrySet()) {
for (Entry<Object,Object> entry : Util.loadProperties(properties).entrySet()) {
addKeyValuePair(prefix, (String)entry.getKey(), Util.replaceMacro(entry.getValue().toString(),vr), false);
}
return this;
......@@ -218,26 +214,12 @@ public class ArgumentListBuilder implements Serializable {
public ArgumentListBuilder addKeyValuePairsFromPropertyString(String prefix, String properties, VariableResolver vr, Set<String> propsToMask) throws IOException {
if(properties==null) return this;
for (Entry<Object,Object> entry : load(properties).entrySet()) {
for (Entry<Object,Object> entry : Util.loadProperties(properties).entrySet()) {
addKeyValuePair(prefix, (String)entry.getKey(), Util.replaceMacro(entry.getValue().toString(),vr), (propsToMask == null) ? false : propsToMask.contains((String)entry.getKey()));
}
return this;
}
@IgnoreJRERequirement
private Properties load(String properties) throws IOException {
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()));
}
return p;
}
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.
先完成此消息的编辑!
想要评论请 注册