diff options
author | Krzysztof Daniel | 2013-12-13 15:40:46 +0000 |
---|---|---|
committer | Krzysztof Daniel | 2013-12-17 15:22:28 +0000 |
commit | 73e3365d5687050be42fe7484560230fc36a99be (patch) | |
tree | f83b4c184fc2c78a0f78bc21f91feaaa695ff11e /bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java | |
parent | 39da65192fec835fafe75c0f863a63757b59f2dd (diff) | |
download | rt.equinox.p2-73e3365d5687050be42fe7484560230fc36a99be.tar.gz rt.equinox.p2-73e3365d5687050be42fe7484560230fc36a99be.tar.xz rt.equinox.p2-73e3365d5687050be42fe7484560230fc36a99be.zip |
Bug 422054: Create profile from existing bundles.infoI20131224-0800
I've hijacked the bug for the purpose of something that is remotely
connected to the problem.
Previous commit extends simpleconfigurator to load bundles from
different locations, but such an extension breaks p2, as the content of
OSGi application no longer corresponds to profile.
In order to fix that, following things are done:
0. A fragment must contain valid P2 metadata next to the .info file.
1. User profile is dropped when there is master configuration change.
Also, when fragments are changed.
2. When a new surrogate profile is created, P2 will add to the master
profile all the units that are found in the fragments repos. Therefore
new user profile will contain all the units that were installed by the
simpleconfigurator. Fragment repos must be runnable.
3. The director application must be configured with extensions if it is
supposed to work.
Change-Id: I6e857ea51dd32ae7fab39d9c39bec8a91eb203b7
Signed-off-by: Krzysztof Daniel <kdaniel@redhat.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java')
-rw-r--r-- | bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java | 106 |
1 files changed, 99 insertions, 7 deletions
diff --git a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java index e99a0f2c1..666f5d85c 100644 --- a/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java +++ b/bundles/org.eclipse.equinox.p2.engine/src/org/eclipse/equinox/internal/p2/engine/SurrogateProfileHandler.java @@ -8,17 +8,19 @@ * Contributors: * IBM Corporation - initial API and implementation * Ericsson AB - Bug 400011 - [shared] Cleanup the SurrogateProfileHandler code + * Red Hat, Inc. - fragments support added. *******************************************************************************/ package org.eclipse.equinox.internal.p2.engine; -import java.io.File; +import java.io.*; import java.lang.ref.SoftReference; import java.net.*; -import java.util.ArrayList; -import java.util.Iterator; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.URIUtil; +import java.util.*; +import org.eclipse.core.runtime.*; +import org.eclipse.equinox.internal.p2.core.helpers.LogHelper; import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; +import org.eclipse.equinox.internal.p2.engine.ProfileParser.ProfileHandler; +import org.eclipse.equinox.internal.p2.engine.SimpleProfileRegistry.Parser; import org.eclipse.equinox.p2.core.IProvisioningAgent; import org.eclipse.equinox.p2.engine.IProfile; import org.eclipse.equinox.p2.metadata.*; @@ -26,6 +28,9 @@ import org.eclipse.equinox.p2.metadata.MetadataFactory.InstallableUnitDescriptio import org.eclipse.equinox.p2.metadata.expression.ExpressionUtil; import org.eclipse.equinox.p2.metadata.expression.IMatchExpression; import org.eclipse.equinox.p2.query.*; +import org.eclipse.equinox.p2.repository.IRepositoryManager; +import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager; +import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager; import org.eclipse.osgi.service.datalocation.Location; import org.eclipse.osgi.util.NLS; @@ -156,25 +161,112 @@ public class SurrogateProfileHandler implements ISurrogateProfileHandler { return profile; } - final IProfile profile = registry.getProfile(id, currentTimestamp); + final Profile profile = (Profile) registry.getProfile(id, currentTimestamp); if (profile != null) cachedProfile = new SoftReference<IProfile>(profile); + + if (!EngineActivator.EXTENDED) { + return profile; + } + + setUpRepos(); return profile; } + /** + * Removes repositories from fragments locations as they might be obsolete and adds them back. + */ + private void setUpRepos() { + //clean old junk + IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) agent.getService(IMetadataRepositoryManager.SERVICE_NAME); + URI[] knownRepositories = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL); + for (URI uri : knownRepositories) { + if ("true".equals(metaManager.getRepositoryProperty(uri, EngineActivator.P2_FRAGMENT_PROPERTY))) { //$NON-NLS-1$ + metaManager.removeRepository(uri); + } + } + + IArtifactRepositoryManager artifactManager = (IArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME); + knownRepositories = artifactManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_LOCAL); + for (URI uri : knownRepositories) { + if ("true".equals(artifactManager.getRepositoryProperty(uri, EngineActivator.P2_FRAGMENT_PROPERTY))) { //$NON-NLS-1$ + artifactManager.removeRepository(uri); + } + } + + File[] fragments = EngineActivator.getExtensionsDirectories(); + for (File f : fragments) { + metaManager.addRepository(f.toURI()); + metaManager.setRepositoryProperty(f.toURI(), EngineActivator.P2_FRAGMENT_PROPERTY, Boolean.TRUE.toString()); + artifactManager.addRepository(f.toURI()); + artifactManager.setRepositoryProperty(f.toURI(), EngineActivator.P2_FRAGMENT_PROPERTY, Boolean.TRUE.toString()); + } + } + /* (non-Javadoc) * @see org.eclipse.equinox.internal.p2.engine.ISurrogateProfileHandler#createProfile(java.lang.String) */ public IProfile createProfile(String id) { - final IProfile sharedProfile = getSharedProfile(id); + final Profile sharedProfile = (Profile) getSharedProfile(id); if (sharedProfile == null) return null; + if (!EngineActivator.EXTENDED) { + Profile userProfile = new Profile(agent, id, null, sharedProfile.getProperties()); + userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString()); + userProfile.setSurrogateProfileHandler(this); + updateProperties(sharedProfile, userProfile); + addSharedProfileBaseIUs(sharedProfile, userProfile); + + return userProfile; + } + + File[] extensionLocations = EngineActivator.getExtensionsDirectories(); + Set<IInstallableUnit> added = new HashSet<IInstallableUnit>(); + for (File extension : extensionLocations) { + if (extension.isDirectory()) { + File[] listFiles = extension.listFiles(new FileFilter() { + + public boolean accept(File pathname) { + if (pathname.getName().endsWith(".profile")) { //$NON-NLS-1$ + return true; + } + return false; + } + }); + for (File profileFile : listFiles) { + Parser extensionParser = profileRegistry.new Parser(EngineActivator.getContext(), EngineActivator.ID); + try { + extensionParser.parse(profileFile); + //there is only one profile as we read only one + String key = extensionParser.getProfileHandlers().keySet().iterator().next(); + + ProfileHandler extensionHandler = extensionParser.getProfileHandlers().get(key); + IInstallableUnit[] installableUnits = extensionHandler.getInstallableUnits(); + for (IInstallableUnit unit : installableUnits) { + if (!added.contains(unit)) { + added.add(unit); + sharedProfile.addInstallableUnit(unit); + } + Map<String, String> iuProperties = extensionHandler.getIUProperties(unit); + if (iuProperties != null && !iuProperties.isEmpty()) { + sharedProfile.addInstallableUnitProperties(unit, iuProperties); + } + } + } catch (IOException e) { + LogHelper.log(new Status(IStatus.ERROR, EngineActivator.ID, NLS.bind(Messages.SurrogateProfileHandler_1, profileFile), e)); + } + } + continue; + } + } + Profile userProfile = new Profile(agent, id, null, sharedProfile.getProperties()); userProfile.setProperty(PROP_SURROGATE, Boolean.TRUE.toString()); userProfile.setSurrogateProfileHandler(this); updateProperties(sharedProfile, userProfile); addSharedProfileBaseIUs(sharedProfile, userProfile); + return userProfile; } |