1810
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.carbide.internal.discovery.ui.wizard;
|
|
18 |
|
|
19 |
import java.net.URI;
|
|
20 |
import java.util.Arrays;
|
|
21 |
import java.util.Collection;
|
|
22 |
import java.util.HashSet;
|
|
23 |
import java.util.Iterator;
|
|
24 |
import java.util.Set;
|
|
25 |
|
|
26 |
import org.eclipse.core.runtime.IProgressMonitor;
|
|
27 |
import org.eclipse.equinox.p2.core.IProvisioningAgent;
|
|
28 |
import org.eclipse.equinox.p2.engine.IProfile;
|
|
29 |
import org.eclipse.equinox.p2.engine.IProfileRegistry;
|
|
30 |
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
|
|
31 |
import org.eclipse.equinox.p2.operations.ProvisioningSession;
|
|
32 |
import org.eclipse.equinox.p2.query.IQueryResult;
|
|
33 |
import org.eclipse.equinox.p2.query.QueryUtil;
|
|
34 |
import org.eclipse.equinox.p2.ui.ProvisioningUI;
|
|
35 |
|
1818
|
36 |
class P2Utils {
|
1810
|
37 |
|
|
38 |
public static Collection<URI> getKnownRepositories() {
|
|
39 |
ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
|
|
40 |
ProvisioningSession session = provisioningUI.getSession();
|
|
41 |
URI[] uris = provisioningUI.getRepositoryTracker().getKnownRepositories(session);
|
|
42 |
return Arrays.asList(uris);
|
|
43 |
}
|
|
44 |
|
|
45 |
public static Collection<FeatureInfo> getInstalledFeatures(IProgressMonitor monitor) {
|
|
46 |
Set<FeatureInfo> infos = new HashSet<FeatureInfo>();
|
|
47 |
ProvisioningUI provisioningUI = ProvisioningUI.getDefaultUI();
|
|
48 |
ProvisioningSession session = provisioningUI.getSession();
|
|
49 |
IProvisioningAgent agent = session.getProvisioningAgent();
|
|
50 |
IProfileRegistry profileRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
|
|
51 |
IProfile profile = null;
|
|
52 |
if (profileRegistry != null) {
|
|
53 |
profile = profileRegistry.getProfile(provisioningUI.getProfileId());
|
|
54 |
if (profile != null) {
|
|
55 |
IQueryResult<IInstallableUnit> result =
|
|
56 |
profile.query(QueryUtil.createIUGroupQuery(), monitor);
|
|
57 |
for (Iterator<IInstallableUnit> iterator = result.iterator(); iterator.hasNext();) {
|
|
58 |
infos.add(new FeatureInfo((IInstallableUnit) iterator.next()));
|
|
59 |
}
|
|
60 |
}
|
|
61 |
}
|
|
62 |
return infos;
|
|
63 |
}
|
|
64 |
}
|