Search in sources :

Example 26 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class ProjectResolver method getRunBundles.

/**
	 * Get the run bundles from the resolution. Resolve if this has not happened
	 * yet.
	 */
public List<Container> getRunBundles() throws Exception {
    Map<Resource, List<Wire>> resolution = this.resolution;
    if (resolution == null) {
        resolution = resolve();
    }
    List<Container> containers = new ArrayList<Container>();
    for (Resource r : resolution.keySet()) {
        IdentityCapability identity = ResourceUtils.getIdentityCapability(r);
        if (identity == null) {
            error("Identity for %s not found", r);
            continue;
        }
        Container bundle = project.getBundle(identity.osgi_identity(), identity.version().toString(), Strategy.EXACT, null);
        if (bundle == null) {
            error("Bundle for %s-%s not found", identity.osgi_identity(), identity.version());
            continue;
        }
        containers.add(bundle);
    }
    return containers;
}
Also used : Container(aQute.bnd.build.Container) Resource(org.osgi.resource.Resource) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IdentityCapability(aQute.bnd.osgi.resource.ResourceUtils.IdentityCapability)

Example 27 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class SubsystemExporter method export.

@Override
public Map.Entry<String, Resource> export(String type, final Project project, Map<String, String> options) throws Exception {
    Jar jar = new Jar(".");
    project.addClose(jar);
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
    manifest.getMainAttributes().putValue("Subsystem-ManifestVersion", "1");
    List<File> files = new ArrayList<File>();
    for (Container c : project.getRunbundles()) {
        switch(c.getType()) {
            case ERROR:
                // skip, already reported
                break;
            case PROJECT:
            case EXTERNAL:
            case REPO:
                files.add(c.getFile());
                break;
            case LIBRARY:
                c.contributeFiles(files, project);
                break;
        }
    }
    for (File file : files) {
        Domain domain = Domain.domain(file);
        String bsn = domain.getBundleSymbolicName().getKey();
        String version = domain.getBundleVersion();
        String path = bsn + "-" + version + ".jar";
        jar.putResource(path, new FileResource(file));
    }
    headers(project, manifest.getMainAttributes());
    set(manifest.getMainAttributes(), SUBSYSTEM_TYPE, OSGI_SUBSYSTEM_FEATURE);
    String ssn = project.getName();
    Collection<String> bsns = project.getBsns();
    if (bsns.size() > 0) {
        ssn = bsns.iterator().next();
    }
    set(manifest.getMainAttributes(), SUBSYSTEM_SYMBOLIC_NAME, ssn);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    manifest.write(bout);
    jar.putResource(OSGI_INF_SUBSYSTEM_MF, new EmbeddedResource(bout.toByteArray(), 0));
    final JarResource jarResource = new JarResource(jar);
    final String name = ssn + ".esa";
    return new Map.Entry<String, Resource>() {

        @Override
        public String getKey() {
            return name;
        }

        @Override
        public Resource getValue() {
            return jarResource;
        }

        @Override
        public Resource setValue(Resource arg0) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : JarResource(aQute.bnd.osgi.JarResource) ArrayList(java.util.ArrayList) FileResource(aQute.bnd.osgi.FileResource) JarResource(aQute.bnd.osgi.JarResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) FileResource(aQute.bnd.osgi.FileResource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) Container(aQute.bnd.build.Container) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 28 with Container

use of aQute.bnd.build.Container in project bnd by bndtools.

the class ProjectResolverTest method testAugment.

// public void testSimple() throws Exception {
// Run run = new Run(ws, IO.work,
// IO.getFile("testdata/projectresolver/simple.bndrun"));
// ProjectResolver pr = new ProjectResolver(run);
// pr.setTrace(true);
// Map<Resource,List<Wire>> resolve = pr.resolve();
// assertTrue(pr.check());
// List<Container> runbundles = pr.getRunBundles();
// assertEquals(2, runbundles.size());
// System.out.println(Strings.join("\n", runbundles));
// pr.close();
// }
public void testAugment() throws Exception {
    try (Builder b = new Builder()) {
        //
        // Create an augment jar. We add a foo capability with bar=1 to
        // promises
        //
        b.setBundleSymbolicName("foo.bar");
        b.setProperty("Provide-Capability", "bnd.augment;path=augments.bnd");
        Jar build = b.build();
        String augm = "-augment.a: osgi.promise;capability:='foo;bar=1'";
        build.putResource("augments.bnd", new EmbeddedResource(augm.getBytes(), 10000));
        //
        // Store it in the repo
        //
        File out = new File(tmp, "for.bar.jar");
        build.write(out);
        add(fr, out);
        try (Run run = new Run(ws, IO.work, IO.getFile("testdata/projectresolver/augment.bndrun"))) {
            run.setTrace(true);
            assertNotNull(ws.getRepositories());
            System.out.println(ws.getRepositories());
            assertNotNull(run.getWorkspace().getPlugins(Repository.class));
            System.out.println(run.getWorkspace().getPlugins(Repository.class));
            ProjectResolver pr = new ProjectResolver(run);
            pr.setTrace(true);
            Map<Resource, List<Wire>> resolve = pr.resolve();
            assertTrue(pr.check());
            List<Container> runbundles = pr.getRunBundles();
            assertEquals(1, runbundles.size());
            assertTrue(run.check());
            pr.close();
        }
    }
}
Also used : ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Builder(aQute.bnd.osgi.Builder) Resource(org.osgi.resource.Resource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Run(aQute.bnd.build.Run) ResourcesRepository(aQute.bnd.osgi.repository.ResourcesRepository) OSGiRepository(aQute.bnd.repository.osgi.OSGiRepository) Repository(org.osgi.service.repository.Repository) Container(aQute.bnd.build.Container) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) List(java.util.List) File(java.io.File)

Aggregations

Container (aQute.bnd.build.Container)28 Project (aQute.bnd.build.Project)19 Workspace (aQute.bnd.build.Workspace)16 ArrayList (java.util.ArrayList)14 File (java.io.File)8 Attrs (aQute.bnd.header.Attrs)5 Jar (aQute.bnd.osgi.Jar)5 Manifest (java.util.jar.Manifest)5 Run (aQute.bnd.build.Run)3 Domain (aQute.bnd.osgi.Domain)3 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)3 FileResource (aQute.bnd.osgi.FileResource)3 Parameters (aQute.bnd.header.Parameters)2 Builder (aQute.bnd.osgi.Builder)2 JarResource (aQute.bnd.osgi.JarResource)2 Resource (aQute.bnd.osgi.Resource)2 ResourceBuilder (aQute.bnd.osgi.resource.ResourceBuilder)2 Version (aQute.bnd.version.Version)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 List (java.util.List)2