use of aQute.bnd.osgi.Clazz in project felix by apache.
the class BndJarResourceStore method accept.
public void accept(ResourceVisitor visitor) {
try {
// Collect all annotated classes
Collection<Clazz> classes = m_analyzer.getClasses("", Clazz.QUERY.CLASSANNOTATIONS.name());
classes = filter(classes);
// Iterates over discovered resources
for (Clazz clazz : classes) {
visitor.visit(clazz.getAbsolutePath());
}
} catch (Exception e) {
m_reporter.error("Cannot find iPOJO annotated types: " + e.getMessage());
}
}
use of aQute.bnd.osgi.Clazz in project felix by apache.
the class SCRDescriptorBndPlugin method getClassFiles.
private Collection<Source> getClassFiles(Analyzer analyzer) throws Exception {
ArrayList<Source> files = new ArrayList<Source>();
Collection<Clazz> expanded = analyzer.getClasses("", QUERY.NAMED.toString(), "*");
for (final Clazz c : expanded) {
files.add(new Source() {
public File getFile() {
log.debug("Found class " + c.getAbsolutePath());
return new File(c.getAbsolutePath());
}
public String getClassName() {
return c.getFQN();
}
});
}
return files;
}
use of aQute.bnd.osgi.Clazz in project sling by apache.
the class ConfigurationClassScannerPlugin method getClassesWithAnnotation.
/**
* Get all classes that implement the given annotation via bnd Analyzer.
* @param analyzer Analyzer
* @param annotation Annotation
* @return Class names
*/
private Collection<String> getClassesWithAnnotation(String annotationClassName, Analyzer analyzer) {
SortedSet<String> classNames = new TreeSet<>();
Collection<Clazz> clazzes = analyzer.getClassspace().values();
Instruction instruction = new Instruction(annotationClassName);
try {
for (Clazz clazz : clazzes) {
if (clazz.isAnnotation() && clazz.is(QUERY.ANNOTATED, instruction, analyzer)) {
classNames.add(clazz.getClassName().getFQN());
}
}
} catch (Exception ex) {
reporter.exception(ex, "Error querying for classes with annotation: " + annotationClassName);
}
return classNames;
}
use of aQute.bnd.osgi.Clazz in project bnd by bndtools.
the class bnd method _xref.
/**
* Cross reference every class in the jar file to the files it references
*/
@Description("Show a cross references for all classes in a set of jars.")
public void _xref(xrefOptions options) throws IOException, Exception {
Analyzer analyzer = new Analyzer();
final MultiMap<TypeRef, TypeRef> table = new MultiMap<TypeRef, TypeRef>();
final MultiMap<PackageRef, PackageRef> packages = new MultiMap<PackageRef, PackageRef>();
Set<TypeRef> set = Create.set();
Instructions filter = new Instructions(options.match());
for (String arg : options._arguments()) {
try {
File file = new File(arg);
try (Jar jar = new Jar(file.getName(), file)) {
for (Map.Entry<String, Resource> entry : jar.getResources().entrySet()) {
String key = entry.getKey();
Resource r = entry.getValue();
if (key.endsWith(".class")) {
TypeRef ref = analyzer.getTypeRefFromPath(key);
if (filter.matches(ref.toString())) {
set.add(ref);
try (InputStream in = r.openInputStream()) {
Clazz clazz = new Clazz(analyzer, key, r);
// TODO use the proper bcp instead
// of using the default layout
Set<TypeRef> s = clazz.parseClassFile();
for (Iterator<TypeRef> t = s.iterator(); t.hasNext(); ) {
TypeRef tr = t.next();
if (tr.isJava() || tr.isPrimitive())
t.remove();
else
packages.add(ref.getPackageRef(), tr.getPackageRef());
}
table.addAll(ref, s);
set.addAll(s);
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
boolean to = options.to();
boolean from = options.from();
if (to == false && from == false)
to = from = true;
if (options.classes()) {
if (to)
printxref(table, ">");
if (from)
printxref(table.transpose(), "<");
} else {
if (to)
printxref(packages, ">");
if (from)
printxref(packages.transpose(), "<");
}
}
use of aQute.bnd.osgi.Clazz in project bnd by bndtools.
the class ClazzTest method test375.
/**
* {@code java.lang.IllegalArgumentException: Expected IDENTIFIER:
* <S:Z>()V;} This actually looks wrong since
*/
public void test375() throws Exception {
try (Analyzer a = new Analyzer()) {
Clazz c = new Clazz(a, "", null);
c.parseDescriptor("<S:[LFoo;>()V", Modifier.PUBLIC);
c.parseDescriptor("<S:[Z>()V", Modifier.PUBLIC);
c.parseDescriptor("<S:Z>()V", Modifier.PUBLIC);
}
}
Aggregations