提交 20bc15e8 编写于 作者: A alanb

8003846: Override mechanism for currency data should not require creating...

8003846: Override mechanism for currency data should not require creating currency.properties in java.home
Reviewed-by: naoto
上级 38221a87
...@@ -56,12 +56,13 @@ import sun.util.logging.PlatformLogger; ...@@ -56,12 +56,13 @@ import sun.util.logging.PlatformLogger;
* no public constructor. You obtain a <code>Currency</code> instance using * no public constructor. You obtain a <code>Currency</code> instance using
* the <code>getInstance</code> methods. * the <code>getInstance</code> methods.
* <p> * <p>
* Users can supersede the Java runtime currency data by creating a properties * Users can supersede the Java runtime currency data by means of the system
* file named <code>&lt;JAVA_HOME&gt;/lib/currency.properties</code>. The contents * property {@code java.util.currency.data}. If this system property is
* of the properties file are key/value pairs of the ISO 3166 country codes * defined then its value is the location of a properties file, the contents of
* and the ISO 4217 currency data respectively. The value part consists of * which are key/value pairs of the ISO 3166 country codes and the ISO 4217
* three ISO 4217 values of a currency, i.e., an alphabetic code, a numeric * currency data respectively. The value part consists of three ISO 4217 values
* code, and a minor unit. Those three ISO 4217 values are separated by commas. * of a currency, i.e., an alphabetic code, a numeric code, and a minor unit.
* Those three ISO 4217 values are separated by commas.
* The lines which start with '#'s are considered comment lines. An optional UTC * The lines which start with '#'s are considered comment lines. An optional UTC
* timestamp may be specified per currency entry if users need to specify a * timestamp may be specified per currency entry if users need to specify a
* cutover date indicating when the new data comes into effect. The timestamp is * cutover date indicating when the new data comes into effect. The timestamp is
...@@ -246,10 +247,13 @@ public final class Currency implements Serializable { ...@@ -246,10 +247,13 @@ public final class Currency implements Serializable {
} }
// look for the properties file for overrides // look for the properties file for overrides
String propsFile = System.getProperty("java.util.currency.data");
if (propsFile == null) {
propsFile = homeDir + File.separator + "lib" +
File.separator + "currency.properties";
}
try { try {
File propFile = new File(homeDir + File.separator + File propFile = new File(propsFile);
"lib" + File.separator +
"currency.properties");
if (propFile.exists()) { if (propFile.exists()) {
Properties props = new Properties(); Properties props = new Properties();
try (FileReader fr = new FileReader(propFile)) { try (FileReader fr = new FileReader(propFile)) {
......
...@@ -27,22 +27,15 @@ import java.util.*; ...@@ -27,22 +27,15 @@ import java.util.*;
import java.util.regex.*; import java.util.regex.*;
public class PropertiesTest { public class PropertiesTest {
public static void main(String[] s) throws Exception { public static void main(String[] args) throws Exception {
for (int i = 0; i < s.length; i ++) { if (args.length == 2 && args[0].equals("-d")) {
if ("-d".equals(s[i])) { dump(args[1]);
i++; } else if (args.length == 4 && args[0].equals("-c")) {
if (i == s.length) { compare(args[1], args[2], args[3]);
throw new RuntimeException("-d needs output file name"); } else {
} else { System.err.println("Usage: java PropertiesTest -d <dumpfile>");
dump(s[i]); System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>");
} System.exit(-1);
} else if ("-c".equals(s[i])) {
if (i+2 == s.length) {
throw new RuntimeException("-d needs two file name arguments, before and after respectively");
} else {
compare(s[++i], s[++i]);
}
}
} }
} }
...@@ -77,15 +70,17 @@ public class PropertiesTest { ...@@ -77,15 +70,17 @@ public class PropertiesTest {
pw.close(); pw.close();
} }
private static void compare(String beforeFile, String afterFile) throws Exception { private static void compare(String beforeFile, String afterFile, String propsFile)
throws IOException
{
// load file contents // load file contents
Properties before = new Properties(); Properties before = new Properties();
try (Reader reader = new FileReader(beforeFile)) {
before.load(reader);
}
Properties after = new Properties(); Properties after = new Properties();
try { try (Reader reader = new FileReader(afterFile)) {
before.load(new FileReader(beforeFile)); after.load(reader);
after.load(new FileReader(afterFile));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} }
// remove the same contents from the 'after' properties // remove the same contents from the 'after' properties
...@@ -103,13 +98,9 @@ public class PropertiesTest { ...@@ -103,13 +98,9 @@ public class PropertiesTest {
} }
// now look at the currency.properties // now look at the currency.properties
String propFileName = System.getProperty("java.home") + File.separator +
"lib" + File.separator + "currency.properties";
Properties p = new Properties(); Properties p = new Properties();
try { try (Reader reader = new FileReader(propsFile)) {
p.load(new FileReader(propFileName)); p.load(reader);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
} }
// test each replacements // test each replacements
......
#!/bin/sh #!/bin/sh
# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
# #
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
# or visit www.oracle.com if you need additional information or have any
# questions.
#
# @test # @test
# @bug 6332666 7180362 # @bug 6332666 7180362 8003846
# @summary tests the capability of replacing the currency data with user # @summary tests the capability of replacing the currency data with user
# specified currency properties file # specified currency properties file
# @build PropertiesTest # @build PropertiesTest
...@@ -36,7 +58,7 @@ case "$OS" in ...@@ -36,7 +58,7 @@ case "$OS" in
;; ;;
Windows* | CYGWIN* ) Windows* | CYGWIN* )
PS=";" PS=";"
FS="\\" FS="/"
;; ;;
* ) * )
echo "Unrecognized system!" echo "Unrecognized system!"
...@@ -44,23 +66,31 @@ case "$OS" in ...@@ -44,23 +66,31 @@ case "$OS" in
;; ;;
esac esac
# Currency dump path #1. Just dump currencies with the bare JRE failures=0
# run run() {
RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} PropertiesTest -d dump1" echo ''
sh -xc "${TESTJAVA}${FS}bin${FS}java -cp ${TESTCLASSES} $*" 2>&1
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
}
echo ${RUNCMD} PROPS=${TESTSRC}${FS}currency.properties
${RUNCMD}
result=$?
if [ $result -eq 0 ]
then
echo "Execution successful"
else
echo "Execution of the test case failed."
fi
# Currency dump path #2. Dump currencies using the JRE with replacement currencies # Dump built-in currency data
run PropertiesTest -d dump1
# Dump built-in currency data + overrides in properties file specified
# by system property.
run -Djava.util.currency.data=${PROPS} PropertiesTest -d dump2
run PropertiesTest -c dump1 dump2 ${PROPS}
# Dump built-in currency data + overrides in properties file copied into
# JRE image.
# copy the test properties file # copy the test properties file
COPIED=0 COPIED=0
...@@ -79,44 +109,27 @@ then ...@@ -79,44 +109,27 @@ then
else else
PROPLOCATION=${WRITABLEJDK}${FS}lib PROPLOCATION=${WRITABLEJDK}${FS}lib
fi fi
cp ${TESTSRC}${FS}currency.properties $PROPLOCATION cp ${PROPS} $PROPLOCATION
# run # run
RUNCMD="${WRITABLEJDK}${FS}bin${FS}java -classpath ${TESTCLASSES} PropertiesTest -d dump2" echo ''
sh -xc "${WRITABLEJDK}${FS}bin${FS}java -cp ${TESTCLASSES} PropertiesTest -d dump3"
echo ${RUNCMD} if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
${RUNCMD}
result=$?
if [ $result -eq 0 ]
then
echo "Execution successful"
else
echo "Execution of the test case failed."
fi
# Now compare the two dump files
RUNCMD="${WRITABLEJDK}${FS}bin${FS}java -classpath ${TESTCLASSES} PropertiesTest -c dump1 dump2"
echo ${RUNCMD}
${RUNCMD}
result=$?
if [ $result -eq 0 ]
then
echo "Execution successful"
else
echo "Execution of the test case failed."
fi
# Cleanup # Cleanup
rm -f dump1
rm -f dump2
rm -f ${PROPLOCATION}${FS}currency.properties rm -f ${PROPLOCATION}${FS}currency.properties
if [ $COPIED -eq 1 ] if [ $COPIED -eq 1 ]
then then
rm -rf $WRITABLEJDK rm -rf $WRITABLEJDK
fi fi
exit $result # compare the two dump files
run PropertiesTest -c dump1 dump3 ${PROPS}
# Results
echo ''
if [ $failures -gt 0 ];
then echo "$failures tests failed";
else echo "All tests passed"; fi
exit $failures
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册