int createSharedData(_TCHAR** id, int size) { HANDLE mapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL); if (mapHandle == 0) return -1; if (id != NULL) { *id = malloc(18 * sizeof(_TCHAR)); #ifdef WIN64 _stprintf(*id, _T_ECLIPSE("%lx_%lx"), GetCurrentProcessId(), (DWORDLONG) mapHandle); #else _stprintf(*id, _T_ECLIPSE("%lx_%lx"), GetCurrentProcessId(), (DWORD) mapHandle); #endif } /* set the shared data to "uninitialized" */ setSharedData(*id, ECLIPSE_UNITIALIZED); return 0; }
/* Create a "SWT_Window_" + APP_NAME string with optional suffix. * Caller should free the memory when finished */ static char * createSWTWindowString(char * suffix, int semaphore) { #ifdef SOLARIS /* solaris requires semaphore names to start with '/' */ char * prefix = semaphore != 0 ? _T_ECLIPSE("/SWT_Window_") : _T_ECLIPSE("SWT_Window_"); #else char * prefix = _T_ECLIPSE("SWT_Window_"); #endif char * result = malloc((_tcslen(prefix) + _tcslen(getOfficialName()) + (suffix != NULL ? _tcslen(suffix) : 0) + 1) * sizeof(char)); if (suffix != NULL) _stprintf(result, _T_ECLIPSE("%s%s%s"), prefix, getOfficialName(), suffix); else _stprintf(result, _T_ECLIPSE("%s%s"), prefix, getOfficialName()); return result; }
static void sendOpenFileMessage(HWND window) { _TCHAR* id; UINT msg; int index = 0; int size = 0; DWORD wParam; #ifdef WIN64 DWORDLONG lParam; #else DWORD lParam; #endif /* what's the longest path? */ while (openFilePath[index] != NULL) { int length = _tcslen(openFilePath[index++]); if (size <= length) size = length + 1; } createSharedData(&id, size * sizeof(_TCHAR)); _stscanf(id, _T_ECLIPSE("%lx_%lx"), &wParam, &lParam); msg = RegisterWindowMessage(_T("SWT_OPENDOC")); index = 0; for(index = 0; openFilePath[index] != NULL; index++) { /* SendMessage does not return until the message has been processed */ setSharedData(id, openFilePath[index]); SendMessage(window, msg, wParam, lParam); } destroySharedData(id); free(id); SetForegroundWindow(window); }
static int getShmID(const _TCHAR* id, LPDWORD processID, LPHANDLE handle) { if (id != NULL && _tcslen(id) > 0) { DWORD i1; #ifdef WIN64 DWORDLONG i2; if (_stscanf(id, _T_ECLIPSE("%lx_%I64x"), &i1, &i2) != 2) return -1; #else DWORD i2; if (_stscanf(id, _T_ECLIPSE("%lx_%lx"), &i1, &i2) != 2) return -1; #endif *processID = (DWORD)i1; *handle = (HANDLE)i2; return 0; } return -1; }
void adjustSearchPath( _TCHAR* vmLib ){ _TCHAR ** paths; _TCHAR* cwd = NULL; _TCHAR * path = NULL, *newPath = NULL; _TCHAR * c; int i, length; int needAdjust = 0, freePath = 0; paths = getVMLibrarySearchPath(vmLib); /* bug 325902 - add current working dir to the end of the search path */ length = GetCurrentDirectory(0, NULL); cwd = malloc((length + 1)* sizeof(_TCHAR)); GetCurrentDirectory(length, cwd); cwd[length - 1] = pathSeparator; cwd[length] = 0; /* first call to GetEnvironmentVariable tells us how big to make the buffer */ length = GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, 0); if (length > 0) { _TCHAR* current [] = { cwd, NULL }; path = malloc(length * sizeof(_TCHAR)); GetEnvironmentVariable(_T_ECLIPSE("PATH"), path, length); needAdjust = !containsPaths(path, paths) || !containsPaths(path, current); freePath = 1; } else { path = _T_ECLIPSE(""); freePath = 0; needAdjust = 1; } if (needAdjust) { c = concatStrings(paths); newPath = malloc((_tcslen(c) + length + 1 + _tcslen(cwd) + 1) * sizeof(_TCHAR)); _stprintf(newPath, _T_ECLIPSE("%s%s%c%s"), c, path, pathSeparator, cwd); SetEnvironmentVariable( _T_ECLIPSE("PATH"), newPath); free(c); free(newPath); } for (i = 0; paths[i] != NULL; i++) free(paths[i]); free(paths); free(cwd); if (freePath) free(path); }
void * loadMotifShimLibrary() { if (eclipseLibrary != NULL) { /* library is the normal eclipse_<ver>.so, look for libeclipse-motif.so beside it */ _TCHAR* eclipseMotifLib = _T_ECLIPSE("libeclipse-motif.so"); _TCHAR* path = strdup(eclipseLibrary); _TCHAR* c = strrchr(path, '/'); if (c == NULL) return NULL; *c = 0; c = malloc((strlen(path) + 2 + strlen(eclipseMotifLib)) * sizeof(char)); _stprintf(c, _T_ECLIPSE("%s/%s"), path, eclipseMotifLib); return dlopen(c, RTLD_LAZY); } return 0; }
int loadMotif() { void * xmLib = NULL, *xtLib = NULL, *x11Lib = NULL, *xinLib = NULL; #ifdef AIX void * motifShim = NULL; #endif char * path = getProgramDir(); int dlFlags = RTLD_LAZY; /* initialize ptr struct to 0's */ memset(&motif, 0, sizeof(struct MOTIF_PTRS)); #ifndef AIX if (path != NULL) { /* look for libXm first in the root of eclipse */ char * lib = malloc((strlen(path) + strlen(_T_ECLIPSE(XM_LIB)) + 2) * sizeof(char)); sprintf( lib, "%s%c%s", path, dirSeparator, XM_LIB); xmLib = dlopen(lib, dlFlags); free(lib); } #else dlFlags |= RTLD_MEMBER; motifShim = loadMotifShimLibrary(); if (motifShim == NULL) return -1; #endif if (xmLib == NULL) { xmLib = dlopen(XM_LIB, dlFlags); } if (xmLib == NULL) { /* bail now, don't load the others, libXm must be loaded first, so leave things for * swt to do later */ return -1; } xtLib = dlopen(XT_LIB, dlFlags); x11Lib = dlopen(X11_LIB, dlFlags); /* printf("XmLib: %s: %x\nXtLib: %s: %x\nX11Lib:%s, %x\n", XM_LIB, xmLib, XT_LIB, xtLib, X11_LIB, x11Lib);*/ #ifndef NO_XINERAMA_EXTENSIONS /* don't fail without Xinerama */ xinLib = dlopen(XIN_LIB, dlFlags); if (xinLib != NULL) loadMotifSymbols(xinLib, xinFunctions); #endif if( xtLib == NULL || x11Lib == NULL) return -1; if (loadMotifSymbols(xmLib, xmFunctions) != 0) return -1; if (loadMotifSymbols(xtLib, xtFunctions) != 0) return -1; if (loadMotifSymbols(x11Lib, x11Functions) != 0) return -1; #ifdef AIX if (loadMotifSymbols(motifShim, shimFunctions) !=0) return -1; #endif return 0; }
static HWND findSWTMessageWindow() { HWND window = NULL; _TCHAR *windowTitle, *windowPrefix, *name; windowPrefix = _T("SWT_Window_"); name = getOfficialName(); windowTitle = malloc((_tcslen(windowPrefix) + _tcslen(name) + 1) * sizeof(_TCHAR)); _stprintf(windowTitle, _T_ECLIPSE("%s%s"), windowPrefix, name); window = FindWindow(NULL, windowTitle); free(windowTitle); return window; }
int isMaxPermSizeVM( _TCHAR * javaVM, _TCHAR * jniLib ) { _TCHAR *vm = (jniLib != NULL) ? jniLib : javaVM; int result = 0; DWORD infoSize; DWORD handle; void * info; _TCHAR *key, *value, *versionKey, *version, *majorVersion = NULL; size_t i; int valueSize, versionSize; if (vm == NULL) return 0; infoSize = GetFileVersionInfoSize(vm, &handle); if (infoSize > 0) { info = malloc(infoSize); if (GetFileVersionInfo(vm, 0, infoSize, info)) { TRANSLATIONS * translations; int translationsSize; VerQueryValue(info, _T_ECLIPSE("\\VarFileInfo\\Translation"), (void *) &translations, &translationsSize); /* this size is only right because %04x is 4 characters */ key = malloc((_tcslen(COMPANY_NAME_KEY) + 1) * sizeof(_TCHAR)); versionKey = malloc((_tcslen(PRODUCT_VERSION_KEY) + 1) * sizeof(_TCHAR)); for (i = 0; i < (translationsSize / sizeof(TRANSLATIONS)); i++) { _stprintf(key, COMPANY_NAME_KEY, translations[i].language, translations[i].codepage); VerQueryValue(info, key, (void *)&value, &valueSize); if ((_tcsncmp(value, SUN_MICROSYSTEMS, _tcslen(SUN_MICROSYSTEMS)) == 0) || (_tcsncmp(value, ORACLE, _tcslen(ORACLE)) == 0)) { _stprintf(versionKey, PRODUCT_VERSION_KEY, translations[i].language, translations[i].codepage); VerQueryValue(info, versionKey, (void *)&version, &versionSize); if (versionSize > 1) { majorVersion = _tcstok(version, "."); } if ((majorVersion != NULL) && (_tcstol(majorVersion, NULL, 10) < 8)) { result = 1; } break; } } free(key); free(versionKey); } free(info); } return result; }
static int setAppWindowPropertyFn() { Window appWindow; Atom propAtom; _TCHAR *propVal; //Look for the SWT window. If it's there, set a property on it. appWindow = gtk.XGetSelectionOwner(gtk_GDK_DISPLAY, appWindowAtom); if (appWindow) { propAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, "org.eclipse.swt.filePath.message", FALSE); //append a colon delimiter in case more than one file gets appended to the app windows property. propVal = concatPaths(openFilePath, _T_ECLIPSE(':')); gtk.XChangeProperty(gtk_GDK_DISPLAY, appWindow, propAtom, propAtom, 8, PropModeAppend, (unsigned char *)propVal, _tcslen(propVal)); free(propVal); windowPropertySet = 1; return 1; } return 0; }
/* return > 0 if we successfully send a message to another eclipse instance */ int reuseWorkbench(_TCHAR** filePath, int timeout) { _TCHAR* mutexPrefix = _T("SWT_Mutex_"); _TCHAR* mutexName, *name; DWORD lock; HWND window = NULL; /* store for later */ openFilePath = filePath; openFileTimeout = timeout; name = getOfficialName(); mutexName = malloc((_tcslen(mutexPrefix) + _tcslen(name) + 1) * sizeof(_TCHAR)); _stprintf(mutexName, _T_ECLIPSE("%s%s"), mutexPrefix, name); mutex = CreateMutex(NULL, FALSE, mutexName); free(mutexName); if (mutex == NULL) return -1; //wait for timeout seconds lock = WaitForSingleObject(mutex, timeout * 1000); if (lock != WAIT_OBJECT_0) { /* failed to get the lock before timeout, We won't be reusing an existing eclipse. */ CloseHandle(mutex); return 0; } /* we have the mutex, look for the SWT window */ window = findSWTMessageWindow(); if (window != NULL) { sendOpenFileMessage(window); ReleaseMutex(mutex); CloseHandle(mutex); return 1; /* success! */ } /* no window, set a timer to look again later */ if (initWindowSystem(0, NULL, 0) == 0) SetTimer( topWindow, findWindowTimerId, findWindowTimeout, findWindowProc ); return 0; }
int reuseWorkbench(_TCHAR** filePath, int timeout) { char *appName, *launcherName; int result = 0; if (initWindowSystem(&initialArgc, initialArgv, 1) != 0) return -1; openFileTimeout = timeout; openFilePath = filePath; //App name is defined in SWT as well. Values must be consistent. appName = createSWTWindowString(NULL, 0); appWindowAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, appName, FALSE); free(appName); //check if app is already running. Just set property if it is. if (setAppWindowProperty() > 0) return 1; /* app is not running, create a launcher window to act as a mutex so we don't need to keep the semaphore locked */ launcherName = createSWTWindowString(_T_ECLIPSE("_Launcher"), 1); launcherWindowAtom = gtk.XInternAtom(gtk_GDK_DISPLAY, launcherName, FALSE); result = executeWithLock(launcherName, createLauncherWindow); free(launcherName); if (result == 1) { //The app is already being launched in another process. Set the property on that app window and exit while (openFileTimeout > 0) { if (setAppWindowProperty() > 0) return 1; //success else { openFileTimeout--; sleep(1); } } //timed out trying to set the app property result = 0; } return result; }
static int setAppWindowPropertyFn() { Window appWindow; GdkWindow *propWindow; GdkAtom propAtom; _TCHAR *propVal; //Look for the SWT window. If it's there, set a property on it. appWindow = gtk.XGetSelectionOwner(gtk_GDK_DISPLAY, appWindowAtom); //appWindow = XGetSelectionOwner(GDK_DISPLAY(), appWindowAtom); if (appWindow) { propAtom = gtk.gdk_atom_intern("org.eclipse.swt.filePath.message", FALSE); //append a colon delimiter in case more than one file gets appended to the app windows property. propVal = concatPaths(openFilePath, _T_ECLIPSE(':')); propWindow = gtk.gdk_window_foreign_new(appWindow); if (propWindow != NULL) { gtk.gdk_property_change(propWindow, propAtom, propAtom, 8, GDK_PROP_MODE_APPEND, (guchar *) propVal, _tcslen(propVal)); free(propVal); return 1; } //else the window got destroyed between XGetSelectionOwner and here (?) free(propVal); } return 0; }
#else #include <Carbon/Carbon.h> #include "NgCommon.h" #include "NgImageData.h" #include "NgWinBMPFileFormat.h" #endif #include <mach-o/dyld.h> #include <pthread.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"); char *findCommand(char *command); /* Global Variables */ char* defaultVM = "java"; char* vmLibrary = "JavaVM"; char* shippedVMDir = "jre/bin/"; static void adjustLibraryPath(char * vmLibrary); static char * findLib(char * command); #ifdef i386 #define JAVA_ARCH "i386" #elif defined(__ppc__) || defined(__powerpc64__) #define JAVA_ARCH "ppc"
/* * Find the VM shared library starting from the java executable */ static _TCHAR* findLib( _TCHAR* command ) { int i, j; size_t pathLength; struct _stat stats; _TCHAR * path; /* path to resulting jvm shared library */ _TCHAR * location; /* points to begining of jvmLocations section of path */ /* for looking in the registry */ HKEY jreKey = NULL; DWORD length = MAX_PATH; _TCHAR keyName[MAX_PATH]; _TCHAR * jreKeyName; if (command != NULL) { location = lastDirSeparator( command ) + 1; /*check first to see if command already points to the library */ if (isVMLibrary(command)) { if (_tstat( command, &stats ) == 0 && (stats.st_mode & S_IFREG) != 0) return command; /* exists */ return NULL; /* doesn't exist */ } pathLength = (size_t) (location - command); path = malloc((pathLength + MAX_LOCATION_LENGTH + 1 + _tcslen(vmLibrary) + 1) * sizeof(_TCHAR)); _tcsncpy(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 */ i = -1; while(jvmLocations[++i] != NULL) { _stprintf(location, _T_ECLIPSE("%s%c%s"), jvmLocations[i], dirSeparator, vmLibrary); if (_tstat( path, &stats ) == 0 && (stats.st_mode & S_IFREG) != 0) { /* found it */ return path; } } /* if command is eclipse/jre, don't look in registry */ location = malloc( (_tcslen( getProgramDir() ) + _tcslen( shippedVMDir ) + 1) * sizeof(_TCHAR) ); _stprintf( location, _T_ECLIPSE("%s%s"), getProgramDir(), shippedVMDir ); if( _tcsncmp(command, location, _tcslen(location)) == 0) { free(location); return NULL; } free(location); } /* Not found yet, try the registry, we will use the first vm >= 1.4 */ jreKeyName = _T("Software\\JavaSoft\\Java Runtime Environment"); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, jreKeyName, 0, KEY_READ, &jreKey) == ERROR_SUCCESS) { if(RegQueryValueEx(jreKey, _T_ECLIPSE("CurrentVersion"), NULL, NULL, (void*)&keyName, &length) == ERROR_SUCCESS) { path = checkVMRegistryKey(jreKey, keyName); if (path != NULL) { RegCloseKey(jreKey); return path; } } j = 0; length = MAX_PATH; while (RegEnumKeyEx(jreKey, j++, keyName, &length, 0, 0, 0, 0) == ERROR_SUCCESS) { /*look for a 1.4 or 1.5 vm*/ if( _tcsncmp(_T("1.4"), keyName, 3) <= 0 ) { path = checkVMRegistryKey(jreKey, keyName); if (path != NULL) { RegCloseKey(jreKey); return path; } } } RegCloseKey(jreKey); } return NULL; }
#include <sys/xattr.h> #include <string.h> #include <unistd.h> #include <sys/stat.h> #include <CoreServices/CoreServices.h> #include <Cocoa/Cocoa.h> #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/bin/"; // relative to launcher int isSunMaxPermSizeVM = 0; static void adjustLibraryPath(char * vmLibrary); static char * findLib(char * command); #ifdef i386 #define JAVA_ARCH "i386"
* which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ #include "eclipseGtk.h" #include "eclipseCommon.h" #include <dlfcn.h> #include <string.h> #include <stdlib.h> struct GTK_PTRS gtk = { 1 }; /* initialize the first field "not_initialized" so we can tell when we've loaded the pointers */ static _TCHAR* minVerMsg1 = _T_ECLIPSE("Starting from the Eclipse 4.7 (Oxygen) release, \nGTK+ versions below"); static _TCHAR* minVerMsg2 = _T_ECLIPSE("are not supported.\nGTK+ version found is"); static _TCHAR* minVerTitle = _T_ECLIPSE("Unsupported GTK+ version"); static _TCHAR* gtkInitFail = _T_ECLIPSE("Unable to initialize GTK+\n"); static _TCHAR* upgradeWarning1 = _T_ECLIPSE("\nPlease upgrade GTK+ to minimum version"); static _TCHAR* upgradeWarning2 = _T_ECLIPSE("\nor use an older version of Eclipse.\nClick OK to Exit."); static int minGtkMajorVersion = 2; static int minGtkMinorVersion = 24; static int minGtkMicroVersion = 0; /* tables to help initialize the function pointers */ /* functions from libgtk-x11-2.0 or libgtk-3.so.0*/ static FN_TABLE gtkFunctions[] = { FN_TABLE_ENTRY(gtk_container_add, 1), FN_TABLE_ENTRY(gtk_dialog_run, 1), FN_TABLE_ENTRY(gtk_image_new_from_pixbuf, 1),
/******************************************************************************* * 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 * Silenio Quarti *******************************************************************************/ #include "eclipseOS.h" #include "eclipseShm.h" static _TCHAR* ECLIPSE_UNITIALIZED = _T_ECLIPSE("ECLIPSE_UNINITIALIZED"); #ifdef _WIN32 #include <stdio.h> #ifdef __MINGW32__ #include <stdlib.h> #endif int createSharedData(_TCHAR** id, int size) { HANDLE mapHandle = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, size, NULL); if (mapHandle == 0) return -1; if (id != NULL) { *id = malloc(18 * sizeof(_TCHAR)); #ifdef WIN64