KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > core > BundleValidationOperation


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.core;
12
13 import java.util.Dictionary JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.resources.IWorkspaceRunnable;
18 import org.eclipse.core.runtime.CoreException;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.osgi.service.resolver.BundleDescription;
22 import org.eclipse.osgi.service.resolver.State;
23 import org.eclipse.osgi.service.resolver.StateObjectFactory;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25
26 public class BundleValidationOperation implements IWorkspaceRunnable {
27     
28     private static StateObjectFactory FACTORY;
29     
30     private IPluginModelBase[] fModels;
31     private Dictionary JavaDoc[] fProperties;
32     private State fState;
33     
34     public BundleValidationOperation(IPluginModelBase[] models) {
35         this(models, new Dictionary JavaDoc[] { TargetPlatformHelper.getTargetEnvironment()});
36     }
37     
38     public BundleValidationOperation(IPluginModelBase[] models, Dictionary JavaDoc[] properties) {
39         fModels = models;
40         fProperties = properties;
41     }
42     
43     public void run(IProgressMonitor monitor) throws CoreException {
44         if (FACTORY == null)
45             FACTORY = Platform.getPlatformAdmin().getFactory();
46         monitor.beginTask("", fModels.length + 1); //$NON-NLS-1$
47
fState = FACTORY.createState(true);
48         for (int i = 0; i < fModels.length; i++) {
49             BundleDescription bundle = fModels[i].getBundleDescription();
50             if (bundle != null)
51                 fState.addBundle(FACTORY.createBundleDescription(bundle));
52             monitor.worked(1);
53         }
54         fState.setPlatformProperties(fProperties);
55         fState.resolve(false);
56         monitor.done();
57     }
58     
59     public Map JavaDoc getResolverErrors() {
60         Map JavaDoc map = new HashMap JavaDoc();
61         BundleDescription[] bundles = fState.getBundles();
62         for (int i = 0; i < bundles.length; i++) {
63             if (!bundles[i].isResolved()) {
64                 map.put(bundles[i], fState.getResolverErrors(bundles[i]));
65             }
66         }
67         return map;
68     }
69     
70     public State getState() {
71         return fState;
72     }
73     
74     public boolean hasErrors() {
75         return fState.getHighestBundleId() > -1
76                 && fState.getBundles().length > fState.getResolvedBundles().length;
77     }
78         
79 }
80
Popular Tags