use of aQute.bnd.osgi.EmbeddedResource in project bnd by bndtools.
the class JarTest method testManualManifest.
public static void testManualManifest() throws Exception {
Jar jar = new Jar("dot");
jar.setManifest(new Manifest());
jar.setDoNotTouchManifest();
jar.putResource("a/b", new FileResource(IO.getFile("testresources/bnd.jar")));
jar.putResource("META-INF/MANIFEST.MF", new EmbeddedResource("Manifest-Version: 1\r\nX: 1\r\n\r\n".getBytes(), 0));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
jar.write(bout);
JarInputStream jin = new JarInputStream(new ByteArrayInputStream(bout.toByteArray()));
Manifest m = jin.getManifest();
assertNotNull(m);
assertEquals("1", m.getMainAttributes().getValue("X"));
jin.close();
}
use of aQute.bnd.osgi.EmbeddedResource in project bnd by bndtools.
the class MakeCopy method make.
public Resource make(Builder builder, String destination, Map<String, String> argumentsOnMake) throws Exception {
String type = argumentsOnMake.get("type");
if (!type.equals("copy"))
return null;
String from = argumentsOnMake.get("from");
if (from == null) {
String content = argumentsOnMake.get("content");
if (content == null)
throw new IllegalArgumentException("No 'from' or 'content' field in copy " + argumentsOnMake);
return new EmbeddedResource(content.getBytes(UTF_8), 0);
}
File f = builder.getFile(from);
if (f.isFile())
return new FileResource(f);
try {
URL url = new URL(from);
return new URLResource(url);
} catch (MalformedURLException mfue) {
// We ignore this
}
throw new IllegalArgumentException("Copy source does not exist " + from + " for destination " + destination);
}
use of aQute.bnd.osgi.EmbeddedResource in project bnd by bndtools.
the class ProjectLauncherImpl method doStart.
/*
* Useful for when exported as folder or unzipped
*/
void doStart(Jar jar, String fqn) throws UnsupportedEncodingException {
String nix = "#!/bin/sh\njava -cp . " + fqn + "\n";
String pc = "java -cp . " + fqn + "\r\n";
jar.putResource("start", new EmbeddedResource(nix, 0));
jar.putResource("start.bat", new EmbeddedResource(pc, 0));
}
use of aQute.bnd.osgi.EmbeddedResource 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.EmbeddedResource 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();
}
}
}
Aggregations