7179349: [macosx] Java processes on Mac should not use default Apple icon

Reviewed-by: anthony
This commit is contained in:
Leonid Romanov 2012-09-24 18:24:30 +04:00
parent 0ea3bcf8a8
commit 914bc61d4b
4 changed files with 102 additions and 16 deletions

View File

@ -28,6 +28,11 @@ LIBRARY = osxapp
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 @@ OTHER_LDLIBS += \
-framework QuartzCore
CPPFLAGS += \
-I$(GEN_DIR) \
$(call NativeSrcDirList,-I,/native/sun/osxapp)
@ -70,6 +76,34 @@ ifeq ($(MILESTONE), internal)
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

View File

@ -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();
}
}
}
}

View File

@ -31,6 +31,7 @@
#import "PropertiesUtilities.h"
#import "ThreadUtilities.h"
#import "QueuingApplicationDelegate.h"
#import "AWTIconData.h"
static BOOL sUsingDefaultNIB = YES;
@ -258,25 +259,26 @@ AWT_ASSERT_APPKIT_THREAD;
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];
}