Search in sources :

Example 16 with Version

use of org.osgi.framework.Version in project aries by apache.

the class DeployedContentHeader method appendResource.

private static StringBuilder appendResource(Resource resource, StringBuilder builder, boolean referenced) {
    String symbolicName = ResourceHelper.getSymbolicNameAttribute(resource);
    Version version = ResourceHelper.getVersionAttribute(resource);
    String type = ResourceHelper.getTypeAttribute(resource);
    builder.append(symbolicName).append(';').append(Clause.ATTRIBUTE_DEPLOYEDVERSION).append('=').append(version.toString()).append(';').append(Clause.ATTRIBUTE_TYPE).append('=').append(type).append(';').append(Clause.ATTRIBUTE_RESOURCEID).append('=').append(Utils.getId(resource)).append(';').append(Clause.DIRECTIVE_REFERENCE).append(":=").append(referenced);
    return builder;
}
Also used : Version(org.osgi.framework.Version)

Example 17 with Version

use of org.osgi.framework.Version in project aries by apache.

the class RawSubsystemResource method createFakeResource.

private static Resource createFakeResource(SubsystemManifest manifest) {
    Header<?> importServiceHeader = manifest.getHeaders().get(APPLICATION_IMPORT_SERVICE_HEADER);
    if (importServiceHeader == null) {
        return null;
    }
    List<Capability> modifiableCaps = new ArrayList<Capability>();
    final List<Capability> fakeCapabilities = Collections.unmodifiableList(modifiableCaps);
    Resource fakeResource = new Resource() {

        @Override
        public List<Capability> getCapabilities(String namespace) {
            if (namespace == null) {
                return fakeCapabilities;
            }
            List<Capability> results = new ArrayList<Capability>();
            for (Capability capability : fakeCapabilities) {
                if (namespace.equals(capability.getNamespace())) {
                    results.add(capability);
                }
            }
            return results;
        }

        @Override
        public List<Requirement> getRequirements(String namespace) {
            return Collections.emptyList();
        }
    };
    modifiableCaps.add(new OsgiIdentityCapability(fakeResource, Constants.ResourceTypeSynthesized, new Version(1, 0, 0), Constants.ResourceTypeSynthesized));
    Map<String, Map<String, String>> serviceImports = ManifestHeaderProcessor.parseImportString(importServiceHeader.getValue());
    for (Entry<String, Map<String, String>> serviceImport : serviceImports.entrySet()) {
        Collection<String> objectClasses = new ArrayList<String>(Arrays.asList(serviceImport.getKey()));
        String filter = serviceImport.getValue().get(IdentityNamespace.REQUIREMENT_FILTER_DIRECTIVE);
        BasicCapability.Builder capBuilder = new BasicCapability.Builder();
        capBuilder.namespace(ServiceNamespace.SERVICE_NAMESPACE);
        capBuilder.attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, objectClasses);
        if (filter != null)
            capBuilder.attributes(new HashMap<String, Object>(SimpleFilter.attributes(filter)));
        capBuilder.attribute("service.imported", "");
        capBuilder.resource(fakeResource);
        modifiableCaps.add(capBuilder.build());
    }
    return fakeResource;
}
Also used : Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Resource(org.osgi.resource.Resource) Requirement(org.osgi.resource.Requirement) Version(org.osgi.framework.Version) Map(java.util.Map) HashMap(java.util.HashMap)

Example 18 with Version

use of org.osgi.framework.Version in project aries by apache.

the class ClientWeavingHookGenericCapabilityTest method mockConsumerBundle.

private Bundle mockConsumerBundle(Dictionary<String, String> headers, BundleRevision rev, Bundle... otherBundles) {
    // Create a mock object for the client bundle which holds the code that uses ServiceLoader.load()
    // or another SPI invocation.
    BundleContext bc = EasyMock.createMock(BundleContext.class);
    Bundle consumerBundle = EasyMock.createMock(Bundle.class);
    EasyMock.expect(consumerBundle.getSymbolicName()).andReturn("testConsumer").anyTimes();
    EasyMock.expect(consumerBundle.getVersion()).andReturn(new Version(1, 2, 3)).anyTimes();
    EasyMock.expect(consumerBundle.getHeaders()).andReturn(headers).anyTimes();
    EasyMock.expect(consumerBundle.getBundleContext()).andReturn(bc).anyTimes();
    EasyMock.expect(consumerBundle.getBundleId()).andReturn(Long.MAX_VALUE).anyTimes();
    EasyMock.expect(consumerBundle.adapt(BundleRevision.class)).andReturn(rev).anyTimes();
    EasyMock.replay(consumerBundle);
    List<Bundle> allBundles = new ArrayList<Bundle>(Arrays.asList(otherBundles));
    allBundles.add(consumerBundle);
    EasyMock.expect(bc.getBundles()).andReturn(allBundles.toArray(new Bundle[] {})).anyTimes();
    EasyMock.replay(bc);
    return consumerBundle;
}
Also used : Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleRevision(org.osgi.framework.wiring.BundleRevision) ArrayList(java.util.ArrayList) BundleContext(org.osgi.framework.BundleContext)

Example 19 with Version

use of org.osgi.framework.Version in project aries by apache.

the class AbstractHeader method appendResource.

// TODO This is specific to deployment manifests and shouldn't be at this level.
protected static void appendResource(Resource resource, StringBuilder builder) {
    Map<String, Object> attributes = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE).get(0).getAttributes();
    String symbolicName = (String) attributes.get(IdentityNamespace.IDENTITY_NAMESPACE);
    Version version = (Version) attributes.get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
    String namespace = (String) attributes.get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
    builder.append(symbolicName).append(';').append(DeployedVersionAttribute.NAME).append('=').append(version.toString()).append(';').append(TypeAttribute.NAME).append('=').append(namespace);
}
Also used : Version(org.osgi.framework.Version)

Example 20 with Version

use of org.osgi.framework.Version in project aries by apache.

the class AriesSubsystemParentsHeader method getClause.

public Clause getClause(BasicSubsystem subsystem) {
    String symbolicName = subsystem.getSymbolicName();
    Version version = subsystem.getVersion();
    String type = subsystem.getType();
    for (Clause clause : clauses) {
        if (symbolicName.equals(clause.getPath()) && clause.getVersion().equals(version) && type.equals(clause.getType()))
            return clause;
    }
    return null;
}
Also used : Version(org.osgi.framework.Version)

Aggregations

Version (org.osgi.framework.Version)165 Test (org.junit.Test)30 Bundle (org.osgi.framework.Bundle)26 ArrayList (java.util.ArrayList)22 Capability (org.osgi.resource.Capability)19 File (java.io.File)17 HashMap (java.util.HashMap)16 Resource (org.osgi.resource.Resource)14 IOException (java.io.IOException)13 InputStream (java.io.InputStream)11 Manifest (java.util.jar.Manifest)11 Map (java.util.Map)9 HashSet (java.util.HashSet)8 Content (org.apache.aries.application.Content)8 AriesApplication (org.apache.aries.application.management.AriesApplication)8 VersionRange (org.apache.felix.utils.version.VersionRange)8 BundleRevision (org.osgi.framework.wiring.BundleRevision)8 List (java.util.List)7 BundleWiring (org.osgi.framework.wiring.BundleWiring)7 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)6