|
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 |
} |