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();
}
};
}
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;
}
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();
}
};
}
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);
}
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);
}
Aggregations