Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Arthorne2007-11-14 04:33:07 +0000
committerJohn Arthorne2007-11-14 04:33:07 +0000
commit2a89a6a4a42b64a4593bb0b25a94905a02d628fa (patch)
tree633152f53eb069e9bdfcc6f8f206bbae641eabdb /bundles/org.eclipse.equinox.p2.metadata
parent72003e99648d46ddd0f20ba9891b0f1fd7804693 (diff)
downloadrt.equinox.p2-2a89a6a4a42b64a4593bb0b25a94905a02d628fa.tar.gz
rt.equinox.p2-2a89a6a4a42b64a4593bb0b25a94905a02d628fa.tar.xz
rt.equinox.p2-2a89a6a4a42b64a4593bb0b25a94905a02d628fa.zip
Move ResolutionHelper and friends to director
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata')
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/ResolutionHelper.java187
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/StateMetadataMap.java34
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/Transformer.java141
-rw-r--r--bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/UnsatisfiedCapability.java56
5 files changed, 1 insertions, 420 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF
index 8675af3f1..533613ca2 100644
--- a/bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.metadata/META-INF/MANIFEST.MF
@@ -7,8 +7,7 @@ Bundle-Localization: plugin
Bundle-Version: 0.1.0.qualifier
Export-Package: org.eclipse.equinox.internal.p2.metadata;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.metadata.repository,org.eclipse.equinox.p2.engine,org.eclipse.equinox.p2.artifact.repository,org.eclipse.equinox.p2.artifact.optimizers,org.eclipse.equinox.p2.artifact.processors",
org.eclipse.equinox.p2.metadata,
- org.eclipse.equinox.p2.query,
- org.eclipse.equinox.p2.resolution
+ org.eclipse.equinox.p2.query
Import-Package: org.eclipse.osgi.service.resolver;version="1.1.0",
org.eclipse.osgi.util;version="1.1.0",
org.osgi.framework;version="1.3.0"
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/ResolutionHelper.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/ResolutionHelper.java
deleted file mode 100644
index f6a84efc6..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/ResolutionHelper.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.p2.resolution;
-
-import java.util.*;
-import org.eclipse.equinox.internal.p2.metadata.MetadataActivator;
-import org.eclipse.equinox.p2.metadata.*;
-import org.eclipse.osgi.service.resolver.*;
-import org.osgi.framework.ServiceReference;
-
-public class ResolutionHelper {
- private static final IInstallableUnitFragment[] NO_FRAGMENTS = new IInstallableUnitFragment[0];
-
- private static boolean DEBUG = false;
-
- private Transformer transformer;
- private State state;
- private Dictionary selectionContext;
- private RecommendationDescriptor recommendations;
- /**
- * Map of IInstallableUnit->(IInstallableUnitFragment) representing the
- * mapping of IUs to the fragment they are bound to.
- */
- private Map fragmentBindings;
-
- public ResolutionHelper(Dictionary selectionContext, RecommendationDescriptor recommendations) {
- this.selectionContext = selectionContext;
- this.recommendations = recommendations;
- }
-
- private void initialize() {
- ServiceReference sr = MetadataActivator.context.getServiceReference(PlatformAdmin.class.getName());
- PlatformAdmin pa = (PlatformAdmin) MetadataActivator.context.getService(sr);
- transformer = new Transformer(pa.getFactory(), selectionContext, recommendations);
- state = pa.getFactory().createState(true);
- fragmentBindings = new HashMap();
- if (selectionContext != null)
- state.setPlatformProperties(selectionContext);
- }
-
- private void addToState(BundleDescription bd) {
- state.addBundle(bd);
- }
-
- private BundleDescription addInResolution(IInstallableUnit toAdd) {
- toAdd.accept(transformer);
- // transformer.visitInstallableUnit(toAdd);
- BundleDescription descriptionToAdd = transformer.getResult();
- // bundleDescriptionToIU.put(descriptionToAdd, toAdd);
- addToState(descriptionToAdd);
- return descriptionToAdd;
- }
-
- /**
- * Indicates if the installable unit to install will have all their constraints satisfied when installed with other installable units.
- * @param toInstall the installable units to install
- * @param existingState the other installable units to resolve against
- * @return true if the installable unit to install resolves, return false otherwise.
- */
- public UnsatisfiedCapability[] install(Set toInstall, Set existingState) {
- initialize();
- BundleDescription[] addedBundle = new BundleDescription[toInstall.size()];
- int j = 0;
- for (Iterator iterator = toInstall.iterator(); iterator.hasNext();) {
- addedBundle[j++] = addInResolution((IInstallableUnit) iterator.next());
- }
-
- for (Iterator iterator = existingState.iterator(); iterator.hasNext();) {
- addInResolution((IInstallableUnit) iterator.next());
- }
-
- state.resolve(); //We may want to resolve in two times. first the existing state, then add the toInstall. This would allow to see what changes when dropping the new iu.
- //Also it could allow us to do an incremental resolution. however the results may differ
-
- ArrayList results = new ArrayList();
- for (int i = 0; i < addedBundle.length; i++) {
- results.addAll(createUnsatisfiedCapabilities(state.getStateHelper().getUnsatisfiedConstraints(addedBundle[i]), addedBundle[i]));
- }
- return (UnsatisfiedCapability[]) results.toArray(new UnsatisfiedCapability[results.size()]);
-
- }
-
- private ArrayList createUnsatisfiedCapabilities(VersionConstraint[] unsatisfied, BundleDescription description) {
- ArrayList results = new ArrayList();
- for (int i = 0; i < unsatisfied.length; i++) {
- RequiredCapability originalDependency = (RequiredCapability) ((StateMetadataMap) description.getUserObject()).getGenericSpecifications().get(unsatisfied[i]);
- results.add(new UnsatisfiedCapability(originalDependency, ((StateMetadataMap) description.getUserObject()).getUnit()));
- }
- return results;
- }
-
- /**
- * Associates installable unit fragments to each IU being installed.
- *
- * TODO: This method should probably be renamed to attachFragments
- */
- public Collection attachCUs(Collection toAttach) {
- initialize();
- for (Iterator iterator = toAttach.iterator(); iterator.hasNext();) {
- addInResolution((IInstallableUnit) iterator.next());
- }
- state.resolve();
- BundleDescription[] bds = state.getBundles();
- for (int i = 0; i < bds.length; i++) {
- if (DEBUG) {
- ResolverError[] re = state.getResolverErrors(bds[i]);
- for (int j = 0; j < re.length; j++) {
- System.out.println(re[j]);
- }
- }
- BundleDescription[] potentialIUFragments = state.getStateHelper().getDependentBundles(new BundleDescription[] {bds[i]});
- // TODO: We need to define a way to allow IUFragments to work together to do configuration work.
- // For now we will select just one fragment by preferring a fragment that matches the host
-
- IInstallableUnit hostIU = ((StateMetadataMap) bds[i].getUserObject()).getUnit();
- IInstallableUnitFragment selectedFragment = null;
- for (int k = 0; k < potentialIUFragments.length; k++) {
- IInstallableUnit dependentIU = ((StateMetadataMap) potentialIUFragments[k].getUserObject()).getUnit();
- if (hostIU.equals(dependentIU))
- continue;
-
- if (dependentIU.isFragment()) {
- IInstallableUnitFragment potentialFragment = (IInstallableUnitFragment) dependentIU;
-
- if (potentialFragment.getHostId() == null) {
- // default fragment - we'll mark it selected but keep looking for a fragment that matches the host
- selectedFragment = potentialFragment;
- } else if (potentialFragment.getHostId().equals(hostIU.getId()) && potentialFragment.getHostVersionRange().isIncluded(hostIU.getVersion())) {
- // matches host - we're done
- selectedFragment = potentialFragment;
- break;
- } // otherwise keep looking
- }
- }
- if (selectedFragment != null)
- fragmentBindings.put(hostIU, selectedFragment);
- }
- //build the collection of resolved IUs
- Collection result = new HashSet(toAttach.size());
- for (Iterator iterator = toAttach.iterator(); iterator.hasNext();) {
- IInstallableUnit iu = (IInstallableUnit) iterator.next();
- IInstallableUnitFragment fragment = (IInstallableUnitFragment) fragmentBindings.get(iu);
- IInstallableUnitFragment[] fragments;
- if (fragment == null)
- fragments = NO_FRAGMENTS;
- else
- fragments = new IInstallableUnitFragment[] {fragment};
- result.add(MetadataFactory.createResolvedInstallableUnit(iu, fragments));
- }
- return result;
- }
-
- public boolean isResolved(IInstallableUnit iu) {
- return state.getBundle(iu.getId(), iu.getVersion()).isResolved();
- }
-
- public ArrayList getAllResolved() {
- BundleDescription[] bd = state.getResolvedBundles();
- ArrayList result = new ArrayList(bd.length);
- for (int i = 0; i < bd.length; i++) {
- result.add(extractIU(bd[i]));
- }
- return result;
- }
-
- private IInstallableUnit extractIU(BundleDescription bd) {
- return ((StateMetadataMap) bd.getUserObject()).getUnit();
- }
-
- public List getSorted() {
- BundleDescription[] toSort = state.getResolvedBundles();
- state.getStateHelper().sortBundles(toSort);
- List result = new ArrayList(toSort.length);
- for (int i = 0; i < toSort.length; i++) {
- result.add(extractIU(toSort[i]));
- }
- return result;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/StateMetadataMap.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/StateMetadataMap.java
deleted file mode 100644
index 9d29bc5d5..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/StateMetadataMap.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.equinox.p2.resolution;
-
-import java.util.Map;
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-
-//Instances of this class are stored in the user object slot of bundlescriptions to ease navigation between the two models.
-public class StateMetadataMap {
- private IInstallableUnit unit;
- private Map correspondingSpecifications; //indexes in this array maps to the ones in the dependencies array. This is gross. TODO
-
- public StateMetadataMap(IInstallableUnit unit, Map correspondingSpecifications) {
- super();
- this.unit = unit;
- this.correspondingSpecifications = correspondingSpecifications;
- }
-
- public IInstallableUnit getUnit() {
- return unit;
- }
-
- public Map getGenericSpecifications() {
- return correspondingSpecifications;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/Transformer.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/Transformer.java
deleted file mode 100644
index 2afb99c84..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/Transformer.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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 http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.p2.resolution;
-
-import java.util.*;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.metadata.MetadataActivator;
-import org.eclipse.equinox.p2.metadata.*;
-import org.eclipse.osgi.service.resolver.*;
-import org.osgi.framework.InvalidSyntaxException;
-
-public class Transformer implements IMetadataVisitor {
- private static final byte IU_KIND = 0;
- private static final String IU_NAMESPACE = "iu.namespace";
- static long iuInternalId = 0;
-
- private Dictionary context = null;
- private StateObjectFactory factory = null;
- private ArrayList iuCapabilities;
- private Map iuDependencies;
- private byte kind = IU_KIND;
-
- private BundleDescription result = null;
-
- private RecommendationDescriptor recommendations = null;
-
- public Transformer(StateObjectFactory factory) {
- this(factory, null, null);
- }
-
- public Transformer(StateObjectFactory factory, Dictionary context, RecommendationDescriptor recommendations) {
- this.factory = factory;
- this.context = context;
- this.recommendations = recommendations;
- }
-
- private String getNamespace() {
- switch (kind) {
- case IU_KIND :
- return IU_NAMESPACE;
- default :
- throw new IllegalStateException("unknown kind"); //This should not happen
- }
- }
-
- public BundleDescription getResult() {
- return result;
- }
-
- private boolean isEnabled(RequiredCapability capability) {
- // If there is no context then be optimistic
- if (context == null)
- return true;
- String filter = capability.getFilter();
- if (filter == null)
- return true;
- try {
- return MetadataActivator.getContext().createFilter(filter).match(context);
- } catch (InvalidSyntaxException e) {
- // If we fail to parse the filter treat it as invalid and be optimistic
- return true;
- }
- }
-
- private String toFilter(VersionRange range) {
- if (range == null)
- return null;
- StringBuffer buf = new StringBuffer();
- buf.append("(&"); //$NON-NLS-1$
- buf.append("(version>=").append(range.getMinimum().toString()).append(')'); //$NON-NLS-1$
- if (!range.getIncludeMinimum())
- buf.append("(!(version=").append(range.getMinimum().toString()).append("))");
- buf.append("(version<=").append(range.getMaximum().toString()).append(')'); //$NON-NLS-1$
- if (!range.getIncludeMaximum())
- buf.append("(!(version=").append(range.getMaximum().toString()).append("))");
- buf.append(')');
- return buf.toString();
- }
-
- public void visitCapability(ProvidedCapability capability) {
- iuCapabilities.add(factory.createGenericDescription(capability.getName(), capability.getNamespace(), capability.getVersion(), null));
- }
-
- public void visitInstallableUnit(IInstallableUnit toTransform) {
- kind = IU_KIND;
-
- //Start with the dependencies
- RequiredCapability[] requires = toTransform.getRequiredCapabilities();
- iuDependencies = new HashMap(requires.length);
- for (int i = 0; i < requires.length; i++) {
- requires[i].accept(this);
- }
-
- //Do the capabilities
- ProvidedCapability[] capabilities = toTransform.getProvidedCapabilities();
- iuCapabilities = new ArrayList(requires.length + 1);
- for (int i = 0; i < capabilities.length; i++) {
- capabilities[i].accept(this);
- }
-
- //Add a capability representing the IU itself
- iuCapabilities.add(factory.createGenericDescription(toTransform.getId(), getNamespace(), toTransform.getVersion(), null));
-
- GenericSpecification[] genericSpecifications = new GenericSpecification[iuDependencies.size()];
- iuDependencies.keySet().toArray(genericSpecifications);
-
- GenericDescription[] genericDescriptions = new GenericDescription[iuCapabilities.size()];
- iuCapabilities.toArray(genericDescriptions);
-
- //Finally create the bundle description
- //TODO Need to create the filter for the IU itself
- result = factory.createBundleDescription(iuInternalId++, toTransform.getId(), toTransform.getVersion(), (String) null, (BundleSpecification[]) null, (HostSpecification) null, (ImportPackageSpecification[]) null, (ExportPackageDescription[]) null, toTransform.isSingleton(), true, true, toTransform.getFilter(), (String[]) null, genericSpecifications, genericDescriptions);
- result.setUserObject(new StateMetadataMap(toTransform, iuDependencies));
- }
-
- public void visitRequiredCapability(RequiredCapability capability) {
- try {
- if (isEnabled(capability)) {
- capability = rewrite(capability);
- iuDependencies.put(factory.createGenericSpecification(capability.getName(), capability.getNamespace(), toFilter(capability.getRange()), capability.isOptional(), capability.isMultiple()), capability);
- }
- } catch (InvalidSyntaxException e) {
- LogHelper.log(new Status(IStatus.ERROR, MetadataActivator.PI_METADATA, "Invalid filter: " + e.getFilter(), e)); //$NON-NLS-1$
- }
- }
-
- private RequiredCapability rewrite(RequiredCapability match) {
- if (recommendations == null)
- return match;
- Recommendation foundRecommendation = recommendations.findRecommendation(match);
- return foundRecommendation != null ? foundRecommendation.newValue() : match;
- }
-}
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/UnsatisfiedCapability.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/UnsatisfiedCapability.java
deleted file mode 100644
index 024b776b2..000000000
--- a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/p2/resolution/UnsatisfiedCapability.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 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 http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors: IBM Corporation - initial API and implementation
- ******************************************************************************/
-package org.eclipse.equinox.p2.resolution;
-
-import org.eclipse.equinox.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.p2.metadata.RequiredCapability;
-
-/**
- * Represents a provisioning dependency that was not satisfied during
- * resolution.
- */
-public class UnsatisfiedCapability {
- private IInstallableUnit owner;
- private RequiredCapability require;
-
- /**
- * Creates a new unresolved dependency
- * @param required The dependency that was not satisfied.
- * @param owner The installable unit whose dependency was not satisfied.
- */
- public UnsatisfiedCapability(RequiredCapability required, IInstallableUnit owner) {
- this.require = required;
- this.owner = owner;
- }
-
- public IInstallableUnit getOwner() {
- return owner;
- }
-
- /**
- * Returns the specific dependency that was not satisfied.
- */
- public RequiredCapability getRequiredCapability() {
- return require;
- }
-
- /**
- * Returns the installable unit whose dependency was not satisfied.
- */
- public IInstallableUnit getUnsatisfiedUnit() {
- return owner;
- }
-
- /**
- * For debugging purposes only.
- */
- public String toString() {
- return "[" + owner + "] " + require.toString(); //$NON-NLS-1$ //$NON-NLS-2$
- }
-}

Back to the top