Search in sources :

Example 1 with ModelledResource

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

the class OBRResolverTest method generateOBRRepoXML.

private void generateOBRRepoXML(String... bundleFiles) throws Exception {
    Set<ModelledResource> mrs = new HashSet<ModelledResource>();
    FileOutputStream fout = new FileOutputStream("repository.xml");
    RepositoryGenerator repositoryGenerator = context().getService(RepositoryGenerator.class);
    ModelledResourceManager modelledResourceManager = context().getService(ModelledResourceManager.class);
    for (String fileName : bundleFiles) {
        File bundleFile = new File(fileName);
        IDirectory jarDir = FileSystem.getFSRoot(bundleFile);
        mrs.add(modelledResourceManager.getModelledResource(bundleFile.toURI().toString(), jarDir));
    }
    repositoryGenerator.generateRepository("Test repo description", mrs, fout);
    fout.close();
}
Also used : RepositoryGenerator(org.apache.aries.application.management.spi.repository.RepositoryGenerator) FileOutputStream(java.io.FileOutputStream) IDirectory(org.apache.aries.util.filesystem.IDirectory) ModelledResourceManager(org.apache.aries.application.modelling.ModelledResourceManager) File(java.io.File) HashSet(java.util.HashSet) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 2 with ModelledResource

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

the class DeployedBundlesTest method testGetRequiredUseBundle_Valid.

@Test
public void testGetRequiredUseBundle_Valid() throws Exception {
    // Get a valid set of deployment information.
    DeployedBundles deployedBundles = validDeployedBundles();
    packagesResolve(deployedBundles);
    // Check all the use-bundle entries are required.
    Collection<ModelledResource> requiredUseBundle = null;
    try {
        requiredUseBundle = deployedBundles.getRequiredUseBundle();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    Assert.assertTrue("RequiredUseBundle=" + requiredUseBundle, requiredUseBundle.size() == 2);
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 3 with ModelledResource

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

the class DeployedBundlesImpl method getDeployedImportService.

/**
   * Get the Deployed-ImportService header. 
   * this.deployedImportService contains all the service import filters for every 
   * blueprint component within the application. We will only write an entry
   * to Deployed-ImportService if
   *   a) the reference isMultiple(), or
   *   b) the service was not available internally when the app was first deployed
   *   
   */
public String getDeployedImportService() {
    logger.debug(LOG_ENTRY, "getDeployedImportService");
    String result = cachedDeployedImportService;
    if (result == null) {
        Collection<ImportedService> deployedBundleServiceImports = new ArrayList<ImportedService>();
        Collection<ExportedService> servicesExportedWithinIsolatedContent = new ArrayList<ExportedService>();
        for (ModelledResource mRes : getDeployedContent()) {
            servicesExportedWithinIsolatedContent.addAll(mRes.getExportedServices());
        }
        for (ModelledResource mRes : fakeDeployedBundles) {
            servicesExportedWithinIsolatedContent.addAll(mRes.getExportedServices());
        }
        for (ImportedService impService : deployedImportService) {
            if (impService.isMultiple()) {
                deployedBundleServiceImports.add(impService);
            } else {
                boolean serviceProvidedWithinIsolatedContent = false;
                Iterator<ExportedService> it = servicesExportedWithinIsolatedContent.iterator();
                while (!serviceProvidedWithinIsolatedContent && it.hasNext()) {
                    ExportedService svc = it.next();
                    serviceProvidedWithinIsolatedContent |= impService.isSatisfied(svc);
                }
                if (!serviceProvidedWithinIsolatedContent) {
                    deployedBundleServiceImports.add(impService);
                }
            }
        }
        result = createManifestString(deployedBundleServiceImports);
        cachedDeployedImportService = result;
    }
    logger.debug(LOG_EXIT, "getDeployedImportService", result);
    return result;
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 4 with ModelledResource

use of org.apache.aries.application.modelling.ModelledResource 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 5 with ModelledResource

use of org.apache.aries.application.modelling.ModelledResource 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)

Aggregations

ModelledResource (org.apache.aries.application.modelling.ModelledResource)41 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ZipOutputStream (java.util.zip.ZipOutputStream)11 ResolverException (org.apache.aries.application.management.ResolverException)11 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)11 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)10 File (java.io.File)8 Content (org.apache.aries.application.Content)8 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)7 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)5 AriesApplication (org.apache.aries.application.management.AriesApplication)5 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)5 HashMap (java.util.HashMap)4 Attributes (java.util.jar.Attributes)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4