Example #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);
   }
 }
Example #2
0
  final void addExportedProvidersFor(
      String symbolicName, String packageName, ArrayList result, KeyedHashSet visited) {
    if (!visited.add(bundle)) return;

    // See if we locally provide the package.
    PackageSource local = null;
    if (isExportedPackage(packageName)) local = proxy.getPackageSource(packageName);
    else if (isSubstitutedExport(packageName)) {
      result.add(findImportedSource(packageName, visited));
      return; // should not continue to required bundles in this case
    }
    // Must search required bundles that are exported first.
    if (requiredBundles != null) {
      int size = reexportTable == null ? 0 : reexportTable.length;
      int reexportIndex = 0;
      for (int i = 0; i < requiredBundles.length; i++) {
        if (local != null) {
          // always add required bundles first if we locally provide the package
          // This allows a bundle to provide a package from a required bundle without
          // re-exporting the whole required bundle.
          requiredBundles[i]
              .getBundleLoader()
              .addExportedProvidersFor(symbolicName, packageName, result, visited);
        } else if (reexportIndex < size && reexportTable[reexportIndex] == i) {
          reexportIndex++;
          requiredBundles[i]
              .getBundleLoader()
              .addExportedProvidersFor(symbolicName, packageName, result, visited);
        }
      }
    }

    // now add the locally provided package.
    if (local != null && local.isFriend(symbolicName)) result.add(local);
  }
Example #3
0
 /**
  * Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this
  * BundleLoader. Duplicate packages are checked and not added again.
  *
  * @param packages the DynamicImport-Package elements to add.
  */
 public final synchronized void addDynamicImportPackage(ManifestElement[] packages) {
   if (packages == null) return;
   ArrayList dynamicImports = new ArrayList(packages.length);
   for (int i = 0; i < packages.length; i++) dynamicImports.add(packages[i].getValue());
   if (dynamicImports.size() > 0)
     addDynamicImportPackage((String[]) dynamicImports.toArray(new String[dynamicImports.size()]));
 }
Example #4
0
 private void addDynamicImportPackage(ImportPackageSpecification[] packages) {
   if (packages == null) return;
   ArrayList dynamicImports = new ArrayList(packages.length);
   for (int i = 0; i < packages.length; i++)
     if (ImportPackageSpecification.RESOLUTION_DYNAMIC.equals(
         packages[i].getDirective(Constants.RESOLUTION_DIRECTIVE)))
       dynamicImports.add(packages[i].getName());
   if (dynamicImports.size() > 0)
     addDynamicImportPackage((String[]) dynamicImports.toArray(new String[dynamicImports.size()]));
 }
Example #5
0
 private static PackageSource createMultiSource(String packageName, PackageSource[] sources) {
   if (sources.length == 1) return sources[0];
   ArrayList sourceList = new ArrayList(sources.length);
   for (int i = 0; i < sources.length; i++) {
     SingleSourcePackage[] innerSources = sources[i].getSuppliers();
     for (int j = 0; j < innerSources.length; j++)
       if (!sourceList.contains(innerSources[j])) sourceList.add(innerSources[j]);
   }
   return new MultiSourcePackage(
       packageName,
       (SingleSourcePackage[]) sourceList.toArray(new SingleSourcePackage[sourceList.size()]));
 }
Example #6
0
  /**
   * Adds a list of DynamicImport-Package manifest elements to the dynamic import tables of this
   * BundleLoader. Duplicate packages are checked and not added again. This method is not thread
   * safe. Callers should ensure synchronization when calling this method.
   *
   * @param packages the DynamicImport-Package elements to add.
   */
  private void addDynamicImportPackage(String[] packages) {
    if (packages == null) return;

    loaderFlags |= FLAG_HASDYNAMICIMPORTS;
    int size = packages.length;
    ArrayList stems;
    if (dynamicImportPackageStems == null) {
      stems = new ArrayList(size);
    } else {
      stems = new ArrayList(size + dynamicImportPackageStems.length);
      for (int i = 0; i < dynamicImportPackageStems.length; i++) {
        stems.add(dynamicImportPackageStems[i]);
      }
    }

    ArrayList names;
    if (dynamicImportPackages == null) {
      names = new ArrayList(size);
    } else {
      names = new ArrayList(size + dynamicImportPackages.length);
      for (int i = 0; i < dynamicImportPackages.length; i++) {
        names.add(dynamicImportPackages[i]);
      }
    }

    for (int i = 0; i < size; i++) {
      String name = packages[i];
      if (isDynamicallyImported(name)) continue;
      if (name.equals("*")) {
        /* shortcut */
        //$NON-NLS-1$
        loaderFlags |= FLAG_HASDYNAMICEIMPORTALL;
        return;
      }

      if (name.endsWith(".*")) // $NON-NLS-1$
      stems.add(name.substring(0, name.length() - 1));
      else names.add(name);
    }

    size = stems.size();
    if (size > 0) dynamicImportPackageStems = (String[]) stems.toArray(new String[size]);

    size = names.size();
    if (size > 0) dynamicImportPackages = (String[]) names.toArray(new String[size]);
  }
Example #7
0
 private PackageSource findRequiredSource(String pkgName, KeyedHashSet visited) {
   if (requiredBundles == null) return null;
   synchronized (requiredSources) {
     PackageSource result = (PackageSource) requiredSources.getByKey(pkgName);
     if (result != null) return result.isNullSource() ? null : result;
   }
   if (visited == null) visited = new KeyedHashSet(false);
   visited.add(bundle); // always add ourselves so we do not recurse back to ourselves
   ArrayList result = new ArrayList(3);
   for (int i = 0; i < requiredBundles.length; i++) {
     BundleLoader requiredLoader = requiredBundles[i].getBundleLoader();
     requiredLoader.addExportedProvidersFor(proxy.getSymbolicName(), pkgName, result, visited);
   }
   // found some so cache the result for next time and return
   PackageSource source;
   if (result.size() == 0) {
     // did not find it in our required bundles lets record the failure
     // so we do not have to do the search again for this package.
     source = NullPackageSource.getNullPackageSource(pkgName);
   } else if (result.size() == 1) {
     // if there is just one source, remember just the single source
     source = (PackageSource) result.get(0);
   } else {
     // if there was more than one source, build a multisource and cache that.
     PackageSource[] srcs = (PackageSource[]) result.toArray(new PackageSource[result.size()]);
     source = createMultiSource(pkgName, srcs);
   }
   synchronized (requiredSources) {
     requiredSources.add(source);
   }
   return source.isNullSource() ? null : source;
 }