changeset 4557:be949e12cab0

7078024: Update JDK service tag for JDK 8 Reviewed-by: paulk
author mchung
date Wed, 07 Sep 2011 13:42:34 -0700
parents fa1e7738a136
children 6dab08f1cabb
files make/com/sun/servicetag/Makefile src/share/classes/com/sun/servicetag/Installer.java src/share/classes/com/sun/servicetag/resources/javase_servicetag.properties test/com/sun/servicetag/JavaServiceTagTest.java test/com/sun/servicetag/JavaServiceTagTest1.java
diffstat 5 files changed, 139 insertions(+), 116 deletions(-) [+]
line wrap: on
line diff
--- a/make/com/sun/servicetag/Makefile	Tue Sep 06 21:19:31 2011 -0700
+++ b/make/com/sun/servicetag/Makefile	Wed Sep 07 13:42:34 2011 -0700
@@ -47,7 +47,7 @@
 # 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 \
--- a/src/share/classes/com/sun/servicetag/Installer.java	Tue Sep 06 21:19:31 2011 -0700
+++ b/src/share/classes/com/sun/servicetag/Installer.java	Wed Sep 07 13:42:34 2011 -0700
@@ -61,8 +61,8 @@
     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 @@
         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 @@
             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 @@
         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 @@
      * 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 @@
                         urnSet.add(urn);
                     }
                 }
-            } finally {
-                if (in != null) {
-                    in.close();
-                }
             }
         }
         return urnSet;
@@ -237,9 +223,9 @@
     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 @@
     }
 
     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 @@
             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;
+        // 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);
         }
-        swordfishProps = new Properties();
-        try {
-            swordfishProps.load(in);
-        } finally {
-            in.close();
-        }
-        return swordfishProps;
+        return svcTagProps;
     }
 
     /**
@@ -546,7 +514,7 @@
             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 @@
         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 @@
         // 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";
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/com/sun/servicetag/resources/javase_servicetag.properties	Wed Sep 07 13:42:34 2011 -0700
@@ -0,0 +1,29 @@
+# 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
--- a/test/com/sun/servicetag/JavaServiceTagTest.java	Tue Sep 06 21:19:31 2011 -0700
+++ b/test/com/sun/servicetag/JavaServiceTagTest.java	Wed Sep 07 13:42:34 2011 -0700
@@ -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 @@
         }
     }
 
+    /**
+     * 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"))) {
-                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"))) {
+        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 {
-            throw new RuntimeException("Unexpected product_urn: " +
-                st.getProductURN());
+            if (!st.getProductURN().equals(jreUrn) ||
+                    !st.getProductName().equals(
+                        props.getProperty("servicetag.jre.name"))) {
+                throw new RuntimeException("Product URN and name don't match.");
+            }
         }
         if (!st.getProductVersion().
                 equals(System.getProperty("java.version"))) {
@@ -160,18 +179,13 @@
         }
     }
 
-    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;
     }
 }
--- a/test/com/sun/servicetag/JavaServiceTagTest1.java	Tue Sep 06 21:19:31 2011 -0700
+++ b/test/com/sun/servicetag/JavaServiceTagTest1.java	Wed Sep 07 13:42:34 2011 -0700
@@ -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 @@
         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"))) {
-                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"))) {
+        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 {
-            throw new RuntimeException("Unexpected product_urn: " +
-                st.getProductURN());
+            if (!st.getProductURN().equals(jreUrn) ||
+                    !st.getProductName().equals(
+                        props.getProperty("servicetag.jre.name"))) {
+                throw new RuntimeException("Product URN and name don't match.");
+            }
         }
+
         if (!st.getProductVersion().
                 equals(System.getProperty("java.version"))) {
             throw new RuntimeException("Unexpected product_version: " +
@@ -233,18 +253,13 @@
         }
     }
 
-    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;
     }
 }