Skip to main content
summaryrefslogtreecommitdiffstats
blob: f3bb80943ba43e931439ed50e3ff746893d284c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*******************************************************************************
 * Copyright (c) 2007, 2008 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.provisional.p2.ui;

import java.net.URI;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.ui.ProvUIActivator;
import org.eclipse.equinox.internal.p2.ui.ProvUIMessages;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IArtifactRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.core.repository.IRepositoryManager;
import org.eclipse.equinox.internal.provisional.p2.query.*;
import org.eclipse.ui.statushandlers.StatusManager;

/**
 * An object that adds queryable support to an artifact repository 
 * manager.  It can be constructed to filter the repositories according to repository filter
 * flags.  When a query is provided, the object being queried is repository URL.
 * Callers interested in only the resulting repository URL's can specify a null query, 
 * in which case the collector will be accepting all iterated URL's.
 */
public class QueryableArtifactRepositoryManager implements IQueryable {

	int flags = IRepositoryManager.REPOSITORIES_ALL;

	public QueryableArtifactRepositoryManager(int flags) {
		this.flags = flags;
	}

	/**
	 * Iterates over the artifact repositories configured in this queryable.
	 * If a query is specified, the query is run on each URI, passing any URIs that satisfy the
	 * query to the provided collector.  If no query is specified, all repository URIs iterated are passed
	 * to the collector.
	 * <p>
	 * This method is long-running; progress and cancellation are provided
	 * by the given progress monitor. 
	 * </p>
	 * 
	 * @param query The query to perform on the URIs, or <code>null</code> if all URIs should
	 * be accepted.
	 * @param result Collects the repository URIs
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting is not desired
	 * @return The collector argument
	 */
	public Collector query(Query query, Collector result, IProgressMonitor monitor) {
		IArtifactRepositoryManager manager = (IArtifactRepositoryManager) ServiceHelper.getService(ProvUIActivator.getContext(), IArtifactRepositoryManager.class.getName());
		if (manager == null) {
			ProvUI.reportStatus(new Status(IStatus.ERROR, ProvUIActivator.PLUGIN_ID, ProvUIMessages.ProvisioningUtil_NoRepositoryManager), StatusManager.SHOW | StatusManager.LOG);
			return result;
		}
		URI[] repoLocations = manager.getKnownRepositories(flags);
		if (monitor == null)
			monitor = new NullProgressMonitor();
		monitor.beginTask(ProvUIMessages.QueryableArtifactRepositoryManager_RepositoryQueryProgress, repoLocations.length);
		for (int i = 0; i < repoLocations.length; i++) {
			if (query == null || query.isMatch(repoLocations[i]))
				result.accept(repoLocations[i]);
			monitor.worked(1);
		}
		monitor.done();
		return result;
	}
}

Back to the top