Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikael Barbero2015-09-25 15:40:16 +0000
committerArun Thondapu2015-12-18 12:08:51 +0000
commit15d56969726892d8f960f4b0562575446c550957 (patch)
treefd2e7808559afcdbc66a42fd5f1175f18fb26809 /features/org.eclipse.equinox.executable.feature/library/cocoa
parentb2d5cd9b7aee527968d3382eff1bb7e64590fc27 (diff)
downloadrt.equinox.framework-15d56969726892d8f960f4b0562575446c550957.tar.gz
rt.equinox.framework-15d56969726892d8f960f4b0562575446c550957.tar.xz
rt.equinox.framework-15d56969726892d8f960f4b0562575446c550957.zip
Bug 383545 - Rename library/carbon to library/cocoa
Change-Id: Ibf3be14f750de816825000a2f1c8d17fbe8ed249 Signed-off-by: Mikael Barbero <mikael@eclipse.org>
Diffstat (limited to 'features/org.eclipse.equinox.executable.feature/library/cocoa')
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/.cvsignore3
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/build.sh81
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml63
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbon.c957
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonCommon.c212
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonMain.c237
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseMain.c15
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/cocoa/make_cocoa.mak93
8 files changed, 1661 insertions, 0 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/.cvsignore b/features/org.eclipse.equinox.executable.feature/library/cocoa/.cvsignore
new file mode 100644
index 000000000..f0fdae47c
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/.cvsignore
@@ -0,0 +1,3 @@
+*.o
+eclipse
+*.so
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/build.sh b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.sh
new file mode 100644
index 000000000..3fda6e820
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.sh
@@ -0,0 +1,81 @@
+#!/bin/sh
+#*******************************************************************************
+# Copyright (c) 2000, 2009 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+# Kevin Cornell (Rational Software Corporation)
+#*******************************************************************************
+#
+# Usage: sh build.sh [<optional switches>] [clean]
+#
+# where the optional switches are:
+# -output <PROGRAM_OUTPUT> - executable filename ("eclipse")
+# -os <DEFAULT_OS> - default Eclipse "-os" value
+# -arch <DEFAULT_OS_ARCH> - default Eclipse "-arch" value
+# -ws <DEFAULT_WS> - default Eclipse "-ws" value
+#
+#
+# This script can also be invoked with the "clean" argument.
+
+cd `dirname $0`
+
+# Define default values for environment variables used in the makefiles.
+programOutput="eclipse"
+defaultOS="macosx"
+defaultOSArch="x86_64"
+defaultWS="cocoa"
+makefile="make_cocoa.mak"
+
+# Parse the command line arguments and override the default values.
+extraArgs=""
+while [ "$1" != "" ]; do
+ if [ "$1" = "-os" ] && [ "$2" != "" ]; then
+ defaultOS="$2"
+ shift
+ elif [ "$1" = "-arch" ] && [ "$2" != "" ]; then
+ defaultOSArch="$2"
+ shift
+ elif [ "$1" = "-ws" ] && [ "$2" != "" ]; then
+ defaultWS="$2"
+ shift
+ elif [ "$1" = "-output" ] && [ "$2" != "" ]; then
+ programOutput="$2"
+ shift
+ else
+ extraArgs="$extraArgs $1"
+ fi
+ shift
+done
+
+echo "build $defaultOSArch"
+
+# Set up environment variables needed by the makefiles.
+PROGRAM_OUTPUT="$programOutput"
+DEFAULT_OS="$defaultOS"
+DEFAULT_OS_ARCH="$defaultOSArch"
+DEFAULT_WS="$defaultWS"
+EXEC_DIR=../../../../../rt.equinox.binaries/org.eclipse.equinox.executable
+PROGRAM_OUTPUT_DIR="$EXEC_DIR/bin/$defaultWS/$defaultOS/$defaultOSArch/Eclipse.app/Contents/MacOS"
+
+# /System/Library/Frameworks/JavaVM.framework/Headers does not exist anymore on Yosemite
+if [ -e /System/Library/Frameworks/JavaVM.framework/Headers ]; then
+ JAVA_HEADERS="-I/System/Library/Frameworks/JavaVM.framework/Headers"
+else
+ JAVA_HEADERS="-I$(/usr/libexec/java_home)/include -I$(/usr/libexec/java_home)/include/darwin"
+fi
+
+export PROGRAM_OUTPUT DEFAULT_OS DEFAULT_OS_ARCH DEFAULT_WS ARCHS PROGRAM_OUTPUT_DIR JAVA_HEADERS
+
+if [ "$extraArgs" != "" ]; then
+ make -f $makefile $extraArgs
+else
+ echo "Building $defaultOS launcher. Defaults: -os $DEFAULT_OS -arch $DEFAULT_OS_ARCH -ws $DEFAULT_WS"
+ make -f $makefile clean
+ make -f $makefile all
+ make -f $makefile install
+fi
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml
new file mode 100644
index 000000000..9561ac508
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/build.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<project default="build_eclipse" basedir=".">
+
+<target name="build_eclipse">
+
+ <loadresource property="WS">
+ <string value="${native}"/>
+ <filterchain>
+ <tokenfilter>
+ <replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\1"/>
+ </tokenfilter>
+ </filterchain>
+ </loadresource>
+
+ <condition property="WS_ARG" value="-ws ${WS}" else="">
+ <isset property="native" />
+ </condition>
+
+ <loadresource property="OS">
+ <string value="${native}"/>
+ <filterchain>
+ <tokenfilter>
+ <replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\2"/>
+ </tokenfilter>
+ </filterchain>
+ </loadresource>
+
+ <condition property="OS_ARG" value="-os ${OS}" else="">
+ <isset property="native" />
+ </condition>
+
+ <loadresource property="ARCH">
+ <string value="${native}"/>
+ <filterchain>
+ <tokenfilter>
+ <replaceregex pattern="([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)\.([A-Za-z0-9_]+)" replace="\3"/>
+ </tokenfilter>
+ </filterchain>
+ </loadresource>
+
+ <condition property="ARCH_ARG" value="-arch ${ARCH}" else="">
+ <isset property="native" />
+ </condition>
+
+ <exec dir="." executable="sh">
+ <arg line="${basedir}/build.sh"/>
+ <arg line="install"/>
+ <arg line="${WS_ARG}"/>
+ <arg line="${OS_ARG}"/>
+ <arg line="${ARCH_ARG}"/>
+ </exec>
+</target>
+
+<target name="clean">
+ <tstamp/>
+ <exec dir="." executable="sh">
+ <arg line="${basedir}/build.sh"/>
+ <arg line="clean"/>
+ </exec>
+</target>
+
+</project>
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbon.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbon.c
new file mode 100644
index 000000000..61bdb8eb3
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbon.c
@@ -0,0 +1,957 @@
+/*
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Andre Weinand (OTI Labs)
+ * David Green - OpenJDK bsd port integration
+ * Rapicorp, Inc - Default the configuration to Application Support (bug 461725)
+ */
+
+/* MacOS X Carbon specific logic for displaying the splash screen. */
+
+#include "eclipseOS.h"
+#include "eclipseCommon.h"
+#include "eclipseJNI.h"
+#include "eclipseUtil.h"
+
+#include <sys/xattr.h>
+ #include <string.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <CoreServices/CoreServices.h>
+#ifdef COCOA
+#include <Cocoa/Cocoa.h>
+#else
+#include <Carbon/Carbon.h>
+#include "NgCommon.h"
+#include "NgImageData.h"
+#include "NgWinBMPFileFormat.h"
+#endif
+#include <mach-o/dyld.h>
+
+#define startupJarName "startup.jar"
+#define LAUNCHER "-launcher"
+#define SPLASH_LAUNCHER "/Resources/Splash.app/Contents/"
+
+#define DEBUG 0
+
+static _TCHAR* noForkingMsg = _T_ECLIPSE("Internal Error, forking the jvm is not supported on MacOS.\n");
+static const _TCHAR* INSTALL_UUID = _T_ECLIPSE("eclipse.uuid");
+
+char *findCommand(char *command);
+
+/* Global Variables */
+char* defaultVM = "java";
+char* vmLibrary = "JavaVM";
+char* shippedVMDir = "../../../jre/Contents/Home/jre/bin/";
+int isSunMaxPermSizeVM = 0;
+
+static void adjustLibraryPath(char * vmLibrary);
+static char * findLib(char * command);
+
+#ifdef i386
+#define JAVA_ARCH "i386"
+#define JAVA_HOME_ARCH "i386"
+#elif defined(__ppc__) || defined(__powerpc64__)
+#define JAVA_ARCH "ppc"
+#define JAVA_HOME_ARCH "ppc"
+#elif defined(__amd64__) || defined(__x86_64__)
+#define JAVA_ARCH "amd64"
+#define JAVA_HOME_ARCH "x86_64"
+#else
+#define JAVA_ARCH DEFAULT_OS_ARCH
+#define JAVA_HOME_ARCH DEFAULT_OS_ARCH
+#endif
+
+#define LIB_PATH_VAR _T_ECLIPSE("LD_LIBRARY_PATH")
+#define DYLD_FALLBACK_VAR _T_ECLIPSE("DYLD_FALLBACK_LIBRARY_PATH")
+
+#define MAX_LOCATION_LENGTH 40 /* none of the jvmLocations strings should be longer than this */
+#define MAX_JVMLIB_LENGTH 15 /* none of the jvmLibs strings should be longer than this */
+static const char* jvmLocations[] = {
+ "../lib/" JAVA_ARCH "/client",
+ "../lib/" JAVA_ARCH "/server",
+ "../lib/client",
+ "../lib/server",
+ "../jre/lib/" JAVA_ARCH "/client",
+ "../jre/lib/" JAVA_ARCH "/server",
+ "../jre/lib/client",
+ "../jre/lib/server",
+ NULL
+};
+static const char* jvmLibs[] = { "libjvm.dylib", "libjvm.jnilib", "libjvm.so", NULL };
+
+/* Define the window system arguments for the various Java VMs. */
+static char* argVM_JAVA[] = { "-XstartOnFirstThread", NULL };
+
+#ifdef COCOA
+static NSWindow* window = nil;
+@interface KeyWindow : NSWindow { }
+- (BOOL)canBecomeKeyWindow;
+@end
+
+@implementation KeyWindow
+- (BOOL)canBecomeKeyWindow {
+ return YES;
+}
+
+- (void)close {
+ [super close];
+ window = nil;
+}
+
++ (int)show: (NSString *) featureImage {
+ ProcessSerialNumber psn;
+ if (GetCurrentProcess(&psn) == noErr) {
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ SetFrontProcess(&psn);
+ }
+ if (window != NULL)
+ return 0; /*already showing */
+ if (featureImage == NULL)
+ return ENOENT;
+
+ int result = ENOENT;
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ [NSApplication sharedApplication];
+ NSImage* image = [[NSImage alloc] initByReferencingFile: featureImage];
+ [featureImage release];
+ if (image != NULL) {
+ NSImageRep* imageRep = [image bestRepresentationForDevice: [[NSScreen mainScreen] deviceDescription]];
+ NSRect rect = {{0, 0}, {[imageRep pixelsWide], [imageRep pixelsHigh]}};
+ [image setSize: NSMakeSize([imageRep pixelsWide], [imageRep pixelsHigh])];
+ [image autorelease];
+ window = [[KeyWindow alloc] initWithContentRect: rect styleMask: NSBorderlessWindowMask backing: NSBackingStoreBuffered defer: 0];
+ if (window != nil) {
+ [window center];
+ [window setBackgroundColor: [NSColor colorWithPatternImage: image]];
+ [window makeKeyAndOrderFront: nil];
+ dispatchMessages();
+ result = 0;
+ }
+ }
+ [pool release];
+ return result;
+}
+
++ (void)shutdown {
+ if (window != 0) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ [window close];
+ window = nil;
+ [pool release];
+ }
+}
+
++ (void)dispatch {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSEvent* event;
+ NSApplication* application = [NSApplication sharedApplication];
+ while ((event = [application nextEventMatchingMask: 0 untilDate: nil inMode: NSDefaultRunLoopMode dequeue: TRUE]) != nil) {
+ [application sendEvent: event];
+ }
+ [pool release];
+}
+
+@end
+
+@interface AppleEventDelegate : NSObject
+- (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+- (void)handleGetURL:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent;
+@end
+@implementation AppleEventDelegate
+ NSTimer *timerOpenDocuments;
+ NSMutableArray *files;
+ NSTimer *timerOpenUrls;
+ NSMutableArray *urls;
+
+- (void)handleOpenDocuments:(NSAppleEventDescriptor *)event withReplyEvent: (NSAppleEventDescriptor *)replyEvent {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ int count = [event numberOfItems];
+ int index = 1;
+
+ if (!files) {
+ files = [NSMutableArray arrayWithCapacity:count];
+ [files retain];
+ }
+
+ for (index = 1; index<=count; index++) {
+ CFURLRef url = NULL;
+ NSAppleEventDescriptor *desc = [event descriptorAtIndex:index], *coerceDesc;
+ if (!desc) continue;
+ if ((coerceDesc = [desc coerceToDescriptorType: typeFSRef]) != NULL) {
+ url = CFURLCreateFromFSRef(kCFAllocatorDefault, [[coerceDesc data] bytes]);
+ } else if ((coerceDesc = [desc coerceToDescriptorType: typeFileURL]) != NULL) {
+ NSData *data = [coerceDesc data];
+ url = CFURLCreateWithBytes(kCFAllocatorDefault, [data bytes], [data length], kCFStringEncodingUTF8, NULL);
+ }
+ if (url) {
+ NSString *pathName = (NSString *)CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
+ [files addObject:pathName];
+ [pathName release];
+ CFRelease(url);
+ }
+ }
+
+ if (!timerOpenDocuments) {
+ timerOpenDocuments = [NSTimer scheduledTimerWithTimeInterval: 1.0
+ target: self
+ selector: @selector(handleOpenDocumentsTimer:)
+ userInfo: nil
+ repeats: YES];
+ }
+ [pool release];
+}
+
+- (void) handleOpenDocumentsTimer: (NSTimer *) timer {
+ NSObject *delegate = [[NSApplication sharedApplication] delegate];
+ if (delegate != NULL && [delegate respondsToSelector: @selector(application:openFiles:)]) {
+ [delegate performSelector:@selector(application:openFiles:) withObject:[NSApplication sharedApplication] withObject:files];
+ [files release];
+ files = NULL;
+ [timerOpenDocuments invalidate];
+ }
+}
+
+- (void)handleGetURL:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+
+ NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
+
+ NSObject *delegate = [[NSApplication sharedApplication] delegate];
+ if (delegate != NULL && [delegate respondsToSelector: @selector(application:openUrls:)]) {
+ [delegate performSelector:@selector(application:openUrls:) withObject:[NSApplication sharedApplication] withObject:[NSArray arrayWithObject:url]];
+ } else {
+ if (!urls) {
+ urls = [NSMutableArray arrayWithCapacity:1];
+ [urls retain];
+ }
+
+ [urls addObject:url];
+
+ if (!timerOpenUrls) {
+ timerOpenUrls = [NSTimer scheduledTimerWithTimeInterval: 1.0
+ target: self
+ selector: @selector(handleOpenUrlsTimer:)
+ userInfo: nil
+ repeats: YES];
+ }
+ }
+
+ [pool release];
+}
+
+- (void) handleOpenUrlsTimer: (NSTimer *) timer {
+ NSObject *delegate = [[NSApplication sharedApplication] delegate];
+ if (delegate != NULL && [delegate respondsToSelector: @selector(application:openUrls:)]) {
+ [delegate performSelector:@selector(application:openUrls:) withObject:[NSApplication sharedApplication] withObject:urls];
+ [urls release];
+ urls = NULL;
+ [timerOpenUrls invalidate];
+ timerOpenUrls = NULL;
+ }
+}
+@end
+#endif
+
+#ifndef COCOA
+static CFMutableArrayRef files;
+static EventHandlerRef appHandler;
+static int SWT_CLASS = 'SWT-';
+static int SWT_OPEN_FILE_KIND = 1;
+static int SWT_OPEN_FILE_PARAM = 'odoc';
+#endif
+
+int main() {
+ return -1;
+}
+
+void installAppleEventHandler();
+
+int reuseWorkbench(_TCHAR** filePath, int timeout) {
+ installAppleEventHandler();
+ return 0;
+}
+
+#ifdef COCOA
+
+/* Show the Splash Window
+ *
+ * Create the splash window, load the bitmap and display the splash window.
+ */
+int showSplash( const _TCHAR* featureImage )
+{
+ int result = 0;
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSString *str = [[NSString stringWithUTF8String: featureImage] retain];
+ if ([NSThread isMainThread]) {
+ result = [KeyWindow show: str];
+ } else {
+ [KeyWindow performSelectorOnMainThread: @selector(show:) withObject: str waitUntilDone: 0];
+ }
+ [pool release];
+ return result;
+}
+
+void takeDownSplash() {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ if ([NSThread isMainThread]) {
+ [KeyWindow shutdown];
+ } else {
+ [KeyWindow performSelectorOnMainThread: @selector(shutdown) withObject: nil waitUntilDone: 0];
+ }
+ [pool release];
+}
+
+void dispatchMessages() {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ if ([NSThread isMainThread]) {
+ [KeyWindow dispatch];
+ } else {
+ [KeyWindow performSelectorOnMainThread: @selector(dispatch) withObject: nil waitUntilDone: 0];
+ }
+ [pool release];
+}
+
+#else
+static WindowRef window;
+static ControlRef pane = NULL;
+static CGImageRef image = NULL;
+static CGImageRef loadBMPImage(const char *image);
+
+typedef CGImageSourceRef (*CGImageSourceCreateWithURL_FUNC) (CFURLRef, CFDictionaryRef);
+typedef CGImageRef (*CGImageSourceCreateImageAtIndex_FUNC)(CGImageSourceRef, size_t, CFDictionaryRef);
+static CGImageSourceCreateWithURL_FUNC createWithURL = NULL;
+static CGImageSourceCreateImageAtIndex_FUNC createAtIndex = NULL;
+
+static pascal OSErr openDocumentsProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon);
+
+static OSStatus drawProc (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, void * data) {
+ int result = CallNextEventHandler(eventHandlerCallRef, eventRef);
+ if (image) {
+ ControlRef control;
+ CGContextRef context;
+
+ GetEventParameter(eventRef, kEventParamDirectObject, typeControlRef, NULL, 4, NULL, &control);
+ GetEventParameter(eventRef, kEventParamCGContextRef, typeCGContextRef, NULL, 4, NULL, &context);
+
+ HIRect rect;
+ HIViewGetBounds(control, &rect);
+ HIViewDrawCGImage(context, &rect, image);
+ }
+ return result;
+}
+
+static OSStatus disposeProc (EventHandlerCallRef eventHandlerCallRef, EventRef eventRef, void * data) {
+ window = NULL;
+ return eventNotHandledErr;
+}
+
+void loadImageFns()
+{
+ static int initialized = 0;
+ static CFBundleRef bundle = NULL;
+
+ if (!initialized) {
+ if (!bundle) bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
+ if (bundle) createAtIndex = (CGImageSourceCreateImageAtIndex_FUNC)CFBundleGetFunctionPointerForName(bundle, CFSTR("CGImageSourceCreateImageAtIndex"));
+ if (bundle) createWithURL = (CGImageSourceCreateWithURL_FUNC)CFBundleGetFunctionPointerForName(bundle, CFSTR("CGImageSourceCreateWithURL"));
+ initialized = 1;
+ }
+}
+
+static OSStatus appleEventProc(EventHandlerCallRef inCaller, EventRef theEvent, void* inRefcon) {
+ EventRecord eventRecord;
+ Boolean release = false;
+ EventQueueRef queue;
+
+ queue = GetCurrentEventQueue();
+ if (IsEventInQueue (queue, theEvent)) {
+ RetainEvent (theEvent);
+ release = true;
+ RemoveEventFromQueue (queue, theEvent);
+ }
+ ConvertEventRefToEventRecord (theEvent, &eventRecord);
+ AEProcessAppleEvent (&eventRecord);
+ if (release) ReleaseEvent (theEvent);
+ return noErr;
+}
+
+static void timerProc(EventLoopTimerRef timer, void *userData) {
+ EventTargetRef target = GetApplicationEventTarget();
+ CFIndex count = CFArrayGetCount (files);
+ int i;
+ for (i=0; i<count; i++) {
+ CFStringRef file = (CFStringRef) CFArrayGetValueAtIndex(files, i);
+ EventRef event = NULL;
+ CreateEvent (NULL, SWT_CLASS, SWT_OPEN_FILE_KIND, 0, kEventAttributeNone, &event);
+ SetEventParameter (event, SWT_OPEN_FILE_PARAM, typeCFStringRef, sizeof(file), &file);
+ OSStatus status = SendEventToEventTarget(event, target);
+ ReleaseEvent(event);
+ if (status == eventNotHandledErr) return;
+ }
+ CFRelease(files);
+ RemoveEventLoopTimer(timer);
+ RemoveEventHandler(appHandler);
+ AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(openDocumentsProc), false);
+}
+
+static pascal OSErr openDocumentsProc(const AppleEvent *theAppleEvent, AppleEvent *reply, long handlerRefcon) {
+ AEDescList docList;
+ FSRef theFSRef;
+ long index;
+ long count = 0;
+
+ AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList);
+ AECountItems(&docList, &count);
+ for(index = 1; index <= count; index++) {
+ AEGetNthPtr(&docList, index, typeFSRef, NULL, NULL, &theFSRef, sizeof(FSRef), NULL);
+ CFURLRef url = CFURLCreateFromFSRef(kCFAllocatorDefault, &theFSRef);
+ CFStringRef pathName = CFURLCopyFileSystemPath(url, kCFURLPOSIXPathStyle);
+ if (!files) {
+ files = CFArrayCreateMutable(kCFAllocatorDefault, count, &kCFTypeArrayCallBacks);
+ InstallEventLoopTimer(GetMainEventLoop(), 1, 1, NewEventLoopTimerUPP(timerProc), NULL, NULL);
+ }
+ CFArrayAppendValue(files, pathName);
+ CFRelease(pathName);
+ CFRelease(url);
+ }
+ AEDisposeDesc(&docList);
+ return noErr;
+}
+
+/* Show the Splash Window
+ *
+ * Create the splash window, load the bitmap and display the splash window.
+ */
+int showSplash( const _TCHAR* featureImage )
+{
+ Rect wRect;
+ int w, h, deviceWidth, deviceHeight;
+ int attributes;
+ EventTypeSpec draw = {kEventClassControl, kEventControlDraw};
+ EventTypeSpec dispose = {kEventClassWindow, kEventWindowDispose};
+ ControlRef root;
+
+ if(window != NULL)
+ return 0; /*already showing */
+ if (featureImage == NULL)
+ return ENOENT;
+
+ loadImageFns();
+ if (createWithURL && createAtIndex) {
+ CFStringRef imageString = CFStringCreateWithCString(kCFAllocatorDefault, featureImage, kCFStringEncodingUTF8);
+ if(imageString != NULL) {
+ CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, imageString, kCFURLPOSIXPathStyle, false);
+ if(url != NULL) {
+ CGImageSourceRef imageSource = createWithURL(url, NULL);
+ if(imageSource != NULL) {
+ image = createAtIndex(imageSource, 0, NULL);
+ }
+ CFRelease(url);
+ }
+ }
+ CFRelease(imageString);
+ } else {
+ image = loadBMPImage(featureImage);
+ }
+
+ /*If the splash image data could not be loaded, return an error.*/
+ if (image == NULL)
+ return ENOENT;
+
+ w = CGImageGetWidth(image);
+ h = CGImageGetHeight(image);
+
+ GetAvailableWindowPositioningBounds(GetMainDevice(), &wRect);
+
+ deviceWidth= wRect.right - wRect.left;
+ deviceHeight= wRect.bottom - wRect.top;
+
+ wRect.left+= (deviceWidth-w)/2;
+ wRect.top+= (deviceHeight-h)/3;
+ wRect.right= wRect.left + w;
+ wRect.bottom= wRect.top + h;
+
+ attributes = kWindowStandardHandlerAttribute | kWindowCompositingAttribute;
+ attributes &= GetAvailableWindowAttributes(kSheetWindowClass);
+ CreateNewWindow(kSheetWindowClass, attributes, &wRect, &window);
+ if (window != NULL) {
+ GetRootControl(window, &root);
+ wRect.left = wRect.top = 0;
+ wRect.right = w;
+ wRect.bottom = h;
+ CreateUserPaneControl(window, &wRect, kControlSupportsEmbedding | kControlSupportsFocus | kControlGetsFocusOnClick, &pane);
+ HIViewAddSubview(root, pane);
+
+ InstallEventHandler(GetControlEventTarget(pane), (EventHandlerUPP)drawProc, 1, &draw, NULL, NULL);
+ InstallEventHandler(GetWindowEventTarget(window), (EventHandlerUPP)disposeProc, 1, &dispose, NULL, NULL);
+ ShowWindow(window);
+ dispatchMessages();
+ }
+
+ return 0;
+}
+
+void takeDownSplash() {
+ if( window != 0) {
+ DisposeWindow(window);
+ window = NULL;
+ }
+ if(image){
+ CGImageRelease(image);
+ image = NULL;
+ }
+}
+
+void dispatchMessages() {
+ EventRef event;
+ EventTargetRef target;
+
+ target = GetEventDispatcherTarget();
+ while( ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &event) == noErr ) {
+ SendEventToEventTarget(event, target);
+ ReleaseEvent(event);
+ }
+}
+#endif
+
+void installAppleEventHandler() {
+#ifdef COCOA
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ AppleEventDelegate *appleEventDelegate = [[AppleEventDelegate alloc] init];
+ [NSApplication sharedApplication];
+ NSAppleEventManager *manager = [NSAppleEventManager sharedAppleEventManager];
+ [manager setEventHandler:appleEventDelegate
+ andSelector:@selector(handleOpenDocuments:withReplyEvent:)
+ forEventClass:kCoreEventClass
+ andEventID:kAEOpenDocuments];
+ [manager setEventHandler:appleEventDelegate
+ andSelector:@selector(handleGetURL:withReplyEvent:)
+ forEventClass:kInternetEventClass
+ andEventID:kAEGetURL];
+// [appleEventDelegate release];
+ [pool release];
+#else
+ EventTypeSpec kEvents[] = { {kEventClassAppleEvent, kEventAppleEvent} };
+ InstallApplicationEventHandler(NewEventHandlerUPP(appleEventProc), GetEventTypeCount(kEvents), kEvents, 0, &appHandler);
+ AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(openDocumentsProc), 0, false);
+#endif
+}
+
+jlong getSplashHandle() {
+ return (jlong)window;
+}
+
+/* Get the window system specific VM arguments */
+char** getArgVM( char* vm )
+{
+ char** result;
+
+ /* Use the default arguments for a standard Java VM */
+ result = argVM_JAVA;
+
+ return result;
+}
+
+char * getJavaVersion(char* command) {
+ FILE *fp;
+ char buffer[4096];
+ char *version = NULL, *firstChar;
+ int numChars = 0;
+ sprintf(buffer,"%s -version 2>&1", command);
+ fp = popen(buffer, "r");
+ if (fp == NULL) {
+ return NULL;
+ }
+ while (fgets(buffer, sizeof(buffer)-1, fp) != NULL) {
+ if (!version) {
+ firstChar = (char *) (strchr(buffer, '"') + 1);
+ if (firstChar != NULL)
+ numChars = (int) (strrchr(buffer, '"') - firstChar);
+
+ /* Allocate a buffer and copy the version string into it. */
+ if (numChars > 0)
+ {
+ version = malloc( numChars + 1 );
+ strncpy(version, firstChar, numChars);
+ version[numChars] = '\0';
+ }
+ }
+ if (strstr(buffer, "Java HotSpot(TM)") || strstr(buffer, "OpenJDK")) {
+ if (version != NULL) {
+ _TCHAR *value = strtok(version, ".");
+ if (value != NULL && (strtol(value, NULL, 10) == 1)) {
+ value = strtok(NULL, ".");
+ if (strtol(value, NULL, 10) < 8) {
+ isSunMaxPermSizeVM = 1;
+ }
+ }
+ }
+ break;
+ }
+ if (strstr(buffer, "IBM") != NULL) {
+ isSunMaxPermSizeVM = 0;
+ break;
+ }
+ }
+ pclose(fp);
+ return version;
+}
+
+char * getJavaHome() {
+ FILE *fp;
+ char path[4096];
+ char *result, *start;
+ sprintf(path, "/usr/libexec/java_home -a %s", JAVA_HOME_ARCH);
+ fp = popen(path, "r");
+ if (fp == NULL) {
+ return NULL;
+ }
+ while (fgets(path, sizeof(path)-1, fp) != NULL) {
+ }
+ result = path;
+ start = strchr(result, '\n');
+ if (start) {
+ start[0] = 0;
+ }
+ sprintf(path, "%s/bin/java", result);
+ pclose(fp);
+ return strdup(path);
+}
+
+char * findVMLibrary( char* command ) {
+ char *start, *end;
+ char *version, *result, *cmd;
+ int length;
+
+ /*check first to see if command already points to the library */
+ if (strcmp(command, JAVA_FRAMEWORK) == 0) {
+ return JAVA_FRAMEWORK;
+ }
+
+ /* select a version to use based on the command */
+ start = strstr(command, "/Versions/");
+ if (start != NULL){
+ start += 10;
+ end = strchr( start, dirSeparator);
+ if (end != NULL && end > start) {
+ length = end - start;
+ version = malloc(length + 1);
+ strncpy(version, start, length);
+ version[length] = 0;
+
+ /*only set a version if it starts with a number */
+ if(strtol(version, NULL, 10) != 0 || version[0] == '0') {
+ setenv("JAVA_JVM_VERSION", version, 1);
+ }
+
+ free(version);
+ }
+ }
+ cmd = command;
+ if (strstr(cmd, "/JavaVM.framework/") != NULL && (strstr(cmd, "/Current/") != NULL || strstr(cmd, "/A/") != NULL)) {
+ cmd = getJavaHome();
+ }
+ // This is necessary to initialize isSunMaxPermSizeVM
+ getJavaVersion(cmd);
+ result = JAVA_FRAMEWORK;
+ if (strstr(cmd, "/JavaVM.framework/") == NULL) {
+ char * lib = findLib(cmd);
+ if (lib != NULL) {
+ // This does not seem to be necessary to load the Mac JVM library
+ if (0) adjustLibraryPath(lib);
+ result = lib;
+ }
+ }
+ if (cmd != command) free(cmd);
+ return result;
+}
+
+static char * findLib(char * command) {
+ int i, q;
+ int pathLength;
+ struct stat stats;
+ char * path; /* path to resulting jvm shared library */
+ char * location; /* points to begining of jvmLocations section of path */
+
+ if (command != NULL) {
+ /*check first to see if command already points to the library */
+ if (isVMLibrary(command)) {
+ if (stat(command, &stats) == 0 && (stats.st_mode & S_IFREG) != 0) { /* found it */
+ return strdup(command);
+ }
+ return NULL;
+ }
+
+ location = strrchr(command, dirSeparator) + 1;
+ pathLength = location - command;
+ path = malloc((pathLength + MAX_LOCATION_LENGTH + 1 + MAX_JVMLIB_LENGTH + 1) * sizeof(char));
+ strncpy(path, command, pathLength);
+ location = &path[pathLength];
+
+ /*
+ * We are trying base/jvmLocations[*]/vmLibrary
+ * where base is the directory containing the given java command, normally jre/bin
+ */
+ for (q = 0; jvmLibs[q] != NULL; ++q) {
+ const char *jvmLib = jvmLibs[q];
+ i = -1;
+ while (jvmLocations[++i] != NULL) {
+ sprintf(location, "%s%c%s", jvmLocations[i], dirSeparator, jvmLib);
+ /*fprintf(stderr,"checking path: %s\n",path);*/
+ if (stat(path, &stats) == 0 && (stats.st_mode & S_IFREG) != 0)
+ { /* found it */
+ return path;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+/* adjust the LD_LIBRARY_PATH for the vmLibrary */
+static void adjustLibraryPath(char * vmLibrary) {
+ char * c;
+ char * ldPath, *dylibPath;
+ char * newPath;
+ int i;
+ int numPaths = 0;
+ int length = 0;
+ int needAdjust = 0, needDylibAdjust = 0;
+
+ char ** paths = getVMLibrarySearchPath(vmLibrary);
+
+ ldPath = (char*) getenv(LIB_PATH_VAR);
+ if (!ldPath) {
+ ldPath = _T_ECLIPSE("");
+ needAdjust = 1;
+ } else {
+ needAdjust = !containsPaths(ldPath, paths);
+ }
+
+ dylibPath = (char*) getenv(DYLD_FALLBACK_VAR);
+ if (!dylibPath) {
+ dylibPath = _T_ECLIPSE("");
+ needDylibAdjust = 1;
+ } else {
+ needDylibAdjust = !containsPaths(dylibPath, paths);
+ }
+
+ if (!needAdjust && !needDylibAdjust) {
+ for (i = 0; paths[i] != NULL; i++)
+ free(paths[i]);
+ free(paths);
+ return;
+ }
+
+ c = concatStrings(paths);
+
+ /* set the value for LD_LIBRARY_PATH */
+ length = strlen(ldPath);
+ newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s"), c, ldPath);
+ setenv(LIB_PATH_VAR, newPath, 1);
+ free(newPath);
+
+ /* set the value for DYLD_FALLBACK_LIBRARY_PATH */
+ length = strlen(dylibPath);
+ newPath = malloc((_tcslen(c) + length + 1) * sizeof(_TCHAR));
+ _stprintf(newPath, _T_ECLIPSE("%s%s"), c, dylibPath);
+ setenv(DYLD_FALLBACK_VAR, newPath, 1);
+ free(newPath);
+ free(c);
+
+ for (i = 0; i < numPaths; i++)
+ free(paths[i]);
+ free(paths);
+
+ /* now we must restart for this to take affect*/
+ restartLauncher(initialArgv[0], initialArgv);
+}
+
+void restartLauncher(char* program, char* args[]) {
+ pid_t pid= fork();
+ if (pid == 0) {
+ /* Child process ... start the JVM */
+ execv(program != NULL ? program : args[0], args);
+
+ /* The JVM would not start ... return error code to parent process. */
+ _exit(errno);
+ } else {
+ exit(0);
+ }
+}
+
+JavaResults* launchJavaVM( _TCHAR* args[] )
+{
+ /*for now always do JNI on Mac, should not come in here */
+ JavaResults * results = malloc(sizeof(JavaResults));
+ results->launchResult = -1;
+ results->runResult = 0;
+ results->errorMessage = _tcsdup(noForkingMsg);
+ return results;
+}
+
+JavaResults* startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[], _TCHAR* jarFile )
+{
+ return startJavaJNI(libPath, vmArgs, progArgs, jarFile);
+}
+
+#ifndef COCOA
+void disposeData(void *info, void *data, size_t size)
+{
+ DisposePtr(data);
+}
+
+/**
+ * loadBMPImage
+ * Create a QuickDraw PixMap representing the given BMP file.
+ *
+ * bmpPathname: absolute path and name to the bmp file
+ *
+ * returned value: the PixMapHandle newly created if successful. 0 otherwise.
+ */
+static CGImageRef loadBMPImage (const char *bmpPathname) {
+ ng_stream_t in;
+ ng_bitmap_image_t image;
+ ng_err_t err= ERR_OK;
+ CGImageRef ref;
+ UBYTE1* data = NULL;
+
+ NgInit();
+
+ if (NgStreamInit(&in, (char*) bmpPathname) != ERR_OK) {
+ NgError(ERR_NG, "Error can't open BMP file");
+ return 0;
+ }
+
+ NgBitmapImageInit(&image);
+ err= NgBmpDecoderReadImage (&in, &image);
+ NgStreamClose(&in);
+
+ if (err != ERR_OK) {
+ NgBitmapImageFree(&image);
+ return 0;
+ }
+
+ UBYTE4 srcDepth= NgBitmapImageBitCount(&image);
+ if (srcDepth != 24) { /* We only support image depth of 24 bits */
+ NgBitmapImageFree(&image);
+ NgError (ERR_NG, "Error unsupported depth - only support 24 bit");
+ return 0;
+ }
+
+ int width= (int)NgBitmapImageWidth(&image);
+ int height= (int)NgBitmapImageHeight(&image);
+ int rowBytes= width * 4;
+ int alphainfo = kCGImageAlphaNoneSkipFirst | (NgIsMSB() ? 0 : kCGBitmapByteOrder32Little);
+ data = (UBYTE1*)NewPtr(rowBytes * height);
+ CGDataProviderRef provider = CGDataProviderCreateWithData(0, data, rowBytes * height, (CGDataProviderReleaseDataCallback)disposeData);
+
+ ref = CGImageCreate(width, height, 8, 32, width * 4, CGColorSpaceCreateDeviceRGB(), alphainfo, provider, NULL, 1, 0);
+ CGDataProviderRelease(provider);
+
+ /* 24 bit source to direct screen destination */
+ NgBitmapImageBlitDirectToDirect(NgBitmapImageImageData(&image), NgBitmapImageBytesPerRow(&image), width, height,
+ data, 32, rowBytes, NgIsMSB(), 0xff0000, 0x00ff00, 0x0000ff);
+
+ NgBitmapImageFree(&image);
+
+ return ref;
+}
+#endif
+
+#define DOCK_ICON_PREFIX "-Xdock:icon="
+#define DOCK_NAME_PREFIX "-Xdock:name="
+#define APP_ICON_PATTERN "APP_ICON_%d"
+#define APP_NAME_PATTERN "APP_NAME_%d"
+
+void processVMArgs(char **vmargs[] )
+{
+ int i = -1;
+ int pid = 0, pidLength = 1, temp = 0;
+ char * name = NULL, *icon = NULL;
+ char * c;
+
+ if( *vmargs == NULL)
+ return;
+
+ while( (*vmargs)[++i] != NULL ) {
+ /*-Xdock:icon -> APP_ICON_<pid>*/
+ if(_tcsncmp((*vmargs)[i], DOCK_ICON_PREFIX, _tcslen(DOCK_ICON_PREFIX)) == 0) {
+ icon = (*vmargs)[i] + _tcslen(DOCK_ICON_PREFIX);
+ }
+ /*-Xdock:name -> APP_NAME_<pid>*/
+ else if(_tcsncmp((*vmargs)[i], DOCK_NAME_PREFIX, _tcslen(DOCK_NAME_PREFIX)) == 0) {
+ name = (*vmargs)[i] + _tcslen(DOCK_NAME_PREFIX);
+ }
+ if (name != NULL && icon != NULL)
+ break;
+ }
+
+ if (name == NULL && icon == NULL)
+ return; /* don't need to do anything */
+
+ temp = pid = getpid();
+ /* how many digits in pid? */
+ while (temp > 9) {
+ pidLength++;
+ temp /= 10;
+ }
+
+ if (name != NULL) {
+ c = malloc( (_tcslen(APP_NAME_PATTERN) + pidLength + 1) * sizeof(char*));
+ _stprintf( c, APP_NAME_PATTERN, pid );
+ setenv(c, name, 1);
+ }
+
+ if (icon != NULL) {
+ c = malloc( (_tcslen(icon) + _tcslen(APP_ICON_PATTERN) + pidLength + 1) * sizeof(char*));
+ _stprintf( c, APP_ICON_PATTERN, pid );
+ setenv(c, icon, 1);
+ }
+}
+
+int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) {
+ return isSunMaxPermSizeVM;
+}
+
+NSString* getApplicationSupport() {
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+ NSString *documentsDirectory = [paths objectAtIndex:0];
+ return documentsDirectory;
+
+}
+
+NSString* getCFBundleIdentifier() {
+ CFBundleRef mainBundle= CFBundleGetMainBundle();
+ return (NSString*) CFBundleGetIdentifier(mainBundle);
+}
+
+const char* getUUID() {
+ const char * installPath = [[[NSBundle mainBundle] resourcePath] fileSystemRepresentation];
+ int bufferLength = getxattr(installPath, INSTALL_UUID, NULL, 0, 0, 0);
+ if (bufferLength != -1) {
+ char *buffer = malloc(bufferLength + 1);
+ buffer[bufferLength] = '\0';
+ getxattr(installPath, INSTALL_UUID, buffer, bufferLength, 0, 0);
+ return buffer;
+ }
+
+ NSString * timestamp = [NSString stringWithFormat:@"%f",[[NSDate date] timeIntervalSince1970] * 1000];
+ const char* timestampAsChar = [timestamp UTF8String];
+ setxattr(installPath, INSTALL_UUID, timestampAsChar, strlen(timestampAsChar), 0, 0);
+ return timestampAsChar;
+}
+
+_TCHAR* getFolderForApplicationData() {
+ NSString* bundleId = getCFBundleIdentifier();
+ NSString* appSupport = getApplicationSupport();
+ return [[NSString stringWithFormat:@"%@/%@_%s", appSupport, bundleId, getUUID()] UTF8String];
+}
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonCommon.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonCommon.c
new file mode 100644
index 000000000..75369f148
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonCommon.c
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2015 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Andrew Niefer
+ *******************************************************************************/
+
+#include "eclipseCommon.h"
+#include "eclipseOS.h"
+
+#include <locale.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <CoreServices/CoreServices.h>
+#ifdef COCOA
+#include <Cocoa/Cocoa.h>
+#else
+#include <Carbon/Carbon.h>
+#endif
+#include <mach-o/dyld.h>
+
+char dirSeparator = '/';
+char pathSeparator = ':';
+
+static CFBundleRef javaVMBundle = NULL;
+
+int initialized = 0;
+
+static void init() {
+ if (!initialized) {
+ ProcessSerialNumber psn;
+ if (GetCurrentProcess(&psn) == noErr) {
+ TransformProcessType(&psn, kProcessTransformToForegroundApplication);
+ SetFrontProcess(&psn);
+ }
+#ifdef COCOA
+ [NSApplication sharedApplication];
+#else
+ ClearMenuBar();
+#endif
+ initialized= true;
+ }
+}
+
+
+/* Initialize Window System
+ *
+ * Initialize Carbon.
+ */
+int initWindowSystem( int* pArgc, char* argv[], int showSplash )
+{
+ char *homeDir = getProgramDir();
+ /*debug("install dir: %s\n", homeDir);*/
+ if (homeDir != NULL)
+ chdir(homeDir);
+
+ if (showSplash)
+ init();
+
+ return 0;
+}
+
+/* Display a Message */
+void displayMessage(char *title, char *message)
+{
+ CFStringRef inError, inDescription= NULL;
+
+ /* try to break the message into a first sentence and the rest */
+ char *pos= strstr(message, ". ");
+ if (pos != NULL) {
+ char *to, *from, *buffer= calloc(pos-message+2, sizeof(char));
+ /* copy and replace line separators with blanks */
+ for (to= buffer, from= message; from <= pos; from++, to++) {
+ char c= *from;
+ if (c == '\n') c= ' ';
+ *to= c;
+ }
+ inError= CFStringCreateWithCString(kCFAllocatorDefault, buffer, kCFStringEncodingUTF8);
+ free(buffer);
+ inDescription= CFStringCreateWithCString(kCFAllocatorDefault, pos+2, kCFStringEncodingUTF8);
+ } else {
+ inError= CFStringCreateWithCString(kCFAllocatorDefault, message, kCFStringEncodingUTF8);
+ }
+
+ init();
+
+#ifdef COCOA
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ NSAlert* alert = [NSAlert alertWithMessageText: (NSString*)(inDescription != nil ? inError : nil) defaultButton: nil alternateButton: nil otherButton: nil informativeTextWithFormat: (NSString*)(inDescription != nil ? inDescription : inError)];
+ [[alert window] setTitle: [NSString stringWithUTF8String: title]];
+ [alert setAlertStyle: NSCriticalAlertStyle];
+ [alert runModal];
+ [pool release];
+#else
+ DialogRef outAlert;
+ OSStatus status= CreateStandardAlert(kAlertStopAlert, inError, inDescription, NULL, &outAlert);
+ if (status == noErr) {
+ DialogItemIndex outItemHit;
+ RunStandardAlert(outAlert, NULL, &outItemHit);
+ } else {
+ /*debug("%s: displayMessage: %s\n", title, message);*/
+ }
+#endif
+ CFRelease(inError);
+ if (inDescription != NULL)
+ CFRelease(inDescription);
+}
+
+static int isLibrary( _TCHAR* vm ){
+ _TCHAR *ch = NULL;
+ if (vm == NULL) return 0;
+ ch = _tcsrchr( vm, '.' );
+ if(ch == NULL)
+ return 0;
+ return (_tcsicmp(ch, _T_ECLIPSE(".so")) == 0) || (_tcsicmp(ch, _T_ECLIPSE(".jnilib")) == 0) || (_tcsicmp(ch, _T_ECLIPSE(".dylib")) == 0);
+}
+
+static void loadVMBundle( char * bundle ) {
+ CFURLRef url = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, (const UInt8 *)bundle, strlen(bundle), true);
+ javaVMBundle = CFBundleCreate(kCFAllocatorDefault, url);
+ CFRelease(url);
+}
+
+/* Load the specified shared library
+ */
+void * loadLibrary( char * library ){
+ if (!isLibrary(library)) {
+ loadVMBundle(library);
+ return (void*) &javaVMBundle;
+ }
+
+ _TCHAR *bundle = strdup(library), *start;
+
+ // check if it's a JVM bundle
+ if (strstr(bundle, "libjvm") && (start = strstr(bundle, "/Contents/Home/")) != NULL) {
+ start[0] = NULL;
+ loadVMBundle(bundle);
+ free(bundle);
+ if (javaVMBundle) {
+ return (void*) &javaVMBundle;
+ }
+ }
+
+ free(bundle);
+ void * result= dlopen(library, RTLD_NOW);
+ if(result == 0)
+ printf("%s\n",dlerror());
+ return result;
+}
+
+/* Unload the shared library
+ */
+void unloadLibrary( void * handle ){
+ if (handle == &javaVMBundle)
+ CFRelease(javaVMBundle);
+ else
+ dlclose(handle);
+}
+
+/* Find the given symbol in the shared library
+ */
+void * findSymbol( void * handle, char * symbol ){
+ if(handle == &javaVMBundle) {
+ CFStringRef string = CFStringCreateWithCString(kCFAllocatorDefault, symbol, kCFStringEncodingASCII);
+ void * ptr = CFBundleGetFunctionPointerForName(javaVMBundle, string);
+ CFRelease(string);
+ return ptr;
+ } else
+ return dlsym(handle, symbol);
+}
+
+char * resolveSymlinks( char * path ) {
+ char * result = 0;
+ CFURLRef url, resolved;
+ CFStringRef string;
+ FSRef fsRef;
+ Boolean isFolder, wasAliased;
+
+ if(path == NULL)
+ return path;
+
+ string = CFStringCreateWithCString(kCFAllocatorDefault, path, kCFStringEncodingUTF8);
+ url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, string, kCFURLPOSIXPathStyle, false);
+ CFRelease(string);
+ if(url == NULL)
+ return path;
+
+ if(CFURLGetFSRef(url, &fsRef)) {
+ if( FSResolveAliasFile(&fsRef, true, &isFolder, &wasAliased) == noErr) {
+ resolved = CFURLCreateFromFSRef(kCFAllocatorDefault, &fsRef);
+ if(resolved != NULL) {
+ string = CFURLCopyFileSystemPath(resolved, kCFURLPOSIXPathStyle);
+ CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(string), kCFStringEncodingUTF8);
+ char *s = malloc(length);
+ if (CFStringGetCString(string, s, length, kCFStringEncodingUTF8)) {
+ result = s;
+ } else {
+ free(s);
+ }
+ CFRelease(string);
+ CFRelease(resolved);
+ }
+ }
+ }
+ CFRelease(url);
+ return result;
+} \ No newline at end of file
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonMain.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonMain.c
new file mode 100644
index 000000000..51cafc275
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseCarbonMain.c
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2006, 2009 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Andrew Niefer
+ */
+
+#include "eclipseCommon.h"
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+#include <CoreServices/CoreServices.h>
+#include <Carbon/Carbon.h>
+#include <mach-o/dyld.h>
+
+
+#define APP_PACKAGE_PATTERN ".app/Contents/MacOS/"
+#define APP_PACKAGE "APP_PACKAGE"
+#define JAVAROOT "JAVAROOT"
+
+static void debug(const char *fmt, ...);
+static void dumpArgs(char *tag, int argc, char* argv[]);
+static char *append(char *buffer, const char *s);
+static char *appendc(char *buffer, char c);
+static char *expandShell(char *arg, const char *appPackage, const char *javaRoot);
+static char *my_strcasestr(const char *big, const char *little);
+
+static FILE *fgConsoleLog;
+static char *fgAppPackagePath;
+static int fgPid;
+
+extern int original_main(int argc, char* argv[]);
+int main( int argc, char* argv[] ) {
+
+ SInt32 systemVersion= 0;
+ if (Gestalt(gestaltSystemVersion, &systemVersion) == noErr) {
+ systemVersion &= 0xffff;
+#ifdef COCOA
+ if (systemVersion < 0x1050) {
+ displayMessage("Error", "This application requires Mac OS X 10.5 (Leopard) or greater.");
+ return 0;
+ }
+#else
+ if (systemVersion < 0x1020) {
+ displayMessage("Error", "This application requires Jaguar (Mac OS X >= 10.2)");
+ return 0;
+ }
+#endif
+ }
+
+ fgConsoleLog= fopen("/dev/console", "w");
+ fgPid= getpid();
+
+ dumpArgs("start", argc, argv);
+ if ( (argc > 1 && strncmp(argv[1], "-psn_", 5) == 0) || argc == 1) {
+ /* find path to application bundle (ignoring case) */
+ char *pos= my_strcasestr(argv[0], APP_PACKAGE_PATTERN);
+ if (pos != NULL) {
+ int l= pos-argv[0] + 4; // reserve space for ".app"
+ fgAppPackagePath= malloc(l+1);
+ strncpy(fgAppPackagePath, argv[0], l);
+ fgAppPackagePath[l]= '\0'; // terminate result
+ }
+
+ /* Get the main bundle for the app */
+ CFBundleRef mainBundle= CFBundleGetMainBundle();
+ if (mainBundle != NULL) {
+
+ /* Get an instance of the info plist.*/
+ CFDictionaryRef bundleInfoDict= CFBundleGetInfoDictionary(mainBundle);
+
+ /* If we succeeded, look for our property. */
+ if (bundleInfoDict != NULL) {
+ CFArrayRef ar= CFDictionaryGetValue(bundleInfoDict, CFSTR("Eclipse"));
+ if (ar) {
+ CFIndex size= CFArrayGetCount(ar);
+ if (size > 0) {
+ int i;
+ char **old_argv= argv;
+ argv= (char**) calloc(size+2, sizeof(char*));
+ argc= 0;
+ argv[argc++]= old_argv[0];
+ for (i= 0; i < size; i++) {
+ CFStringRef sr= (CFStringRef) CFArrayGetValueAtIndex (ar, i);
+ CFIndex argStringSize= CFStringGetMaximumSizeForEncoding(CFStringGetLength(sr), kCFStringEncodingUTF8);
+ char *s= malloc(argStringSize);
+ if (CFStringGetCString(sr, s, argStringSize, kCFStringEncodingUTF8)) {
+ argv[argc++]= expandShell(s, fgAppPackagePath, NULL);
+ } else {
+ fprintf(fgConsoleLog, "can't extract bytes\n");
+ }
+ //free(s);
+ }
+ }
+ } else {
+ fprintf(fgConsoleLog, "no Eclipse dict found\n");
+ }
+ } else {
+ fprintf(fgConsoleLog, "no bundle dict found\n");
+ }
+ } else {
+ fprintf(fgConsoleLog, "no bundle found\n");
+ }
+ }
+ int exitcode= original_main(argc, argv);
+ debug("<<<< exit(%d)\n", exitcode);
+ fclose(fgConsoleLog);
+ return exitcode;
+}
+
+static void debug(const char *fmt, ...) {
+#if DEBUG
+ va_list ap;
+ va_start(ap, fmt);
+ fprintf(fgConsoleLog, "%05d: ", fgPid);
+ vfprintf(fgConsoleLog, fmt, ap);
+ va_end(ap);
+#endif
+}
+
+static void dumpArgs(char *tag, int argc, char* argv[]) {
+#if DEBUG
+ int i;
+ if (argc < 0) {
+ argc= 0;
+ for (i= 0; argv[i] != NULL; i++)
+ argc++;
+ }
+ debug(">>>> %s:", tag);
+ for (i= 0; i < argc && argv[i] != NULL; i++)
+ fprintf(fgConsoleLog, " <%s>", argv[i]);
+ fprintf(fgConsoleLog, "\n");
+#endif
+}
+
+/*
+ * Expand $APP_PACKAGE, $JAVA_HOME, and does tilde expansion.
+
+ A word beginning with an unquoted tilde character (~) is
+ subject to tilde expansion. All the characters up to a
+ slash (/) or the end of the word are treated as a username
+ and are replaced with the user's home directory. If the
+ username is missing (as in ~/foobar), the tilde is
+ replaced with the value of the HOME variable (the current
+ user's home directory).
+ */
+static char *expandShell(char *arg, const char *appPackage, const char *javaRoot) {
+
+ if (index(arg, '~') == NULL && index(arg, '$') == NULL)
+ return arg;
+
+ char *buffer= strdup("");
+ char c, lastChar= ' ';
+ const char *cp= arg;
+ while ((c = *cp++) != 0) {
+ if (isspace(lastChar) && c == '~') {
+ char name[100], *dir= NULL;
+ int j= 0;
+ for (; (c = *cp) != 0; cp++) {
+ if (! isalnum(c))
+ break;
+ name[j++]= c;
+ lastChar= c;
+ }
+ name[j]= '\0';
+ if (j > 0) {
+ struct passwd *pw= getpwnam(name);
+ if (pw != NULL)
+ dir= pw->pw_dir;
+ } else {
+ dir= getenv("HOME");
+ }
+ if (dir != NULL)
+ buffer= append(buffer, dir);
+
+ } else if (c == '$') {
+ int l= strlen(APP_PACKAGE);
+ if (appPackage != NULL && strncmp(cp, APP_PACKAGE, l) == 0) {
+ cp+= l;
+ buffer= append(buffer, appPackage);
+ } else {
+ int l= strlen(JAVAROOT);
+ if (javaRoot != NULL && strncmp(cp, JAVAROOT, l) == 0) {
+ cp+= l;
+ buffer= append(buffer, javaRoot);
+ } else {
+ buffer= appendc(buffer, c);
+ }
+ }
+ } else
+ buffer= appendc(buffer, c);
+ lastChar= c;
+ }
+ return buffer;
+}
+
+static char *my_strcasestr(const char *big, const char *little) {
+ char *cp, *s, *t;
+ for (cp= (char*) big; *cp; cp++) {
+ for (s= cp, t= (char*) little; *s && *t; s++, t++)
+ if (toupper(*s) != toupper(*t))
+ break;
+ if (*t == '\0')
+ return cp;
+ }
+ return NULL;
+}
+
+static char *append(char *buffer, const char *s) {
+ int bl= strlen(buffer);
+ int sl= strlen(s);
+ buffer= realloc(buffer, bl+sl+1);
+ strcpy(&buffer[bl], s);
+ return buffer;
+}
+
+static char *appendc(char *buffer, char c) {
+ int bl= strlen(buffer);
+ buffer= realloc(buffer, bl+2);
+ buffer[bl++]= c;
+ buffer[bl]= '\0';
+ return buffer;
+} \ No newline at end of file
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseMain.c b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseMain.c
new file mode 100644
index 000000000..c0eaffa13
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/eclipseMain.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Andre Weinand (OTI Labs)
+ */
+
+#define main original_main
+
+#include "../eclipseMain.c"
diff --git a/features/org.eclipse.equinox.executable.feature/library/cocoa/make_cocoa.mak b/features/org.eclipse.equinox.executable.feature/library/cocoa/make_cocoa.mak
new file mode 100644
index 000000000..0d267a094
--- /dev/null
+++ b/features/org.eclipse.equinox.executable.feature/library/cocoa/make_cocoa.mak
@@ -0,0 +1,93 @@
+#**********************************************************************
+# Copyright (c) 2000, 2008 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Kevin Cornell (Rational Software Corporation)
+#**********************************************************************
+include ../make_version.mak
+# Makefile for creating the Cocoa eclipse launcher program.
+
+# This makefile expects the following environment variables set:
+#
+# PROGRAM_OUTPUT - the filename of the output executable
+# DEFAULT_OS - the default value of the "-os" switch
+# DEFAULT_OS_ARCH - the default value of the "-arch" switch
+# DEFAULT_WS - the default value of the "-ws" switch
+
+#default value for PROGRAM_OUTPUT
+ifeq ($(PROGRAM_OUTPUT),)
+ PROGRAM_OUTPUT=eclipse
+endif
+PROGRAM_LIBRARY=eclipse_$(LIB_VERSION).so
+
+# Define the object modules to be compiled and flags.
+MAIN_OBJS = eclipseMain.o eclipseCarbonMain.o
+COMMON_OBJS = eclipseConfig.o eclipseCommon.o eclipseCarbonCommon.o
+DLL_OBJS = eclipse.o eclipseCarbon.o eclipseUtil.o eclipseJNI.o eclipseShm.o
+#NgImageData.o NgWinBMPFileFormat.o NgCommon.o
+
+EXEC = $(PROGRAM_OUTPUT)
+DLL = $(PROGRAM_LIBRARY)
+LIBS = -framework Cocoa
+
+CFLAGS = -O -s \
+ -Wall \
+ -DCOCOA -xobjective-c \
+ -arch x86_64 \
+ -DMACOSX \
+ -DDEFAULT_OS="\"$(DEFAULT_OS)\"" \
+ -DDEFAULT_OS_ARCH="\"$(DEFAULT_OS_ARCH)\"" \
+ -DDEFAULT_WS="\"$(DEFAULT_WS)\"" \
+ -I.. -I../motif $(JAVA_HEADERS)
+
+all: $(EXEC) $(DLL)
+
+eclipse.o: ../eclipse.c ../eclipseOS.h ../eclipseCommon.h ../eclipseJNI.h
+ $(CC) $(CFLAGS) -c ../eclipse.c -o $@
+
+eclipseCarbonMain.o : eclipseCarbonMain.c
+ $(CC) $(CFLAGS) -c eclipseCarbonMain.c -o $@
+
+eclipseMain.o: ../eclipseUnicode.h ../eclipseCommon.h eclipseMain.c ../eclipseMain.c
+ $(CC) $(CFLAGS) -c eclipseMain.c -o $@
+
+eclipseJNI.o: ../eclipseJNI.c ../eclipseCommon.h ../eclipseOS.h ../eclipseJNI.h
+ $(CC) $(CFLAGS) -c ../eclipseJNI.c -o $@
+
+eclipseUtil.o: ../eclipseUtil.c ../eclipseUtil.h ../eclipseOS.h
+ $(CC) $(CFLAGS) -c ../eclipseUtil.c -o $@
+
+eclipseConfig.o: ../eclipseConfig.c ../eclipseConfig.h ../eclipseOS.h
+ $(CC) $(CFLAGS) -c ../eclipseConfig.c -o $@
+
+eclipseCommon.o: ../eclipseCommon.h ../eclipseUnicode.h ../eclipseCommon.c
+ $(CC) $(CFLAGS) -c ../eclipseCommon.c -o $@
+
+eclipseShm.o: ../eclipseShm.h ../eclipseUnicode.h ../eclipseShm.c
+ $(CC) $(CFLAGS) -c ../eclipseShm.c -o $@
+
+NgCommon.o: ../motif/NgCommon.c
+ $(CC) $(CFLAGS) -c ../motif/NgCommon.c -o $@
+
+NgWinBMPFileFormat.o: ../motif/NgWinBMPFileFormat.c
+ $(CC) $(CFLAGS) -c ../motif/NgWinBMPFileFormat.c -o $@
+
+NgImageData.o: ../motif/NgImageData.c
+ $(CC) $(CFLAGS) -c ../motif/NgImageData.c -o $@
+
+$(EXEC): $(MAIN_OBJS) $(COMMON_OBJS)
+ $(CC) -o $(EXEC) $(ARCHS) $(MAIN_OBJS) $(COMMON_OBJS) $(LIBS)
+
+$(DLL): $(DLL_OBJS) $(COMMON_OBJS)
+ $(CC) -bundle -o $(DLL) $(ARCHS) $(DLL_OBJS) $(COMMON_OBJS) $(LIBS)
+
+install: all
+ cp -v $(EXEC) $(PROGRAM_OUTPUT_DIR)
+ rm -f $(EXEC) $(OBJS)
+
+clean:
+ rm -f $(EXEC) $(DLL) $(MAIN_OBJS) $(COMMON_OBJS) $(DLL_OBJS)

Back to the top