private Object[] getDependencies(BundleDescription desc) { // use map to store dependencies so if Import-Package is supplied by same BundleDescription as // supplier of Require-Bundle, it only shows up once // Also, have to use BundleSpecficiation instead of BundleDescroption to show re-exported icon // on re-exported Required-Bundles // Have to use ImportPackageSpecification to determine if an import is optional and should be // filtered. HashMap<Object, Object> dependencies = new HashMap<Object, Object>(); BundleSpecification[] requiredBundles = desc.getRequiredBundles(); for (int i = 0; i < requiredBundles.length; i++) { BaseDescription bd = requiredBundles[i].getSupplier(); if (bd != null) dependencies.put(bd, requiredBundles[i]); else dependencies.put(requiredBundles[i], requiredBundles[i]); } ImportPackageSpecification[] importedPkgs = desc.getImportPackages(); for (int i = 0; i < importedPkgs.length; i++) { BaseDescription bd = importedPkgs[i].getSupplier(); if (bd != null && bd instanceof ExportPackageDescription) { BundleDescription exporter = ((ExportPackageDescription) bd).getExporter(); if (exporter != null) { Object obj = dependencies.get(exporter); if (obj == null) { dependencies.put(exporter, importedPkgs[i]); } else if (!Constants.RESOLUTION_OPTIONAL.equals( importedPkgs[i].getDirective(Constants.RESOLUTION_DIRECTIVE)) && obj instanceof ImportPackageSpecification && Constants.RESOLUTION_OPTIONAL.equals( ((ImportPackageSpecification) obj) .getDirective(Constants.RESOLUTION_DIRECTIVE))) { // if we have a non-optional Import-Package dependency on a bundle which we already // depend on, check to make sure our // current dependency is not optional. If it is, replace the optional dependency with // the non-optional one dependencies.put(exporter, importedPkgs[i]); } } } // ignore unresolved packages } // include fragments which are "linked" to this bundle BundleDescription frags[] = desc.getFragments(); for (int i = 0; i < frags.length; i++) { if (!frags[i].equals(fFragmentDescription)) dependencies.put(frags[i], frags[i]); } return dependencies.values().toArray(); }
protected List<Clause> getOptionalImports(String importsStr) { Clause[] imports = Parser.parseHeader(importsStr); List<Clause> result = new LinkedList<Clause>(); for (int i = 0; i < imports.length; i++) { String resolution = imports[i].getDirective(Constants.RESOLUTION_DIRECTIVE); if (Constants.RESOLUTION_OPTIONAL.equals(resolution)) { result.add(imports[i]); } } return result; }
/** * Recursively adds the given {@link BundleDescription} and its dependents to the given {@link * Set} * * @param desc the {@link BundleDescription} to compute dependencies for * @param set the {@link Set} to collect results in * @param includeOptional if optional dependencies should be included * @param excludeFragments a collection of <b>fragment</b> bundle symbolic names to exclude from * the dependency resolution */ private static void addBundleAndDependencies( BundleDescription desc, Set<String> set, boolean includeOptional, Set<String> excludeFragments) { if (desc != null && set.add(desc.getSymbolicName())) { BundleSpecification[] required = desc.getRequiredBundles(); for (int i = 0; i < required.length; i++) { if (includeOptional || !required[i].isOptional()) { addBundleAndDependencies( (BundleDescription) required[i].getSupplier(), set, includeOptional, excludeFragments); } } ImportPackageSpecification[] importedPkgs = desc.getImportPackages(); for (int i = 0; i < importedPkgs.length; i++) { ExportPackageDescription exporter = (ExportPackageDescription) importedPkgs[i].getSupplier(); // Continue if the Imported Package is unresolved of the package is optional and don't want // optional packages if (exporter == null || (!includeOptional && Constants.RESOLUTION_OPTIONAL.equals( importedPkgs[i].getDirective(Constants.RESOLUTION_DIRECTIVE)))) { continue; } addBundleAndDependencies(exporter.getExporter(), set, includeOptional, excludeFragments); } BundleDescription[] fragments = desc.getFragments(); for (int i = 0; i < fragments.length; i++) { if (!fragments[i].isResolved()) { continue; } String id = fragments[i].getSymbolicName(); if (!excludeFragments.contains(id)) { addBundleAndDependencies(fragments[i], set, includeOptional, excludeFragments); } } HostSpecification host = desc.getHost(); if (host != null) { addBundleAndDependencies( (BundleDescription) host.getSupplier(), set, includeOptional, excludeFragments); } } }
private void executeAdd(IModelChangeProvider model, Object[] elements) { IPluginBase pluginBase = null; IBuild build = null; IBundleModel bundleModel = null; if (model instanceof IPluginModelBase) { pluginBase = ((IPluginModelBase) model).getPluginBase(); } else if (model instanceof IBuildModel) { build = ((IBuildModel) model).getBuild(); } else if (model instanceof IBundleModel) { bundleModel = (IBundleModel) model; } try { for (Object element : elements) { if (element instanceof IPluginImport) { pluginBase.add((IPluginImport) element); } else if (element instanceof IPluginLibrary) { pluginBase.add((IPluginLibrary) element); } else if (element instanceof IPluginExtensionPoint) { pluginBase.add((IPluginExtensionPoint) element); } else if (element instanceof IPluginExtension) { pluginBase.add((IPluginExtension) element); } else if (element instanceof IPluginElement) { IPluginElement e = (IPluginElement) element; Object parent = e.getParent(); if (parent instanceof PluginLibraryNode && e instanceof PluginElementNode) { ((PluginLibraryNode) parent).addContentFilter((PluginElementNode) e); } else if (parent instanceof IPluginParent) { ((IPluginParent) parent).add(e); } } else if (element instanceof IBuildEntry) { IBuildEntry e = (IBuildEntry) element; build.add(e); } else if (element instanceof BundleObject) { if (element instanceof ImportPackageObject) { IManifestHeader header = bundleModel.getBundle().getManifestHeader(Constants.IMPORT_PACKAGE); if (header != null && header instanceof ImportPackageHeader) { ((ImportPackageHeader) header).addPackage((PackageObject) element); } } if (element instanceof RequireBundleObject) { IBaseModel aggModel = getEditor().getAggregateModel(); if (aggModel instanceof BundlePluginModel) { BundlePluginModel pluginModel = (BundlePluginModel) aggModel; RequireBundleObject requireBundle = (RequireBundleObject) element; pluginBase = pluginModel.getPluginBase(); String elementValue = requireBundle.getValue(); IPluginImport importNode = null; if (pluginModel.getPluginFactory() instanceof BundlePluginModelBase) importNode = ((BundlePluginModelBase) pluginModel.getPluginFactory()) .createImport(elementValue); String version = ((RequireBundleObject) element).getAttribute(Constants.BUNDLE_VERSION_ATTRIBUTE); IManifestHeader header = bundleModel.getBundle().getManifestHeader(Constants.REQUIRE_BUNDLE); int bundleManifestVersion = BundlePluginBase.getBundleManifestVersion( ((RequireBundleHeader) header).getBundle()); boolean option = (bundleManifestVersion > 1) ? Constants.RESOLUTION_OPTIONAL.equals( requireBundle.getDirective(Constants.RESOLUTION_DIRECTIVE)) : "true" .equals( requireBundle.getAttribute( ICoreConstants.OPTIONAL_ATTRIBUTE)); // $NON-NLS-1$; boolean exported = (bundleManifestVersion > 1) ? Constants.VISIBILITY_REEXPORT.equals( requireBundle.getDirective(Constants.VISIBILITY_DIRECTIVE)) : "true" .equals( requireBundle.getAttribute( ICoreConstants.REPROVIDE_ATTRIBUTE)); // $NON-NLS-1$; if (importNode != null) { importNode.setVersion(version); importNode.setOptional(option); importNode.setReexported(exported); } if (pluginBase instanceof BundlePluginBase && importNode != null) ((BundlePluginBase) pluginBase).add(importNode); } } if (element instanceof ExportPackageObject) { IManifestHeader header = bundleModel.getBundle().getManifestHeader(Constants.EXPORT_PACKAGE); if (header != null && header instanceof ExportPackageHeader) { ((ExportPackageHeader) header).addPackage((PackageObject) element); } } } } } catch (CoreException e) { PDEPlugin.logException(e); } }