diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query')
4 files changed, 164 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/IUPropertyQuery.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/IUPropertyQuery.java new file mode 100644 index 000000000..95f3f3375 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/IUPropertyQuery.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2007, 2009 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.internal.p2.metadata.query; + +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.query.MatchQuery; + +/** + * A query that searches for {@link IInstallableUnit} instances that have + * a property whose value matches the provided value. If no property name is + * specified, then all {@link IInstallableUnit} instances are accepted. + */ +public class IUPropertyQuery extends MatchQuery<IInstallableUnit> { + private String propertyName; + private String propertyValue; + + /** + * Creates a new query on the given property name and value. + */ + public IUPropertyQuery(String propertyName, String propertyValue) { + this.propertyName = propertyName; + this.propertyValue = propertyValue; + } + + /* (non-Javadoc) + * @see org.eclipse.equinox.p2.query2.Query#isMatch(java.lang.Object) + */ + public boolean isMatch(IInstallableUnit candidate) { + if (propertyName == null) + return true; + String value = getProperty(candidate, propertyName); + if (value != null && (value.equals(propertyValue) || propertyValue == null)) + return true; + return false; + } + + protected String getProperty(IInstallableUnit iu, String name) { + return iu.getProperty(name); + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/LatestIUVersionQuery.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/LatestIUVersionQuery.java new file mode 100644 index 000000000..fe79d9404 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/LatestIUVersionQuery.java @@ -0,0 +1,48 @@ +/******************************************************************************* +* Copyright (c) 2009 EclipseSource 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: +* EclipseSource - initial API and implementation +******************************************************************************/ +package org.eclipse.equinox.internal.p2.metadata.query; + +import java.util.*; +import org.eclipse.equinox.p2.metadata.IVersionedId; +import org.eclipse.equinox.p2.query.*; + +/** + * This query returns the latest version for each unique VersionedID. + * All other elements are discarded. + */ +public class LatestIUVersionQuery<T extends IVersionedId> extends ContextQuery<T> { + + /** + * Performs the LatestIUVersionQuery + */ + public IQueryResult<T> perform(Iterator<T> iterator) { + HashMap<String, T> greatestIUVersion = new HashMap<String, T>(); + while (iterator.hasNext()) { + T versionedID = iterator.next(); + if (greatestIUVersion.containsKey(versionedID.getId())) { + T currentIU = greatestIUVersion.get(versionedID.getId()); + if (currentIU.getVersion().compareTo(versionedID.getVersion()) < 0) + greatestIUVersion.put(versionedID.getId(), versionedID); + } else + greatestIUVersion.put(versionedID.getId(), versionedID); + } + + Collection<T> values = greatestIUVersion.values(); + Iterator<T> valuesIterator = values.iterator(); + boolean continueGather = true; + + Collector<T> result = new Collector<T>(); + while (valuesIterator.hasNext() && continueGather) { + T nextIU = valuesIterator.next(); + continueGather = result.accept(nextIU); + } + return result; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/ObjectMatchQuery.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/ObjectMatchQuery.java new file mode 100644 index 000000000..f48e50aac --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/ObjectMatchQuery.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 Cloudsmith Inc. 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: + * Cloudsmith Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.equinox.internal.p2.metadata.query; + +import org.eclipse.equinox.p2.query.MatchQuery; + +/** + * Special implementation for use without generic support + */ +public abstract class ObjectMatchQuery extends MatchQuery<Object> { + public boolean isMatch(Object candidate) { + return true; + } +} diff --git a/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/UpdateQuery.java b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/UpdateQuery.java new file mode 100644 index 000000000..2a58b8bf9 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.metadata/src/org/eclipse/equinox/internal/p2/metadata/query/UpdateQuery.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2008, 2009 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.internal.p2.metadata.query; + +import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnitPatch; +import org.eclipse.equinox.internal.provisional.p2.metadata.IUpdateDescriptor; +import org.eclipse.equinox.p2.metadata.IInstallableUnit; +import org.eclipse.equinox.p2.metadata.IRequirement; +import org.eclipse.equinox.p2.query.MatchQuery; + +/** + * A query that finds all IUs that are considered an "Update" of the + * specified IU. + */ +public class UpdateQuery extends MatchQuery<IInstallableUnit> { + private IInstallableUnit updateFrom; + + public UpdateQuery(IInstallableUnit updateFrom) { + this.updateFrom = updateFrom; + } + + public boolean isMatch(IInstallableUnit candidate) { + if (candidate instanceof IInstallableUnitPatch && !(updateFrom instanceof IInstallableUnitPatch)) { + IInstallableUnitPatch potentialPatch = (IInstallableUnitPatch) candidate; + IRequirement lifeCycle = potentialPatch.getLifeCycle(); + if (lifeCycle == null) + return false; + return updateFrom.satisfies(lifeCycle); + } + IUpdateDescriptor descriptor = candidate.getUpdateDescriptor(); + if (descriptor != null && descriptor.isUpdateOf(updateFrom)) { + if (!updateFrom.getId().equals(candidate.getId())) + return true; + return updateFrom.getVersion().compareTo(candidate.getVersion()) < 0; + } + return false; + } +} |