1 /******************************************************************************* 2 * Copyright (c) 2007, 2018 IBM Corporation and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * IBM Corporation - initial API and implementation 13 * Cloudsmith Inc. - converted into expression based query 14 *******************************************************************************/ 15 package org.eclipse.equinox.p2.engine.query; 16 17 import org.eclipse.equinox.p2.metadata.IInstallableUnit; 18 import org.eclipse.equinox.p2.metadata.expression.*; 19 import org.eclipse.equinox.p2.query.ExpressionMatchQuery; 20 21 /** 22 * A query that searches for {@link IInstallableUnit} instances that have 23 * a property associated with the specified profile, whose value matches the provided value. 24 * @since 2.0 25 */ 26 public class IUProfilePropertyQuery extends ExpressionMatchQuery<IInstallableUnit> { 27 /** 28 * A property value constant that will match any defined property value. 29 * @see #IUProfilePropertyQuery(String, String) 30 */ 31 public static final String ANY = "*"; //$NON-NLS-1$ 32 33 private static final IExpression matchValue = ExpressionUtil.parse("profileProperties[$0] == $1"); //$NON-NLS-1$ 34 private static final IExpression matchAny = ExpressionUtil.parse("profileProperties[$0] != null"); //$NON-NLS-1$ 35 createMatch(String propertyName, String propertyValue)36 private static IMatchExpression<IInstallableUnit> createMatch(String propertyName, String propertyValue) { 37 IExpressionFactory factory = ExpressionUtil.getFactory(); 38 return ANY.equals(propertyValue) ? factory.matchExpression(matchAny, propertyName) : factory.<IInstallableUnit> matchExpression(matchValue, propertyName, propertyValue); 39 } 40 41 /** 42 * Creates a new query on the given property name and value. 43 * Because the queryable for this query is typically the profile 44 * instance, we use a reference to the profile rather than the 45 * profile id for performance reasons. 46 * @param propertyName The name of the property to match 47 * @param propertyValue The value to compare to. A value of {@link #ANY} will match any value. 48 */ IUProfilePropertyQuery(String propertyName, String propertyValue)49 public IUProfilePropertyQuery(String propertyName, String propertyValue) { 50 super(IInstallableUnit.class, createMatch(propertyName, propertyValue)); 51 } 52 } 53