aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Georgi2013-12-12 04:23:31 (EST)
committerDani Megert2014-04-10 11:19:41 (EDT)
commit5a4097eae1f20c85550bbc584589c02ff4a6710c (patch)
treede26cab73427c6274cbe4894240bda5098d5e46c
parent0b8935d41933c2c0237d88e7fc8ab4374a2fb818 (diff)
downloadeclipse.platform.ui-5a4097eae1f20c85550bbc584589c02ff4a6710c.zip
eclipse.platform.ui-5a4097eae1f20c85550bbc584589c02ff4a6710c.tar.gz
eclipse.platform.ui-5a4097eae1f20c85550bbc584589c02ff4a6710c.tar.bz2
Bug 423882 - Warn user if workspace is newer than IDErefs/changes/87/19687/19
Refine the workspace version check and show up * a warning if workspace > IDE * an info if workspace < IDE. Compare against only major and minor version of the IDE, so that for a change of just the patch segment no info is shown. As a reference bundle use org.eclipse.platform since its feature is most likely to change when the "IDE" changes. Don't want to check against the feature itself as that might not be installed at all. Compatibility notes: - If coming from legacy workspaces, we don't complain since that might be too intrusive. - We also write an incremented legacy version, so that when going back from an updated workspace to a legacy workspace the old IDE would complain as well. - If org.eclipse.platform bundle is not installed, no check is performed. Change-Id: I2ef3053d4a61782315c95543c5d7b535e0bef0a6 Signed-off-by: Christian Georgi <christian.georgi@sap.com>
-rw-r--r--bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java114
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java9
-rw-r--r--bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties15
3 files changed, 100 insertions, 38 deletions
diff --git a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java
index ff3c272..d1ce47a 100644
--- a/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java
+++ b/bundles/org.eclipse.ui.ide.application/src/org/eclipse/ui/internal/ide/application/IDEApplication.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2003, 2013 IBM Corporation and others.
+ * Copyright (c) 2003, 2014 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
* Helmut J. Haigermoser - Bug 359838 - The "Workspace Unavailable" error
* Lars Vogel <Lars.Vogel@gmail.com> - Bug 422954
+ * Christian Georgi (SAP) - Bug 423882 - Warn user if workspace is newer than IDE
*******************************************************************************/
package org.eclipse.ui.internal.ide.application;
@@ -29,13 +30,12 @@ import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.Window;
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
@@ -45,6 +45,8 @@ import org.eclipse.ui.internal.ide.ChooseWorkspaceDialog;
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.eclipse.ui.internal.ide.StatusUtil;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
/**
* The "main program" for the Eclipse IDE.
@@ -60,9 +62,17 @@ public class IDEApplication implements IApplication, IExecutableExtension {
private static final String VERSION_FILENAME = "version.ini"; //$NON-NLS-1$
- private static final String WORKSPACE_VERSION_KEY = "org.eclipse.core.runtime"; //$NON-NLS-1$
+ // Use the branding plug-in of the platform feature since this is most likely
+ // to change on an update of the IDE.
+ private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME = "org.eclipse.platform"; //$NON-NLS-1$
+ private static final Version WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION;
+ static {
+ Bundle bundle = Platform.getBundle(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME);
+ WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION = bundle != null ? bundle.getVersion() : null/*not installed*/;
+ }
- private static final String WORKSPACE_VERSION_VALUE = "1"; //$NON-NLS-1$
+ private static final String WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY = "org.eclipse.core.runtime"; //$NON-NLS-1$
+ private static final String WORKSPACE_CHECK_LEGACY_VERSION_INCREMENTED = "2"; //$NON-NLS-1$ legacy version=1
private static final String PROP_EXIT_CODE = "eclipse.exitcode"; //$NON-NLS-1$
@@ -362,8 +372,12 @@ public class IDEApplication implements IApplication, IExecutableExtension {
return false;
}
- String version = readWorkspaceVersion(url);
+ if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
+ // no reference bundle installed, no check possible
+ return true;
+ }
+ Version version = readWorkspaceVersion(url);
// if the version could not be read, then there is not any existing
// workspace data to trample, e.g., perhaps its a new directory that
// is just starting to be used as a workspace
@@ -371,33 +385,46 @@ public class IDEApplication implements IApplication, IExecutableExtension {
return true;
}
- final int ide_version = Integer.parseInt(WORKSPACE_VERSION_VALUE);
- int workspace_version = Integer.parseInt(version);
+ final Version ide_version = toMajorMinorVersion(WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION);
+ Version workspace_version = toMajorMinorVersion(version);
+ int versionCompareResult = workspace_version.compareTo(ide_version);
// equality test is required since any version difference (newer
// or older) may result in data being trampled
- if (workspace_version == ide_version) {
+ if (versionCompareResult == 0) {
return true;
}
- // At this point workspace has been detected to be from a version
- // other than the current ide version -- find out if the user wants
- // to use it anyhow.
- String title = IDEWorkbenchMessages.IDEApplication_versionTitle;
- String message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage, url.getFile());
-
- MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL
- | SWT.ICON_WARNING | SWT.APPLICATION_MODAL);
- mbox.setText(title);
- mbox.setMessage(message);
- return mbox.open() == SWT.OK;
+ // At this point workspace has been detected to be from a version
+ // other than the current ide version -- find out if the user wants
+ // to use it anyhow.
+ int severity;
+ String title;
+ String message;
+ if (versionCompareResult < 0) {
+ // Workspace < IDE. Update must be possible without issues,
+ // so only inform user about it.
+ severity = MessageDialog.INFORMATION;
+ title = IDEWorkbenchMessages.IDEApplication_versionTitle_olderWorkspace;
+ message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage_olderWorkspace, url.getFile());
+ } else {
+ // Workspace > IDE. It must have been opened with a newer IDE version.
+ // Downgrade might be problematic, so warn user about it.
+ severity = MessageDialog.WARNING;
+ title = IDEWorkbenchMessages.IDEApplication_versionTitle_newerWorkspace;
+ message = NLS.bind(IDEWorkbenchMessages.IDEApplication_versionMessage_newerWorkspace, url.getFile());
+ }
+
+ MessageDialog dialog = new MessageDialog(shell, title, null, message, severity,
+ new String[] {IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 0);
+ return dialog.open() == Window.OK;
}
/**
* Look at the argument URL for the workspace's version information. Return
* that version if found and null otherwise.
*/
- private static String readWorkspaceVersion(URL workspace) {
+ private static Version readWorkspaceVersion(URL workspace) {
File versionFile = getVersionFile(workspace, false);
if (versionFile == null || !versionFile.exists()) {
return null;
@@ -415,12 +442,25 @@ public class IDEApplication implements IApplication, IExecutableExtension {
is.close();
}
- return props.getProperty(WORKSPACE_VERSION_KEY);
+ String versionString = props.getProperty(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME);
+ if (versionString != null) {
+ return Version.parseVersion(versionString);
+ }
+
+ // be graceful if coming from legacy workspaces
+ return null;
} catch (IOException e) {
- IDEWorkbenchPlugin.log("Could not read version file", new Status( //$NON-NLS-1$
+ IDEWorkbenchPlugin.log("Could not read version file " + versionFile, new Status( //$NON-NLS-1$
+ IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
+ IStatus.ERROR,
+ e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$
+ e));
+ return null;
+ } catch (IllegalArgumentException e) {
+ IDEWorkbenchPlugin.log("Could not parse version in " + versionFile, new Status( //$NON-NLS-1$
IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
IStatus.ERROR,
- e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$,
+ e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$
e));
return null;
}
@@ -432,6 +472,11 @@ public class IDEApplication implements IApplication, IExecutableExtension {
* so the function is silent about failure
*/
private static void writeWorkspaceVersion() {
+ if (WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION == null) {
+ // no reference bundle installed, no check possible
+ return;
+ }
+
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null || instanceLoc.isReadOnly()) {
return;
@@ -444,11 +489,17 @@ public class IDEApplication implements IApplication, IExecutableExtension {
OutputStream output = null;
try {
- String versionLine = WORKSPACE_VERSION_KEY + '='
- + WORKSPACE_VERSION_VALUE;
-
output = new FileOutputStream(versionFile);
- output.write(versionLine.getBytes("UTF-8")); //$NON-NLS-1$
+ Properties props = new Properties();
+
+ // write new property
+ props.setProperty(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME, WORKSPACE_CHECK_REFERENCE_BUNDLE_VERSION.toString());
+
+ // write legacy property with an incremented version,
+ // so that pre-4.4 IDEs will also warn about the workspace
+ props.setProperty(WORKSPACE_CHECK_REFERENCE_BUNDLE_NAME_LEGACY, WORKSPACE_CHECK_LEGACY_VERSION_INCREMENTED);
+
+ props.store(output, null);
} catch (IOException e) {
IDEWorkbenchPlugin.log("Could not write version file", //$NON-NLS-1$
StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
@@ -500,6 +551,13 @@ public class IDEApplication implements IApplication, IExecutableExtension {
}
}
+ /**
+ * @return the major and minor parts of the given version
+ */
+ private static Version toMajorMinorVersion(Version version) {
+ return new Version(version.getMajor(), version.getMinor(), 0);
+ }
+
/* (non-Javadoc)
* @see org.eclipse.equinox.app.IApplication#stop()
*/
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
index 1f95f05..373b75a 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2013 IBM Corporation and others.
+ * Copyright (c) 2005, 2014 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
@@ -14,6 +14,7 @@
* Serge Beauchamp (Freescale Semiconductor) - [252996] Resource filters
* Markus Schorn (Wind River Systems) - bug 284447
* James Blackburn (Broadcom Corp.) - bug 340978
+ * Christian Georgi (SAP) - Bug 423882 - Warn user if workspace is newer than IDE
*******************************************************************************/
package org.eclipse.ui.internal.ide;
@@ -950,8 +951,10 @@ public class IDEWorkbenchMessages extends NLS {
public static String IDEApplication_workspaceCannotBeSetMessage;
public static String IDEApplication_workspaceCannotLockTitle;
public static String IDEApplication_workspaceCannotLockMessage;
- public static String IDEApplication_versionTitle;
- public static String IDEApplication_versionMessage;
+ public static String IDEApplication_versionTitle_newerWorkspace;
+ public static String IDEApplication_versionTitle_olderWorkspace;
+ public static String IDEApplication_versionMessage_newerWorkspace;
+ public static String IDEApplication_versionMessage_olderWorkspace;
public static String GlobalBuildAction_BuildRunningTitle;
public static String GlobalBuildAction_BuildRunningMessage;
public static String CleanDialog_buildCleanAuto;
diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
index 79ee2aa..c51dc35 100644
--- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
+++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2013 IBM Corporation and others.
+# Copyright (c) 2000, 2014 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
@@ -18,6 +18,7 @@
# Markus Schorn (Wind River Systems) - bug 284447
# James Blackburn (Broadcom Corp.) - bug 340978
# Helmut J. Haigermoser (Wind River Systems) - bug 359838
+# Christian Georgi (SAP) - Bug 423882 - Warn user if workspace is newer than IDE
###############################################################################
# package: org.eclipse.ui.ide
@@ -970,12 +971,12 @@ IDEApplication_workspaceCannotBeSetTitle=Workspace Cannot Be Created
IDEApplication_workspaceCannotBeSetMessage=Could not launch the product because the specified workspace cannot be created. The specified workspace directory is either invalid or read-only.
IDEApplication_workspaceCannotLockTitle=Workspace Cannot Be Locked
IDEApplication_workspaceCannotLockMessage=Could not launch the product because the associated workspace at ''{0}'' is currently in use by another Eclipse application.
-IDEApplication_versionTitle = Different Workspace Version
-IDEApplication_versionMessage = \
-This workspace was written with a different version of the product and needs to be updated.\n\n\
-{0}\n\n\
-Updating the workspace may make it incompatible with other versions of the product.\n\
-Press OK to update the workspace and open it. Press Cancel to select a different workspace.
+IDEApplication_versionTitle_olderWorkspace=Older Workspace Version
+IDEApplication_versionTitle_newerWorkspace=Newer Workspace Version
+IDEApplication_versionMessage_olderWorkspace=Workspace ''{0}'' was written with an older version of the product and will be updated. \
+Updating the workspace can make it incompatible with older versions of the product.\n\nAre you sure you want to continue with this workspace?
+IDEApplication_versionMessage_newerWorkspace=Workspace ''{0}'' was written with a newer version of the product and can be incompatible with this version. \
+If you continue, this can cause unexpected behavior or data loss.\n\nAre you sure you want to continue with this workspace?
CleanDialog_buildCleanAuto=Clean will discard all build problems and built states. The projects will be rebuilt from scratch.
CleanDialog_buildCleanManual=Clean will discard all build problems and built states. The next time a build occurs the projects will be rebuilt from scratch.