View | Details | Raw Unified | Return to bug 301658
Collapse All | Expand All

(-)META-INF/MANIFEST.MF (-1 lines)
Lines 54-60 Link Here
54
   org.eclipse.pde.ui,
54
   org.eclipse.pde.ui,
55
   org.eclipse.equinox.p2.repository.tools,
55
   org.eclipse.equinox.p2.repository.tools,
56
   org.eclipse.pde.core",
56
   org.eclipse.pde.core",
57
 org.eclipse.equinox.internal.p2.query;x-friends:="org.eclipse.equinox.p2.ql,org.eclipse.equinox.p2.ui",
58
 org.eclipse.equinox.internal.provisional.p2.metadata;
57
 org.eclipse.equinox.internal.provisional.p2.metadata;
59
  x-friends:="org.eclipse.equinox.p2.artifact.optimizers,
58
  x-friends:="org.eclipse.equinox.p2.artifact.optimizers,
60
   org.eclipse.equinox.p2.artifact.processors,
59
   org.eclipse.equinox.p2.artifact.processors,
(-)src/org/eclipse/equinox/internal/p2/query/QueryHelpers.java (-58 lines)
Removed Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
******************************************************************************/
10
package org.eclipse.equinox.internal.p2.query;
11
12
13
import java.lang.reflect.InvocationTargetException;
14
import java.lang.reflect.Method;
15
import org.eclipse.equinox.p2.query.IQuery;
16
17
/**
18
 * Static helper methods for the Query API.
19
 * 
20
 * @noextend This class is not intended to be subclassed by clients.
21
 */
22
public class QueryHelpers {
23
	/**
24
	 * Gets the ID for a Query. 
25
	 * 
26
	 * @noreference This method is not intended to be referenced by clients.
27
	 */
28
	public static String getId(IQuery<?> query) {
29
		return query.getClass().getName();
30
	}
31
32
	/**
33
	 * Gets a particular property of a query.
34
	 * @param query The query to retrieve the property from
35
	 * @param property The property to retrieve 
36
	 * 
37
	 * @noreference This method is not intended to be referenced by clients.
38
	 */
39
	public static Object getProperty(IQuery<?> query, String property) {
40
		Class<?> clazz = query.getClass();
41
		Object result = null;
42
		try {
43
			Method method = clazz.getMethod("get" + property, new Class[0]); //$NON-NLS-1$
44
			result = method.invoke(query, new Object[0]);
45
		} catch (SecurityException e) {
46
			return null;
47
		} catch (NoSuchMethodException e) {
48
			return null;
49
		} catch (IllegalArgumentException e) {
50
			return null;
51
		} catch (IllegalAccessException e) {
52
			return null;
53
		} catch (InvocationTargetException e) {
54
			return null;
55
		}
56
		return result;
57
	}
58
}
(-)src/org/eclipse/equinox/p2/query/CompoundQuery.java (-16 lines)
Lines 14-20 Link Here
14
import java.lang.reflect.Array;
14
import java.lang.reflect.Array;
15
import java.util.*;
15
import java.util.*;
16
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
17
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
18
17
19
/**
18
/**
20
 * A query that combines a group of sub-queries.<P>
19
 * A query that combines a group of sub-queries.<P>
Lines 97-117 Link Here
97
	}
96
	}
98
97
99
	/**
98
	/**
100
	 * Gets the ID for this Query. 
101
	 */
102
	public String getId() {
103
		return QueryHelpers.getId(this);
104
	}
105
106
	/**
107
	 * Gets a particular property of the query.
108
	 * @param property The property to retrieve 
109
	 */
110
	public Object getProperty(String property) {
111
		return QueryHelpers.getProperty(this, property);
112
	}
113
114
	/**
115
	 * The compound query instantiated when all queries are Match Queries.
99
	 * The compound query instantiated when all queries are Match Queries.
116
	 */
100
	 */
117
	private static class MatchCompoundQuery<T> extends CompoundQuery<T> implements IMatchQuery<T> {
101
	private static class MatchCompoundQuery<T> extends CompoundQuery<T> implements IMatchQuery<T> {
(-)src/org/eclipse/equinox/p2/query/ContextQuery.java (-15 lines)
Lines 10-16 Link Here
10
package org.eclipse.equinox.p2.query;
10
package org.eclipse.equinox.p2.query;
11
11
12
import java.util.Iterator;
12
import java.util.Iterator;
13
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
14
13
15
/**
14
/**
16
 * ContextQuery is the abstract superclass for Queries that require the entire
15
 * ContextQuery is the abstract superclass for Queries that require the entire
Lines 43-60 Link Here
43
	 */
42
	 */
44
	public abstract IQueryResult<T> perform(Iterator<T> iterator);
43
	public abstract IQueryResult<T> perform(Iterator<T> iterator);
45
44
46
	/**
47
	 * Gets the ID for this Query. 
48
	 */
49
	public String getId() {
50
		return QueryHelpers.getId(this);
51
	}
52
53
	/**
54
	 * Gets a particular property of the query.
55
	 * @param property The property to retrieve 
56
	 */
57
	public Object getProperty(String property) {
58
		return QueryHelpers.getProperty(this, property);
59
	}
60
}
45
}
(-)src/org/eclipse/equinox/p2/query/IQuery.java (-13 lines)
Lines 39-55 Link Here
39
	 */
39
	 */
40
	public abstract IQueryResult<T> perform(Iterator<T> iterator);
40
	public abstract IQueryResult<T> perform(Iterator<T> iterator);
41
41
42
	/**
43
	 * Gets a unique identifier for this query.
44
	 * @return a unique identifier for this query
45
	 */
46
	public String getId();
47
48
	/**
49
	 * Gets a particular property of the query.
50
	 * @param property The property to retrieve 
51
	 * @return The value of the retrieved property, or <code>null</code>
52
	 * if no such property is defined.
53
	 */
54
	public Object getProperty(String property);
55
}
42
}
(-)src/org/eclipse/equinox/p2/query/MatchQuery.java (-16 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.p2.query;
11
package org.eclipse.equinox.p2.query;
12
12
13
import java.util.Iterator;
13
import java.util.Iterator;
14
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
15
14
16
/**
15
/**
17
 * This class represents the superclass of most of p2's queries.  Every element
16
 * This class represents the superclass of most of p2's queries.  Every element
Lines 41-61 Link Here
41
	public abstract boolean isMatch(T candidate);
40
	public abstract boolean isMatch(T candidate);
42
41
43
	/**
42
	/**
44
	 * Gets the ID for this Query. 
45
	 */
46
	public String getId() {
47
		return QueryHelpers.getId(this);
48
	}
49
50
	/**
51
	 * Gets a particular property of the query.
52
	 * @param property The property to retrieve 
53
	 */
54
	public Object getProperty(String property) {
55
		return QueryHelpers.getProperty(this, property);
56
	}
57
58
	/**
59
	 * Performs this query on the given iterator, passing all objects in the iterator 
43
	 * Performs this query on the given iterator, passing all objects in the iterator 
60
	 * that match the criteria of this query to the given result.
44
	 * that match the criteria of this query to the given result.
61
	 */
45
	 */
(-)src/org/eclipse/equinox/p2/query/PipedQuery.java (-15 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.p2.query;
11
package org.eclipse.equinox.p2.query;
12
12
13
import java.util.*;
13
import java.util.*;
14
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
15
14
16
/**
15
/**
17
 * A PipedQuery is a composite query in which each sub-query is executed in succession.  
16
 * A PipedQuery is a composite query in which each sub-query is executed in succession.  
Lines 47-66 Link Here
47
	}
46
	}
48
47
49
	/*(non-Javadoc)
48
	/*(non-Javadoc)
50
	 * @see org.eclipse.equinox.p2.query.IQuery#getId()
51
	 */
52
	public String getId() {
53
		return QueryHelpers.getId(this);
54
	}
55
56
	/*(non-Javadoc)
57
	 * @see org.eclipse.equinox.p2.query.IQuery#getProperty(java.lang.String)
58
	 */
59
	public Object getProperty(String property) {
60
		return QueryHelpers.getProperty(this, property);
61
	}
62
63
	/*(non-Javadoc)
64
	 * @see org.eclipse.equinox.p2.query.ICompositeQuery#getQueries()
49
	 * @see org.eclipse.equinox.p2.query.ICompositeQuery#getQueries()
65
	 */
50
	 */
66
	public List<IQuery<T>> getQueries() {
51
	public List<IQuery<T>> getQueries() {
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 14-20 Link Here
14
 org.eclipse.equinox.internal.p2.metadata,
14
 org.eclipse.equinox.internal.p2.metadata,
15
 org.eclipse.equinox.internal.p2.metadata.expression,
15
 org.eclipse.equinox.internal.p2.metadata.expression,
16
 org.eclipse.equinox.internal.p2.metadata.expression.parser,
16
 org.eclipse.equinox.internal.p2.metadata.expression.parser,
17
 org.eclipse.equinox.internal.p2.query,
18
 org.eclipse.equinox.internal.provisional.p2.metadata,
17
 org.eclipse.equinox.internal.provisional.p2.metadata,
19
 org.eclipse.equinox.p2.metadata,
18
 org.eclipse.equinox.p2.metadata,
20
 org.eclipse.equinox.p2.metadata.expression,
19
 org.eclipse.equinox.p2.metadata.expression,
(-)src/org/eclipse/equinox/p2/ql/QLQuery.java (-11 lines)
Lines 11-17 Link Here
11
package org.eclipse.equinox.p2.ql;
11
package org.eclipse.equinox.p2.ql;
12
12
13
import java.util.Locale;
13
import java.util.Locale;
14
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
15
import org.eclipse.equinox.p2.query.IQuery;
14
import org.eclipse.equinox.p2.query.IQuery;
16
15
17
/**
16
/**
Lines 34-47 Link Here
34
		this.locale = locale;
33
		this.locale = locale;
35
	}
34
	}
36
35
37
	/**
38
	 * Gets the ID for this Query. 
39
	 */
40
	public String getId() {
41
		return QueryHelpers.getId(this);
42
	}
43
44
	public Object getProperty(String property) {
45
		return QueryHelpers.getProperty(this, property);
46
	}
47
}
36
}
(-)src/org/eclipse/equinox/p2/tests/core/PropertyLookupQuery1.java (-27 lines)
Removed Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
******************************************************************************/
10
package org.eclipse.equinox.p2.tests.core;
11
12
import org.eclipse.equinox.p2.query.MatchQuery;
13
14
public class PropertyLookupQuery1 extends MatchQuery {
15
16
	public String getSomeProperty() {
17
		return "foo";
18
	}
19
20
	public String getThatProperty(Object param) {
21
		return "bar";
22
	}
23
24
	public boolean isMatch(Object candidate) {
25
		return false;
26
	}
27
}
(-)src/org/eclipse/equinox/p2/tests/core/PropertyLookupQuery2.java (-25 lines)
Removed Link Here
1
/******************************************************************************* 
2
* Copyright (c) 2009 EclipseSource and others. All rights reserved. This
3
* program and the accompanying materials are made available under the terms of
4
* the Eclipse Public License v1.0 which accompanies this distribution, and is
5
* available at http://www.eclipse.org/legal/epl-v10.html
6
*
7
* Contributors:
8
*   EclipseSource - initial API and implementation
9
******************************************************************************/
10
package org.eclipse.equinox.p2.tests.core;
11
12
import java.util.Iterator;
13
import org.eclipse.equinox.p2.query.Collector;
14
import org.eclipse.equinox.p2.query.ContextQuery;
15
16
public class PropertyLookupQuery2 extends ContextQuery {
17
18
	public String getSomeOtherProperty() {
19
		return "bar";
20
	}
21
22
	public Collector perform(Iterator iterator) {
23
		return null;
24
	}
25
}
(-)src/org/eclipse/equinox/p2/tests/core/QueryTest.java (-31 lines)
Lines 99-135 Link Here
99
		assertTrue("1.4", query.areHooksExecutedProperly());
99
		assertTrue("1.4", query.areHooksExecutedProperly());
100
	}
100
	}
101
101
102
	public void testPropertyLookupMatchQuery() {
103
		IQuery query1 = new PropertyLookupQuery1();
104
		Object property = query1.getProperty("SomeProperty");
105
		assertEquals("1.0", "foo", property);
106
	}
107
108
	public void testPropertyLookupContextQuery() {
109
		IQuery query1 = new PropertyLookupQuery2();
110
		Object property = query1.getProperty("SomeOtherProperty");
111
		assertEquals("1.0", "bar", property);
112
	}
113
114
	public void testPropertyLookupInvalidProperty1() {
115
		IQuery query1 = new PropertyLookupQuery1();
116
		Object property = query1.getProperty("ThisProperty");
117
		assertEquals("1.0", null, property);
118
	}
119
120
	public void testPropertyLookupInvalidProperty2() {
121
		IQuery query1 = new PropertyLookupQuery1();
122
		Object property = query1.getProperty("SomeOtherProperty");
123
		assertEquals("1.0", null, property);
124
	}
125
126
	public void testIDLookup() {
127
		IQuery query1 = new PropertyLookupQuery1();
128
		IQuery query2 = new PropertyLookupQuery2();
129
		assertEquals("1.0", "org.eclipse.equinox.p2.tests.core.PropertyLookupQuery1", query1.getId());
130
		assertEquals("1.0", "org.eclipse.equinox.p2.tests.core.PropertyLookupQuery2", query2.getId());
131
	}
132
133
	public void testPerformHooksOnQueryFail() {
102
	public void testPerformHooksOnQueryFail() {
134
		List items = Arrays.asList("red", new Object());
103
		List items = Arrays.asList("red", new Object());
135
		PerformHookQuery query = new PerformHookQuery();
104
		PerformHookQuery query = new PerformHookQuery();
(-)META-INF/MANIFEST.MF (-1 lines)
Lines 13-19 Link Here
13
 org.eclipse.equinox.internal.p2.metadata,
13
 org.eclipse.equinox.internal.p2.metadata,
14
 org.eclipse.equinox.internal.p2.metadata.query,
14
 org.eclipse.equinox.internal.p2.metadata.query,
15
 org.eclipse.equinox.internal.p2.metadata.repository,
15
 org.eclipse.equinox.internal.p2.metadata.repository,
16
 org.eclipse.equinox.internal.p2.query,
17
 org.eclipse.equinox.internal.p2.repository.helpers,
16
 org.eclipse.equinox.internal.p2.repository.helpers,
18
 org.eclipse.equinox.internal.provisional.configurator,
17
 org.eclipse.equinox.internal.provisional.configurator,
19
 org.eclipse.equinox.internal.provisional.p2.core,
18
 org.eclipse.equinox.internal.provisional.p2.core,
(-)src/org/eclipse/equinox/internal/p2/ui/RepositoryLocationQuery.java (-16 lines)
Lines 13-19 Link Here
13
13
14
import java.net.URI;
14
import java.net.URI;
15
import java.util.Iterator;
15
import java.util.Iterator;
16
import org.eclipse.equinox.internal.p2.query.QueryHelpers;
17
import org.eclipse.equinox.p2.query.*;
16
import org.eclipse.equinox.p2.query.*;
18
import org.eclipse.equinox.p2.repository.IRepository;
17
import org.eclipse.equinox.p2.repository.IRepository;
19
18
Lines 27-47 Link Here
27
 */
26
 */
28
public class RepositoryLocationQuery implements IQuery<URI> {
27
public class RepositoryLocationQuery implements IQuery<URI> {
29
28
30
	/**
31
	 * Gets the ID for this Query. 
32
	 */
33
	public String getId() {
34
		return QueryHelpers.getId(this);
35
	}
36
37
	/**
38
	 * Gets a particular property of the query.
39
	 * @param property The property to retrieve 
40
	 */
41
	public Object getProperty(String property) {
42
		return QueryHelpers.getProperty(this, property);
43
	}
44
45
	public IQueryResult<URI> perform(Iterator<URI> iterator) {
29
	public IQueryResult<URI> perform(Iterator<URI> iterator) {
46
		Collector<URI> result = new Collector<URI>();
30
		Collector<URI> result = new Collector<URI>();
47
		while (iterator.hasNext()) {
31
		while (iterator.hasNext()) {

Return to bug 301658