diff options
author | Pascal Rapicault (Ericsson) | 2013-02-15 16:02:49 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-02-15 16:02:49 +0000 |
commit | 1ff11052e53d648dec8305eea7c51a111e53d39a (patch) | |
tree | b5932e4a01b46ed6a52ba589d7ba03fbafa569a2 | |
parent | 68c4f16c543515b74a3d62145039b58f4cd38812 (diff) | |
download | rt.equinox.p2-1ff11052e53d648dec8305eea7c51a111e53d39a.tar.gz rt.equinox.p2-1ff11052e53d648dec8305eea7c51a111e53d39a.tar.xz rt.equinox.p2-1ff11052e53d648dec8305eea7c51a111e53d39a.zip |
Change logic to detect base change
2 files changed, 63 insertions, 33 deletions
diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java index 2448fa65e..674b1f217 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/AutomaticUpdateScheduler.java @@ -17,12 +17,9 @@ import com.ibm.icu.util.ULocale; import java.util.Iterator; import java.util.Set; import org.eclipse.core.runtime.*; -import org.eclipse.core.runtime.preferences.ConfigurationScope; -import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; import org.eclipse.equinox.internal.p2.garbagecollector.GarbageCollector; import org.eclipse.equinox.internal.p2.metadata.query.UpdateQuery; -import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.AbstractPage_c; import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.migration.ImportFromInstallationWizard_c; import org.eclipse.equinox.internal.provisional.p2.updatechecker.*; import org.eclipse.equinox.p2.core.IProvisioningAgent; @@ -98,33 +95,27 @@ public class AutomaticUpdateScheduler implements IStartup { IProvisioningAgent agent = (IProvisioningAgent) ServiceHelper.getService(AutomaticUpdatePlugin.getContext(), IProvisioningAgent.SERVICE_NAME); IProfileRegistry registry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME); IProfile currentProfile = registry.getProfile(profileId); - - if (performMigration(agent, registry, currentProfile)) + if (currentProfile != null && performMigration(agent, registry, currentProfile)) return; garbageCollect(); scheduleUpdate(); } - //This method returns whether the migration dialog is shown or not + //The return value indicates if the migration dialog has been shown or not. It does not indicate whether the migration has completed. private boolean performMigration(IProvisioningAgent agent, IProfileRegistry registry, IProfile currentProfile) { boolean skipWizard = Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ECLIPSE_P2_SKIP_MIGRATION_WIZARD)); if (skipWizard) return false; - if (!baseChanged(agent, registry, currentProfile)) + if (!baseChangedSinceLastPresentationOfWizard(agent, registry, currentProfile)) return false; - IScopeContext[] contexts = new IScopeContext[] {ConfigurationScope.INSTANCE}; - boolean remindMeLater = Platform.getPreferencesService().getBoolean("org.eclipse.equinox.p2.ui", AbstractPage_c.REMIND_ME_LATER, true, contexts); - - final IProfile previousProfile = findProfileBeforeReset(registry, currentProfile); + final IProfile previousProfile = findMostRecentReset(registry, currentProfile); - if (previousProfile != null && currentProfile != null) { + if (previousProfile != null) { if (needsMigration(previousProfile, currentProfile)) { - if (remindMeLater) { - openMigrationWizard(previousProfile); - } + openMigrationWizard(previousProfile); } } return true; @@ -176,27 +167,37 @@ public class AutomaticUpdateScheduler implements IStartup { } - private boolean baseChanged(IProvisioningAgent agent, IProfileRegistry registry, IProfile profile) { - //Access the running profile to force its reinitialization if it has not been done. - registry.getProfile(profile.getProfileId()); - String resetState = (String) agent.getService(IProfileRegistry.SERVICE_SHARED_INSTALL_NEW_TIMESTAMP); - if (resetState == null) - return false; - - final String PREF_MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$ - - //Have we already shown the migration dialog - if (AutomaticUpdatePlugin.getDefault().getPreferenceStore().getString(PREF_MIGRATION_DIALOG_SHOWN) == resetState) + private boolean baseChangedSinceLastPresentationOfWizard(IProvisioningAgent agent, IProfileRegistry registry, IProfile profile) { + long lastShownMigration = getLastShownMigration(); + IProfile lastReset = findMostRecentReset(registry, profile); + if (lastReset == null) return false; + return lastShownMigration < lastReset.getTimestamp(); + + // && !remindMeLater()) + // return false; + // + // final String PREF_MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$ + // + // //Have we already shown the migration dialog + // if (AutomaticUpdatePlugin.getDefault().getPreferenceStore().getString(PREF_MIGRATION_DIALOG_SHOWN) == resetState) + // return false; + // + // //Remember that we are showing the migration dialog + // AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(PREF_MIGRATION_DIALOG_SHOWN, resetState); + // AutomaticUpdatePlugin.getDefault().savePreferences(); + // + // return true; + } - //Remember that we are showing the migration dialog - AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(PREF_MIGRATION_DIALOG_SHOWN, resetState); - AutomaticUpdatePlugin.getDefault().savePreferences(); + public static final String MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$ - return true; + //Get the timestamp that we migrated from + private long getLastShownMigration() { + return AutomaticUpdatePlugin.getDefault().getPreferenceStore().getLong(MIGRATION_DIALOG_SHOWN); } - private IProfile findProfileBeforeReset(IProfileRegistry registry, IProfile profile) { + private IProfile findMostRecentReset(IProfileRegistry registry, IProfile profile) { long[] history = registry.listProfileTimestamps(profile.getProfileId()); int index = history.length - 1; boolean found = false; diff --git a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java index d9080332d..852a6c8c8 100644 --- a/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java +++ b/bundles/org.eclipse.equinox.p2.ui.sdk.scheduler/src/org/eclipse/equinox/internal/p2/ui/sdk/scheduler/migration/ImportFromInstallationWizard_c.java @@ -17,8 +17,10 @@ import org.eclipse.equinox.internal.p2.ui.ProvUIActivator; import org.eclipse.equinox.internal.p2.ui.dialogs.ISelectableIUsPage; import org.eclipse.equinox.internal.p2.ui.dialogs.InstallWizard; import org.eclipse.equinox.internal.p2.ui.model.IUElementListRoot; -import org.eclipse.equinox.p2.engine.IProfile; -import org.eclipse.equinox.p2.engine.ProvisioningContext; +import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdatePlugin; +import org.eclipse.equinox.internal.p2.ui.sdk.scheduler.AutomaticUpdateScheduler; +import org.eclipse.equinox.p2.core.ProvisionException; +import org.eclipse.equinox.p2.engine.*; import org.eclipse.equinox.p2.metadata.IInstallableUnit; import org.eclipse.equinox.p2.operations.InstallOperation; import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob; @@ -69,4 +71,31 @@ public class ImportFromInstallationWizard_c extends InstallWizard implements IIm protected ProvisioningContext getProvisioningContext() { return ((ImportFromInstallationPage_c) mainPage).getProvisioningContext(); } + + @Override + public boolean performFinish() { + cleanupProfileRegistry(); + rememberShownMigration(toImportFrom.getTimestamp()); + return super.performFinish(); + } + + //Remember the timestamp that we migrated from. + private void rememberShownMigration(long timestamp) { + AutomaticUpdatePlugin.getDefault().getPreferenceStore().setValue(AutomaticUpdateScheduler.MIGRATION_DIALOG_SHOWN, timestamp); + } + + //Purge the profile registry from all the entries that are no longer relevant + //We keep the base we import from on purpose to help with debugging + private void cleanupProfileRegistry() { + IProfileRegistry registry = (IProfileRegistry) ProvisioningUI.getDefaultUI().getSession().getProvisioningAgent().getService(IProfileRegistry.SERVICE_NAME); + long[] history = registry.listProfileTimestamps(toImportFrom.getProfileId()); + for (int i = 0; i < history.length; i++) { + if (history[i] < toImportFrom.getTimestamp()) + try { + registry.removeProfile(toImportFrom.getProfileId(), history[i]); + } catch (ProvisionException e) { + //Can't happen + } + } + } } |