Fix for Bug 34031 [runtime] Workspace version?
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 b4a111a..61c569e 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
@@ -514,6 +514,7 @@ */ public static void loaderShutdown() { assertInitialized(); + writeVersion(); registry.shutdown(null); clearLockFile(); if (DEBUG_PLUGINS && DEBUG_PLUGINS_DUMP != null) { @@ -587,6 +588,75 @@ getRuntimePlugin().getLog().log(problems); loadKeyring(); } +/** + * Write out the version of the Runtime plug-in into a known file. If the file + * already exists then merge with its current contents. + * <p> + * It is very important that this code be run after the plug-in registry has + * been initialized. + */ +private static void writeVersion() { + File versionFile = metaArea.getVersionPath().toFile(); + Properties settings = new Properties(); + + // if a file already exists then load the current settings + if (versionFile.exists()) { + InputStream input = null; + try { + input = new BufferedInputStream(new FileInputStream(versionFile)); + settings.load(input); + } catch (FileNotFoundException e) { + // shouldn't happen because of the java.io.File.exists() check above + } catch (IOException e) { + // Return here rather than continue. If we continue then we run the risk + // of overwriting the file later and losing any already existing values + // that we don't know about. + log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, Policy.bind("meta.readVersion", versionFile.toString()), e)); //$NON-NLS-1$ + return; + } finally { + if (input != null) + try { + input.close(); + } catch (IOException e) { + // ignore + } + } + } + + // Add this check to ensure that we don't get an NPE if we mistakenly call this + // method before the plug-in registry has been initialized. + if (registry == null) + return; + + IPluginDescriptor plugin = registry.getPluginDescriptor(Platform.PI_RUNTIME); + if (plugin == null) { + // log a message saying that we couldn't find the runtime plug-in. + // this shouldn't happen. + log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, Policy.bind("meta.noRuntime"), null)); //$NON-NLS-1$ + return; + } + + // add our plug-in version to the file + settings.put(plugin.getUniqueIdentifier(), plugin.getVersionIdentifier().toString()); + + // write the file to disk + OutputStream output = null; + try { + output = new BufferedOutputStream(new FileOutputStream(versionFile)); + settings.store(output, null); + } catch (IOException e) { + // Fail silently. Not a catastrophe if we can't write the version file. We don't + // want to fail execution. + log(new Status(IStatus.ERROR, Platform.PI_RUNTIME, 1, Policy.bind("meta.writeVersion", versionFile.toString()), e)); //$NON-NLS-1$ + } finally { + if (output != null) + try { + output.close(); + } catch (IOException e) { + // ignore + } + } +} /** * Opens the password database (if any) initally provided to the platform at startup. */
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 61131ca..73184c5 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
@@ -1,11 +1,11 @@ -/******************************************************************************* +/********************************************************************** * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials + * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html * - * Contributors: + * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ @@ -29,6 +29,7 @@ /* package */ static final String F_OPTIONS = ".options"; //$NON-NLS-1$ /* package */ static final String F_KEYRING = ".keyring"; //$NON-NLS-1$ /* package */ static final String F_LOCK_FILE = ".lock"; //$NON-NLS-1$ + /* package */ static final String F_VERSION = "version.ini"; //$NON-NLS-1$ /** * Internal name of the preference storage file (value * <code>"pref_store.ini"</code>) in this plug-in's (read-write) state area. @@ -116,6 +117,12 @@ return getLocation().append(F_REGISTRY); } /** + * Return the path to the version.ini file. + */ +public IPath getVersionPath() { + return getLocation().append(F_VERSION); +} +/** * */ public IPath getSnapshotPath() {
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 74566fe..e6f8800 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
@@ -105,6 +105,9 @@ meta.invalidRegDebug = Unable to create file \"{0}\" for plug-in registry debug information. meta.infoRegDebug = Plug-in registry debug information created in file \"{0}\". meta.unableToDeleteCache = Unable to delete registry cache file \"{0}\". +meta.writeVersion = Unable to write workspace version file: \"{0}\". +meta.readVersion = Unable to read workspace version file: \"{0}\". +meta.noRuntime = Could not find org.eclipse.core.runtime plug-in in registry while writing workspace version file. ### URL url.badVariant=Unsupported \"platform:\" protocol variation \"{0}\".