Search in sources :

Example 6 with ImportedService

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

the class ModellerTest method checkTestBundleResource.

private void checkTestBundleResource(ModelledResource resource) {
    assertNotNull(resource);
    assertEquals("file:///test.bundle.uri", resource.getLocation());
    // sanity check that we have parsed the manifest and package imports / exports
    assertEquals("test.bundle", resource.getSymbolicName());
    assertEquals("1.0.0", resource.getVersion());
    assertEquals(1, resource.getExportedPackages().size());
    assertEquals(3, resource.getImportedPackages().size());
    boolean foundFirstPackage = false;
    for (ImportedPackage pack : resource.getImportedPackages()) {
        if ("javax.jms".equals(pack.getPackageName()) && "1.1.0".equals(pack.getVersionRange()))
            foundFirstPackage = true;
    }
    assertTrue(foundFirstPackage);
    ExportedPackage epack = resource.getExportedPackages().iterator().next();
    assertEquals("wibble", epack.getPackageName());
    assertEquals("1.0.0", epack.getVersion());
    assertEquals("true", epack.getAttributes().get("directive:"));
    // sanity check that we have parsed the services
    assertEquals(4, resource.getExportedServices().size());
    assertEquals(4, resource.getImportedServices().size());
    boolean foundFirst = false;
    for (ImportedService service : resource.getImportedServices()) {
        if ("foo.bar.MyInjectedService".equals(service.getInterface())) {
            foundFirst = true;
            assertTrue(service.isOptional());
            assertFalse(service.isList());
            assertEquals("anOptionalReference", service.getId());
        }
    }
    assertTrue(foundFirst);
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) ImportedService(org.apache.aries.application.modelling.ImportedService)

Example 7 with ImportedService

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

the class AbstractBundleResourceTest method testBundleResource.

@Test
public void testBundleResource() throws Exception {
    assertEquals("The bundle symbolic name is wrong.", "test.bundle1", bundleResource.getSymbolicName());
    assertEquals("The bundle version is wrong.", "2.0.0.build-121", bundleResource.getVersion().toString());
    assertEquals("The bundle presentation name is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    int count = 0;
    for (ImportedPackage ip : bundleResource.getImportedPackages()) {
        String filter = ip.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ip.getPackageName().equals("org.osgi.framework")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "org.osgi.framework");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.3.0");
        } else if (ip.getPackageName().equals("aries.ws.kernel.file")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.kernel.file");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.application.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.application.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Company wrong", parsedFilterElements.get("company"), "yang");
            assertTrue("mandatory filter missing", filter.contains("(mandatory:<*company)"));
        } else if (ip.getPackageName().equals("aries.ws.ffdc")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.ffdc)(version>=0.0.0))", ip.getAttributeFilter());
            assertTrue("Optional import not correctly represented", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.app.framework.plugin")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.app.framework.plugin");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0)");
        } else if (ip.getPackageName().equals("aries.ejs.ras")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ejs.ras");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.event")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.event");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.app.container.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.app.container.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("bundle-symbolic-name"), "B");
            assertEquals("Wrong bundle version", parsedFilterElements.get("bundle-version"), "[1.2.0,2.2.0)");
        } else if (ip.getPackageName().equals("aries.ws.eba.bla")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bla");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.launcher")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.launcher");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0]");
            assertTrue("Dynamic-ImportPackage should be optional", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle4")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle4");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle5")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle5");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle6")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle6");
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle6)(version>=0.0.0))", ip.getAttributeFilter());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle7")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle7)(version>=0.0.0))", ip.getAttributeFilter());
        }
    }
    for (ImportedBundle ib : bundleResource.getRequiredBundles()) {
        String filter = ib.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ib.getSymbolicName().equals("com.acme.facade")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.facade");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ib.getSymbolicName().equals("com.acme.bar")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.bar");
        } else if (ib.getSymbolicName().equals("aries.ws.eba.framework")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "aries.ws.eba.framework");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "(3.0.0,4.0.0)");
        } else if (ib.getSymbolicName().equals("com.de.ba")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.de.ba");
        } else if (ib.getSymbolicName().equals("com.ab.de")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.ab.de");
        }
    }
    for (ImportedService svc : bundleResource.getImportedServices()) {
        if (svc.getInterface().equals("aries.ws.eba.import")) {
            count++;
            String filter = svc.getAttributeFilter();
            Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
            assertEquals("Wrong object class", parsedFilterElements.get("objectClass"), "aries.ws.eba.import");
            assertTrue("(service=service) should be present", svc.getAttributeFilter().contains("(service=service)"));
            assertTrue("(mandatory:<*service) should be present", svc.getAttributeFilter().contains("(mandatory:<*service)"));
        }
    }
    assertEquals("Not all requirements are listed.", bundleResource.getImportedPackages().size() + bundleResource.getImportedServices().size() + bundleResource.getRequiredBundles().size(), count);
    //verify the capability
    int verifiedExport = 0;
    for (ExportedPackage cap : bundleResource.getExportedPackages()) {
        if (cap.getPackageName().equals("aries.ws.eba.bundle1")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "2.2.0", cap.getVersion());
            assertEquals("The export package is not expected.", "test.bundle1", cap.getAttributes().get("bundle-symbolic-name"));
            assertEquals("The export package is not expected.", "2.0.0.build-121", cap.getAttributes().get("bundle-version").toString());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle2")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle3")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        }
    }
    assertEquals("The number of exports are not expected.", bundleResource.getExportedPackages().size(), verifiedExport);
    // bundle resource
    assertEquals("The bundle resource is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    assertEquals("The bundle resource is wrong.", "2.0.0.build-121", bundleResource.getExportedBundle().getVersion());
    assertEquals("The bundle resource is wrong.", "test.bundle1", bundleResource.getExportedBundle().getSymbolicName());
    for (ExportedService svc : bundleResource.getExportedServices()) {
        assertEquals("The export service is wrong", "aries.ws.eba.export", svc.getInterfaces().iterator().next());
    }
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) ImportedService(org.apache.aries.application.modelling.ImportedService) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle) Test(org.junit.Test)

Example 8 with ImportedService

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

the class AbstractParserProxy method parseCDRForReferences.

/**
	   * Extract References metadata from a ComponentDefinitionRegistry. 
	   * @param cdr                       ComponentDefinitionRegistry
	   * @return List<WrappedReferenceMetadata>
	   * @throws InvalidAttributeException 
	   */
private List<ImportedService> parseCDRForReferences(ComponentDefinitionRegistry cdr) throws InvalidAttributeException {
    _logger.debug(LOG_ENTRY, "parseCDRForReferences", new Object[] { cdr });
    List<ImportedService> result = new ArrayList<ImportedService>();
    for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
        if (compMetadata instanceof ServiceReferenceMetadata) {
            ServiceReferenceMetadata referenceMetadata = (ServiceReferenceMetadata) compMetadata;
            boolean optional = referenceMetadata.getAvailability() == ServiceReferenceMetadata.AVAILABILITY_OPTIONAL;
            String iface = referenceMetadata.getInterface();
            String compName = referenceMetadata.getComponentName();
            String blueprintFilter = referenceMetadata.getFilter();
            String id = referenceMetadata.getId();
            boolean isMultiple = (referenceMetadata instanceof ReferenceListMetadata);
            // For now we blacklist certain objectClasses and filters - this is a pretty dreadful thing to do. 
            if (!isBlacklisted(iface, blueprintFilter)) {
                ImportedService ref = _modellingManager.getImportedService(optional, iface, compName, blueprintFilter, id, isMultiple);
                result.add(ref);
            }
        }
    }
    _logger.debug(LOG_EXIT, "parseCDRForReferences", new Object[] { result });
    return result;
}
Also used : ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata)

Example 9 with ImportedService

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

the class DeployedBundlesTest method createModelledServiceBundle.

public static ModelledResource createModelledServiceBundle(String bundleName, String bundleVersion, Collection<String> importService, Collection<String> exportService) throws InvalidAttributeException {
    Attributes att = new Attributes();
    att.put(new Attributes.Name(Constants.BUNDLE_SYMBOLICNAME), bundleName);
    att.put(new Attributes.Name(Constants.BUNDLE_VERSION), bundleVersion);
    att.put(new Attributes.Name(Constants.BUNDLE_MANIFESTVERSION), "2");
    List<ImportedService> importedServices = new ArrayList<ImportedService>();
    for (String s : importService) {
        importedServices.add(new ImportedServiceImpl(false, s, null, null, null, false));
    }
    List<ExportedService> exportedServices = new ArrayList<ExportedService>();
    for (String s : exportService) {
        exportedServices.add(new ExportedServiceImpl(null, 0, Collections.singleton(s), Collections.<String, Object>emptyMap()));
    }
    return new ModelledResourceImpl(null, att, importedServices, exportedServices);
}
Also used : ImportedServiceImpl(org.apache.aries.application.modelling.impl.ImportedServiceImpl) ModelledResourceImpl(org.apache.aries.application.modelling.impl.ModelledResourceImpl) ExportedService(org.apache.aries.application.modelling.ExportedService) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ExportedServiceImpl(org.apache.aries.application.modelling.impl.ExportedServiceImpl)

Example 10 with ImportedService

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

the class ModelledResourceManagerImpl method getBlueprintServiceElements.

private ParsedServiceElements getBlueprintServiceElements(BundleManifest bundleMf, Iterable<InputStream> blueprints) throws ModellerException {
    _logger.debug(LOG_ENTRY, "getServiceElements", new Object[] { bundleMf, blueprints });
    Set<ExportedService> services = new HashSet<ExportedService>();
    Set<ImportedService> references = new HashSet<ImportedService>();
    try {
        for (InputStream is : blueprints) {
            try {
                ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
                services.addAll(pse.getServices());
                references.addAll(pse.getReferences());
            } finally {
                IOUtils.close(is);
            }
        }
    } catch (Exception e) {
        ModellerException m = new ModellerException(e);
        _logger.debug(LOG_EXIT, "getServiceElements", m);
        throw m;
    }
    ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
    _logger.debug(LOG_EXIT, "getServiceElements", result);
    return result;
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ModellerException(org.apache.aries.application.modelling.ModellerException) ImportedService(org.apache.aries.application.modelling.ImportedService) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) ModellerException(org.apache.aries.application.modelling.ModellerException) HashSet(java.util.HashSet) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Aggregations

ImportedService (org.apache.aries.application.modelling.ImportedService)10 ExportedService (org.apache.aries.application.modelling.ExportedService)8 ParsedServiceElements (org.apache.aries.application.modelling.ParsedServiceElements)4 ArrayList (java.util.ArrayList)3 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)3 ModellerException (org.apache.aries.application.modelling.ModellerException)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 HashSet (java.util.HashSet)2 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)2 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)2 InputStream (java.io.InputStream)1 Attributes (java.util.jar.Attributes)1 ZipInputStream (java.util.zip.ZipInputStream)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)1 ModelledResource (org.apache.aries.application.modelling.ModelledResource)1 ServiceModeller (org.apache.aries.application.modelling.ServiceModeller)1 ExportedServiceImpl (org.apache.aries.application.modelling.impl.ExportedServiceImpl)1