Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5923b22118039bd06728319bc4c5a757591a2033 (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
74
75
76
77
78
79
80
/*******************************************************************************
 *  Copyright (c) 2005, 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.p2.tests.full;

import org.eclipse.equinox.internal.p2.director.ProfileChangeRequest;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.engine.IProfile;
import org.eclipse.equinox.p2.engine.ProvisioningContext;
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
import org.eclipse.equinox.p2.planner.IPlanner;
import org.eclipse.equinox.p2.query.*;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
import org.eclipse.equinox.p2.tests.TestActivator;
import org.osgi.framework.ServiceReference;

public class RepoValidator extends AbstractProvisioningTest {
	public void testValidate() throws ProvisionException, URISyntaxException {
		URI repoLoc = new URI("http://fullmoon.ottawa.ibm.com/eclipse/updates/3.5-I-builds/");
		ServiceReference sr = TestActivator.context.getServiceReference(IPlanner.SERVICE_NAME);
		if (sr == null) {
			throw new RuntimeException("Planner service not available");
		}
		IPlanner planner = (IPlanner) TestActivator.context.getService(sr);
		if (planner == null) {
			throw new RuntimeException("Planner could not be loaded");
		}

		IMetadataRepositoryManager mgr = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
		if (mgr == null) {
			throw new RuntimeException("Repository manager could not be loaded");
		}
		IMetadataRepository validatedRepo = mgr.loadRepository(repoLoc, null);

		Map properties = new HashMap();
		properties.put("osgi.os", "win32");
		properties.put("osgi.ws", "win32");
		properties.put("osgi.arch", "x86");
		IProfile p = createProfile("repoValidator", properties);

		IQuery q;

		q = QueryUtil.createIUQuery("org.eclipse.rcp.feature.group");

		//		q = InstallableUnitQuery.ANY;
		IQueryResult iusToTest = validatedRepo.query(q, null);

		ProvisioningContext pc = new ProvisioningContext(getAgent());
		pc.setMetadataRepositories(new URI[] {repoLoc});
		for (Iterator iterator = iusToTest.iterator(); iterator.hasNext();) {
			try {
				IInstallableUnit isInstallable = (IInstallableUnit) iterator.next();
				ProfileChangeRequest req = new ProfileChangeRequest(p);
				req.setProfileProperty("eclipse.p2.install.features", "true");
				req.addInstallableUnits(new IInstallableUnit[] {isInstallable});
				//				System.out.println("Working on: " + isInstallable);
				IStatus s = planner.getProvisioningPlan(req, pc, null).getStatus();
				if (!s.isOK()) {
					System.err.println("Can't resolve: " + isInstallable);
				}
			} catch (ArrayIndexOutOfBoundsException e) {
				//ignore
			}
		}
	}
}

Back to the top