01: /*******************************************************************************
02: * Copyright (c) 2003, 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.ArrayList;
13:
14: import org.eclipse.osgi.service.resolver.BundleDescription;
15: import org.eclipse.osgi.service.resolver.ExportPackageDescription;
16:
17: public class PDEStateHelper {
18:
19: /**
20: * Returns the bundles that export packages imported by the given bundle
21: * via the Import-Package header
22: *
23: * @param root the given bundle
24: *
25: * @return an array of bundles that export packages being imported by the given bundle
26: */
27: public static BundleDescription[] getImportedBundles(
28: BundleDescription root) {
29: if (root == null)
30: return new BundleDescription[0];
31: ExportPackageDescription[] packages = root.getResolvedImports();
32: ArrayList resolvedImports = new ArrayList(packages.length);
33: for (int i = 0; i < packages.length; i++)
34: if (!root.getLocation().equals(
35: packages[i].getExporter().getLocation())
36: && !resolvedImports.contains(packages[i]
37: .getExporter()))
38: resolvedImports.add(packages[i].getExporter());
39: return (BundleDescription[]) resolvedImports
40: .toArray(new BundleDescription[resolvedImports.size()]);
41: }
42:
43: }
|