Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti2013-12-06 11:18:21 -0500
committerSilenio Quarti2013-12-06 11:18:21 -0500
commit72c26472b6269957b427fbc4b5251d5f3d047745 (patch)
tree328936e99519431252072c5262fbeb7a3e3c15ea /features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
parent38ce3e64440c1f5b4d2414987af381845829f78d (diff)
downloadrt.equinox.framework-72c26472b6269957b427fbc4b5251d5f3d047745.tar.gz
rt.equinox.framework-72c26472b6269957b427fbc4b5251d5f3d047745.tar.xz
rt.equinox.framework-72c26472b6269957b427fbc4b5251d5f3d047745.zip
Bug 420471 - rt.equinox.framework/bundles/org.eclipse.equinox.executable should be removed (from master)I20131209-0800I20131208-2000
Diffstat (limited to 'features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c')
-rw-r--r--features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c238
1 files changed, 123 insertions, 115 deletions
diff --git a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
index 29348fc56..0170578b3 100644
--- a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
+++ b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c
@@ -30,7 +30,6 @@
#include "NgWinBMPFileFormat.h"
#endif
#include <mach-o/dyld.h>
-#include <pthread.h>
#define startupJarName "startup.jar"
#define LAUNCHER "-launcher"
@@ -70,26 +69,22 @@ static char * findLib(char * command);
#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",
- "../jre/lib/" JAVA_ARCH "/client",
- "../jre/lib/" JAVA_ARCH "/server",
- "../jre/lib/client",
- "../jre/lib/server", NULL };
+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 };
-/* thread stuff */
-typedef struct {
- _TCHAR * libPath;
- _TCHAR ** vmArgs;
- _TCHAR ** progArgs;
- _TCHAR * jarFile;
- JavaResults* result;
-} StartVMArgs;
-
#ifdef COCOA
static NSWindow* window = nil;
@interface KeyWindow : NSWindow { }
@@ -106,6 +101,59 @@ static NSWindow* window = nil;
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
@@ -163,10 +211,6 @@ static NSWindow* window = nil;
@end
#endif
-static CFRunLoopRef loopRef = NULL;
-static void * startThread(void * init);
-static void runEventLoop(CFRunLoopRef ref);
-static void dummyCallback(void * info) {}
#ifndef COCOA
static CFMutableArrayRef files;
static EventHandlerRef appHandler;
@@ -194,50 +238,36 @@ int reuseWorkbench(_TCHAR** filePath, int timeout) {
*/
int showSplash( const _TCHAR* featureImage )
{
- if (window != NULL)
- return 0; /*already showing */
- if (featureImage == NULL)
- return ENOENT;
-
- int result = ENOENT;
+ int result = 0;
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [NSApplication sharedApplication];
- NSImage* image = [[NSImage alloc] initByReferencingFile: [NSString stringWithUTF8String: featureImage]];
- 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;
- }
+ 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() {
- if (window != 0) {
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [window close];
- window = nil;
- [pool release];
+ 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];
- NSEvent* event;
- NSApplication* application = [NSApplication sharedApplication];
- while ((event = [application nextEventMatchingMask: 0 untilDate: nil inMode: NSDefaultRunLoopMode dequeue: TRUE]) != nil) {
- [application sendEvent: event];
+ if ([NSThread isMainThread]) {
+ [KeyWindow dispatch];
+ } else {
+ [KeyWindow performSelectorOnMainThread: @selector(dispatch) withObject: nil waitUntilDone: 0];
}
- [pool release];
+ [pool release];
}
#else
@@ -477,6 +507,43 @@ char** getArgVM( char* vm )
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")) {
+ isSUN = 1;
+ break;
+ }
+ if (strstr(buffer, "IBM") != NULL) {
+ isSUN = 0;
+ break;
+ }
+ }
+ pclose(fp);
+ return version;
+}
+
char * getJavaHome() {
FILE *fp;
char path[4096];
@@ -531,11 +598,14 @@ char * findVMLibrary( char* command ) {
if (strstr(cmd, "/JavaVM.framework/") != NULL && (strstr(cmd, "/Current/") != NULL || strstr(cmd, "/A/") != NULL)) {
cmd = getJavaHome();
}
+ // This is necessary to initialize isSUN
+ getJavaVersion(cmd);
result = JAVA_FRAMEWORK;
if (strstr(cmd, "/JavaVM.framework/") == NULL) {
char * lib = findLib(cmd);
if (lib != NULL) {
- adjustLibraryPath(lib);
+ // This does not seem to be necessary to load the Mac JVM library
+ if (0) adjustLibraryPath(lib);
result = lib;
}
}
@@ -670,69 +740,7 @@ JavaResults* launchJavaVM( _TCHAR* args[] )
JavaResults* startJavaVM( _TCHAR* libPath, _TCHAR* vmArgs[], _TCHAR* progArgs[], _TCHAR* jarFile )
{
- if (secondThread == 0) {
- /* Set an environment variable that tells the AWT (if started) we started the JVM on the main thread. */
- char firstThreadEnvVariable[80];
- sprintf(firstThreadEnvVariable, "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
- setenv(firstThreadEnvVariable, "1", 1);
- return startJavaJNI(libPath, vmArgs, progArgs, jarFile);
- }
-
- /* else, --launcher.secondThread was specified, create a new thread and run the
- * vm on it. This main thread will run the CFRunLoop
- */
- pthread_t thread;
- struct rlimit limit = {0, 0};
- int stackSize = 0;
- if (getrlimit(RLIMIT_STACK, &limit) == 0) {
- if (limit.rlim_cur != 0) {
- stackSize = limit.rlim_cur;
- }
- }
-
- /* initialize thread attributes */
- pthread_attr_t attributes;
- pthread_attr_init(&attributes);
- pthread_attr_setscope(&attributes, PTHREAD_SCOPE_SYSTEM);
- pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_DETACHED);
- if (stackSize != 0)
- pthread_attr_setstacksize(&attributes, stackSize);
-
- /* arguments to start the vm */
- StartVMArgs args;
- args.libPath = libPath;
- args.vmArgs = vmArgs;
- args.progArgs = progArgs;
- args.jarFile = jarFile;
- args.result = 0;
-
- loopRef = CFRunLoopGetCurrent();
-
- /* create the thread */
- pthread_create( &thread, &attributes, &startThread, &args);
- pthread_attr_destroy(&attributes);
-
- runEventLoop(loopRef);
-
- return args.result;
-}
-
-void * startThread(void * init) {
- StartVMArgs *args = (StartVMArgs *) init;
- args->result = startJavaJNI(args->libPath, args->vmArgs, args->progArgs, args->jarFile);
- return NULL;
-}
-
-void runEventLoop(CFRunLoopRef ref) {
- CFRunLoopSourceContext sourceContext = { .version = 0, .info = NULL, .retain = NULL, .release = NULL,
- .copyDescription = NULL, .equal = NULL, .hash = NULL,
- .schedule = NULL, .cancel = NULL, .perform = &dummyCallback };
-
- CFRunLoopSourceRef sourceRef = CFRunLoopSourceCreate(NULL, 0, &sourceContext);
- CFRunLoopAddSource(ref, sourceRef, kCFRunLoopCommonModes);
-
- CFRunLoopRun();
- CFRelease(sourceRef);
+ return startJavaJNI(libPath, vmArgs, progArgs, jarFile);
}
#ifndef COCOA

Back to the top