use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class DistroCommandTest method testDistroJarNotResolvable.
public void testDistroJarNotResolvable() throws Exception {
bnd bnd = new bnd();
CommandLine cmdline = new CommandLine(null);
List<String> remoteArgs = new ArrayList<>();
RemoteOptions remoteOptions = cmdline.getOptions(RemoteOptions.class, remoteArgs);
File distro = new File("generated/tmp/test.distro.jar");
if (distro.exists()) {
assertTrue(distro.delete());
}
List<String> distroArgs = new ArrayList<>();
distroArgs.add("-o");
distroArgs.add(distro.getPath());
distroArgs.add("test.distro");
distroArgs.add("1.0.0");
DistroOptions distroOptions = cmdline.getOptions(DistroOptions.class, distroArgs);
new RemoteCommand(bnd, remoteOptions)._distro(distroOptions);
assertTrue(distro.exists());
Domain domain = Domain.domain(distro);
Parameters providedCapabilities = domain.getProvideCapability();
assertTrue(providedCapabilities.containsKey("osgi.unresolvable"));
Parameters requiredCapabilities = domain.getRequireCapability();
assertTrue(requiredCapabilities.containsKey("osgi.unresolvable"));
Attrs attrs = requiredCapabilities.get("osgi.unresolvable");
assertEquals("(&(must.not.resolve=*)(!(must.not.resolve=*)))", attrs.get("filter:"));
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class bnd method _export.
public void _export(ExportOptions opts) throws Exception {
Project project = getProject(opts.project());
if (project == null) {
error("No project");
return;
}
// temporary
project.getWorkspace().addBasicPlugin(new SubsystemExporter());
List<Exporter> exporters = project.getPlugins(Exporter.class);
Exporter exporter = null;
for (Exporter e : exporters) {
String[] types = e.getTypes();
for (String type : types) {
if (type.equals(opts.exporter()))
;
}
}
for (String bndrun : opts._arguments()) {
File f = getFile(bndrun);
if (!f.isFile()) {
error("No such file: %s", f);
continue;
}
Run run = new Run(project.getWorkspace(), getBase(), f);
run.getSettings(this);
Parameters exports = new Parameters();
List<String> types = opts.exporter();
if (types != null) {
for (String type : types) {
exports.putAll(new Parameters(type, this));
}
} else {
String exportTypes = run.getProperty(Constants.EXPORTTYPE);
exports.putAll(new Parameters(exportTypes, this));
}
for (Entry<String, Attrs> e : exports.entrySet()) {
logger.debug("exporting {} to {} with {}", run, e.getKey(), e.getValue());
Map.Entry<String, Resource> result = run.export(e.getKey(), e.getValue());
getInfo(run);
if (result != null && isOk()) {
String name = result.getKey();
File output = new File(project.getTarget(), opts.output() == null ? name : opts.output());
if (output.isDirectory())
output = new File(output, name);
IO.mkdirs(output.getParentFile());
logger.debug("Got a result for {}, store in {}", e.getKey(), output);
IO.copy(result.getValue().openInputStream(), output);
}
}
}
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class bnd method _find.
public void _find(FindOptions options) throws Exception {
List<File> files = new ArrayList<File>();
List<String> args = options._arguments();
if (args.size() == 0) {
Project p = getProject();
if (p == null) {
error("This is not a project directory and you have specified no jar files ...");
return;
}
File output = p.getOutput();
if (output.exists()) {
files.add(output);
}
for (Container c : p.getBuildpath()) {
files.add(c.getFile());
}
} else {
for (String f : args) {
File file = getFile(f);
files.add(file);
}
}
for (File f : files) {
logger.debug("find {}", f);
try (Jar jar = new Jar(f)) {
Manifest m = jar.getManifest();
if (m != null) {
Domain domain = Domain.domain(m);
if (options.exports() != null) {
Parameters ep = domain.getExportPackage();
for (Glob g : options.exports()) {
for (Entry<String, Attrs> exp : ep.entrySet()) {
if (g.matcher(exp.getKey()).matches()) {
String v = exp.getValue().get(VERSION_ATTRIBUTE);
if (v == null)
v = "0";
out.printf(">%s: %s-%s%n", f.getPath(), exp.getKey(), v);
}
}
}
}
if (options.imports() != null) {
Parameters ip = domain.getImportPackage();
for (Glob g : options.imports()) {
for (Entry<String, Attrs> imp : ip.entrySet()) {
if (g.matcher(imp.getKey()).matches()) {
String v = imp.getValue().get(VERSION_ATTRIBUTE);
if (v == null)
v = "0";
out.printf("<%s: %s-%s%n", f.getPath(), imp.getKey(), v);
}
}
}
}
}
}
}
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class DSAnnotations method addServiceCapability.
private void addServiceCapability(String[] objectClass, Set<String> provides) {
if (objectClass.length > 0) {
Parameters p = new Parameters();
Attrs a = new Attrs();
StringBuilder sb = new StringBuilder();
String sep = "";
for (String oc : objectClass) {
sb.append(sep).append(oc);
sep = ",";
}
a.put("objectClass:List<String>", sb.toString());
p.put("osgi.service", a);
String s = p.toString();
provides.add(s);
}
}
use of aQute.bnd.header.Parameters in project bnd by bndtools.
the class DSAnnotations method updateHeader.
/**
* Updates specified header, sorting and removing duplicates. Destroys
* contents of set parameter.
*
* @param analyzer
* @param name header name
* @param set values to add to header; contents are not preserved.
*/
private void updateHeader(Analyzer analyzer, String name, TreeSet<String> set) {
if (!set.isEmpty()) {
String value = analyzer.getProperty(name);
if (value != null) {
Parameters p = OSGiHeader.parseHeader(value);
for (Map.Entry<String, Attrs> entry : p.entrySet()) {
StringBuilder sb = new StringBuilder(entry.getKey());
if (entry.getValue() != null) {
sb.append(";");
entry.getValue().append(sb);
}
set.add(sb.toString());
}
}
String header = Strings.join(set);
analyzer.setProperty(name, header);
}
}
Aggregations