diff options
author | Pascal Rapicault (Ericsson) | 2013-01-28 02:33:32 +0000 |
---|---|---|
committer | Pascal Rapicault | 2013-01-28 03:10:07 +0000 |
commit | bc11d565b32b5b5c8bb5c93e5ea666b1d06b43ff (patch) | |
tree | 6c458b135672de141be0be4d51a086463c3e6bd5 /bundles/org.eclipse.equinox.p2.engine | |
parent | ba4e7abda6e44ad47aead2fade320f9be08b27d5 (diff) | |
download | rt.equinox.p2-bc11d565b32b5b5c8bb5c93e5ea666b1d06b43ff.tar.gz rt.equinox.p2-bc11d565b32b5b5c8bb5c93e5ea666b1d06b43ff.tar.xz rt.equinox.p2-bc11d565b32b5b5c8bb5c93e5ea666b1d06b43ff.zip |
Annotate new profile with a base profile timestamp
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine')
3 files changed, 73 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java index e1367ea37..9e0265404 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java @@ -6,7 +6,7 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Ericsson AB (Pascal Rapicault) - reading preferences from base in shared install + * Ericsson AB - ongoing development ******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; @@ -38,6 +38,8 @@ import org.xml.sax.SAXException; public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { + private static final String SIMPLE_PROFILE_REGISTRY_INTERNAL = "_simpleProfileRegistry_internal_"; + private static final String ECLIPSE_IGNORE_USER_CONFIGURATION = "eclipse.ignoreUserConfiguration"; //$NON-NLS-1$ private static final String PROFILE_REGISTRY = "profile registry"; //$NON-NLS-1$ private static final String PROFILE_PROPERTIES_FILE = "state.properties"; //$NON-NLS-1$ @@ -246,25 +248,52 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { if (self != null && self.equals(id)) { boolean resetProfile = false; if (profile != null && ignoreExistingProfile(profile)) { - internalSetProfileStateProperty(profile, profile.getTimestamp(), "RESET", "RESET"); + internalSetProfileStateProperty(profile, profile.getTimestamp(), IProfile.STATE_PROP_SHARED_INSTALL, IProfile.STATE_SHARED_INSTALL_VALUE_BEFOREFLUSH); profile = null; resetProfile = true; } if (profile == null) { profile = createSurrogateProfile(id); - if (resetProfile) - internalSetProfileStateProperty(profile, profile.getTimestamp(), "NEW", "NEW"); - else - internalSetProfileStateProperty(profile, profile.getTimestamp(), "FIRST", "FIRST"); + if (resetProfile) { + //Now that we created a new profile. Tag it, override the property and register the timestamp in the agent registry for pickup by other + internalSetProfileStateProperty(profile, profile.getTimestamp(), IProfile.STATE_PROP_SHARED_INSTALL, IProfile.STATE_SHARED_INSTALL_VALUE_NEW); + internalSetProfileStateProperty(profile, profile.getTimestamp(), SIMPLE_PROFILE_REGISTRY_INTERNAL + getBaseTimestamp(profile.getProfileId()), getBaseTimestamp(id)); + System.setProperty(ECLIPSE_IGNORE_USER_CONFIGURATION, "profileFlushed"); //$NON-NLS-1$ + agent.registerService(SERVICE_SHARED_INSTALL_NEW_TIMESTAMP, Long.toString(profile.getTimestamp())); + } else { + //This is the first time we create the shared profile. Tag it as such and also remember the timestamp of the base + internalSetProfileStateProperty(profile, profile.getTimestamp(), IProfile.STATE_PROP_SHARED_INSTALL, IProfile.STATE_SHARED_INSTALL_VALUE_INITIAL); + internalSetProfileStateProperty(profile, profile.getTimestamp(), SIMPLE_PROFILE_REGISTRY_INTERNAL + getBaseTimestamp(profile.getProfileId()), getBaseTimestamp(id)); + } } } return profile; } private boolean ignoreExistingProfile(IProfile profile) { - if (internalGetProfileStateProperties(profile, profile.getTimestamp(), false).containsKey("NEW")) + if (!Boolean.TRUE.toString().equalsIgnoreCase(System.getProperty(ECLIPSE_IGNORE_USER_CONFIGURATION))) + return false; + + String baseTimestamp = getBaseTimestamp(profile.getProfileId()); + if (baseTimestamp == null) + return false; + + if (internalGetProfileStateProperties(profile, SIMPLE_PROFILE_REGISTRY_INTERNAL + baseTimestamp, false).size() != 0) return false; - return "true".equals(System.getProperty("eclipse.ignoreUserConfiguration")); + + return true; + } + + private String getBaseTimestamp(String id) { + IProvisioningAgent installer = (IProvisioningAgent) agent.getService(IProvisioningAgent.SHARED_BASE_AGENT); + if (installer == null) + return null; + IProfileRegistry registry = (IProfileRegistry) installer.getService(IProfileRegistry.SERVICE_NAME); + long[] revisions = registry.listProfileTimestamps(id); + if (revisions.length >= 1) { + return Long.toString(revisions[revisions.length - 1]); + } + return null; } private Profile createSurrogateProfile(String id) { @@ -310,7 +339,6 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { return result; } - // public synchronized void updateProfile(Profile profile) { String id = profile.getProfileId(); Profile current = getProfileMap().get(id); @@ -1139,13 +1167,15 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { throw new NullPointerException(); Profile internalProfile = internalGetProfile(id); - return internalGetProfileStateProperties(internalProfile, userKey); + return internalGetProfileStateProperties(internalProfile, userKey, true); } - private Map<String, String> internalGetProfileStateProperties(IProfile profile, String userKey) { + private Map<String, String> internalGetProfileStateProperties(IProfile profile, String userKey, boolean lock) { Map<String, String> result = new HashMap<String, String>(); - if (!internalLockProfile(profile)) - throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_in_use); + lock = lock || lastAccessedProperties == null; + if (lock) + if (!internalLockProfile(profile)) + throw new IllegalStateException(Messages.SimpleProfileRegistry_Profile_in_use); try { Properties properties = readStateProperties(profile.getProfileId()); Iterator<Object> keys = properties.keySet().iterator(); @@ -1160,7 +1190,8 @@ public class SimpleProfileRegistry implements IProfileRegistry, IAgentService { } catch (ProvisionException e) { LogHelper.log(e); } finally { - internalUnlockProfile(profile); + if (lock) + internalUnlockProfile(profile); } return result; } diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java index 1f8de7645..7bd0060c2 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfile.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Ericsson AB - ongoing development *******************************************************************************/ package org.eclipse.equinox.p2.engine; @@ -146,6 +147,29 @@ public interface IProfile extends IQueryable<IInstallableUnit> { public static final String STATE_PROP_TAG = "org.eclipse.equinox.p2.state.tag"; //$NON-NLS-1$ /** + * Profile state metadata property key used to represent the state of the user profile when running in shared install. + * The value for this property could be: {@value #STATE_PROP_INITIAL}, {@value #STATE_SHARED_INSTALL_VALUE_BEFOREFLUSH}, or {@value #STATE_SHARED_INSTALL_VALUE_NEW} + * @since 2.3 + */ + public static final String STATE_PROP_SHARED_INSTALL = "org.eclipse.equinox.p2.state.shared"; //$NON-NLS-1$ + + /** + * Value to represent a user profile the first time it is created. + * @since 2.3 + */ + public static final String STATE_SHARED_INSTALL_VALUE_INITIAL = "initial"; //$NON-NLS-1$ + /** + * Value to represent a user profile before it is being flushed because the base had changed. + * @since 2.3 + */ + public static final String STATE_SHARED_INSTALL_VALUE_BEFOREFLUSH = "beforeFlush"; //$NON-NLS-1$ + /** + * Value to represent the new user profile created once the base profile has been flushed. + * @since 2.3 + */ + public static final String STATE_SHARED_INSTALL_VALUE_NEW = "new"; //$NON-NLS-1$ + + /** * Profile property constant for additional parameters of the downloading stats(e.g., package=jee&os=linux). * @since 2.2 */ diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java index 381a61e20..b2490c894 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/p2/engine/IProfileRegistry.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. + * Copyright (c) 2007, 2013 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Ericsson AB - ongoing development *******************************************************************************/ package org.eclipse.equinox.p2.engine; @@ -37,6 +38,8 @@ public interface IProfileRegistry { */ public static final String SERVICE_NAME = IProfileRegistry.class.getName(); + public static final String SERVICE_SHARED_INSTALL_NEW_TIMESTAMP = IProfileRegistry.class.getName() + '_' + "NEW_SELF_TIMESTAMP"; //$NON-NLS-1$ + /** * Return the profile in the registry that has the given id. If it does not exist, * then return <code>null</code>. |