changeset 5163:23f237259967

7179349: [macosx] Java processes on Mac should not use default Apple icon Reviewed-by: anthony, art
author leonidr
date Tue, 26 Jun 2012 16:39:29 +0400
parents 9de9cbe25f0b
children dacbc7112dde
files make/sun/osxapp/Makefile make/sun/osxapp/ToBin.java src/macosx/native/sun/osxapp/NSApplicationAWT.m src/macosx/native/sun/osxapp/resource/icons/JavaApp.icns
diffstat 4 files changed, 105 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/make/sun/osxapp/Makefile	Tue Jun 26 16:29:50 2012 +0400
+++ b/make/sun/osxapp/Makefile	Tue Jun 26 16:39:29 2012 +0400
@@ -28,6 +28,11 @@
 PRODUCT = sun
 include $(BUILDDIR)/common/Defs.gmk
 
+GEN_DIR=$(GENSRCDIR)/sun/osxapp
+ICON_DATA = $(GEN_DIR)/AWTIconData.h
+
+CLASSES_INIT += $(ICON_DATA)
+
 #
 # Files
 #
@@ -63,6 +68,7 @@
 	-framework QuartzCore
 
 CPPFLAGS += \
+        -I$(GEN_DIR) \
         $(call NativeSrcDirList,-I,/native/sun/osxapp)
 
 
@@ -70,6 +76,34 @@
   CPPFLAGS += -DINTERNAL_BUILD
 endif
 
-clean clobber::
+TEMPDIR_CLASSES = $(TEMPDIR)/classes
 
-.PHONY:
+$(TEMPDIR_CLASSES)/sun/osxapp/ToBin.class: ToBin.java
+	@$(prep-target)
+	$(BOOT_JAVAC_CMD) -d $(TEMPDIR_CLASSES) $<
+
+ifdef OPENJDK
+    ICONS_PATH_PREFIX=$(PLATFORM_SRC_MACOS)
+else
+    ICONS_PATH_PREFIX=$(CLOSED_SRC)/macosx
+endif
+
+generated.clean:
+	$(RM) -r $(GEN_DIR)/*.h
+
+ICONPATH=$(ICONS_PATH_PREFIX)/native/sun/osxapp/resource/icons
+ICON = $(ICONPATH)/JavaApp.icns
+
+$(GEN_DIR)/AWTIconData.h: $(TEMPDIR_CLASSES)/sun/osxapp/ToBin.class $(ICON) 
+	$(prep-target)
+	$(RM) $(ICON_DATA)
+	$(ECHO) "static unsigned char sAWTIconData[] = { " >> $(ICON_DATA);  \
+	$(CAT) $(ICON) | \
+	    $(BOOT_JAVA_CMD) -cp $(TEMPDIR_CLASSES) -Djava.awt.headless=true \
+	    sun.osxapp.ToBin >> $(ICON_DATA); \
+	$(ECHO) "};" >> $(ICON_DATA);
+
+
+clean clobber:: generated.clean
+
+.PHONY: generated.clean
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/make/sun/osxapp/ToBin.java	Tue Jun 26 16:39:29 2012 +0400
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 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.  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.
+ */
+
+package sun.osxapp;
+
+import java.io.*;
+
+public class ToBin {
+    public static void main(String[] args) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        int nRead;
+        byte[] data = new byte[4096];
+
+        while ((nRead = System.in.read(data, 0, data.length)) != -1) {
+            baos.write(data, 0, nRead);
+        }
+
+        baos.flush();
+
+        byte[] buf = baos.toByteArray();
+        for (int i = 0; i < buf.length; i++) {
+            System.out.print(String.format("0x%1$02X", buf[i]) + ", ");
+            if (i % 20 == 0) {
+                System.out.println();
+            }
+        }
+    }
+}
--- a/src/macosx/native/sun/osxapp/NSApplicationAWT.m	Tue Jun 26 16:29:50 2012 +0400
+++ b/src/macosx/native/sun/osxapp/NSApplicationAWT.m	Tue Jun 26 16:39:29 2012 +0400
@@ -31,6 +31,7 @@
 #import "PropertiesUtilities.h"
 #import "ThreadUtilities.h"
 #import "QueuingApplicationDelegate.h"
+#import "AWTIconData.h"
 
 static BOOL sUsingDefaultNIB = YES;
 static NSString *SHARED_FRAMEWORK_BUNDLE = @"/System/Library/Frameworks/JavaVM.framework";
@@ -257,22 +258,26 @@
         theIconPath = [PropertiesUtilities javaSystemPropertyForKey:@"apple.awt.application.icon" withEnv:env];
     }
 
-    // If the icon file wasn't specified as an argument and we need to get an icon
-    // we'll use the generic java app icon.
-    NSString *defaultIconPath = [NSString stringWithFormat:@"%@%@", SHARED_FRAMEWORK_BUNDLE, @"/Resources/GenericApp.icns"];
-    if (([NSApp applicationIconImage] == nil) && (theIconPath == nil)) {
-        theIconPath = defaultIconPath;
+    // Use the path specified to get the icon image
+    NSImage* iconImage = nil;
+    if (theIconPath != nil) {
+        iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];
+    } 
+
+    // If no icon file was specified or we failed to get the icon image
+    // and we need to get an icon, then use the default icon
+    if (iconImage == nil) {
+        NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
+        if (bundleIcon == nil) {
+            NSData* iconData;
+            iconData = [[NSData alloc] initWithBytesNoCopy: sAWTIconData length: sizeof(sAWTIconData) freeWhenDone: NO];
+            iconImage = [[NSImage alloc] initWithData: iconData];
+            [iconData release];
+        }
     }
 
-    // Set up the dock icon if we have an icon name.
-    if (theIconPath != nil) {
-        NSImage *iconImage = [[NSImage alloc] initWithContentsOfFile:theIconPath];
-
-        // If we failed for some reason fall back to the default icon.
-        if (iconImage == nil) {
-            iconImage = [[NSImage alloc] initWithContentsOfFile:defaultIconPath];
-        }
-
+    // Set up the dock icon if we have an icon image.
+    if (iconImage != nil) {
         [NSApp setApplicationIconImage:iconImage];
         [iconImage release];
     }
Binary file src/macosx/native/sun/osxapp/resource/icons/JavaApp.icns has changed