diff options
author | Pascal Rapicault | 2015-04-17 20:44:54 +0000 |
---|---|---|
committer | Pascal Rapicault | 2015-04-20 22:09:24 +0000 |
commit | 44336d8123b71d1df865d51e0f2eaf2e1bad615f (patch) | |
tree | a29ad412f37b97b1849446f9ec5d6d83cde29a64 | |
parent | 5ebd8e732dcca11efc03ac4721e1909565caf679 (diff) | |
download | rt.equinox.framework-44336d8123b71d1df865d51e0f2eaf2e1bad615f.tar.gz rt.equinox.framework-44336d8123b71d1df865d51e0f2eaf2e1bad615f.tar.xz rt.equinox.framework-44336d8123b71d1df865d51e0f2eaf2e1bad615f.zip |
Bug 461725 - [Mac] Default the configuration to Application SupportI20150421-0800
Change-Id: I6fa3f69c56592245992c11db37ac91e254ad7d68
Signed-off-by: Pascal Rapicault <pascal@rapicorp.com>
6 files changed, 117 insertions, 11 deletions
diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/JNIBridge.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/JNIBridge.java index 57749e486..932a26ebd 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/JNIBridge.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/JNIBridge.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2009 IBM Corporation and others. + * 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Rapicorp, Inc - Default the configuration to Application Support (bug 461725) *******************************************************************************/ package org.eclipse.equinox.launcher; @@ -33,6 +34,8 @@ public class JNIBridge { private native void _takedown_splash(); + private native String _get_os_recommended_folder(); + private native int OleInitialize(int reserved); private native void OleUninitialize(); @@ -191,4 +194,16 @@ public class JNIBridge { } return true; } + + public String getOSRecommendedFolder() { + try { + return _get_os_recommended_folder(); + } catch (UnsatisfiedLinkError e) { + if (!libraryLoaded) { + loadLibrary(); + return getOSRecommendedFolder(); + } + return null; + } + } } diff --git a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java index a27330349..76f172202 100644 --- a/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java +++ b/bundles/org.eclipse.equinox.launcher/src/org/eclipse/equinox/launcher/Main.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2014 IBM Corporation and others. + * 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 @@ -10,6 +10,7 @@ * Anton Leherbauer (Wind River Systems) - bug 301226 * Red Hat Inc. - bug 373640, 379102 * Ericsson AB (Pascal Rapicault) - bug 304132 + * Rapicorp, Inc - Default the configuration to Application Support (bug 461725) *******************************************************************************/ package org.eclipse.equinox.launcher; @@ -142,8 +143,9 @@ public class Main { private static final String LAUNCHER = "-launcher"; //$NON-NLS-1$ private static final String PROTECT = "-protect"; //$NON-NLS-1$ - //currently the only level of protection we care about - private static final String MASTER = "master"; //$NON-NLS-1$ + //currently the only level of protection we care about. + private static final String PROTECT_MASTER = "master"; //$NON-NLS-1$ + private static final String PROTECT_BASE = "base"; //$NON-NLS-1$ private static final String LIBRARY = "--launcher.library"; //$NON-NLS-1$ private static final String APPEND_VMARGS = "--launcher.appendVmargs"; //$NON-NLS-1$ @@ -241,7 +243,7 @@ public class Main { protected BufferedWriter log = null; protected boolean newSession = true; - private boolean protectMaster; + private boolean protectBase = false; // for variable substitution public static final String VARIABLE_DELIM_STRING = "$"; //$NON-NLS-1$ @@ -428,6 +430,9 @@ public class Main { * Sets up the JNI bridge to native calls */ private void setupJNI(URL[] defaultPath) { + if (bridge != null) + return; + String libPath = null; if (library != null) { @@ -569,7 +574,7 @@ public class Main { setupVMProperties(); processConfiguration(); - if (protectMaster && (System.getProperty(PROP_SHARED_CONFIG_AREA) == null)) { + if (protectBase && (System.getProperty(PROP_SHARED_CONFIG_AREA) == null)) { System.err.println("This application is configured to run in a cascaded mode only."); //$NON-NLS-1$ System.setProperty(PROP_EXITCODE, "" + 14); //$NON-NLS-1$ return; @@ -1300,6 +1305,10 @@ public class Main { // exist, use "eclipse" as the application-id. URL install = getInstallLocation(); + if (protectBase) { + return computeDefaultUserAreaLocation(CONFIG_DIR); + } + // TODO a little dangerous here. Basically we have to assume that it is a file URL. if (install.getProtocol().equals("file")) { //$NON-NLS-1$ File installDir = new File(install.getFile()); @@ -1350,6 +1359,16 @@ public class Main { File installDir = new File(installURL.getFile()); String installDirHash = getInstallDirHash(); + if (protectBase && Constants.OS_MACOSX.equals(os)) { + initializeBridgeEarly(); + String macConfiguration = computeConfigurationLocationForMacOS(); + if (macConfiguration != null) { + return macConfiguration; + } + if (debug) + System.out.println("Computation of Mac specific configuration folder failed."); //$NON-NLS-1$ + } + String appName = "." + ECLIPSE; //$NON-NLS-1$ File eclipseProduct = new File(installDir, PRODUCT_SITE_MARKER); if (eclipseProduct.exists()) { @@ -1378,10 +1397,25 @@ public class Main { return new File(userHome, appName + "/" + pathAppendage).getAbsolutePath(); //$NON-NLS-1$ } + private String computeConfigurationLocationForMacOS() { + if (bridge != null) { + String folder = bridge.getOSRecommendedFolder(); + if (debug) + System.out.println("App folder provided by MacOS is: " + folder); //$NON-NLS-1$ + if (folder != null) + return folder + '/' + CONFIG_DIR; + } + return null; + } + private String OS_WS_ARCHToString() { return getOS() + '_' + getWS() + '_' + getArch(); } + private void initializeBridgeEarly() { + setupJNI(null); + } + /** * Return hash code identifying an absolute installation path * @return hash code as String @@ -1586,8 +1620,8 @@ public class Main { found = true; //consume next parameter configArgs[configArgIndex++] = i++; - if (args[i].equalsIgnoreCase(MASTER)) { - protectMaster = true; + if (args[i].equalsIgnoreCase(PROTECT_MASTER) || args[i].equalsIgnoreCase(PROTECT_BASE)) { + protectBase = true; } } 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 b76584a56..024f524d7 100644 --- a/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c +++ b/features/org.eclipse.equinox.executable.feature/library/carbon/eclipseCarbon.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * 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 @@ -9,6 +9,7 @@ * 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. */ @@ -18,6 +19,8 @@ #include "eclipseJNI.h" #include "eclipseUtil.h" +#include <sys/xattr.h> + #include <string.h> #include <unistd.h> #include <sys/stat.h> #include <CoreServices/CoreServices.h> @@ -38,6 +41,7 @@ #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); @@ -869,3 +873,37 @@ void processVMArgs(char **vmargs[] ) 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/eclipseJNI.c b/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.c index 845c646c6..cce91e1b7 100644 --- a/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.c +++ b/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.c @@ -30,7 +30,8 @@ static JNINativeMethod natives[] = {{"_update_splash", "()V", (void *)&update_sp {"_set_exit_data", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)&set_exit_data}, {"_set_launcher_info", "(Ljava/lang/String;Ljava/lang/String;)V", (void *)&set_launcher_info}, {"_show_splash", "(Ljava/lang/String;)V", (void *)&show_splash}, - {"_takedown_splash", "()V", (void *)&takedown_splash}}; + {"_takedown_splash", "()V", (void *)&takedown_splash}, + {"_get_os_recommended_folder", "()Ljava/lang/String;", (void *)&get_os_recommended_folder}}; /* local methods */ static jstring newJavaString(JNIEnv *env, _TCHAR * str); @@ -134,6 +135,14 @@ JNIEXPORT void JNICALL takedown_splash(JNIEnv * env, jobject obj){ takeDownSplash(); } +JNIEXPORT jstring JNICALL get_os_recommended_folder(JNIEnv * env, jobject obj){ +#ifdef MACOSX + return newJavaString(env, getFolderForApplicationData()); +#else + return NULL; +#endif +} + /* * On AIX we need the location of the eclipse shared library so that we * can find the libeclipse-motif.so library. Reach into the JNIBridge diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.h b/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.h index 3ef4b89dc..a53eaedd4 100644 --- a/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.h +++ b/features/org.eclipse.equinox.executable.feature/library/eclipseJNI.h @@ -30,6 +30,7 @@ typedef jint (JNICALL *JNI_createJavaVM)(JavaVM **pvm, JNIEnv **env, void *args) #define show_splash Java_org_eclipse_equinox_launcher_JNIBridge__1show_1splash #define get_splash_handle Java_org_eclipse_equinox_launcher_JNIBridge__1get_1splash_1handle #define takedown_splash Java_org_eclipse_equinox_launcher_JNIBridge__1takedown_1splash +#define get_os_recommended_folder Java_org_eclipse_equinox_launcher_JNIBridge__1get_1os_1recommended_1folder #ifdef __cplusplus extern "C" { @@ -70,6 +71,12 @@ JNIEXPORT void JNICALL show_splash(JNIEnv *, jobject, jstring); */ JNIEXPORT void JNICALL takedown_splash(JNIEnv *, jobject); +/* + * org_eclipse_equinox_launcher_JNIBridge#_get_os_recommended_folder + * Signature: ()Ljava/lang/String + */ +JNIEXPORT jstring JNICALL get_os_recommended_folder(JNIEnv *, jobject); + #ifdef __cplusplus } #endif diff --git a/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h b/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h index 3beca9c71..7e78322b1 100644 --- a/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h +++ b/features/org.eclipse.equinox.executable.feature/library/eclipseOS.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Kevin Cornell (Rational Software Corporation) + * Rapicorp, Inc - Default the configuration to Application Support (bug 461725) *******************************************************************************/ #ifndef ECLIPSE_OS_H @@ -117,5 +118,7 @@ extern _TCHAR ** getVMLibrarySearchPath(_TCHAR * vmLibrary); extern int reuseWorkbench(_TCHAR** filePath, int timeout); +extern _TCHAR* getFolderForApplicationData(); + #endif /* ECLIPSE_OS_H */ |