use of aQute.bnd.osgi.Domain in project bndtools by bndtools.
the class MavenWorkspaceRepository method getBsnFromMavenProject.
private String getBsnFromMavenProject(MavenProject mavenProject) throws Exception {
final File bundleFile = getBundleFile(mavenProject);
if (bundleFile.exists()) {
Domain domain = Domain.domain(bundleFile);
String bsn = domain.getBundleSymbolicName().getKey();
return bsn;
}
return null;
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class AnalyzerTest method testGenerateManifest.
/**
* Fastest way to create a manifest
*
* @throws Exception
*/
public static void testGenerateManifest() throws Exception {
Analyzer analyzer = new Analyzer();
try {
Jar bin = new Jar(IO.getFile("jar/osgi.jar"));
bin.setManifest(new Manifest());
analyzer.setJar(bin);
analyzer.addClasspath(IO.getFile("jar/spring.jar"));
analyzer.setProperty("Bundle-SymbolicName", "org.osgi.core");
analyzer.setProperty("Export-Package", "org.osgi.framework,org.osgi.service.event");
analyzer.setProperty("Bundle-Version", "1.0.0.x");
analyzer.setProperty("Import-Package", "*");
Manifest manifest = analyzer.calcManifest();
assertTrue(analyzer.check());
manifest.write(System.err);
Domain main = Domain.domain(manifest);
Parameters export = main.getExportPackage();
Parameters expected = new Parameters("org.osgi.framework;version=\"1.3\",org.osgi.service.event;uses:=\"org.osgi.framework\";version=\"1.0.1\"");
assertTrue(expected.isEqual(export));
assertEquals("1.0.0.x", manifest.getMainAttributes().getValue("Bundle-Version"));
} finally {
analyzer.close();
}
}
use of aQute.bnd.osgi.Domain 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.Domain in project bnd by bndtools.
the class IndexFile method updateDescriptor.
void updateDescriptor(BundleDescriptor descriptor, File file) {
try {
if (file == null || !file.isFile()) {
File descriptorFile = getDescriptorFile(descriptor.archive);
IO.delete(descriptorFile);
reporter.error("Could not find file %s", descriptor.archive);
descriptor.error = "File not found";
} else {
if (descriptor.lastModified != file.lastModified()) {
Domain m = Domain.domain(file);
if (m == null)
m = Domain.domain(Collections.<String, String>emptyMap());
Entry<String, Attrs> bsn = m.getBundleSymbolicName();
descriptor.bsn = bsn != null ? bsn.getKey() : null;
descriptor.version = m.getBundleVersion() == null ? null : Version.parseVersion(m.getBundleVersion());
if (descriptor.bsn == null) {
descriptor.bsn = descriptor.archive.getWithoutVersion();
descriptor.version = descriptor.archive.revision.version.getOSGiVersion();
} else if (descriptor.version == null)
descriptor.version = Version.LOWEST;
descriptor.description = m.getBundleDescription();
descriptor.id = SHA1.digest(file).digest();
descriptor.included = false;
descriptor.lastModified = file.lastModified();
descriptor.sha256 = SHA256.digest(file).digest();
saveDescriptor(descriptor);
refresh.set(true);
}
if (descriptor.promise == null && file != null)
descriptor.promise = Promises.resolved(file);
}
} catch (Exception e) {
e.printStackTrace();
descriptor.error = e.toString();
refresh.set(true);
}
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class ResourceBuilder method addFile.
public boolean addFile(File file, URI uri) throws Exception {
if (uri == null)
uri = file.toURI();
Domain manifest = Domain.domain(file);
String mime = BUNDLE_MIME_TYPE;
boolean hasIdentity = false;
if (manifest != null)
hasIdentity = addManifest(manifest);
else
mime = JAR_MIME_TYPE;
String sha256 = SHA256.digest(file).asHex();
addContentCapability(uri, sha256, file.length(), mime);
return hasIdentity;
}
Aggregations