use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.
the class ClassParserTest method testParameterAnnotation.
public void testParameterAnnotation() throws Exception {
InputStream in = getClass().getResourceAsStream("Test2.jclass");
assertNotNull(in);
Clazz clazz = new Clazz(a, "test", null);
clazz.parseClassFile(in);
Set<PackageRef> set = clazz.getReferred();
assertTrue(set.contains(a.getPackageRef("test")));
assertTrue(set.contains(a.getPackageRef("test/annotations")));
}
use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.
the class ClazzTest method testModuleInfo.
public void testModuleInfo() throws Exception {
try (Analyzer a = new Analyzer()) {
Clazz c = new Clazz(a, "", null);
c.parseClassFile(new FileInputStream("jar/module-info.jclass"), new ClassDataCollector() {
});
assertTrue(c.isModule());
Set<PackageRef> referred = c.getReferred();
Descriptors d = new Descriptors();
assertFalse(referred.contains(d.getPackageRef("")));
}
}
use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.
the class ClazzTest method testAnalyzerCrawlInvokeInterfaceAIOOBException.
public void testAnalyzerCrawlInvokeInterfaceAIOOBException() throws Exception {
try (Analyzer a = new Analyzer()) {
Clazz c = new Clazz(a, "", null);
c.parseClassFile(new FileInputStream("jar/AnalyzerCrawlInvokerInterfaceAIOOBTest.jclass"), new ClassDataCollector() {
});
Set<PackageRef> referred = c.getReferred();
System.out.println(referred);
}
}
use of aQute.bnd.osgi.Descriptors.PackageRef in project bnd by bndtools.
the class DescriptorsTest method testReferences.
public static void testReferences() {
Descriptors d = new Descriptors();
TypeRef r = d.getTypeRef("[B");
assertNotNull(r);
assertEquals("byte[]", r.getFQN());
assertNotNull(r.getPackageRef());
assertEquals(".", r.getPackageRef().getFQN());
PackageRef a = d.getPackageRef("a.b.c");
PackageRef b = d.getPackageRef("a/b/c");
assertTrue(a == b);
}
use of aQute.bnd.osgi.Descriptors.PackageRef in project bndtools by bndtools.
the class Printer method doPrint.
private void doPrint(File file, int options) throws ZipException, IOException, Exception {
try (Jar jar = new Jar(file.getName(), file)) {
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 " + file);
else {
out.println("[MANIFEST " + jar.getName() + "]");
printManifest(manifest);
}
out.println();
}
if ((options & IMPEXP) != 0) {
out.println("[IMPEXP]");
Manifest m = jar.getManifest();
if (m != null) {
Domain domain = Domain.domain(m);
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("Import-Package", new TreeMap<String, Attrs>(imports));
print("Export-Package", new TreeMap<String, Attrs>(exports));
} else
warning("File has no manifest");
}
if ((options & (USES | USEDBY)) != 0) {
out.println();
try (Analyzer analyzer = new Analyzer()) {
analyzer.setPedantic(isPedantic());
analyzer.setJar(jar);
analyzer.analyze();
if ((options & USES) != 0) {
out.println("[USES]");
printMultiMap(analyzer.getUses());
out.println();
}
if ((options & USEDBY) != 0) {
out.println("[USEDBY]");
Map<PackageRef, Set<PackageRef>> usedBy = CollectionUtil.invertMapOfCollection(analyzer.getUses());
printMultiMap(usedBy);
}
analyzer.setJar((Jar) null);
}
out.println();
}
if ((options & COMPONENT) != 0) {
printComponents(jar);
out.println();
}
if ((options & METATYPE) != 0) {
printMetatype(jar);
out.println();
}
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();
}
}
}
out.println();
}
}
}
Aggregations