7179349: [macosx] Java processes on Mac should not use default Apple icon
authorleonidr
Mon, 24 Sep 2012 18:24:30 +0400
changeset 13992 d1b65c4e924c
parent 13991 e62879b84a14
child 13993 8b3fe3d8badb
7179349: [macosx] Java processes on Mac should not use default Apple icon Reviewed-by: anthony
jdk/make/sun/osxapp/Makefile
jdk/make/sun/osxapp/ToBin.java
jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m
jdk/src/macosx/native/sun/osxapp/resource/icons/JavaApp.icns
--- a/jdk/make/sun/osxapp/Makefile	Mon Sep 24 15:25:17 2012 +0400
+++ b/jdk/make/sun/osxapp/Makefile	Mon Sep 24 18:24:30 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
+
+$(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
 
-.PHONY:
+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/jdk/make/sun/osxapp/ToBin.java	Mon Sep 24 18:24:30 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/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m	Mon Sep 24 15:25:17 2012 +0400
+++ b/jdk/src/macosx/native/sun/osxapp/NSApplicationAWT.m	Mon Sep 24 18:24:30 2012 +0400
@@ -31,6 +31,7 @@
 #import "PropertiesUtilities.h"
 #import "ThreadUtilities.h"
 #import "QueuingApplicationDelegate.h"
+#import "AWTIconData.h"
 
 
 static BOOL sUsingDefaultNIB = YES;
@@ -258,25 +259,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 (theIconPath == nil) {
+    // 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 there is no bundle's icon, then use the default icon
+    if (iconImage == nil) {
         NSString* bundleIcon = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleIconFile"];
         if (bundleIcon == nil) {
-            theIconPath = defaultIconPath;
+            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 jdk/src/macosx/native/sun/osxapp/resource/icons/JavaApp.icns has changed