提交 4367f712 编写于 作者: M mchung

7078024: Update JDK service tag for JDK 8

Reviewed-by: paulk
上级 83fe1bfa
......@@ -47,7 +47,7 @@ FILES_copy = $(SERVICETAG_RESOURCES_DIR)/product_registration.xsd \
# Add all properties files to the FILES_copy list
SWORDFISH_properties := $(shell \
$(CD) $(SHARE_SRC)/classes/com/sun/servicetag/resources; \
$(FIND) . -name 'javase_*_swordfish.properties' -print ; \
$(FIND) . -name 'javase_*.properties' -print ; \
)
FILES_copy += $(shell \
for f in $(SWORDFISH_properties) ; do \
......
......@@ -61,8 +61,8 @@ public class Installer {
private static RegistrationData registration;
private static boolean supportRegistration;
private static String registerHtmlParent;
private static Set<Locale> supportedLocales = new HashSet<Locale>();
private static Properties swordfishProps = null;
private static Set<Locale> supportedLocales = new HashSet<>();
private static Properties svcTagProps = null;
private static String[] jreArchs = null;
static {
String dir = System.getProperty(SVCTAG_DIR_PATH);
......@@ -94,7 +94,7 @@ public class Installer {
boolean cleanup = false;
try {
// Check if we have the swordfish entries for this JRE version
if (loadSwordfishEntries() == null) {
if (loadServiceTagProps() == null) {
return null;
}
......@@ -144,18 +144,14 @@ public class Installer {
return registration;
}
if (regXmlFile.exists()) {
BufferedInputStream in = null;
try {
in = new BufferedInputStream(new FileInputStream(regXmlFile));
try (BufferedInputStream in =
new BufferedInputStream(new FileInputStream(regXmlFile)))
{
registration = RegistrationData.loadFromXML(in);
} catch (IllegalArgumentException ex) {
System.err.println("Error: Bad registration data \"" +
regXmlFile + "\":" + ex.getMessage());
throw ex;
} finally {
if (in != null) {
in.close();
}
}
} else {
registration = new RegistrationData();
......@@ -186,18 +182,14 @@ public class Installer {
deleteRegistrationHtmlPage();
getRegistrationHtmlPage();
BufferedOutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(regXmlFile));
try (BufferedOutputStream out =
new BufferedOutputStream(new FileOutputStream(regXmlFile)))
{
getRegistrationData().storeToXML(out);
} catch (IllegalArgumentException ex) {
System.err.println("Error: Bad registration data \"" +
regXmlFile + "\":" + ex.getMessage());
throw ex;
} finally {
if (out != null) {
out.close();
}
}
}
......@@ -206,11 +198,9 @@ public class Installer {
* or empty set if file not exists.
*/
private static Set<String> getInstalledURNs() throws IOException {
Set<String> urnSet = new HashSet<String>();
Set<String> urnSet = new HashSet<>();
if (serviceTagFile.exists()) {
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(serviceTagFile));
try (BufferedReader in = new BufferedReader(new FileReader(serviceTagFile))) {
String urn;
while ((urn = in.readLine()) != null) {
urn = urn.trim();
......@@ -218,10 +208,6 @@ public class Installer {
urnSet.add(urn);
}
}
} finally {
if (in != null) {
in.close();
}
}
}
return urnSet;
......@@ -237,9 +223,9 @@ public class Installer {
private static ServiceTag[] getJavaServiceTagArray() throws IOException {
RegistrationData regData = getRegistrationData();
Set<ServiceTag> svcTags = regData.getServiceTags();
Set<ServiceTag> result = new HashSet<ServiceTag>();
Set<ServiceTag> result = new HashSet<>();
Properties props = loadSwordfishEntries();
Properties props = loadServiceTagProps();
String jdkUrn = props.getProperty("servicetag.jdk.urn");
String jreUrn = props.getProperty("servicetag.jre.urn");
for (ServiceTag st : svcTags) {
......@@ -343,8 +329,7 @@ public class Installer {
}
private static ServiceTag newServiceTag(String svcTagSource) throws IOException {
// Load the swoRDFish information for the service tag creation
Properties props = loadSwordfishEntries();
Properties props = loadServiceTagProps();
// Determine the product URN and name
String productURN;
......@@ -442,52 +427,35 @@ public class Installer {
return;
}
PrintWriter out = null;
try {
out = new PrintWriter(serviceTagFile);
try (PrintWriter out = new PrintWriter(serviceTagFile)) {
ServiceTag[] javaSvcTags = getJavaServiceTagArray();
for (ServiceTag st : javaSvcTags) {
// Write the instance_run to the servicetag file
String instanceURN = st.getInstanceURN();
out.println(instanceURN);
}
} finally {
if (out != null) {
out.close();
}
}
}
/**
* Load the values associated with the swoRDFish metadata entries
* for Java SE. The swoRDFish metadata entries are different for
* different release.
* Load the properties for generating Java SE service tags.
*
* @param version Version of Java SE
*/
private static synchronized Properties loadSwordfishEntries() throws IOException {
if (swordfishProps != null) {
return swordfishProps;
private static synchronized Properties loadServiceTagProps() throws IOException {
if (svcTagProps != null) {
return svcTagProps;
}
// The version string for Java SE 6 is 1.6.0
// We just need the minor number in the version string
int version = Util.getJdkVersion();
String filename = "/com/sun/servicetag/resources/javase_" +
version + "_swordfish.properties";
InputStream in = Installer.class.getResourceAsStream(filename);
if (in == null) {
return null;
}
swordfishProps = new Properties();
try {
swordfishProps.load(in);
} finally {
in.close();
// For Java SE 8 and later releases, JDK and JRE both use
// the same product number. The sworRDFish metadata were
// for legacy Sun part number.
String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
try (InputStream in = Installer.class.getResourceAsStream(filename)) {
svcTagProps = new Properties();
svcTagProps.load(in);
}
return swordfishProps;
return svcTagProps;
}
/**
......@@ -546,7 +514,7 @@ public class Installer {
return jreArchs;
}
Set<String> archs = new HashSet<String>();
Set<String> archs = new HashSet<>();
String os = System.getProperty("os.name");
if (os.equals("SunOS") || os.equals("Linux")) {
......@@ -681,16 +649,16 @@ public class Installer {
String country = locale.getCountry();
String variant = locale.getVariant();
List<Locale> locales = new ArrayList<Locale>(3);
List<Locale> locales = new ArrayList<>(3);
if (variant.length() > 0) {
locales.add(locale);
}
if (country.length() > 0) {
locales.add((locales.size() == 0) ?
locales.add((locales.isEmpty()) ?
locale : new Locale(language, country, ""));
}
if (language.length() > 0) {
locales.add((locales.size() == 0) ?
locales.add((locales.isEmpty()) ?
locale : new Locale(language, "", ""));
}
return locales;
......@@ -788,14 +756,11 @@ public class Installer {
// Format the registration data in one single line
StringBuilder payload = new StringBuilder();
String xml = regData.toString().replaceAll("\"", "%22");
BufferedReader reader = new BufferedReader(new StringReader(xml));
try {
try (BufferedReader reader = new BufferedReader(new StringReader(xml))) {
String line = null;
while ((line = reader.readLine()) != null) {
payload.append(line.trim());
}
} finally {
reader.close();
}
String resourceFilename = "/com/sun/servicetag/resources/register";
......
# Copyright (c) 2011, 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. Oracle designates this
# particular file as subject to the "Classpath" exception as provided
# by Oracle in the LICENSE file that accompanied this code.
#
# 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.
servicetag.jdk.urn = Q8549
servicetag.jdk.name = Java Development Kit
servicetag.jre.urn = Q8549
servicetag.jre.name = Java Runtime Environment
servicetag.parent.urn = Q8549
servicetag.parent.name = Java Platform, Standard Edition
......@@ -25,7 +25,7 @@
/*
* @test
* @bug 6622366
* @bug 6622366 7078024
* @summary Basic Test for ServiceTag.getJavaServiceTag()
* Disable creating the service tag in the system registry.
* Verify the existence of registration.xml file and the
......@@ -86,23 +86,42 @@ public class JavaServiceTagTest {
}
}
/**
* Tests if the running platform is a JDK.
*/
static boolean isJDK() {
// Determine the JRE path by checking the existence of
// <HOME>/jre/lib and <HOME>/lib.
String javaHome = System.getProperty("java.home");
String jrepath = javaHome + File.separator + "jre";
File f = new File(jrepath, "lib");
if (!f.exists()) {
// java.home usually points to the JRE path
jrepath = javaHome;
}
return jrepath.endsWith(File.separator + "jre");
}
private static void checkServiceTag(ServiceTag st) throws IOException {
Properties props = loadSwordfishEntries();
if (st.getProductURN().
equals(props.getProperty("servicetag.jdk.urn"))) {
if (!st.getProductName().
equals(props.getProperty("servicetag.jdk.name"))) {
Properties props = loadServiceTagProps();
// jdk 8 and later, JDK and JRE have the same product URN.
String jdkUrn = props.getProperty("servicetag.jdk.urn");
String jreUrn = props.getProperty("servicetag.jre.urn");
boolean isJdk = isJDK();
if (isJdk) {
if (!st.getProductURN().equals(jdkUrn) ||
!st.getProductName().equals(
props.getProperty("servicetag.jdk.name"))) {
throw new RuntimeException("Product URN and name don't match.");
}
} else if (st.getProductURN().
equals(props.getProperty("servicetag.jre.urn"))) {
if (!st.getProductName().
equals(props.getProperty("servicetag.jre.name"))) {
} else {
if (!st.getProductURN().equals(jreUrn) ||
!st.getProductName().equals(
props.getProperty("servicetag.jre.name"))) {
throw new RuntimeException("Product URN and name don't match.");
}
} else {
throw new RuntimeException("Unexpected product_urn: " +
st.getProductURN());
}
if (!st.getProductVersion().
equals(System.getProperty("java.version"))) {
......@@ -160,18 +179,13 @@ public class JavaServiceTagTest {
}
}
private static Properties loadSwordfishEntries()
private static Properties loadServiceTagProps()
throws IOException {
int version = sun.misc.Version.jdkMinorVersion();
String filename = "/com/sun/servicetag/resources/javase_" +
version + "_swordfish.properties";
InputStream in = Installer.class.getClass().getResourceAsStream(filename);
Properties props = new Properties();
try {
String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
try (InputStream in = Installer.class.getClass().getResourceAsStream(filename)) {
Properties props = new Properties();
props.load(in);
} finally {
in.close();
return props;
}
return props;
}
}
......@@ -25,7 +25,7 @@
/*
* @test
* @bug 6622366
* @bug 6622366 7078024
* @summary Basic Test for ServiceTag.getJavaServiceTag(String)
* to verify that the registration.xml and servicetag files
* are both created correctly.
......@@ -157,25 +157,45 @@ public class JavaServiceTagTest1 {
return svctag;
}
/**
* Tests if the running platform is a JDK.
*/
static boolean isJDK() {
// Determine the JRE path by checking the existence of
// <HOME>/jre/lib and <HOME>/lib.
String javaHome = System.getProperty("java.home");
String jrepath = javaHome + File.separator + "jre";
File f = new File(jrepath, "lib");
if (!f.exists()) {
// java.home usually points to the JRE path
jrepath = javaHome;
}
return jrepath.endsWith(File.separator + "jre");
}
private static void checkServiceTag(ServiceTag st, String source)
throws IOException {
Properties props = loadSwordfishEntries();
if (st.getProductURN().
equals(props.getProperty("servicetag.jdk.urn"))) {
if (!st.getProductName().
equals(props.getProperty("servicetag.jdk.name"))) {
Properties props = loadServiceTagProps();
// jdk 8 and later, JDK and JRE have the same product URN.
String jdkUrn = props.getProperty("servicetag.jdk.urn");
String jreUrn = props.getProperty("servicetag.jre.urn");
boolean isJdk = isJDK();
if (isJdk) {
if (!st.getProductURN().equals(jdkUrn) ||
!st.getProductName().equals(
props.getProperty("servicetag.jdk.name"))) {
throw new RuntimeException("Product URN and name don't match.");
}
} else if (st.getProductURN().
equals(props.getProperty("servicetag.jre.urn"))) {
if (!st.getProductName().
equals(props.getProperty("servicetag.jre.name"))) {
} else {
if (!st.getProductURN().equals(jreUrn) ||
!st.getProductName().equals(
props.getProperty("servicetag.jre.name"))) {
throw new RuntimeException("Product URN and name don't match.");
}
} else {
throw new RuntimeException("Unexpected product_urn: " +
st.getProductURN());
}
if (!st.getProductVersion().
equals(System.getProperty("java.version"))) {
throw new RuntimeException("Unexpected product_version: " +
......@@ -233,18 +253,13 @@ public class JavaServiceTagTest1 {
}
}
private static Properties loadSwordfishEntries()
private static Properties loadServiceTagProps()
throws IOException {
int version = sun.misc.Version.jdkMinorVersion();
String filename = "/com/sun/servicetag/resources/javase_" +
version + "_swordfish.properties";
InputStream in = Installer.class.getClass().getResourceAsStream(filename);
Properties props = new Properties();
try {
String filename = "/com/sun/servicetag/resources/javase_servicetag.properties";
try (InputStream in = Installer.class.getClass().getResourceAsStream(filename)) {
Properties props = new Properties();
props.load(in);
} finally {
in.close();
return props;
}
return props;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册