Search in sources :

Example 6 with JarResource

use of aQute.bnd.osgi.JarResource 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 7 with JarResource

use of aQute.bnd.osgi.JarResource in project bnd by bndtools.

the class MakeBnd method make.

public Resource make(Builder builder, String destination, Map<String, String> argumentsOnMake) throws Exception {
    String type = argumentsOnMake.get("type");
    if (!"bnd".equals(type))
        return null;
    String recipe = argumentsOnMake.get("recipe");
    if (recipe == null) {
        builder.error("No recipe specified on a make instruction for %s", destination);
        return null;
    }
    File bndfile = builder.getFile(recipe);
    if (bndfile.isFile()) {
        // We do not use a parent because then we would
        // build ourselves again. So we can not blindly
        // inherit the properties.
        Builder bchild = builder.getSubBuilder();
        bchild.removeBundleSpecificHeaders();
        // We must make sure that we do not include ourselves again!
        bchild.setProperty(Analyzer.INCLUDE_RESOURCE, "");
        bchild.setProperty(Analyzer.INCLUDERESOURCE, "");
        bchild.setProperties(bndfile, builder.getBase());
        Jar jar = bchild.build();
        Jar dot = builder.getJar();
        if (builder.hasSources()) {
            for (String key : jar.getResources().keySet()) {
                if (key.startsWith("OSGI-OPT/src"))
                    dot.putResource(key, jar.getResource(key));
            }
        }
        builder.getInfo(bchild, bndfile.getName() + ": ");
        return new JarResource(jar);
    }
    return null;
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) Jar(aQute.bnd.osgi.Jar) File(java.io.File)

Example 8 with JarResource

use of aQute.bnd.osgi.JarResource 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<Container> distro = project.getBundles(Strategy.LOWEST, project.getProperty(Constants.DISTRO), Constants.DISTRO);
    List<File> distroFiles = getBundles(distro, project);
    List<File> files = getBundles(project.getRunbundles(), project);
    MultiMap<String, Attrs> imports = new MultiMap<String, Attrs>();
    MultiMap<String, Attrs> exports = new MultiMap<String, Attrs>();
    Parameters requirements = new Parameters();
    Parameters capabilities = new Parameters();
    for (File file : files) {
        Domain domain = Domain.domain(file);
        String bsn = domain.getBundleSymbolicName().getKey();
        String version = domain.getBundleVersion();
        for (Entry<String, Attrs> e : domain.getImportPackage().entrySet()) {
            imports.add(e.getKey(), e.getValue());
        }
        for (Entry<String, Attrs> e : domain.getExportPackage().entrySet()) {
            exports.add(e.getKey(), e.getValue());
        }
        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 : Parameters(aQute.bnd.header.Parameters) JarResource(aQute.bnd.osgi.JarResource) Attrs(aQute.bnd.header.Attrs) FileResource(aQute.bnd.osgi.FileResource) JarResource(aQute.bnd.osgi.JarResource) FileResource(aQute.bnd.osgi.FileResource) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Resource(aQute.bnd.osgi.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) MultiMap(aQute.lib.collections.MultiMap) Container(aQute.bnd.build.Container) Entry(java.util.Map.Entry) EmbeddedResource(aQute.bnd.osgi.EmbeddedResource) Jar(aQute.bnd.osgi.Jar) Domain(aQute.bnd.osgi.Domain) File(java.io.File)

Example 9 with JarResource

use of aQute.bnd.osgi.JarResource in project bnd by bndtools.

the class MakeTest method testComplexOnDemand.

/**
	 * Check if we can create a jar on demand through the make facility with a
	 * new name.
	 * 
	 * @throws Exception
	 */
public static void testComplexOnDemand() throws Exception {
    Builder bmaker = new Builder();
    Properties p = new Properties();
    p.setProperty("-resourceonly", "true");
    p.setProperty("-plugin", "aQute.bnd.make.MakeBnd, aQute.bnd.make.MakeCopy");
    p.setProperty("-make", "(*).jar;type=bnd;recipe=bnd/$1.bnd");
    p.setProperty("Include-Resource", "www/xyz.jar=ondemand.jar");
    bmaker.setProperties(p);
    bmaker.setClasspath(new String[] { "bin" });
    Jar jar = bmaker.build();
    Resource resource = jar.getResource("www/xyz.jar");
    assertNotNull(resource);
    assertTrue(resource instanceof JarResource);
    report(bmaker);
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) Resource(aQute.bnd.osgi.Resource) JarResource(aQute.bnd.osgi.JarResource) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Example 10 with JarResource

use of aQute.bnd.osgi.JarResource in project bnd by bndtools.

the class ResourcesTest method testOnDemandResource.

/**
	 * Check if we can create a jar on demand through the make facility.
	 * 
	 * @throws Exception
	 */
public static void testOnDemandResource() throws Exception {
    Builder bmaker = new Builder();
    Properties p = new Properties();
    p.setProperty("-resourceonly", "true");
    p.setProperty("-plugin", "aQute.bnd.make.MakeBnd, aQute.bnd.make.MakeCopy");
    p.setProperty("-make", "(*).jar;type=bnd;recipe=bnd/$1.bnd");
    p.setProperty("Include-Resource", "ondemand.jar");
    bmaker.setProperties(p);
    bmaker.setClasspath(new String[] { "bin" });
    Jar jar = bmaker.build();
    Resource resource = jar.getResource("ondemand.jar");
    assertNotNull(resource);
    assertTrue(bmaker.check());
    assertTrue(resource instanceof JarResource);
    report(bmaker);
}
Also used : JarResource(aQute.bnd.osgi.JarResource) Builder(aQute.bnd.osgi.Builder) JarResource(aQute.bnd.osgi.JarResource) Resource(aQute.bnd.osgi.Resource) Jar(aQute.bnd.osgi.Jar) Properties(java.util.Properties)

Aggregations

Jar (aQute.bnd.osgi.Jar)11 JarResource (aQute.bnd.osgi.JarResource)11 File (java.io.File)7 Builder (aQute.bnd.osgi.Builder)5 Manifest (java.util.jar.Manifest)5 Resource (aQute.bnd.osgi.Resource)4 Parameters (aQute.bnd.header.Parameters)3 Properties (java.util.Properties)3 Container (aQute.bnd.build.Container)2 Domain (aQute.bnd.osgi.Domain)2 EmbeddedResource (aQute.bnd.osgi.EmbeddedResource)2 FileResource (aQute.bnd.osgi.FileResource)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Attrs (aQute.bnd.header.Attrs)1 Verifier (aQute.bnd.osgi.Verifier)1 RepositoryPlugin (aQute.bnd.service.RepositoryPlugin)1 PutResult (aQute.bnd.service.RepositoryPlugin.PutResult)1 MultiMap (aQute.lib.collections.MultiMap)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1