8039269: images/cursors should not be in ${java.home}/lib
Reviewed-by: mchung, alanb, erikj
--- a/jdk/make/copy/Copy-java.desktop.gmk Mon Feb 16 19:10:05 2015 +0300
+++ b/jdk/make/copy/Copy-java.desktop.gmk Mon Feb 16 20:01:17 2015 +0300
@@ -100,34 +100,3 @@
TARGETS += $(PSFONTPROPFILE_TARGET_FILES)
################################################################################
-#
-# Copy cursor.properties and cursors gif files to LIB_DST_DIR
-#
-ifneq ($(OPENJDK_TARGET_OS), macosx)
- OPENJDK_TARGET_OS_LIB_SRC := $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/conf
-else
- OPENJDK_TARGET_OS_LIB_SRC := $(JDK_TOPDIR)/src/java.desktop/macosx/conf
-endif
-
-CURSORS_DEST_DIR := $(LIB_DST_DIR)/images/cursors
-CURSORS_OPENJDK_TARGET_OS_LIB_SRC := $(JDK_TOPDIR)/src/java.desktop/$(OPENJDK_TARGET_OS_TYPE)/conf/images/cursors
-
-$(CURSORS_DEST_DIR)/cursors.properties: $(CURSORS_OPENJDK_TARGET_OS_LIB_SRC)/cursors.properties
- $(call install-file)
-
-TARGETS += $(CURSORS_DEST_DIR)/cursors.properties
-
-CURSORS_LIB_SRC := $(JDK_TOPDIR)/src/java.desktop/share/conf/images/cursors
-ifeq ($(OPENJDK_TARGET_OS), windows)
- CURSORS_SRC_FILES := $(CURSORS_LIB_SRC)/invalid32x32.gif $(wildcard $(CURSORS_LIB_SRC)/win32_*.gif)
-else # OPENJDK_TARGET_OS
- CURSORS_SRC_FILES := $(CURSORS_LIB_SRC)/invalid32x32.gif $(wildcard $(CURSORS_LIB_SRC)/motif_*.gif)
-endif # OPENJDK_TARGET_OS
-CURSORS_TARGET_FILES := $(subst $(CURSORS_LIB_SRC),$(CURSORS_DEST_DIR),$(CURSORS_SRC_FILES))
-
-$(CURSORS_DEST_DIR)/%: $(CURSORS_LIB_SRC)/%
- $(call install-file)
-
-TARGETS += $(CURSORS_TARGET_FILES)
-
-################################################################################
--- a/jdk/make/gensrc/Gensrc-java.desktop.gmk Mon Feb 16 19:10:05 2015 +0300
+++ b/jdk/make/gensrc/Gensrc-java.desktop.gmk Mon Feb 16 20:01:17 2015 +0300
@@ -66,8 +66,11 @@
PROP_SRC_DIRS += $(JDK_TOPDIR)/src/java.desktop/share/classes/com/sun/java/swing/plaf/gtk/resources
endif
+PROP_SRC_FILES := $(filter-out %cursors.properties, \
+ $(filter %.properties, $(call CacheFind, $(PROP_SRC_DIRS))))
+
$(eval $(call SetupCompileProperties,COMPILE_PROPERTIES, \
- $(filter %.properties, $(call CacheFind, $(PROP_SRC_DIRS))), ListResourceBundle))
+ $(PROP_SRC_FILES), ListResourceBundle))
GENSRC_JAVA_DESKTOP += $(COMPILE_PROPERTIES)
--- a/jdk/src/java.desktop/share/classes/java/awt/Cursor.java Mon Feb 16 19:10:05 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/java/awt/Cursor.java Mon Feb 16 20:01:17 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015, 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
@@ -24,18 +24,17 @@
*/
package java.awt;
-import java.io.File;
-import java.io.FileInputStream;
-
import java.beans.ConstructorProperties;
+import java.io.InputStream;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
import java.util.Hashtable;
import java.util.Properties;
import java.util.StringTokenizer;
-import java.security.AccessController;
-
+import sun.awt.AWTAccessor;
import sun.util.logging.PlatformLogger;
-import sun.awt.AWTAccessor;
/**
* A class to encapsulate the bitmap representation of the mouse cursor.
@@ -160,28 +159,19 @@
public static final int CUSTOM_CURSOR = -1;
/*
- * hashtable, filesystem dir prefix, filename, and properties for custom cursors support
+ * hashtable, resource prefix, filename, and properties for custom cursors
+ * support
*/
-
private static final Hashtable<String,Cursor> systemCustomCursors = new Hashtable<>(1);
- private static final String systemCustomCursorDirPrefix = initCursorDir();
-
- private static String initCursorDir() {
- String jhome = java.security.AccessController.doPrivileged(
- new sun.security.action.GetPropertyAction("java.home"));
- return jhome +
- File.separator + "lib" + File.separator + "images" +
- File.separator + "cursors" + File.separator;
- }
-
- private static final String systemCustomCursorPropertiesFile = systemCustomCursorDirPrefix + "cursors.properties";
+ private static final String RESOURCE_PREFIX = "/sun/awt/resources/cursors/";
+ private static final String PROPERTIES_FILE = RESOURCE_PREFIX + "cursors.properties";
private static Properties systemCustomCursorProperties = null;
- private static final String CursorDotPrefix = "Cursor.";
- private static final String DotFileSuffix = ".File";
- private static final String DotHotspotSuffix = ".HotSpot";
- private static final String DotNameSuffix = ".Name";
+ private static final String CURSOR_DOT_PREFIX = "Cursor.";
+ private static final String DOT_FILE_SUFFIX = ".File";
+ private static final String DOT_HOTSPOT_SUFFIX = ".HotSpot";
+ private static final String DOT_NAME_SUFFIX = ".Name";
/*
* JDK 1.1 serialVersionUID
@@ -307,8 +297,8 @@
loadSystemCustomCursorProperties();
}
- String prefix = CursorDotPrefix + name;
- String key = prefix + DotFileSuffix;
+ String prefix = CURSOR_DOT_PREFIX + name;
+ String key = prefix + DOT_FILE_SUFFIX;
if (!systemCustomCursorProperties.containsKey(key)) {
if (log.isLoggable(PlatformLogger.Level.FINER)) {
@@ -320,11 +310,10 @@
final String fileName =
systemCustomCursorProperties.getProperty(key);
- String localized = systemCustomCursorProperties.getProperty(prefix + DotNameSuffix);
+ final String localized = systemCustomCursorProperties.getProperty(
+ prefix + DOT_NAME_SUFFIX, name);
- if (localized == null) localized = name;
-
- String hotspot = systemCustomCursorProperties.getProperty(prefix + DotHotspotSuffix);
+ String hotspot = systemCustomCursorProperties.getProperty(prefix + DOT_HOTSPOT_SUFFIX);
if (hotspot == null)
throw new AWTException("no hotspot property defined for cursor: " + name);
@@ -334,31 +323,25 @@
if (st.countTokens() != 2)
throw new AWTException("failed to parse hotspot property for cursor: " + name);
- int x = 0;
- int y = 0;
-
+ final Point hotPoint;
try {
- x = Integer.parseInt(st.nextToken());
- y = Integer.parseInt(st.nextToken());
+ hotPoint = new Point(Integer.parseInt(st.nextToken()),
+ Integer.parseInt(st.nextToken()));
} catch (NumberFormatException nfe) {
throw new AWTException("failed to parse hotspot property for cursor: " + name);
}
try {
- final int fx = x;
- final int fy = y;
- final String flocalized = localized;
+ final Toolkit toolkit = Toolkit.getDefaultToolkit();
+ final String file = RESOURCE_PREFIX + fileName;
- cursor = java.security.AccessController.<Cursor>doPrivileged(
- new java.security.PrivilegedExceptionAction<Cursor>() {
- public Cursor run() throws Exception {
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- Image image = toolkit.getImage(
- systemCustomCursorDirPrefix + fileName);
- return toolkit.createCustomCursor(
- image, new Point(fx,fy), flocalized);
- }
- });
+ cursor = AccessController.doPrivileged(
+ (PrivilegedExceptionAction<Cursor>) () -> {
+ URL url = Cursor.class.getResource(file);
+ Image image = toolkit.getImage(url);
+ return toolkit.createCustomCursor(image, hotPoint,
+ localized);
+ });
} catch (Exception e) {
throw new AWTException(
"Exception: " + e.getClass() + " " + e.getMessage() +
@@ -452,26 +435,19 @@
systemCustomCursorProperties = new Properties();
try {
- AccessController.<Object>doPrivileged(
- new java.security.PrivilegedExceptionAction<Object>() {
- public Object run() throws Exception {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(
- systemCustomCursorPropertiesFile);
- systemCustomCursorProperties.load(fis);
- } finally {
- if (fis != null)
- fis.close();
- }
- return null;
- }
- });
+ AccessController.doPrivileged(
+ (PrivilegedExceptionAction<Object>) () -> {
+ try (InputStream is = Cursor.class
+ .getResourceAsStream(PROPERTIES_FILE)) {
+ systemCustomCursorProperties.load(is);
+ }
+ return null;
+ });
} catch (Exception e) {
systemCustomCursorProperties = null;
throw new AWTException("Exception: " + e.getClass() + " " +
e.getMessage() + " occurred while loading: " +
- systemCustomCursorPropertiesFile);
+ PROPERTIES_FILE);
}
}
}
Binary file jdk/src/java.desktop/share/classes/sun/awt/resources/cursors/CopyDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/classes/sun/awt/resources/cursors/LinkDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/classes/sun/awt/resources/cursors/MoveDrop32x32.gif has changed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/src/java.desktop/share/classes/sun/awt/resources/cursors/cursors.properties Mon Feb 16 20:01:17 2015 +0300
@@ -0,0 +1,40 @@
+#
+#
+# Cursors Properties file
+#
+# Names GIF89 sources for Custom Cursors and their associated HotSpots
+#
+# Note: the syntax of the property name is significant and is parsed
+# by java.awt.Cursor
+#
+# The syntax is: Cursor.<name>.<geom>.File=<filename>
+# Cursor.<name>.<geom>.HotSpot=<x>,<y>
+# Cursor.<name>.<geom>.Name=<localized name>
+#
+Cursor.CopyDrop.32x32.File=CopyDrop32x32.gif
+Cursor.CopyDrop.32x32.HotSpot=0,0
+Cursor.CopyDrop.32x32.Name=CopyDrop32x32
+#
+Cursor.MoveDrop.32x32.File=MoveDrop32x32.gif
+Cursor.MoveDrop.32x32.HotSpot=0,0
+Cursor.MoveDrop.32x32.Name=MoveDrop32x32
+#
+Cursor.LinkDrop.32x32.File=LinkDrop32x32.gif
+Cursor.LinkDrop.32x32.HotSpot=0,0
+Cursor.LinkDrop.32x32.Name=LinkDrop32x32
+#
+Cursor.CopyNoDrop.32x32.File=invalid32x32.gif
+Cursor.CopyNoDrop.32x32.HotSpot=6,2
+Cursor.CopyNoDrop.32x32.Name=CopyNoDrop32x32
+#
+Cursor.MoveNoDrop.32x32.File=invalid32x32.gif
+Cursor.MoveNoDrop.32x32.HotSpot=6,2
+Cursor.MoveNoDrop.32x32.Name=MoveNoDrop32x32
+#
+Cursor.LinkNoDrop.32x32.File=invalid32x32.gif
+Cursor.LinkNoDrop.32x32.HotSpot=6,2
+Cursor.LinkNoDrop.32x32.Name=LinkNoDrop32x32
+#
+Cursor.Invalid.32x32.File=invalid32x32.gif
+Cursor.Invalid.32x32.HotSpot=6,2
+Cursor.Invalid.32x32.Name=Invalid32x32
Binary file jdk/src/java.desktop/share/classes/sun/awt/resources/cursors/invalid32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/invalid32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_CopyDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_CopyNoDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_LinkDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_LinkNoDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_MoveDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/motif_MoveNoDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_CopyDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_CopyNoDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_LinkDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_LinkNoDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_MoveDrop32x32.gif has changed
Binary file jdk/src/java.desktop/share/conf/images/cursors/win32_MoveNoDrop32x32.gif has changed
--- a/jdk/src/java.desktop/unix/conf/images/cursors/cursors.properties Mon Feb 16 19:10:05 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-#
-#
-# Cursors Properties file
-#
-# Names GIF89 sources for Custom Cursors and their associated HotSpots
-#
-# Note: the syntax of the property name is significant and is parsed
-# by java.awt.Cursor
-#
-# The syntax is: Cursor.<name>.<geom>.File=<filename>
-# Cursor.<name>.<geom>.HotSpot=<x>,<y>
-# Cursor.<name>.<geom>.Name=<localized name>
-#
-Cursor.CopyDrop.32x32.File=motif_CopyDrop32x32.gif
-Cursor.CopyDrop.32x32.HotSpot=0,0
-Cursor.CopyDrop.32x32.Name=CopyDrop32x32
-#
-Cursor.MoveDrop.32x32.File=motif_MoveDrop32x32.gif
-Cursor.MoveDrop.32x32.HotSpot=0,0
-Cursor.MoveDrop.32x32.Name=MoveDrop32x32
-#
-Cursor.LinkDrop.32x32.File=motif_LinkDrop32x32.gif
-Cursor.LinkDrop.32x32.HotSpot=0,0
-Cursor.LinkDrop.32x32.Name=LinkDrop32x32
-#
-Cursor.CopyNoDrop.32x32.File=motif_CopyNoDrop32x32.gif
-Cursor.CopyNoDrop.32x32.HotSpot=6,2
-Cursor.CopyNoDrop.32x32.Name=CopyNoDrop32x32
-#
-Cursor.MoveNoDrop.32x32.File=motif_MoveNoDrop32x32.gif
-Cursor.MoveNoDrop.32x32.HotSpot=6,2
-Cursor.MoveNoDrop.32x32.Name=MoveNoDrop32x32
-#
-Cursor.LinkNoDrop.32x32.File=motif_LinkNoDrop32x32.gif
-Cursor.LinkNoDrop.32x32.HotSpot=6,2
-Cursor.LinkNoDrop.32x32.Name=LinkNoDrop32x32
-#
-Cursor.Invalid.32x32.File=invalid32x32.gif
-Cursor.Invalid.32x32.HotSpot=6,2
-Cursor.Invalid.32x32.Name=Invalid32x32
Binary file jdk/src/java.desktop/windows/classes/sun/awt/resources/cursors/CopyDrop32x32.gif has changed
Binary file jdk/src/java.desktop/windows/classes/sun/awt/resources/cursors/LinkDrop32x32.gif has changed
Binary file jdk/src/java.desktop/windows/classes/sun/awt/resources/cursors/MoveDrop32x32.gif has changed
--- a/jdk/src/java.desktop/windows/conf/images/cursors/cursors.properties Mon Feb 16 19:10:05 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-#
-#
-# Cursors Properties file
-#
-# Names GIF89 sources for Custom Cursors and their associated HotSpots
-#
-# Note: the syntax of the property name is significant and is parsed
-# by java.awt.Cursor
-#
-# The syntax is: Cursor.<name>.<geom>.File=win32_<filename>
-# Cursor.<name>.<geom>.HotSpot=<x>,<y>
-# Cursor.<name>.<geom>.Name=<localized name>
-#
-Cursor.CopyDrop.32x32.File=win32_CopyDrop32x32.gif
-Cursor.CopyDrop.32x32.HotSpot=0,0
-Cursor.CopyDrop.32x32.Name=CopyDrop32x32
-#
-Cursor.MoveDrop.32x32.File=win32_MoveDrop32x32.gif
-Cursor.MoveDrop.32x32.HotSpot=0,0
-Cursor.MoveDrop.32x32.Name=MoveDrop32x32
-#
-Cursor.LinkDrop.32x32.File=win32_LinkDrop32x32.gif
-Cursor.LinkDrop.32x32.HotSpot=0,0
-Cursor.LinkDrop.32x32.Name=LinkDrop32x32
-#
-Cursor.CopyNoDrop.32x32.File=win32_CopyNoDrop32x32.gif
-Cursor.CopyNoDrop.32x32.HotSpot=6,2
-Cursor.CopyNoDrop.32x32.Name=CopyNoDrop32x32
-#
-Cursor.MoveNoDrop.32x32.File=win32_MoveNoDrop32x32.gif
-Cursor.MoveNoDrop.32x32.HotSpot=6,2
-Cursor.MoveNoDrop.32x32.Name=MoveNoDrop32x32
-#
-Cursor.LinkNoDrop.32x32.File=win32_LinkNoDrop32x32.gif
-Cursor.LinkNoDrop.32x32.HotSpot=6,2
-Cursor.LinkNoDrop.32x32.Name=LinkNoDrop32x32
-#
-Cursor.Invalid.32x32.File=invalid32x32.gif
-Cursor.Invalid.32x32.HotSpot=6,2
-Cursor.Invalid.32x32.Name=Invalid32x32
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/Cursor/GetSystemCustomCursor/GetSystemCustomCursor.java Mon Feb 16 20:01:17 2015 +0300
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+import java.awt.AWTException;
+import java.awt.Cursor;
+
+/**
+ * @test
+ * @bug 8039269
+ * @author Sergey Bylokhov
+ */
+public final class GetSystemCustomCursor {
+
+ public static void main(final String[] args) throws AWTException {
+ // This list is copied from cursors.properties
+ String[] names = {"CopyDrop.32x32", "MoveDrop.32x32", "LinkDrop.32x32",
+ "CopyNoDrop.32x32", "MoveNoDrop.32x32",
+ "LinkNoDrop.32x32", "Invalid.32x32"};
+ for (final String name : names) {
+ if (Cursor.getSystemCustomCursor(name) == null) {
+ throw new RuntimeException("Cursor is null: " + name);
+ }
+ }
+ System.out.println("Test passed");
+ }
+}