01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.core;
11:
12: import java.util.Dictionary;
13: import java.util.HashMap;
14: import java.util.Map;
15:
16: import org.eclipse.core.resources.IWorkspaceRunnable;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IProgressMonitor;
19: import org.eclipse.core.runtime.Platform;
20: import org.eclipse.osgi.service.resolver.BundleDescription;
21: import org.eclipse.osgi.service.resolver.State;
22: import org.eclipse.osgi.service.resolver.StateObjectFactory;
23: import org.eclipse.pde.core.plugin.IPluginModelBase;
24:
25: public class BundleValidationOperation implements IWorkspaceRunnable {
26:
27: private static StateObjectFactory FACTORY;
28:
29: private IPluginModelBase[] fModels;
30: private Dictionary[] fProperties;
31: private State fState;
32:
33: public BundleValidationOperation(IPluginModelBase[] models) {
34: this (models, new Dictionary[] { TargetPlatformHelper
35: .getTargetEnvironment() });
36: }
37:
38: public BundleValidationOperation(IPluginModelBase[] models,
39: Dictionary[] properties) {
40: fModels = models;
41: fProperties = properties;
42: }
43:
44: public void run(IProgressMonitor monitor) throws CoreException {
45: if (FACTORY == null)
46: FACTORY = Platform.getPlatformAdmin().getFactory();
47: monitor.beginTask("", fModels.length + 1); //$NON-NLS-1$
48: fState = FACTORY.createState(true);
49: for (int i = 0; i < fModels.length; i++) {
50: BundleDescription bundle = fModels[i]
51: .getBundleDescription();
52: if (bundle != null)
53: fState.addBundle(FACTORY
54: .createBundleDescription(bundle));
55: monitor.worked(1);
56: }
57: fState.setPlatformProperties(fProperties);
58: fState.resolve(false);
59: monitor.done();
60: }
61:
62: public Map getResolverErrors() {
63: Map map = new HashMap();
64: BundleDescription[] bundles = fState.getBundles();
65: for (int i = 0; i < bundles.length; i++) {
66: if (!bundles[i].isResolved()) {
67: map.put(bundles[i], fState
68: .getResolverErrors(bundles[i]));
69: }
70: }
71: return map;
72: }
73:
74: public State getState() {
75: return fState;
76: }
77:
78: public boolean hasErrors() {
79: return fState.getHighestBundleId() > -1
80: && fState.getBundles().length > fState
81: .getResolvedBundles().length;
82: }
83:
84: }
|