Merge changes from Rollup2
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java index c4adb5f..bd3d978 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/InternalPlatform.java
@@ -42,6 +42,9 @@ private static boolean splashDown = false; private static boolean cacheRegistry = false; + private static File lockFile = null; + private static RandomAccessFile lockRAF = null; + // default plugin data private static final String PI_XML = "org.apache.xerces"; private static final String PLUGINSDIR = "plugins/"; @@ -169,6 +172,48 @@ } return result == null ? null : result.toString(); } +/** + * Closes the open lock file handle, and makes a silent best + * attempt to delete the file. + */ +private static synchronized void clearLockFile() { + try { + if (lockRAF != null) { + lockRAF.close(); + lockRAF = null; + } + } catch (IOException e) { + } + if (lockFile != null) { + lockFile.delete(); + lockFile = null; + } +} +/** + * Creates a lock file in the meta-area that indicates the meta-area + * is in use, preventing other eclipse instances from concurrently + * using the same meta-area. + */ +private static synchronized void createLockFile() throws CoreException { + String lockLocation = metaArea.getLocation().append(PlatformMetaArea.F_LOCK_FILE).toOSString(); + lockFile = new File(lockLocation); + //if the lock file already exists, try to delete, + //assume failure means another eclipse has it open + if (lockFile.exists()) + lockFile.delete(); + if (lockFile.exists()) { + String message = Policy.bind("meta.inUse", lockLocation); + throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, Platform.FAILED_WRITE_METADATA, message, null)); + } + try { + //open the lock file so other instances can't co-exist + lockRAF = new RandomAccessFile(lockFile, "rw"); + lockRAF.writeByte(0); + } catch (IOException e) { + String message = Policy.bind("meta.failCreateLock", lockLocation); + throw new CoreException(new Status(IStatus.ERROR, Platform.PI_RUNTIME, Platform.FAILED_WRITE_METADATA, message, e)); + } +} /** * Creates and remembers a spoofed up class loader which loads the @@ -476,6 +521,7 @@ public static void loaderShutdown() { assertInitialized(); registry.shutdown(null); + clearLockFile(); if (DEBUG_PLUGINS) { // We are debugging so output the registry in XML // format. @@ -526,6 +572,7 @@ public static void loaderStartup(URL[] pluginPath, String locationString, Properties bootOptions, String[] args) throws CoreException { processCommandLine(args); setupMetaArea(locationString); + createLockFile(); adapterManager = new AdapterManager(); loadOptions(bootOptions); createXMLClassLoader();
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java index 2ba0f02..2c85efa 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/PlatformMetaArea.java
@@ -22,6 +22,8 @@ /* package */ static final String F_BACKUP = ".bak"; /* package */ static final String F_OPTIONS = ".options"; /* package */ static final String F_KEYRING = ".keyring"; + /* package */ static final String F_LOCK_FILE = ".lock"; + /** * */
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties index edd0d4f..edc98a6 100644 --- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties +++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/runtime/messages.properties
@@ -34,6 +34,10 @@ ### metadata meta.unableToWriteRegistry = Unable to write plug-in registry to cache. meta.appNotInit = The application has not been initialized. +meta.failCreateLock = Unable to create platform lock file: {0}. +meta.inUse = \nThe platform metadata area is already in use by another platform instance, or there was a failure\n\ + in deleting the old lock file. If no other platform instances are running, delete the \n\ + lock file ({0}) and try starting the platform again. meta.pluginProblems = Problems occurred when invoking code from plug-in: {0}. meta.notDir = Specified platform location {0} is not a directory. meta.readPlatformMeta = Could not read platform metadata: {0}.