8039271: CMM profile files (cmm/*) should not be in ${java.home}/lib
authorprr
Fri, 22 Aug 2014 11:02:00 -0700
changeset 26357 bd702816164f
parent 26356 5a24e67172c0
child 26358 abfc0d4035bf
8039271: CMM profile files (cmm/*) should not be in ${java.home}/lib Reviewed-by: bae, mchung, erikj
jdk/make/copy/Copy-java.desktop.gmk
jdk/make/profile-includes.txt
jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java
jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/CIEXYZ.pf
jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/GRAY.pf
jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/LINEAR_RGB.pf
jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/PYCC.pf
jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/sRGB.pf
jdk/src/java.desktop/share/conf/cmm/lcms/CIEXYZ.pf
jdk/src/java.desktop/share/conf/cmm/lcms/GRAY.pf
jdk/src/java.desktop/share/conf/cmm/lcms/LINEAR_RGB.pf
jdk/src/java.desktop/share/conf/cmm/lcms/PYCC.pf
jdk/src/java.desktop/share/conf/cmm/lcms/sRGB.pf
jdk/test/java/awt/color/LoadStandardProfilesTest.java
--- a/jdk/make/copy/Copy-java.desktop.gmk	Fri Aug 22 10:33:05 2014 -0700
+++ b/jdk/make/copy/Copy-java.desktop.gmk	Fri Aug 22 11:02:00 2014 -0700
@@ -43,25 +43,6 @@
 
 ################################################################################
 
-ICCPROFILE_DEST_DIR := $(LIB_DST_DIR)/cmm
-
-ifdef OPENJDK
-  ICCPROFILE_SRC_DIR := $(JDK_TOPDIR)/src/java.desktop/share/conf/cmm/lcms
-else
-  ICCPROFILE_SRC_DIR := $(JDK_TOPDIR)/src/closed/java.desktop/share/conf/cmm/kcms
-endif
-
-ICCPROFILE_SRCS := $(wildcard $(ICCPROFILE_SRC_DIR)/*.pf)
-ICCPROFILE_TARGET_FILES := $(subst $(ICCPROFILE_SRC_DIR),$(ICCPROFILE_DEST_DIR),$(ICCPROFILE_SRCS))
-
-$(ICCPROFILE_DEST_DIR)%.pf: $(ICCPROFILE_SRC_DIR)%.pf
-	$(call install-file)
-	$(CHMOD) 444 $@
-
-DESKTOP_CONF_FILES += $(ICCPROFILE_TARGET_FILES)
-
-################################################################################
-
 ifneq ($(FREETYPE_BUNDLE_LIB_PATH), )
   # We need to bundle the freetype library, so it will be available at runtime as well as link time.
   #
--- a/jdk/make/profile-includes.txt	Fri Aug 22 10:33:05 2014 -0700
+++ b/jdk/make/profile-includes.txt	Fri Aug 22 11:02:00 2014 -0700
@@ -168,11 +168,6 @@
     $(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)t2k$(SHARED_LIBRARY_SUFFIX) \
     $(OPENJDK_TARGET_CPU_LEGACY_LIB)/$(LIBRARY_PREFIX)unpack$(SHARED_LIBRARY_SUFFIX) \
     charsets.jar \
-    cmm/CIEXYZ.pf \
-    cmm/GRAY.pf \
-    cmm/LINEAR_RGB.pf \
-    cmm/PYCC.pf \
-    cmm/sRGB.pf \
     ext/cldrdata.jar \
     ext/dnsns.jar \
     ext/nashorn.jar \
--- a/jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java	Fri Aug 22 10:33:05 2014 -0700
+++ b/jdk/src/java.desktop/share/classes/java/awt/color/ICC_Profile.java	Fri Aug 22 11:02:00 2014 -0700
@@ -968,20 +968,22 @@
      */
     public static ICC_Profile getInstance(String fileName) throws IOException {
         ICC_Profile thisProfile;
-        FileInputStream fis = null;
+        InputStream is = null;
 
 
         File f = getProfileFile(fileName);
         if (f != null) {
-            fis = new FileInputStream(f);
+            is = new FileInputStream(f);
+        } else {
+            is = getStandardProfileInputStream(fileName);
         }
-        if (fis == null) {
+        if (is == null) {
             throw new IOException("Cannot open file " + fileName);
         }
 
-        thisProfile = getInstance(fis);
+        thisProfile = getInstance(is);
 
-        fis.close();    /* close the file */
+        is.close();    /* close the file */
 
         return thisProfile;
     }
@@ -1086,28 +1088,17 @@
 
     void activateDeferredProfile() throws ProfileDataException {
         byte profileData[];
-        FileInputStream fis;
         final String fileName = deferralInfo.filename;
 
         profileActivator = null;
         deferralInfo = null;
-        PrivilegedAction<FileInputStream> pa = new PrivilegedAction<FileInputStream>() {
-            public FileInputStream run() {
-                File f = getStandardProfileFile(fileName);
-                if (f != null) {
-                    try {
-                        return new FileInputStream(f);
-                    } catch (FileNotFoundException e) {}
-                }
-                return null;
-            }
-        };
-        if ((fis = AccessController.doPrivileged(pa)) == null) {
+        InputStream is = getStandardProfileInputStream(fileName);
+        if (is == null) {
             throw new ProfileDataException("Cannot open file " + fileName);
         }
         try {
-            profileData = getProfileDataFromStream(fis);
-            fis.close();    /* close the file */
+            profileData = getProfileDataFromStream(is);
+            is.close();    /* close the file */
         }
         catch (IOException e) {
             ProfileDataException pde = new
@@ -1810,10 +1801,12 @@
      * fileName may be an absolute or a relative file specification.
      * Relative file names are looked for in several places: first, relative
      * to any directories specified by the java.iccprofile.path property;
-     * second, relative to any directories specified by the java.class.path
-     * property; finally, in a directory used to store profiles always
-     * available, such as a profile for sRGB.  Built-in profiles use .pf as
-     * the file name extension for profiles, e.g. sRGB.pf.
+     * second, relative to any directories specified by the java.class.path.
+     * The built-in profile files are now loaded as resources, since they
+     * may not be individual disk files, and so this method will not find
+     * these and on a null return, the caller needs to try as resources.
+     * Built-in profiles use .pf as the file name extension for profiles,
+     * e.g. sRGB.pf.
      */
     private static File getProfileFile(String fileName) {
         String path, dir, fullPath;
@@ -1849,30 +1842,22 @@
                         fullPath = dir + File.separatorChar + fileName;
                     f = new File(fullPath);
                 }
-            }
+        }
 
-        if ((f == null) || (!f.isFile())) {
-            /* try the directory of built-in profiles */
-            f = getStandardProfileFile(fileName);
+        if (f != null && !f.isFile()) {
+            f = null;
         }
-        if (f != null && f.isFile()) {
-            return f;
-        }
-        return null;
+        return f;
     }
 
     /**
-     * Returns a file object corresponding to a built-in profile
+     * Returns a stream corresponding to a built-in profile
      * specified by fileName.
      * If there is no built-in profile with such name, then the method
      * returns null.
      */
-    private static File getStandardProfileFile(String fileName) {
-        String dir = System.getProperty("java.home") +
-            File.separatorChar + "lib" + File.separatorChar + "cmm";
-        String fullPath = dir + File.separatorChar + fileName;
-        File f = new File(fullPath);
-        return (f.isFile() && isChildOf(f, dir)) ? f : null;
+    private static InputStream getStandardProfileInputStream(String fileName) {
+        return PCMM.class.getResourceAsStream("profiles/" + fileName);
     }
 
     /**
@@ -1901,7 +1886,7 @@
     private static boolean standardProfileExists(final String fileName) {
         return AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                 public Boolean run() {
-                    return getStandardProfileFile(fileName) != null;
+                    return PCMM.class.getResource("profiles/"+fileName) != null;
                 }
             });
     }
Binary file jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/CIEXYZ.pf has changed
Binary file jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/GRAY.pf has changed
Binary file jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/LINEAR_RGB.pf has changed
Binary file jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/PYCC.pf has changed
Binary file jdk/src/java.desktop/share/classes/sun/java2d/cmm/profiles/sRGB.pf has changed
Binary file jdk/src/java.desktop/share/conf/cmm/lcms/CIEXYZ.pf has changed
Binary file jdk/src/java.desktop/share/conf/cmm/lcms/GRAY.pf has changed
Binary file jdk/src/java.desktop/share/conf/cmm/lcms/LINEAR_RGB.pf has changed
Binary file jdk/src/java.desktop/share/conf/cmm/lcms/PYCC.pf has changed
Binary file jdk/src/java.desktop/share/conf/cmm/lcms/sRGB.pf has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/color/LoadStandardProfilesTest.java	Fri Aug 22 11:02:00 2014 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2014, 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 8039271
+ * @summary test all standard profiles load correctly.
+ */
+
+import java.awt.color.ICC_Profile;
+
+public class LoadStandardProfilesTest {
+
+    public static void main(String args[]) {
+        try {
+            ICC_Profile sRGB      = ICC_Profile.getInstance("sRGB.pf");
+            ICC_Profile gray      = ICC_Profile.getInstance("GRAY.pf");
+            ICC_Profile pycc      = ICC_Profile.getInstance("PYCC.pf");
+            ICC_Profile ciexyz    = ICC_Profile.getInstance("CIEXYZ.pf");
+            ICC_Profile linearRGB = ICC_Profile.getInstance("LINEAR_RGB.pf");
+
+            if (sRGB == null ||
+                gray == null ||
+                pycc == null ||
+                ciexyz == null ||
+                linearRGB == null)
+            {
+                throw new RuntimeException("null profile.");
+            }
+        } catch (Exception e) {
+           throw new RuntimeException(e);
+        }
+    }
+}