use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class ResolveTest method testenRouteGuard.
/**
* The enRoute base guard resolved but is missing bundles, the runbundles do
* not run
*/
public void testenRouteGuard() throws Exception {
MockRegistry registry = new MockRegistry();
Repository repo = createRepo(IO.getFile("testdata/enroute/index.xml"));
registry.addPlugin(repo);
List<Requirement> reqs = CapReqBuilder.getRequirementsFrom(new Parameters("osgi.wiring.package;filter:='(osgi.wiring.package=org.osgi.service.async)'"));
Collection<Capability> pack = repo.findProviders(reqs).get(reqs.get(0));
assertEquals(2, pack.size());
ResourceBuilder b = new ResourceBuilder();
File guard = IO.getFile("testdata/enroute/osgi.enroute.base.guard.jar");
Domain manifest = Domain.domain(guard);
b.addManifest(manifest);
Repository resourceRepository = new ResourcesRepository(b.build());
registry.addPlugin(resourceRepository);
Processor model = new Processor();
model.setRunfw("org.eclipse.osgi");
model.setRunblacklist("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.api)',osgi.identity;filter:='(osgi.identity=osgi.cmpn)',osgi.identity;filter:='(osgi.identity=osgi.core)");
model.setRunRequires("osgi.identity;filter:='(osgi.identity=osgi.enroute.base.guard)'");
model.setRunee("JavaSE-1.8");
try {
BndrunResolveContext context = new BndrunResolveContext(model, null, registry, log);
Resolver resolver = new BndResolver(new ResolverLogger(4));
Map<Resource, List<Wire>> resolved = resolver.resolve(context);
Set<Resource> resources = resolved.keySet();
} catch (ResolutionException e) {
String msg = e.getMessage().replaceAll("\\[caused by:", "\n->");
System.out.println(msg);
fail(msg);
}
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class bnd method doPrint.
private void doPrint(Jar jar, int options, printOptions po) throws ZipException, IOException, Exception {
if ((options & VERIFY) != 0) {
Verifier verifier = new Verifier(jar);
verifier.setPedantic(isPedantic());
verifier.verify();
getInfo(verifier);
}
if ((options & MANIFEST) != 0) {
Manifest manifest = jar.getManifest();
if (manifest == null)
warning("JAR has no manifest %s", jar);
else {
err.println("[MANIFEST " + jar.getName() + "]");
printManifest(manifest);
}
out.println();
}
if ((options & IMPEXP) != 0) {
out.println("[IMPEXP]");
Manifest m = jar.getManifest();
Domain domain = Domain.domain(m);
if (m != null) {
Parameters imports = domain.getImportPackage();
Parameters exports = domain.getExportPackage();
for (String p : exports.keySet()) {
if (imports.containsKey(p)) {
Attrs attrs = imports.get(p);
if (attrs.containsKey(VERSION_ATTRIBUTE)) {
exports.get(p).put("imported-as", attrs.get(VERSION_ATTRIBUTE));
}
}
}
print(Constants.IMPORT_PACKAGE, new TreeMap<String, Attrs>(imports));
print(Constants.EXPORT_PACKAGE, new TreeMap<String, Attrs>(exports));
} else
warning("File has no manifest");
}
if ((options & CAPABILITIES) != 0) {
out.println("[CAPABILITIES]");
Manifest m = jar.getManifest();
Domain domain = Domain.domain(m);
if (m != null) {
Parameters provide = domain.getProvideCapability();
Parameters require = domain.getRequireCapability();
print(Constants.PROVIDE_CAPABILITY, new TreeMap<String, Attrs>(provide));
print(Constants.REQUIRE_CAPABILITY, new TreeMap<String, Attrs>(require));
} else
warning("File has no manifest");
}
if ((options & (USES | USEDBY | API)) != 0) {
out.println();
try (Analyzer analyzer = new Analyzer()) {
analyzer.setPedantic(isPedantic());
analyzer.setJar(jar);
Manifest m = jar.getManifest();
if (m != null) {
String s = m.getMainAttributes().getValue(Constants.EXPORT_PACKAGE);
if (s != null)
analyzer.setExportPackage(s);
}
analyzer.analyze();
boolean java = po.java();
Packages exports = analyzer.getExports();
if ((options & API) != 0) {
Map<PackageRef, List<PackageRef>> apiUses = analyzer.cleanupUses(analyzer.getAPIUses(), !po.java());
if (!po.xport()) {
if (exports.isEmpty())
warning("Not filtering on exported only since exports are empty");
else
apiUses.keySet().retainAll(analyzer.getExports().keySet());
}
out.println("[API USES]");
printMultiMap(apiUses);
Set<PackageRef> privates = analyzer.getPrivates();
for (PackageRef export : exports.keySet()) {
Map<Def, List<TypeRef>> xRef = analyzer.getXRef(export, privates, Modifier.PROTECTED + Modifier.PUBLIC);
if (!xRef.isEmpty()) {
out.println();
out.printf("%s refers to private Packages (not good)\n\n", export);
for (Entry<Def, List<TypeRef>> e : xRef.entrySet()) {
TreeSet<PackageRef> refs = new TreeSet<Descriptors.PackageRef>();
for (TypeRef ref : e.getValue()) refs.add(ref.getPackageRef());
refs.retainAll(privates);
//
out.printf(//
"%60s %-40s %s\n", //
e.getKey().getOwnerType().getFQN(), e.getKey().getName(), refs);
}
out.println();
}
}
out.println();
}
Map<PackageRef, List<PackageRef>> uses = analyzer.cleanupUses(analyzer.getUses(), !po.java());
if ((options & USES) != 0) {
out.println("[USES]");
printMultiMap(uses);
out.println();
}
if ((options & USEDBY) != 0) {
out.println("[USEDBY]");
MultiMap<PackageRef, PackageRef> usedBy = new MultiMap<Descriptors.PackageRef, Descriptors.PackageRef>(uses).transpose();
printMultiMap(usedBy);
}
}
}
if ((options & COMPONENT) != 0) {
printComponents(out, jar);
}
if ((options & METATYPE) != 0) {
printMetatype(out, jar);
}
if ((options & LIST) != 0) {
out.println("[LIST]");
for (Map.Entry<String, Map<String, Resource>> entry : jar.getDirectories().entrySet()) {
String name = entry.getKey();
Map<String, Resource> contents = entry.getValue();
out.println(name);
if (contents != null) {
for (String element : contents.keySet()) {
int n = element.lastIndexOf('/');
if (n > 0)
element = element.substring(n + 1);
out.print(" ");
out.print(element);
String path = element;
if (name.length() != 0)
path = name + "/" + element;
Resource r = contents.get(path);
if (r != null) {
String extra = r.getExtra();
if (extra != null) {
out.print(" extra='" + escapeUnicode(extra) + "'");
}
}
out.println();
}
} else {
out.println(name + " <no contents>");
}
}
out.println();
}
}
use of aQute.bnd.osgi.Domain in project bnd by bndtools.
the class bnd method _select.
@Description("Helps finding information in a set of JARs by filtering on manifest data and printing out selected information.")
public void _select(selectOptions opts) throws Exception {
PrintStream out = this.out;
Filter filter = null;
if (opts.where() != null) {
String w = opts.where();
if (!w.startsWith("("))
w = "(" + w + ")";
filter = new Filter(w);
}
Instructions instructions = new Instructions(opts.header());
for (String s : opts._arguments()) {
Jar jar = getJar(s);
if (jar == null) {
err.println("no file " + s);
continue;
}
Domain domain = Domain.domain(jar.getManifest());
Hashtable<String, Object> ht = new Hashtable<String, Object>();
Iterator<String> i = domain.iterator();
Set<String> realNames = new HashSet<String>();
while (i.hasNext()) {
String key = i.next();
String value = domain.get(key).trim();
ht.put(key.trim().toLowerCase(), value);
realNames.add(key);
}
ht.put("resources", jar.getResources().keySet());
realNames.add("resources");
if (filter != null) {
if (!filter.match(ht))
continue;
}
Set<Instruction> unused = new HashSet<Instruction>();
Collection<String> select = instructions.select(realNames, unused, true);
for (String h : select) {
if (opts.path()) {
out.print(jar.getSource().getAbsolutePath() + ":");
}
if (opts.name()) {
out.print(jar.getSource().getName() + ":");
}
if (opts.key()) {
out.print(h + ":");
}
out.println(ht.get(h.toLowerCase()));
}
for (Instruction ins : unused) {
String literal = ins.getLiteral();
if (literal.equals("name"))
out.println(jar.getSource().getName());
else if (literal.equals("path"))
out.println(jar.getSource().getAbsolutePath());
else if (literal.equals("size") || literal.equals("length"))
out.println(jar.getSource().length());
else if (literal.equals("modified"))
out.println(new Date(jar.getSource().lastModified()));
}
}
}
use of aQute.bnd.osgi.Domain 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.osgi.Domain 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);
}
}
}
}
}
}
}
}
Aggregations