Search in sources :

Example 11 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.

the class BndrunResolveContext method init.

/**
	 * Initializes the resolver. Here we will load all the information from the
	 * model.
	 */
@Override
public synchronized void init() {
    if (initialized)
        return;
    initialized = true;
    try {
        if (getLevel() <= 0) {
            Integer level = Converter.cnv(Integer.class, properties.getProperty("-resolvedebug", "0"));
            if (level != null)
                setLevel(level);
        }
        loadPreferences();
        Processor augments = loadRepositories();
        constructBlacklist(augments);
        Map<String, Set<String>> effectiveSet = loadEffectiveSet();
        if (effectiveSet != null)
            addEffectiveSet(effectiveSet);
        //
        // Create a resource from the -runrequire that contains
        // all the requirement
        //
        setInputResource(constructInputRequirements());
        //
        // We gradually build up the system resource that contains
        // the system packages, the EE, etc.
        //
        ResourceBuilder system = new ResourceBuilder();
        //
        // Let's identify the system resource to make it look less
        // ugly
        //
        //
        // If we have a distro, we do not load the environment
        // settings
        //
        String distro = properties.mergeProperties(Constants.DISTRO);
        if (distro != null && !distro.trim().isEmpty()) {
            loadPath(system, distro, Constants.DISTRO);
            loadProvidedCapabilities(system);
        } else {
            //
            // Load the EE's and packages that belong to it.
            //
            EE tmp = EE.parse(properties.getProperty(Constants.RUNEE));
            EE ee = (tmp != null) ? tmp : EE.JavaSE_1_6;
            system.addAllExecutionEnvironments(ee);
            //
            // We make the system packages as coming from the system
            // resource
            //
            Parameters systemPackages = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMPACKAGES), project);
            system.addExportPackages(systemPackages);
            //
            // We make the system capabilities as coming from the system
            // resource
            //
            Parameters systemCapabilities = new Parameters(properties.mergeProperties(Constants.RUNSYSTEMCAPABILITIES), project);
            system.addProvideCapabilities(systemCapabilities);
            loadProvidedCapabilities(system);
            //
            // Load the frameworks capabilities
            //
            loadFramework(system);
            //
            // Analyze the path and add all exported packages and provided
            // capabilities
            // to the system resource
            //
            String runpath = properties.mergeProperties(Constants.RUNPATH);
            if (runpath != null && !runpath.trim().isEmpty())
                loadPath(system, runpath, Constants.RUNPATH);
        }
        //
        // We've not gathered all the capabilities of the system
        // so we can create the resource and set it as the system resource
        //
        //
        // TODO Add osgi.wiring.bundle + osgi.wiring.host
        // filed a bug about using the impl version for the system
        // capabilities
        //
        List<Capability> frameworkPackages = system.findCapabilities(PackageNamespace.PACKAGE_NAMESPACE, "(" + PackageNamespace.PACKAGE_NAMESPACE + "=org.osgi.framework)");
        if (!frameworkPackages.isEmpty()) {
            Capability c = frameworkPackages.get(0);
            Version version = (Version) c.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
            CapReqBuilder crb = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE);
            crb.addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, "system.bundle");
            crb.addAttribute(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE, version);
            system.addCapability(crb);
        }
        setSystemResource(system.build());
    } catch (Exception e) {
        log.log(LogService.LOG_ERROR, e.getMessage(), e);
        throw new RuntimeException(e);
    }
    super.init();
}
Also used : EE(aQute.bnd.build.model.EE) CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Processor(aQute.bnd.osgi.Processor) Set(java.util.Set) HashSet(java.util.HashSet) Parameters(aQute.bnd.header.Parameters) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version)

Example 12 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.

the class BndrunResolveContext method constructInputRequirements.

Resource constructInputRequirements() throws Exception {
    ResourceBuilder resBuilder = new ResourceBuilder();
    CapReqBuilder identity = new CapReqBuilder(IdentityNamespace.IDENTITY_NAMESPACE).addAttribute(IdentityNamespace.IDENTITY_NAMESPACE, IDENTITY_INITIAL_RESOURCE);
    resBuilder.addCapability(identity);
    Parameters inputRequirements = new Parameters(properties.mergeProperties(Constants.RUNREQUIRES), project);
    if (inputRequirements != null && !inputRequirements.isEmpty()) {
        List<Requirement> requires = CapReqBuilder.getRequirementsFrom(inputRequirements);
        resBuilder.addRequirements(requires);
    }
    return resBuilder.build();
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Parameters(aQute.bnd.header.Parameters)

Example 13 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.

the class BndrunResolveContext method loadPath.

/**
	 * Add a path to the system resource. This is done by the bnd launcher for
	 * -runpath and it is also used for -distro.
	 */
public void loadPath(ResourceBuilder system, String path, String what) throws Exception {
    if (project != null) {
        List<Container> containers = Container.flatten(project.getBundles(Strategy.HIGHEST, path, what));
        for (Container c : containers) {
            Manifest manifest = c.getManifest();
            if (manifest != null) {
                ResourceBuilder rb = new ResourceBuilder();
                rb.addManifest(Domain.domain(manifest));
                addSystemResource(system, rb.build());
            }
        }
    } else {
        super.loadPath(system, path, what);
    }
}
Also used : Container(aQute.bnd.build.Container) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Manifest(java.util.jar.Manifest)

Example 14 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.

the class AbstractResolveContext method setInputRequirements.

public void setInputRequirements(Requirement... reqs) throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    for (Requirement r : reqs) {
        rb.addRequirement(r);
    }
    setInputResource(rb.build());
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder)

Example 15 with ResourceBuilder

use of aQute.bnd.osgi.resource.ResourceBuilder in project bnd by bndtools.

the class PersistentResourceTest method testSimple.

public void testSimple() throws Exception {
    ResourceBuilder rb = new ResourceBuilder();
    rb.addCapability(new CapReqBuilder("test").addAttribute("double", 3.0).addAttribute("long", 3L).addAttribute("string", "3.0").addAttribute("version", new Version("3.0")).buildSyntheticCapability());
    Resource r = rb.build();
    PersistentResource pr = new PersistentResource(r);
    String s = new JSONCodec().enc().put(pr).toString();
    PersistentResource pr2 = new JSONCodec().dec().from(s).get(PersistentResource.class);
    List<Capability> capabilities = pr.getResource().getCapabilities(null);
    List<Requirement> requirements = pr.getResource().getRequirements(null);
    assertEquals(1, capabilities.size());
    assertEquals(0, requirements.size());
    Capability capability = capabilities.get(0);
    assertEquals("test", capability.getNamespace());
    assertEquals(3.0, capability.getAttributes().get("double"));
    assertEquals(3L, capability.getAttributes().get("long"));
    assertEquals("3.0", capability.getAttributes().get("string"));
    assertEquals(new Version("3.0"), capability.getAttributes().get("version"));
    assertEquals(0, capability.getDirectives().size());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) JSONCodec(aQute.lib.json.JSONCodec)

Aggregations

ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)41 Resource (org.osgi.resource.Resource)22 File (java.io.File)13 CapReqBuilder (aQute.bnd.osgi.resource.CapReqBuilder)8 Capability (org.osgi.resource.Capability)8 Requirement (org.osgi.resource.Requirement)8 Parameters (aQute.bnd.header.Parameters)6 ResourcesRepository (aQute.bnd.osgi.repository.ResourcesRepository)6 Version (org.osgi.framework.Version)6 Domain (aQute.bnd.osgi.Domain)5 Resolution (biz.aQute.resolve.ResolverValidator.Resolution)5 HashSet (java.util.HashSet)5 IOException (java.io.IOException)4 URI (java.net.URI)4 ArrayList (java.util.ArrayList)4 Processor (aQute.bnd.osgi.Processor)3 HashMap (java.util.HashMap)3 List (java.util.List)3 VersionedClause (aQute.bnd.build.model.clauses.VersionedClause)2 Referral (aQute.bnd.deployer.repository.api.Referral)2