use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class MacroTest method testFindPath.
public static void testFindPath() throws IOException {
try (Analyzer analyzer = new Analyzer()) {
analyzer.setJar(IO.getFile("jar/asm.jar"));
Macro m = new Macro(analyzer);
assertTrue(m.process("${findname;(.*)\\.class;$1.xyz}").indexOf("FieldVisitor.xyz,") >= 0);
assertTrue(m.process("${findname;(.*)\\.class;$1.xyz}").indexOf("MethodVisitor.xyz,") >= 0);
assertTrue(m.process("${findpath;(.*)\\.class}").indexOf("org/objectweb/asm/AnnotationVisitor.class,") >= 0);
assertTrue(m.process("${findpath;(.*)\\.class}").indexOf("org/objectweb/asm/ByteVector.class, org/objectweb/asm/ClassAdapter.class,") >= 0);
assertEquals("META-INF/MANIFEST.MF", m.process("${findpath;META-INF/MANIFEST.MF}"));
assertEquals("Label.class", m.process("${findname;Label\\..*}"));
assertEquals("Adapter, Visitor, Writer", m.process("${findname;Method(.*)\\.class;$1}"));
}
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class PropertiesTest method testBadProperties.
public static void testBadProperties() throws Exception {
Analyzer analyzer = new Analyzer();
analyzer.setPedantic(true);
analyzer.setProperties(IO.getFile("src/test/badproperties.prop"));
String s = analyzer.getProperty(Analyzer.IMPORT_PACKAGE);
Parameters map = analyzer.parseHeader(s);
assertEquals(2, map.size());
assertTrue(map.containsKey("org.osgi.service.cm"));
assertTrue(map.containsKey("org.osgi.util.tracker"));
assertEquals(1, analyzer.getWarnings().size());
System.err.println(analyzer.getWarnings());
assertTrue(analyzer.getWarnings().get(0).indexOf("Empty clause, usually caused by repeating a comma without") >= 0);
System.err.println(analyzer.getWarnings());
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class VerifierTest method testInvalidCaseForHeader.
public static void testInvalidCaseForHeader() throws Exception {
Properties p = new Properties();
p.put("Export-package", "org.apache.mina.*");
p.put("Bundle-Classpath", ".");
Analyzer analyzer = new Analyzer();
analyzer.setProperties(p);
analyzer.getProperties();
System.err.println("Errors " + analyzer.getErrors());
System.err.println("Warnings " + analyzer.getWarnings());
assertEquals(0, analyzer.getErrors().size());
assertEquals(2, analyzer.getWarnings().size());
}
use of aQute.bnd.osgi.Analyzer in project bnd by bndtools.
the class ParseSignatureBuilder method parse.
public void parse(InputStream in) throws Exception {
Analyzer analyzer = new Analyzer();
Clazz clazz = new Clazz(analyzer, "", null);
clazz.parseClassFile(in, new ClassDataCollector() {
Scope s;
Scope enclosing;
Scope declaring;
@Override
public void classBegin(int access, TypeRef name) {
s = root.getScope(name.getBinary());
s.access = Access.modifier(access);
s.kind = Kind.CLASS;
}
@Override
public void extendsClass(TypeRef name) {
// s.setBase(new GenericType(name));
}
@Override
public void implementsInterfaces(TypeRef[] names) {
s.setParameterTypes(convert(names));
}
GenericType[] convert(TypeRef[] names) {
GenericType[] tss = new GenericType[names.length];
for (int i = 0; i < names.length; i++) {
// tss[i] = new GenericType(names[i]);
}
return tss;
}
@Override
public void method(Clazz.MethodDef defined) {
String descriptor;
Kind kind;
if (defined.isConstructor()) {
descriptor = ":" + defined.getDescriptor();
kind = Kind.CONSTRUCTOR;
} else {
descriptor = defined.getName() + ":" + defined.getDescriptor();
kind = Kind.METHOD;
}
Scope m = s.getScope(descriptor);
m.access = Access.modifier(defined.getAccess());
m.kind = kind;
m.declaring = s;
s.add(m);
}
@Override
public void field(Clazz.FieldDef defined) {
String descriptor = defined.getName() + ":" + defined.getDescriptor();
Kind kind = Kind.FIELD;
Scope m = s.getScope(descriptor);
m.access = Access.modifier(defined.getAccess());
m.kind = kind;
m.declaring = s;
s.add(m);
}
@Override
public void classEnd() {
if (enclosing != null)
s.setEnclosing(enclosing);
if (declaring != null)
s.setDeclaring(declaring);
}
@Override
public void enclosingMethod(TypeRef cName, String mName, String mDescriptor) {
enclosing = root.getScope(cName.getBinary());
if (mName != null) {
enclosing = enclosing.getScope(Scope.methodIdentity(mName, mDescriptor));
}
}
@Override
public void innerClass(TypeRef innerClass, TypeRef outerClass, String innerName, int innerClassAccessFlags) {
if (outerClass != null && innerClass != null && innerClass.getBinary().equals(s.name))
declaring = root.getScope(outerClass.getBinary());
}
});
}
use of aQute.bnd.osgi.Analyzer 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