diff --git a/core/src/main/java/hudson/Util.java b/core/src/main/java/hudson/Util.java index b7d76ca56a1a19c0709bc939648c4c4c313fc00a..412ab84d92ff207334562169f5f2157b201e8150 100644 --- a/core/src/main/java/hudson/Util.java +++ b/core/src/main/java/hudson/Util.java @@ -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! diff --git a/core/src/main/java/hudson/util/ArgumentListBuilder.java b/core/src/main/java/hudson/util/ArgumentListBuilder.java index 247378cb4378703c7ad09f419fd9b7795225ccf4..8d41ba2ea5c7161aa9cf2ceaf75d3b1789c95751 100644 --- a/core/src/main/java/hudson/util/ArgumentListBuilder.java +++ b/core/src/main/java/hudson/util/ArgumentListBuilder.java @@ -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 entry : load(properties).entrySet()) { + for (Entry 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 propsToMask) throws IOException { if(properties==null) return this; - for (Entry entry : load(properties).entrySet()) { + for (Entry 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()]); }