Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 229342 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/equinox/internal/provisional/p2/engine/ISurrogateProfileHandler.java (+2 lines)
Lines 13-16 Link Here
13
13
14
	public abstract Collector queryProfile(IProfile profile, Query query, Collector collector, IProgressMonitor monitor);
14
	public abstract Collector queryProfile(IProfile profile, Query query, Collector collector, IProgressMonitor monitor);
15
15
16
	public abstract boolean updateProfile(Profile selfProfile);
17
16
}
18
}
(-)src/org/eclipse/equinox/internal/p2/engine/Messages.java (+2 lines)
Lines 55-60 Link Here
55
	public static String TouchpointManager_Required_Touchpoint_Not_Found;
55
	public static String TouchpointManager_Required_Touchpoint_Not_Found;
56
	public static String TouchpointManager_Touchpoint_Type_Mismatch;
56
	public static String TouchpointManager_Touchpoint_Type_Mismatch;
57
57
58
	public static String shared_profile_not_found;
59
58
	static {
60
	static {
59
		// initialize resource bundles
61
		// initialize resource bundles
60
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
62
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
(-)src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java (-39 / +105 lines)
Lines 17-99 Link Here
17
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
17
import org.eclipse.equinox.internal.provisional.p2.engine.IProfile;
18
import org.eclipse.equinox.internal.provisional.p2.engine.ISurrogateProfileHandler;
18
import org.eclipse.equinox.internal.provisional.p2.engine.ISurrogateProfileHandler;
19
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
19
import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
20
import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
20
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
21
import org.eclipse.equinox.internal.provisional.p2.query.Collector;
21
import org.eclipse.equinox.internal.provisional.p2.query.Query;
22
import org.eclipse.equinox.internal.provisional.p2.query.Query;
22
import org.eclipse.osgi.service.datalocation.Location;
23
import org.eclipse.osgi.service.datalocation.Location;
24
import org.eclipse.osgi.util.NLS;
23
25
24
public class SurrogateProfileHandler implements ISurrogateProfileHandler {
26
public class SurrogateProfileHandler implements ISurrogateProfileHandler {
25
27
26
	private static final String ORG_ECLIPSE_EQUINOX_P2_NATIVE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$
28
	private static final String NATIVE_TOUCHPOINT_TYPE = "org.eclipse.equinox.p2.native"; //$NON-NLS-1$
27
	private static final String ORG_ECLIPSE_EQUINOX_P2_TYPE_ROOT = "org.eclipse.equinox.p2.type.root"; //$NON-NLS-1$
29
	private static final String PROP_TYPE_ROOT = "org.eclipse.equinox.p2.type.root"; //$NON-NLS-1$
28
	private static final String P2_ENGINE_DIR = "p2/" + EngineActivator.ID + "/"; //$NON-NLS-1$//$NON-NLS-2$
30
	private static final String P2_ENGINE_DIR = "p2/" + EngineActivator.ID + "/"; //$NON-NLS-1$//$NON-NLS-2$
29
	private static final String OSGI_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$
31
	private static final String OSGI_INSTALL_AREA = "osgi.install.area"; //$NON-NLS-1$
30
	private static final String ECLIPSE_INI_IGNORED = "eclipse.ini.ignored"; //$NON-NLS-1$
32
	private static final String ECLIPSE_INI_IGNORED = "eclipse.ini.ignored"; //$NON-NLS-1$
31
	private static final String IU_LOCKED = Integer.toString(IInstallableUnit.LOCK_UNINSTALL | IInstallableUnit.LOCK_UPDATE);
33
	private static final String IU_LOCKED = Integer.toString(IInstallableUnit.LOCK_UNINSTALL | IInstallableUnit.LOCK_UPDATE);
32
34
	private static final String PROP_SURROGATE = "org.eclipse.equinox.p2.surrogate"; //$NON-NLS-1$
33
	/**
35
	private static final String PROP_SHARED_TIMESTAMP = "org.eclipse.equinox.p2.shared.timestamp"; //$NON-NLS-1$
34
	 * Profile property constant indicating the bundle pool cache location.
36
	private static final String PROP_BASE = "org.eclipse.equinox.p2.base"; //$NON-NLS-1$
35
	 */
37
	private static final String PROP_RESOLVE = "org.eclipse.equinox.p2.resolve"; //$NON-NLS-1$
36
	public static final String PROP_SURROGATE = "org.eclipse.equinox.p2.surrogate"; //$NON-NLS-1$
38
	private static final String OPTIONAL = "OPTIONAL"; //$NON-NLS-1$
39
	private static final String PROP_INCLUSION_RULES = "org.eclipse.equinox.p2.internal.inclusion.rules"; //$NON-NLS-1$
37
40
38
	private SimpleProfileRegistry profileRegistry;
41
	private SimpleProfileRegistry profileRegistry;
39
42
40
	private synchronized SimpleProfileRegistry getProfileRegistry() {
43
	private static void addSharedProfileBaseIUs(final IProfile sharedProfile, final Profile userProfile) {
41
		if (profileRegistry == null) {
42
			String installArea = EngineActivator.getContext().getProperty(OSGI_INSTALL_AREA);
43
			try {
44
				URL registryURL = new URL(installArea + P2_ENGINE_DIR + SimpleProfileRegistry.DEFAULT_STORAGE_DIR);
45
				File sharedRegistryDirectory = new File(registryURL.getPath());
46
				profileRegistry = new SimpleProfileRegistry(sharedRegistryDirectory, null);
47
			} catch (MalformedURLException e) {
48
				//this is not possible because we know the above URL is valid
49
			}
50
		}
51
		return profileRegistry;
52
	}
53
54
	/* (non-Javadoc)
55
	 * @see org.eclipse.equinox.internal.p2.engine.ISurrogateProfileHandler#createProfile(java.lang.String)
56
	 */
57
	public Profile createProfile(String id) {
58
		final IProfile sharedProfile = getProfileRegistry().getProfile(id);
59
		if (sharedProfile == null)
60
			return null;
61
62
		Query rootIUQuery = new Query() {
44
		Query rootIUQuery = new Query() {
63
			public boolean isMatch(Object candidate) {
45
			public boolean isMatch(Object candidate) {
64
				if (candidate instanceof IInstallableUnit) {
46
				if (candidate instanceof IInstallableUnit) {
65
					IInstallableUnit iu = (IInstallableUnit) candidate;
47
					IInstallableUnit iu = (IInstallableUnit) candidate;
66
					if (Boolean.valueOf(sharedProfile.getInstallableUnitProperty(iu, ORG_ECLIPSE_EQUINOX_P2_TYPE_ROOT)).booleanValue())
48
					if (Boolean.valueOf(sharedProfile.getInstallableUnitProperty(iu, PROP_TYPE_ROOT)).booleanValue())
67
						return true;
49
						return true;
68
					if (iu.getTouchpointType().getId().equals(ORG_ECLIPSE_EQUINOX_P2_NATIVE))
50
					if (iu.getTouchpointType().getId().equals(NATIVE_TOUCHPOINT_TYPE))
69
						return true;
51
						return true;
70
				}
52
				}
71
				return false;
53
				return false;
72
			}
54
			}
73
		};
55
		};
74
75
		Collector rootIUs = sharedProfile.query(rootIUQuery, new Collector(), null);
56
		Collector rootIUs = sharedProfile.query(rootIUQuery, new Collector(), null);
76
77
		Profile userProfile = new Profile(id, null, sharedProfile.getProperties());
78
		userProfile.setSurrogateProfileHandler(this);
79
		for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) {
57
		for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) {
80
			IInstallableUnit iu = (IInstallableUnit) iterator.next();
58
			IInstallableUnit iu = (IInstallableUnit) iterator.next();
81
			userProfile.addInstallableUnit(iu);
59
			userProfile.addInstallableUnit(iu);
82
			userProfile.addInstallableUnitProperties(iu, sharedProfile.getInstallableUnitProperties(iu));
60
			userProfile.addInstallableUnitProperties(iu, sharedProfile.getInstallableUnitProperties(iu));
83
			userProfile.setInstallableUnitProperty(iu, IInstallableUnit.PROP_PROFILE_LOCKED_IU, IU_LOCKED);
61
			userProfile.setInstallableUnitProperty(iu, IInstallableUnit.PROP_PROFILE_LOCKED_IU, IU_LOCKED);
62
			userProfile.setInstallableUnitProperty(iu, PROP_BASE, Boolean.TRUE.toString());
84
		}
63
		}
64
	}
85
65
86
		//update properties
66
	private static void removeUserProfileBaseIUs(final Profile userProfile) {
87
		userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString());
67
		Query rootIUQuery = new Query() {
68
			public boolean isMatch(Object candidate) {
69
				if (candidate instanceof IInstallableUnit) {
70
					IInstallableUnit iu = (IInstallableUnit) candidate;
71
					if (Boolean.valueOf(userProfile.getInstallableUnitProperty(iu, PROP_BASE)).booleanValue())
72
						return true;
73
				}
74
				return false;
75
			}
76
		};
77
		Collector rootIUs = userProfile.query(rootIUQuery, new Collector(), null);
78
		for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) {
79
			IInstallableUnit iu = (IInstallableUnit) iterator.next();
80
			userProfile.removeInstallableUnit(iu);
81
		}
82
	}
83
84
	private static void markRootsOptional(final Profile userProfile) {
85
		Query rootIUQuery = new Query() {
86
			public boolean isMatch(Object candidate) {
87
				if (candidate instanceof IInstallableUnit) {
88
					IInstallableUnit iu = (IInstallableUnit) candidate;
89
					if (Boolean.valueOf(userProfile.getInstallableUnitProperty(iu, PROP_TYPE_ROOT)).booleanValue())
90
						return true;
91
				}
92
				return false;
93
			}
94
		};
95
		Collector rootIUs = userProfile.query(rootIUQuery, new Collector(), null);
96
		for (Iterator iterator = rootIUs.iterator(); iterator.hasNext();) {
97
			IInstallableUnit iu = (IInstallableUnit) iterator.next();
98
			userProfile.setInstallableUnitProperty(iu, PROP_INCLUSION_RULES, OPTIONAL);
99
		}
100
	}
101
102
	private static void updateProperties(final IProfile sharedProfile, Profile userProfile) {
103
		userProfile.setProperty(PROP_SHARED_TIMESTAMP, Long.toString(sharedProfile.getTimestamp()));
88
		Location installLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
104
		Location installLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
89
		File installFolder = new File(installLocation.getURL().getPath());
105
		File installFolder = new File(installLocation.getURL().getPath());
90
106
91
		if (Boolean.valueOf(userProfile.getProperty(IProfile.PROP_ROAMING)).booleanValue()) {
107
		if (Boolean.valueOf(sharedProfile.getProperty(IProfile.PROP_ROAMING)).booleanValue()) {
92
			userProfile.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.getAbsolutePath());
108
			userProfile.setProperty(IProfile.PROP_INSTALL_FOLDER, installFolder.getAbsolutePath());
93
			userProfile.setProperty(IProfile.PROP_SHARED_CACHE, installFolder.getAbsolutePath());
109
			userProfile.setProperty(IProfile.PROP_SHARED_CACHE, installFolder.getAbsolutePath());
94
			userProfile.setProperty(IProfile.PROP_ROAMING, Boolean.FALSE.toString());
110
			userProfile.setProperty(IProfile.PROP_ROAMING, Boolean.FALSE.toString());
95
		} else {
111
		} else {
96
			String cache = userProfile.getProperty(IProfile.PROP_CACHE);
112
			String cache = sharedProfile.getProperty(IProfile.PROP_CACHE);
97
			if (cache != null)
113
			if (cache != null)
98
				userProfile.setProperty(IProfile.PROP_SHARED_CACHE, cache);
114
				userProfile.setProperty(IProfile.PROP_SHARED_CACHE, cache);
99
		}
115
		}
Lines 106-111 Link Here
106
122
107
		File launcherConfigFile = new File(configurationFolder, ECLIPSE_INI_IGNORED);
123
		File launcherConfigFile = new File(configurationFolder, ECLIPSE_INI_IGNORED);
108
		userProfile.setProperty(IProfile.PROP_LAUNCHER_CONFIGURATION, launcherConfigFile.getAbsolutePath());
124
		userProfile.setProperty(IProfile.PROP_LAUNCHER_CONFIGURATION, launcherConfigFile.getAbsolutePath());
125
	}
126
127
	private synchronized SimpleProfileRegistry getProfileRegistry() {
128
		if (profileRegistry == null) {
129
			String installArea = EngineActivator.getContext().getProperty(OSGI_INSTALL_AREA);
130
			try {
131
				URL registryURL = new URL(installArea + P2_ENGINE_DIR + SimpleProfileRegistry.DEFAULT_STORAGE_DIR);
132
				File sharedRegistryDirectory = new File(registryURL.getPath());
133
				profileRegistry = new SimpleProfileRegistry(sharedRegistryDirectory, null);
134
			} catch (MalformedURLException e) {
135
				//this is not possible because we know the above URL is valid
136
			}
137
		}
138
		return profileRegistry;
139
	}
140
141
	/* (non-Javadoc)
142
	 * @see org.eclipse.equinox.internal.p2.engine.ISurrogateProfileHandler#createProfile(java.lang.String)
143
	 */
144
	public Profile createProfile(String id) {
145
		final IProfile sharedProfile = getProfileRegistry().getProfile(id);
146
		if (sharedProfile == null)
147
			return null;
148
149
		Profile userProfile = new Profile(id, null, sharedProfile.getProperties());
150
		userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString());
151
		userProfile.setSurrogateProfileHandler(this);
152
		updateProperties(sharedProfile, userProfile);
153
		addSharedProfileBaseIUs(sharedProfile, userProfile);
109
		return userProfile;
154
		return userProfile;
110
	}
155
	}
111
156
Lines 126-129 Link Here
126
171
127
		return profile.query(query, collector, monitor);
172
		return profile.query(query, collector, monitor);
128
	}
173
	}
174
175
	public boolean updateProfile(Profile userProfile) {
176
		final IProfile sharedProfile = getProfileRegistry().getProfile(userProfile.getProfileId());
177
		if (sharedProfile == null)
178
			throw new IllegalStateException(NLS.bind(Messages.shared_profile_not_found, userProfile.getProfileId()));
179
180
		String sharedTimeStamp = Long.toString(sharedProfile.getTimestamp());
181
		String userSharedTimeStamp = userProfile.getProperty(PROP_SHARED_TIMESTAMP);
182
183
		if (userSharedTimeStamp != null && userSharedTimeStamp.equals(sharedTimeStamp))
184
			return false;
185
186
		updateProperties(sharedProfile, userProfile);
187
		removeUserProfileBaseIUs(userProfile);
188
		if (!userProfile.query(InstallableUnitQuery.ANY, new Collector(), null).isEmpty()) {
189
			userProfile.setProperty(PROP_RESOLVE, Boolean.TRUE.toString());
190
			markRootsOptional(userProfile);
191
		}
192
		addSharedProfileBaseIUs(sharedProfile, userProfile);
193
		return true;
194
	}
129
}
195
}
(-)src/org/eclipse/equinox/internal/p2/engine/messages.properties (+1 lines)
Lines 42-44 Link Here
42
profile_not_registered=Profile {0} not registered.
42
profile_not_registered=Profile {0} not registered.
43
reg_dir_not_available=Registry Directory not available.
43
reg_dir_not_available=Registry Directory not available.
44
thread_not_owner=Thread not lock owner.
44
thread_not_owner=Thread not lock owner.
45
shared_profile_not_found=Shared profile {0} not found.
(-)src/org/eclipse/equinox/internal/p2/engine/SimpleProfileRegistry.java (-6 / +16 lines)
Lines 128-142 Link Here
128
	 * If the current profile for self is marked as a roaming profile, we need
128
	 * If the current profile for self is marked as a roaming profile, we need
129
	 * to update its install and bundle pool locations.
129
	 * to update its install and bundle pool locations.
130
	 */
130
	 */
131
	private void updateRoamingProfile(Map profileMap) {
131
	private void updateSelfProfile(Map profileMap) {
132
		if (profileMap == null)
132
		if (profileMap == null)
133
			return;
133
			return;
134
		Profile selfProfile = (Profile) profileMap.get(self);
134
		Profile selfProfile = (Profile) profileMap.get(self);
135
		if (selfProfile == null)
135
		if (selfProfile == null)
136
			return;
136
			return;
137
138
		boolean changed = false;
137
		//only update if self is a roaming profile
139
		//only update if self is a roaming profile
138
		if (!Boolean.valueOf(selfProfile.getProperty(IProfile.PROP_ROAMING)).booleanValue())
140
		if (Boolean.valueOf(selfProfile.getProperty(IProfile.PROP_ROAMING)).booleanValue())
139
			return;
141
			changed = updateRoamingProfile(selfProfile);
142
143
		if (surrogateProfileHandler != null && surrogateProfileHandler.isSurrogate(selfProfile))
144
			changed = changed || surrogateProfileHandler.updateProfile(selfProfile);
145
146
		if (changed)
147
			saveProfile(selfProfile);
148
	}
149
150
	private boolean updateRoamingProfile(Profile selfProfile) {
140
		Location installLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
151
		Location installLocation = (Location) ServiceHelper.getService(EngineActivator.getContext(), Location.class.getName(), Location.INSTALL_FILTER);
141
		File location = new File(installLocation.getURL().getPath());
152
		File location = new File(installLocation.getURL().getPath());
142
		boolean changed = false;
153
		boolean changed = false;
Lines 148-155 Link Here
148
			selfProfile.setProperty(IProfile.PROP_CACHE, location.getAbsolutePath());
159
			selfProfile.setProperty(IProfile.PROP_CACHE, location.getAbsolutePath());
149
			changed = true;
160
			changed = true;
150
		}
161
		}
151
		if (changed)
162
		return changed;
152
			saveProfile(selfProfile);
153
	}
163
	}
154
164
155
	public synchronized String toString() {
165
	public synchronized String toString() {
Lines 216-222 Link Here
216
		if (!hasBeenRestored) {
226
		if (!hasBeenRestored) {
217
			//update roaming profile on first load
227
			//update roaming profile on first load
218
			hasBeenRestored = true;
228
			hasBeenRestored = true;
219
			updateRoamingProfile(result);
229
			updateSelfProfile(result);
220
		}
230
		}
221
		return result;
231
		return result;
222
	}
232
	}
(-)src/org/eclipse/equinox/internal/simpleconfigurator/SimpleConfiguratorImpl.java (-12 / +13 lines)
Lines 78-92 Link Here
78
			//if it is an relative file URL, then resolve it against the configuration area
78
			//if it is an relative file URL, then resolve it against the configuration area
79
			URL[] configURL = EquinoxUtils.getConfigAreaURL(context);
79
			URL[] configURL = EquinoxUtils.getConfigAreaURL(context);
80
			if (configURL != null) {
80
			if (configURL != null) {
81
				File target = new File(configURL[0].getFile(), url.getFile());
81
				File userConfig = new File(configURL[0].getFile(), url.getFile());
82
				if (target.exists())
82
				if (configURL.length == 1)
83
					return target.toURL();
83
					return userConfig.exists() ? userConfig.toURL() : null;
84
				else if (configURL.length > 1) {
84
85
					target = new File(configURL[1].getFile(), url.getFile());
85
				File sharedConfig = new File(configURL[1].getFile(), url.getFile());
86
					if (target.exists())
86
				if (!userConfig.exists())
87
						return target.toURL();
87
					return sharedConfig.exists() ? sharedConfig.toURL() : null;
88
				}
88
89
				return null;
89
				if (!sharedConfig.exists())
90
					return userConfig.toURL();
91
92
				return (sharedConfig.lastModified() > userConfig.lastModified()) ? sharedConfig.toURL() : userConfig.toURL();
90
			}
93
			}
91
		} catch (MalformedURLException e) {
94
		} catch (MalformedURLException e) {
92
			return null;
95
			return null;
Lines 130-138 Link Here
130
133
131
	public void applyConfiguration() throws IOException {
134
	public void applyConfiguration() throws IOException {
132
		synchronized (configurationLock) {
135
		synchronized (configurationLock) {
133
			if (configurationURL == null)
136
			configurationURL = getConfigurationURL();
134
				configurationURL = getConfigurationURL();
135
136
			applyConfiguration(configurationURL);
137
			applyConfiguration(configurationURL);
137
		}
138
		}
138
	}
139
	}
(-)src/org/eclipse/equinox/internal/p2/reconciler/dropins/ProfileSynchronizer.java (-1 / +6 lines)
Lines 256-261 Link Here
256
256
257
	public ProfileChangeRequest createProfileChangeRequest(ProvisioningContext context) {
257
	public ProfileChangeRequest createProfileChangeRequest(ProvisioningContext context) {
258
		ProfileChangeRequest request = new ProfileChangeRequest(profile);
258
		ProfileChangeRequest request = new ProfileChangeRequest(profile);
259
260
		boolean resolve = Boolean.valueOf(profile.getProperty("org.eclipse.equinox.p2.resolve")).booleanValue();
261
		if (resolve)
262
			request.removeProfileProperty("org.eclipse.equinox.p2.resolve");
263
259
		List toAdd = new ArrayList();
264
		List toAdd = new ArrayList();
260
		List toRemove = new ArrayList();
265
		List toRemove = new ArrayList();
261
266
Lines 298-304 Link Here
298
				toRemove.add(iu);
303
				toRemove.add(iu);
299
		}
304
		}
300
305
301
		if (toAdd.isEmpty() && toRemove.isEmpty())
306
		if (toAdd.isEmpty() && toRemove.isEmpty() && !resolve)
302
			return null;
307
			return null;
303
308
304
		context.setExtraIUs(toAdd);
309
		context.setExtraIUs(toAdd);

Return to bug 229342