Ejemplo n.º 1
0
 private BundleRevisionDTO getBundleRevisionDTO(BundleRevision revision) {
   if (revision == null) {
     return null;
   }
   BundleRevisionDTO dto = resources.get(revision);
   if (dto != null) {
     return dto;
   }
   dto = new BundleRevisionDTO();
   dto.id = identifier(revision);
   resources.put(revision, dto);
   dto.bundle = revision.getBundle().getBundleId();
   dto.symbolicName = revision.getSymbolicName();
   dto.type = revision.getTypes();
   dto.version = revision.getVersion().toString();
   dto.capabilities = getListCapabilityDTO(revision.getDeclaredCapabilities(null));
   dto.requirements = getListRequirementDTO(revision.getDeclaredRequirements(null));
   return dto;
 }
Ejemplo n.º 2
0
  private List<Definition> resolveAspectsForBundle(
      final List<String> fingerprintElements,
      final Bundle bundle,
      final BundleRevision bundleRevision) {
    final List<Definition> result = new ArrayList<Definition>();
    final BundleWiring wiring = bundleRevision.getWiring();

    if (wiring != null && weavingBundleContext != null) {

      Definition aspects = null;

      // fragments
      for (final BundleWire hostWire : wiring.getProvidedWires(HostNamespace.HOST_NAMESPACE)) {
        final Bundle fragmentBundle = hostWire.getRequirer().getBundle();
        if (fragmentBundle != null) {
          aspects = aspectAdmin.getAspectDefinition(fragmentBundle);
          if (aspects != null) {
            result.add(aspects);
            fingerprintElements.add(
                fragmentBundle.getSymbolicName()
                    + ":" //$NON-NLS-1$
                    + hostWire.getRequirer().getVersion().toString());
          }
        }
      }

      // required bundles
      final List<BundleWire> requiredBundles =
          wiring.getRequiredWires(BundleNamespace.BUNDLE_NAMESPACE);
      ManifestElement[] requireHeaders = null;
      if (!requiredBundles.isEmpty()) {
        try {
          requireHeaders =
              ManifestElement.parseHeader(
                  Constants.REQUIRE_BUNDLE,
                  bundle.getHeaders("").get(Constants.REQUIRE_BUNDLE)); // $NON-NLS-1$
        } catch (final BundleException e) {
        }
      }
      for (final BundleWire requiredBundleWire : requiredBundles) {
        final Bundle requiredBundle = requiredBundleWire.getProvider().getBundle();
        if (requiredBundle != null) {
          final int applyPolicy =
              getApplyAspectsPolicy(requireHeaders, requiredBundle.getSymbolicName());

          aspects = aspectAdmin.resolveRequiredBundle(requiredBundle, applyPolicy);

          if (aspects != null) {
            result.add(aspects);
            fingerprintElements.add(
                requiredBundle.getSymbolicName()
                    + ":" //$NON-NLS-1$
                    + requiredBundleWire.getProvider().getVersion().toString());
          }
        }
      }

      // imported packages
      final List<BundleWire> importedPackages =
          wiring.getRequiredWires(PackageNamespace.PACKAGE_NAMESPACE);
      ManifestElement[] importHeaders = null;
      if (!importedPackages.isEmpty()) {
        try {
          importHeaders =
              ManifestElement.parseHeader(
                  Constants.IMPORT_PACKAGE,
                  bundle.getHeaders("").get(Constants.IMPORT_PACKAGE)); // $NON-NLS-1$
        } catch (final BundleException e) {
        }
      }
      for (final BundleWire importPackageWire : importedPackages) {
        final Bundle exportingBundle = importPackageWire.getProvider().getBundle();
        if (exportingBundle != null) {
          final String importedPackage =
              (String)
                  importPackageWire
                      .getCapability()
                      .getAttributes()
                      .get(PackageNamespace.PACKAGE_NAMESPACE);

          final int applyPolicy = getApplyAspectsPolicy(importHeaders, importedPackage);

          aspects =
              aspectAdmin.resolveImportedPackage(exportingBundle, importedPackage, applyPolicy);

          if (aspects != null) {
            result.add(aspects);
            final Object v =
                importPackageWire
                    .getCapability()
                    .getAttributes()
                    .get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            final String version = v == null ? Version.emptyVersion.toString() : v.toString();
            fingerprintElements.add(
                importedPackage
                    + ":" //$NON-NLS-1$
                    + version);
          }
        }
      }

      // supplementers
      final Supplementer[] supplementers =
          this.supplementerRegistry.getSupplementers(bundleRevision.getBundle().getBundleId());

      for (int i = 0; i < supplementers.length; i++) {
        aspects =
            aspectAdmin.getExportedAspectDefinitions(supplementers[i].getSupplementerBundle());
        if (aspects != null) {
          result.add(aspects);
          fingerprintElements.add(
              supplementers[i].getSymbolicName()
                  + ":" //$NON-NLS-1$
                  + getBundleVersion(supplementers[i].getSupplementerBundle()));
        }
      }

      // this bundle
      aspects = aspectAdmin.getAspectDefinition(bundle);
      if (aspects != null) {
        final String finishedValue =
            bundle
                .getHeaders("")
                .get( //$NON-NLS-1$
                    AspectAdmin.AOP_BUNDLE_FINISHED_HEADER);
        if (finishedValue == null || !AspectAdmin.AOP_BUNDLE_FINISHED_VALUE.equals(finishedValue)) {
          result.add(aspects);
          fingerprintElements.add(
              bundle.getSymbolicName()
                  + ":" //$NON-NLS-1$
                  + bundleRevision.getVersion().toString());
        }
      }
    }

    return result;
  }