提交 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;
* no public constructor. You obtain a <code>Currency</code> instance using
* the <code>getInstance</code> methods.
* <p>
* Users can supersede the Java runtime currency data by creating a properties
* file named <code>&lt;JAVA_HOME&gt;/lib/currency.properties</code>. The contents
* of the properties file are key/value pairs of the ISO 3166 country codes
* and the ISO 4217 currency data respectively. The value part consists of
* three ISO 4217 values of a currency, i.e., an alphabetic code, a numeric
* code, and a minor unit. Those three ISO 4217 values are separated by commas.
* Users can supersede the Java runtime currency data by means of the system
* property {@code java.util.currency.data}. If this system property is
* defined then its value is the location of a properties file, the contents of
* which are key/value pairs of the ISO 3166 country codes and the ISO 4217
* currency data respectively. The value part consists of three ISO 4217 values
* 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
* 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
......@@ -246,10 +247,13 @@ public final class Currency implements Serializable {
}
// 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 {
File propFile = new File(homeDir + File.separator +
"lib" + File.separator +
"currency.properties");
File propFile = new File(propsFile);
if (propFile.exists()) {
Properties props = new Properties();
try (FileReader fr = new FileReader(propFile)) {
......
......@@ -27,22 +27,15 @@ import java.util.*;
import java.util.regex.*;
public class PropertiesTest {
public static void main(String[] s) throws Exception {
for (int i = 0; i < s.length; i ++) {
if ("-d".equals(s[i])) {
i++;
if (i == s.length) {
throw new RuntimeException("-d needs output file name");
} else {
dump(s[i]);
}
} 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]);
}
}
public static void main(String[] args) throws Exception {
if (args.length == 2 && args[0].equals("-d")) {
dump(args[1]);
} else if (args.length == 4 && args[0].equals("-c")) {
compare(args[1], args[2], args[3]);
} else {
System.err.println("Usage: java PropertiesTest -d <dumpfile>");
System.err.println(" java PropertiesTest -c <beforedump> <afterdump> <propsfile>");
System.exit(-1);
}
}
......@@ -77,15 +70,17 @@ public class PropertiesTest {
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
Properties before = new Properties();
try (Reader reader = new FileReader(beforeFile)) {
before.load(reader);
}
Properties after = new Properties();
try {
before.load(new FileReader(beforeFile));
after.load(new FileReader(afterFile));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
try (Reader reader = new FileReader(afterFile)) {
after.load(reader);
}
// remove the same contents from the 'after' properties
......@@ -103,13 +98,9 @@ public class PropertiesTest {
}
// now look at the currency.properties
String propFileName = System.getProperty("java.home") + File.separator +
"lib" + File.separator + "currency.properties";
Properties p = new Properties();
try {
p.load(new FileReader(propFileName));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
try (Reader reader = new FileReader(propsFile)) {
p.load(reader);
}
// test each replacements
......
#!/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
# @bug 6332666 7180362
# @bug 6332666 7180362 8003846
# @summary tests the capability of replacing the currency data with user
# specified currency properties file
# @build PropertiesTest
......@@ -36,7 +58,7 @@ case "$OS" in
;;
Windows* | CYGWIN* )
PS=";"
FS="\\"
FS="/"
;;
* )
echo "Unrecognized system!"
......@@ -44,23 +66,31 @@ case "$OS" in
;;
esac
# Currency dump path #1. Just dump currencies with the bare JRE
failures=0
# run
RUNCMD="${TESTJAVA}${FS}bin${FS}java -classpath ${TESTCLASSES} PropertiesTest -d dump1"
run() {
echo ''
sh -xc "${TESTJAVA}${FS}bin${FS}java -cp ${TESTCLASSES} $*" 2>&1
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
}
echo ${RUNCMD}
${RUNCMD}
result=$?
PROPS=${TESTSRC}${FS}currency.properties
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
COPIED=0
......@@ -79,44 +109,27 @@ then
else
PROPLOCATION=${WRITABLEJDK}${FS}lib
fi
cp ${TESTSRC}${FS}currency.properties $PROPLOCATION
cp ${PROPS} $PROPLOCATION
# run
RUNCMD="${WRITABLEJDK}${FS}bin${FS}java -classpath ${TESTCLASSES} PropertiesTest -d dump2"
echo ${RUNCMD}
${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
echo ''
sh -xc "${WRITABLEJDK}${FS}bin${FS}java -cp ${TESTCLASSES} PropertiesTest -d dump3"
if [ $? != 0 ]; then failures=`expr $failures + 1`; fi
# Cleanup
rm -f dump1
rm -f dump2
rm -f ${PROPLOCATION}${FS}currency.properties
if [ $COPIED -eq 1 ]
then
rm -rf $WRITABLEJDK
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.
先完成此消息的编辑!
想要评论请 注册