Search in sources :

Example 1 with ExportedPackage

use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.

the class DeployedBundlesImpl method getRequiredUseBundle.

/**
   * Get the subset of bundles specified in use-bundle that are actually required to
   * satisfy direct requirements of deployed content.
   * @return a set of bundle metadata.
   * @throws ResolverException if the requirements could not be resolved.
   */
public Collection<ModelledResource> getRequiredUseBundle() throws ResolverException {
    logger.debug(LOG_ENTRY, "getRequiredUseBundle");
    Collection<ModelledResource> usedUseBundles = cachedRequiredUseBundle;
    if (usedUseBundles == null) {
        Collection<ImportedPackage> externalReqs = getExternalPackageRequirements();
        usedUseBundles = new HashSet<ModelledResource>();
        for (ImportedPackage req : externalReqs) {
            // Find a match from the supplied bundle capabilities.
            ExportedPackage match = getPackageMatch(req, deployedUseBundle);
            if (match != null) {
                usedUseBundles.add(match.getBundle());
            }
        }
        cachedRequiredUseBundle = usedUseBundles;
    }
    logger.debug(LOG_EXIT, "getRequiredUseBundle", usedUseBundles);
    return usedUseBundles;
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 2 with ExportedPackage

use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.

the class DeployedBundlesImpl method getPackageMatch.

/**
   * Get a package match between the specified requirement and a capability of the supplied
   * bundles. The resulting match object might not refer to any matching capability.
   * @param requirement the {@link ImportedPackageImpl} to be matched.
   * @param bundles the bundles to be searched for matching capabilities.
   * @return an ExportedPackageImpl or null if no match is found.
   */
private ExportedPackage getPackageMatch(ImportedPackage requirement, Collection<ModelledResource> bundles) {
    logger.debug(LOG_ENTRY, "getPackageMatch", new Object[] { requirement, bundles });
    ExportedPackage result = null;
    outer: for (ModelledResource bundle : bundles) {
        for (ExportedPackage pkg : bundle.getExportedPackages()) {
            if (requirement.isSatisfied(pkg)) {
                result = pkg;
                break outer;
            }
        }
    }
    logger.debug(LOG_EXIT, "getPackageMatch", new Object[] { result });
    return result;
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 3 with ExportedPackage

use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.

the class DeployedBundlesImpl method getExternalPackageRequirements.

/**
   * Get all the requirements of bundles in deployed content that are not satisfied
   * by other bundles in deployed content.
   * @return a collection of package requirements.
   * @throws ResolverException if the requirements could not be resolved.
   */
private Collection<ImportedPackage> getExternalPackageRequirements() throws ResolverException {
    logger.debug(LOG_ENTRY, "getExternalPackageRequirements");
    Collection<ImportedPackage> result = cachedExternalRequirements;
    if (result == null) {
        // Get all the internal requirements.
        Collection<ImportedPackage> requirements = new ArrayList<ImportedPackage>();
        Collection<ExportedPackage> internalExports = new ArrayList<ExportedPackage>();
        for (ModelledResource bundle : deployedContent) {
            requirements.addAll(bundle.getImportedPackages());
            internalExports.addAll(bundle.getExportedPackages());
        }
        // Filter out requirements satisfied by internal capabilities.
        result = new ArrayList<ImportedPackage>();
        for (ImportedPackage req : requirements) {
            boolean satisfied = false;
            for (ExportedPackage export : internalExports) {
                if (req.isSatisfied(export)) {
                    satisfied = true;
                    break;
                }
            }
            //If we didn't find a match then it must come from outside
            if (!satisfied)
                result.add(req);
        }
        PackageRequirementMerger merger = new PackageRequirementMerger(result);
        if (!merger.isMergeSuccessful()) {
            List<String> pkgNames = new ArrayList<String>(merger.getInvalidRequirements());
            StringBuilder buff = new StringBuilder();
            for (String pkgName : merger.getInvalidRequirements()) {
                buff.append(pkgName).append(", ");
            }
            int buffLen = buff.length();
            String pkgString = (buffLen > 0 ? buff.substring(0, buffLen - 2) : "");
            ResolverException re = new ResolverException(MessageUtil.getMessage("INCOMPATIBLE_PACKAGE_VERSION_REQUIREMENTS", new Object[] { assetName, pkgString }));
            re.setUnsatisfiedRequirements(pkgNames);
            logger.debug(LOG_EXIT, "getExternalPackageRequirements", re);
            throw re;
        }
        result = merger.getMergedRequirements();
        cachedExternalRequirements = result;
    }
    logger.debug(LOG_EXIT, "getExternalPackageRequirements", result);
    return result;
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) PackageRequirementMerger(org.apache.aries.application.modelling.internal.PackageRequirementMerger) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage)

Example 4 with ExportedPackage

use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.

the class ExportedPackageTest method testEqualsForIdenticalPackages.

@Test
public void testEqualsForIdenticalPackages() {
    String packageName = "package.name";
    String version = "1.0.0";
    ExportedPackage package1 = instantiatePackage(packageName, version);
    // I should hope so!
    assertEquals(package1, package1);
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Test(org.junit.Test)

Example 5 with ExportedPackage

use of org.apache.aries.application.modelling.ExportedPackage in project aries by apache.

the class ExportedPackageTest method testEqualsForEqualPackagesWithDifferentAttributes.

@Test
public void testEqualsForEqualPackagesWithDifferentAttributes() {
    String packageName = "package.name";
    String version = "1.0.0";
    ExportedPackage package1 = instantiatePackage(packageName, version, "att=something");
    ExportedPackage package2 = instantiatePackage(packageName, version, "att=something.else");
    assertFalse("Unexpectedly reported as equal" + package1 + "==" + package2, package1.equals(package2));
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Test(org.junit.Test)

Aggregations

ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)15 Test (org.junit.Test)8 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)6 ModelledResource (org.apache.aries.application.modelling.ModelledResource)6 ArrayList (java.util.ArrayList)5 ResolverException (org.apache.aries.application.management.ResolverException)4 List (java.util.List)3 Content (org.apache.aries.application.Content)3 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)2 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)2 ImportedService (org.apache.aries.application.modelling.ImportedService)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2 HashSet (java.util.HashSet)1 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)1 AriesApplication (org.apache.aries.application.management.AriesApplication)1 PreResolveHook (org.apache.aries.application.management.spi.resolve.PreResolveHook)1 ExportedService (org.apache.aries.application.modelling.ExportedService)1