KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 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.HashSet JavaDoc;
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.osgi.service.resolver.BundleDescription;
17 import org.eclipse.osgi.service.resolver.BundleSpecification;
18 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
19 import org.eclipse.osgi.service.resolver.HostSpecification;
20 import org.eclipse.osgi.service.resolver.State;
21 import org.eclipse.pde.core.plugin.IPluginExtension;
22 import org.eclipse.pde.core.plugin.IPluginModelBase;
23
24 public class RequiredDependencyManager {
25     
26     public static Set JavaDoc addRequiredPlugins(Object JavaDoc[] selected, String JavaDoc[] implicit, State state) {
27         Set JavaDoc set = new HashSet JavaDoc();
28         for (int i = 0; i < selected.length; i++) {
29             if (!(selected[i] instanceof IPluginModelBase))
30                 continue;
31             IPluginModelBase model = (IPluginModelBase)selected[i];
32             addBundleAndDependencies(model.getBundleDescription(), set);
33             IPluginExtension[] extensions = model.getPluginBase().getExtensions();
34             for (int j = 0; j < extensions.length; j++) {
35                 String JavaDoc point = extensions[j].getPoint();
36                 if (point != null) {
37                     int dot = point.lastIndexOf('.');
38                     if (dot != -1) {
39                         String JavaDoc id = point.substring(0, dot);
40                         addBundleAndDependencies(state.getBundle(id, null), set);
41                     }
42                 }
43             }
44         }
45         
46         for (int i = 0; i < implicit.length; i++) {
47             addBundleAndDependencies(state.getBundle(implicit[i], null), set);
48         }
49         
50         for (int i = 0; i < selected.length; i++) {
51             if (!(selected[i] instanceof IPluginModelBase))
52                 continue;
53             IPluginModelBase model = (IPluginModelBase)selected[i];
54             set.remove(model.getPluginBase().getId());
55         }
56         return set;
57     }
58     
59     private static void addBundleAndDependencies(BundleDescription desc, Set JavaDoc set) {
60         if (desc != null && set.add(desc.getSymbolicName())) {
61             BundleSpecification[] required = desc.getRequiredBundles();
62             for (int i = 0; i < required.length; i++) {
63                 addBundleAndDependencies((BundleDescription)required[i].getSupplier(), set);
64             }
65             ExportPackageDescription[] exported = desc.getResolvedImports();
66             for (int i = 0; i < exported.length; i++) {
67                 addBundleAndDependencies(exported[i].getExporter(), set);
68             }
69             BundleDescription[] fragments = desc.getFragments();
70             for (int i = 0; i < fragments.length; i++) {
71                 if (!fragments[i].isResolved())
72                     continue;
73                 String JavaDoc id = fragments[i].getSymbolicName();
74                 if (!"org.eclipse.ui.workbench.compatibility".equals(id)) //$NON-NLS-1$
75
addBundleAndDependencies(fragments[i], set);
76             }
77             HostSpecification host = desc.getHost();
78             if (host != null)
79                 addBundleAndDependencies((BundleDescription)host.getSupplier(), set);
80         }
81     }
82     
83 }
84
Popular Tags