Change logic to detect base change
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 2448fa6..674b1f2 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 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 @@
 		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 = findMostRecentReset(registry, currentProfile);
 
-		final IProfile previousProfile = findProfileBeforeReset(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 @@
 
 	}
 
-	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)
+	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();
 
-		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;
+		//		&& !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;
 	}
 
-	private IProfile findProfileBeforeReset(IProfileRegistry registry, IProfile profile) {
+	public static final String MIGRATION_DIALOG_SHOWN = "migrationDialogShown"; //$NON-NLS-1$
+
+	//Get the timestamp that we migrated from 
+	private long getLastShownMigration() {
+		return AutomaticUpdatePlugin.getDefault().getPreferenceStore().getLong(MIGRATION_DIALOG_SHOWN);
+	}
+
+	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 d908033..852a6c8 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.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 @@
 	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
+				}
+		}
+	}
 }