Пример #1
1
 public void computeImports() throws CoreException {
   // some existing imports may valid and can be preserved
   Vector preservedImports = new Vector(fImports.size());
   // new imports
   ArrayList newImports = new ArrayList();
   IPluginModelBase model = null;
   for (int i = 0; i < fPlugins.size(); i++) {
     IFeaturePlugin fp = (IFeaturePlugin) fPlugins.get(i);
     ModelEntry entry = PluginRegistry.findEntry(fp.getId());
     if (entry == null) continue;
     IPluginModelBase[] models = entry.getActiveModels();
     for (int j = 0; j < models.length; j++) {
       IPluginModelBase m = models[j];
       if (fp.getVersion().equals(m.getPluginBase().getVersion())
           || fp.getVersion().equals("0.0.0")) // $NON-NLS-1$
       model = m;
     }
     if (model != null) {
       addPluginImports(preservedImports, newImports, model.getPluginBase());
       if (model.isFragmentModel()) {
         BundleDescription desc = model.getBundleDescription();
         if (desc == null) continue;
         HostSpecification hostSpec = desc.getHost();
         String id = hostSpec.getName();
         String version = null;
         int match = IMatchRules.NONE;
         VersionRange versionRange = hostSpec.getVersionRange();
         if (!(versionRange == null || VersionRange.emptyRange.equals(versionRange))) {
           version =
               versionRange.getMinimum() != null ? versionRange.getMinimum().toString() : null;
           match = PluginBase.getMatchRule(versionRange);
         }
         addNewDependency(id, version, match, preservedImports, newImports);
       }
     }
   }
   // preserve imports of features
   for (int i = 0; i < fImports.size(); i++) {
     IFeatureImport iimport = (IFeatureImport) fImports.get(i);
     if (iimport.getType() == IFeatureImport.FEATURE) preservedImports.add(iimport);
   }
   // removed = old - preserved
   Vector removedImports = ((Vector) fImports.clone());
   removedImports.removeAll(preservedImports);
   // perform remove
   fImports = preservedImports;
   if (removedImports.size() > 0) {
     fireStructureChanged(
         (IFeatureImport[]) removedImports.toArray(new IFeatureImport[removedImports.size()]),
         IModelChangedEvent.REMOVE);
   }
   // perform add
   if (newImports.size() > 0) {
     fImports.addAll(newImports);
     fireStructureChanged(
         (IFeatureImport[]) newImports.toArray(new IFeatureImport[newImports.size()]),
         IModelChangedEvent.INSERT);
   }
 }
Пример #2
0
 /*
  * get the loader proxy for a bundle description
  */
 public final BundleLoaderProxy getLoaderProxy(BundleDescription source) {
   BundleLoaderProxy sourceProxy = (BundleLoaderProxy) source.getUserObject();
   if (sourceProxy == null) {
     // may need to force the proxy to be created
     long exportingID = source.getBundleId();
     BundleHost exportingBundle = (BundleHost) bundle.getFramework().getBundle(exportingID);
     if (exportingBundle == null) return null;
     sourceProxy = exportingBundle.getLoaderProxy();
   }
   return sourceProxy;
 }
Пример #3
0
 public static void closeBundleLoader(BundleLoaderProxy proxy) {
   if (proxy == null) return;
   // First close the BundleLoader
   BundleLoader loader = proxy.getBasicBundleLoader();
   if (loader != null) loader.close();
   proxy.setStale();
   // if proxy is not null then make sure to unset user object
   // associated with the proxy in the state
   BundleDescription description = proxy.getBundleDescription();
   description.setUserObject(null);
 }
Пример #4
0
 public synchronized KeyedHashSet getImportedSources(KeyedHashSet visited) {
   if ((loaderFlags & FLAG_IMPORTSINIT) != 0) return importedSources;
   BundleDescription bundleDesc = proxy.getBundleDescription();
   ExportPackageDescription[] packages = bundleDesc.getResolvedImports();
   if (packages != null && packages.length > 0) {
     if (importedSources == null) importedSources = new KeyedHashSet(packages.length, false);
     for (int i = 0; i < packages.length; i++) {
       if (packages[i].getExporter() == bundleDesc)
         continue; // ignore imports resolved to this bundle
       PackageSource source = createExportPackageSource(packages[i], visited);
       if (source != null) importedSources.add(source);
     }
   }
   loaderFlags |= FLAG_IMPORTSINIT;
   return importedSources;
 }
 private boolean isAffected(BundleDescription desc, BundleDescription dependent) {
   ImportPackageSpecification[] imports = dependent.getImportPackages();
   Iterator iter = fElements.keySet().iterator();
   while (iter.hasNext()) {
     String name = ((IJavaElement) iter.next()).getElementName();
     for (int i = 0; i < imports.length; i++) {
       if (name.equals(imports[i].getName())) {
         BaseDescription supplier = imports[i].getSupplier();
         if (supplier instanceof ExportPackageDescription) {
           if (desc.equals(((ExportPackageDescription) supplier).getExporter())) return true;
         }
       }
     }
   }
   return false;
 }
 /**
  * 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 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 void addBundleManifestChange(CompositeChange result, IProgressMonitor pm)
     throws CoreException {
   super.addBundleManifestChange(result, pm);
   IMonitorModelBase model = MonitorRegistry.findModel(fProject);
   if (model != null) {
     BundleDescription desc = model.getBundleDescription();
     if (desc != null) {
       BundleDescription[] dependents = desc.getDependents();
       for (int i = 0; i < dependents.length; i++) {
         if (isAffected(desc, dependents[i])) {
           IMonitorModelBase candidate = MonitorRegistry.findModel(dependents[i]);
           if (candidate instanceof IBundlePluginModelBase) {
             IFile file = (IFile) candidate.getUnderlyingResource();
             addBundleManifestChange(file, result, pm);
           }
         }
       }
     }
   }
 }
  protected Object[] findCallees(IPluginModelBase model) {
    BundleDescription desc = model.getBundleDescription();
    if (desc == null) return new Object[0];
    fFragmentDescription = null;
    HostSpecification spec = desc.getHost();
    if (spec != null) {
      fFragmentDescription = desc;
      Object[] fragmentDependencies = getDependencies(desc);
      BaseDescription host = spec.getSupplier();
      if (host instanceof BundleDescription) {
        BundleDescription hostDesc = (BundleDescription) host;
        // check to see if the host is already included as a dependency.  If so, we don't need to
        // include the host manually.
        for (int i = 0; i < fragmentDependencies.length; i++) {
          BundleDescription dependency = null;
          if (fragmentDependencies[i] instanceof BundleSpecification)
            dependency = ((BundleSpecification) fragmentDependencies[i]).getBundle();
          else if (fragmentDependencies[i] instanceof ImportPackageSpecification) {
            ExportPackageDescription epd =
                (ExportPackageDescription)
                    ((ImportPackageSpecification) fragmentDependencies[i]).getSupplier();
            if (epd != null) dependency = epd.getSupplier();
          }
          if (dependency != null && dependency.equals(hostDesc)) return fragmentDependencies;
        }

        // host not included as dependency, include it manually.
        Object[] result = new Object[fragmentDependencies.length + 1];
        result[0] = hostDesc;
        System.arraycopy(fragmentDependencies, 0, result, 1, fragmentDependencies.length);
        return result;
      }
      return fragmentDependencies;
    }
    return getDependencies(desc);
  }
  /**
   * Build the table of plug-in dependencies. Iterate over all the plug-ins in the plug-in registry
   * and the cycle through the list of pre-requisites and create the parent/child relationships in
   * the nodes.
   */
  private Map getDependencyGraph() {
    if (dependencyGraph != null) return dependencyGraph;
    // Build up the dependency graph (see PluginDependencyGraphNode) so
    // we have the information readily available for any plug-in.
    State state = Platform.getPlatformAdmin().getState(false);
    BundleDescription[] plugins = state.getBundles();
    dependencyGraph = new HashMap();
    for (int i = 0; i < plugins.length; i++) {
      BundleDescription descriptor = plugins[i];
      PluginDependencyGraphNode node =
          (PluginDependencyGraphNode) dependencyGraph.get(new Long(descriptor.getBundleId()));
      if (node == null) {
        node = new PluginDependencyGraphNode(descriptor);
        dependencyGraph.put(new Long(descriptor.getBundleId()), node);
      }

      // Cycle through the prerequisites
      BundleSpecification[] requires = descriptor.getRequiredBundles();
      for (int j = 0; j < requires.length; j++) {
        BundleDescription childDesc = (BundleDescription) requires[j].getSupplier();
        // if the child doesn't exist then move to the next child
        if (childDesc == null) continue;

        // if the child entry is not in the table yet then add it
        PluginDependencyGraphNode childNode =
            (PluginDependencyGraphNode) dependencyGraph.get(new Long(childDesc.getBundleId()));
        if (childNode == null) {
          childNode = new PluginDependencyGraphNode(childDesc);
          dependencyGraph.put(new Long(childDesc.getBundleId()), childNode);
        }

        // Add the child to this node's children and set this node as an ancestor
        // of the child node
        node.addChild(childNode);
        childNode.addAncestor(node);
      }
    }
    return dependencyGraph;
  }
Пример #11
0
  /**
   * BundleLoader runtime constructor. This object is created lazily when the first request for a
   * resource is made to this bundle.
   *
   * @param bundle Bundle object for this loader.
   * @param proxy the BundleLoaderProxy for this loader.
   * @exception org.osgi.framework.BundleException
   */
  protected BundleLoader(BundleHost bundle, BundleLoaderProxy proxy) throws BundleException {
    this.bundle = bundle;
    this.proxy = proxy;
    try {
      bundle.getBundleData().open(); /* make sure the BundleData is open */
    } catch (IOException e) {
      throw new BundleException(Msg.BUNDLE_READ_EXCEPTION, e);
    }
    BundleDescription description = proxy.getBundleDescription();
    // init the require bundles list.
    BundleDescription[] required = description.getResolvedRequires();
    if (required.length > 0) {
      // get a list of re-exported symbolic names
      HashSet reExportSet = new HashSet(required.length);
      BundleSpecification[] requiredSpecs = description.getRequiredBundles();
      if (requiredSpecs != null && requiredSpecs.length > 0)
        for (int i = 0; i < requiredSpecs.length; i++)
          if (requiredSpecs[i].isExported()) reExportSet.add(requiredSpecs[i].getName());

      requiredBundles = new BundleLoaderProxy[required.length];
      int[] reexported = new int[required.length];
      int reexportIndex = 0;
      for (int i = 0; i < required.length; i++) {
        requiredBundles[i] = getLoaderProxy(required[i]);
        if (reExportSet.contains(required[i].getSymbolicName())) reexported[reexportIndex++] = i;
      }
      if (reexportIndex > 0) {
        reexportTable = new int[reexportIndex];
        System.arraycopy(reexported, 0, reexportTable, 0, reexportIndex);
      } else {
        reexportTable = null;
      }
      requiredSources = new KeyedHashSet(10, false);
    } else {
      requiredBundles = null;
      reexportTable = null;
      requiredSources = null;
    }

    // init the provided packages set
    ExportPackageDescription[] exports = description.getSelectedExports();
    if (exports != null && exports.length > 0) {
      exportedPackages =
          Collections.synchronizedCollection(
              exports.length > 10
                  ? (Collection) new HashSet(exports.length)
                  : new ArrayList(exports.length));
      initializeExports(exports, exportedPackages);
    } else {
      exportedPackages = Collections.synchronizedCollection(new ArrayList(0));
    }

    ExportPackageDescription substituted[] = description.getSubstitutedExports();
    if (substituted.length > 0) {
      substitutedPackages =
          substituted.length > 10
              ? (Collection) new HashSet(substituted.length)
              : new ArrayList(substituted.length);
      for (int i = 0; i < substituted.length; i++)
        substitutedPackages.add(substituted[i].getName());
    } else {
      substitutedPackages = null;
    }

    // This is the fastest way to access to the description for fragments since the
    // hostdescription.getFragments() is slow
    BundleFragment[] fragmentObjects = bundle.getFragments();
    BundleDescription[] fragments =
        new BundleDescription[fragmentObjects == null ? 0 : fragmentObjects.length];
    for (int i = 0; i < fragments.length; i++)
      fragments[i] = fragmentObjects[i].getBundleDescription();
    // init the dynamic imports tables
    if (description.hasDynamicImports()) addDynamicImportPackage(description.getImportPackages());
    // ...and its fragments
    for (int i = 0; i < fragments.length; i++)
      if (fragments[i].isResolved() && fragments[i].hasDynamicImports())
        addDynamicImportPackage(fragments[i].getImportPackages());

    // Initialize the policy handler
    String buddyList = null;
    try {
      buddyList = (String) bundle.getBundleData().getManifest().get(Constants.BUDDY_LOADER);
    } catch (BundleException e) {
      // do nothing; buddyList == null
    }
    policy =
        buddyList != null
            ? new PolicyHandler(this, buddyList, bundle.getFramework().getPackageAdmin())
            : null;
    if (policy != null) policy.open(bundle.getFramework().getSystemBundleContext());
  }