Search in sources :

Example 1 with PreferredProviderHeader

use of org.apache.aries.subsystem.core.archive.PreferredProviderHeader in project aries by apache.

the class BigApplicationTest method createApplication.

private InputStream createApplication(String symbolicName) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    addBundles(zos, "preferredbundle", "package", Constants.EXPORT_PACKAGE);
    addBundles(zos, "exportbundle", "package", Constants.EXPORT_PACKAGE);
    addBundles(zos, "importbundle", "package", Constants.IMPORT_PACKAGE);
    zos.putNextEntry(new ZipEntry("OSGI-INF/SUBSYSTEM.MF"));
    StringBuilder preferredProviders = new StringBuilder("preferredbundle0;type=osgi.bundle");
    for (int i = 1; i < BUNDLE_COUNT; i++) {
        preferredProviders.append(",preferredbundle").append(i).append(";type=osgi.bundle");
    }
    new SubsystemManifest.Builder().symbolicName(symbolicName).type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).header(new PreferredProviderHeader(preferredProviders.toString())).build().write(zos);
    zos.closeEntry();
    zos.close();
    return new ByteArrayInputStream(baos.toByteArray());
}
Also used : SubsystemManifest(org.apache.aries.subsystem.core.archive.SubsystemManifest) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PreferredProviderHeader(org.apache.aries.subsystem.core.archive.PreferredProviderHeader)

Example 2 with PreferredProviderHeader

use of org.apache.aries.subsystem.core.archive.PreferredProviderHeader in project aries by apache.

the class SubsystemResolverHook method filterMatches.

public void filterMatches(BundleRequirement requirement, Collection<BundleCapability> candidates) {
    // Filter out candidates that don't come from preferred providers when
    // there is at least one preferred provider.
    // (1) Find the subsystem(s) containing requirement.getResource() as a
    // constituent.
    Collection<BasicSubsystem> requirers = subsystems.getSubsystemsReferencing(requirement.getResource());
    // (2) For each candidate, ask each subsystem if the candidate or any of
    // the candidate's containing subsystems is a preferred provider. If at
    // least one preferred provider exists, filter out all other candidates
    // that are not also preferred providers.
    Collection<BundleCapability> preferredProviders = new ArrayList<BundleCapability>(candidates.size());
    for (BundleCapability candidate : candidates) for (BasicSubsystem subsystem : requirers) {
        PreferredProviderHeader header = subsystem.getSubsystemManifest().getPreferredProviderHeader();
        if (header != null && (header.contains(candidate.getResource()) || isResourceConstituentOfPreferredSubsystem(candidate.getResource(), subsystem)))
            preferredProviders.add(candidate);
    }
    if (!preferredProviders.isEmpty())
        candidates.retainAll(preferredProviders);
}
Also used : ArrayList(java.util.ArrayList) BundleCapability(org.osgi.framework.wiring.BundleCapability) PreferredProviderHeader(org.apache.aries.subsystem.core.archive.PreferredProviderHeader)

Example 3 with PreferredProviderHeader

use of org.apache.aries.subsystem.core.archive.PreferredProviderHeader in project aries by apache.

the class ManyFeaturesWithSharedBundlesTest method createApplication.

private InputStream createApplication(String symbolicName) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ZipOutputStream zos = new ZipOutputStream(baos);
    addBundles(zos, "applicationbundle", "package", Constants.IMPORT_PACKAGE);
    zos.putNextEntry(new ZipEntry("OSGI-INF/SUBSYSTEM.MF"));
    StringBuilder preferredProviders = new StringBuilder("featurebundle0;type=osgi.bundle");
    for (int i = 1; i < BUNDLE_COUNT; i++) {
        preferredProviders.append(",featurebundle").append(i).append(";type=osgi.bundle");
    }
    new SubsystemManifest.Builder().symbolicName(symbolicName).type(SubsystemConstants.SUBSYSTEM_TYPE_APPLICATION).header(new PreferredProviderHeader(preferredProviders.toString())).build().write(zos);
    zos.closeEntry();
    zos.close();
    return new ByteArrayInputStream(baos.toByteArray());
}
Also used : SubsystemManifest(org.apache.aries.subsystem.core.archive.SubsystemManifest) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PreferredProviderHeader(org.apache.aries.subsystem.core.archive.PreferredProviderHeader)

Aggregations

PreferredProviderHeader (org.apache.aries.subsystem.core.archive.PreferredProviderHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ZipEntry (java.util.zip.ZipEntry)2 ZipOutputStream (java.util.zip.ZipOutputStream)2 SubsystemManifest (org.apache.aries.subsystem.core.archive.SubsystemManifest)2 ArrayList (java.util.ArrayList)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1