use of aQute.bnd.osgi.Clazz in project bnd by bndtools.
the class MetatypePlugin method analyzeJar.
public boolean analyzeJar(Analyzer analyzer) throws Exception {
Parameters map = analyzer.parseHeader(analyzer.getProperty(Constants.METATYPE));
Jar jar = analyzer.getJar();
for (String name : map.keySet()) {
Collection<Clazz> metatypes = analyzer.getClasses("", QUERY.ANNOTATED.toString(), //
"aQute.bnd.annotation.metatype.Meta$OCD", //
QUERY.NAMED.toString(), //
name);
for (Clazz c : metatypes) {
analyzer.warning("%s annotation used in class %s. Bnd metatype annotations are deprecated as of Bnd 3.2 and support will be removed in Bnd 4.0. Please change to use OSGi Metatype annotations.", "aQute.bnd.annotation.metatype.Meta$OCD", c);
jar.putResource("OSGI-INF/metatype/" + c.getFQN() + ".xml", new MetaTypeReader(c, analyzer));
}
}
return false;
}
use of aQute.bnd.osgi.Clazz in project bnd by bndtools.
the class AnalyzerTest method testFindClass.
public static void testFindClass() throws Exception {
Builder a = new Builder();
try {
a.setProperty("Export-Package", "org.osgi.service.io");
a.addClasspath(IO.getFile("jar/osgi.jar"));
a.build();
System.err.println(a.getErrors());
System.err.println(a.getWarnings());
Collection<Clazz> c = a.getClasses("", "IMPORTS", "javax.microedition.io");
System.err.println(c);
} finally {
a.close();
}
}
use of aQute.bnd.osgi.Clazz in project bndtools by bndtools.
the class BndBuilderCapReqLoader method findImportingClasses.
static List<Clazz> findImportingClasses(String pkgName, Builder builder) throws Exception {
List<Clazz> classes = new LinkedList<Clazz>();
Collection<Clazz> importers = builder.getClasses("", "IMPORTING", pkgName);
// Remove *this* package
for (Clazz clazz : importers) {
String fqn = clazz.getFQN();
int dot = fqn.lastIndexOf('.');
if (dot >= 0) {
String pkg = fqn.substring(0, dot);
if (!pkgName.equals(pkg))
classes.add(clazz);
}
}
return classes;
}
use of aQute.bnd.osgi.Clazz in project bndtools by bndtools.
the class BndBuilderCapReqLoader method loadRequirements.
@Override
public Map<String, List<RequirementWrapper>> loadRequirements() throws Exception {
Builder builder = getBuilder();
if (builder == null)
return Collections.emptyMap();
Jar jar = builder.getJar();
if (jar == null)
return Collections.emptyMap();
Manifest manifest = jar.getManifest();
if (manifest == null)
return Collections.emptyMap();
Attributes attribs = manifest.getMainAttributes();
Map<String, List<RequirementWrapper>> requirements = new HashMap<String, List<RequirementWrapper>>();
// Process imports
String importPkgStr = attribs.getValue(Constants.IMPORT_PACKAGE);
Parameters importsMap = new Parameters(importPkgStr);
for (Entry<String, Attrs> entry : importsMap.entrySet()) {
String pkgName = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(PackageNamespace.PACKAGE_NAMESPACE);
String filter = createVersionFilter(PackageNamespace.PACKAGE_NAMESPACE, pkgName, attrs.get(Constants.VERSION_ATTRIBUTE), PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE);
rb.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
Collection<Clazz> importers = findImportingClasses(pkgName, builder);
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
rw.requirers = importers;
addRequirement(requirements, rw);
}
// Process require-bundle
String requireBundleStr = attribs.getValue(Constants.REQUIRE_BUNDLE);
Parameters requireBundles = new Parameters(requireBundleStr);
for (Entry<String, Attrs> entry : requireBundles.entrySet()) {
String bsn = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(BundleNamespace.BUNDLE_NAMESPACE);
String filter = createVersionFilter(BundleNamespace.BUNDLE_NAMESPACE, bsn, attrs.get(Constants.BUNDLE_VERSION_ATTRIBUTE), AbstractWiringNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE);
rb.addDirective(Namespace.REQUIREMENT_FILTER_DIRECTIVE, filter);
if (Constants.RESOLUTION_OPTIONAL.equals(attrs.get(Constants.RESOLUTION_DIRECTIVE + ":")))
rb.addDirective(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, Namespace.RESOLUTION_OPTIONAL);
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
addRequirement(requirements, rw);
}
// Process generic requires
String requiresStr = attribs.getValue(Constants.REQUIRE_CAPABILITY);
Parameters requires = new Parameters(requiresStr);
for (Entry<String, Attrs> entry : requires.entrySet()) {
String ns = Processor.removeDuplicateMarker(entry.getKey());
Attrs attrs = entry.getValue();
CapReqBuilder rb = new CapReqBuilder(ns);
for (String key : attrs.keySet()) {
if (key.endsWith(":"))
rb.addDirective(key.substring(0, key.length() - 1), attrs.get(key));
else
rb.addAttribute(key, attrs.getTyped(key));
}
RequirementWrapper rw = new RequirementWrapper();
rw.requirement = rb.buildSyntheticRequirement();
addRequirement(requirements, rw);
}
return requirements;
}
use of aQute.bnd.osgi.Clazz in project bnd by bndtools.
the class AnnotationReader method doComponent.
/**
* @param annotation
* @throws Exception
*/
@SuppressWarnings("deprecation")
protected void doComponent(Component comp, Annotation annotation) throws Exception {
if (!mismatchedAnnotations.isEmpty()) {
String componentName = comp.name();
componentName = (componentName == null) ? className.getFQN() : componentName;
for (Entry<String, List<DeclarativeServicesAnnotationError>> e : mismatchedAnnotations.entrySet()) {
for (DeclarativeServicesAnnotationError errorDetails : e.getValue()) {
if (errorDetails.fieldName != null) {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s on field %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.fieldName).details(errorDetails);
} else if (errorDetails.methodName != null) {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s on method %s with signature %s. It is an error to mix these two types of annotations", componentName, e.getKey(), errorDetails.methodName, errorDetails.methodSignature).details(errorDetails);
} else {
analyzer.error("The DS component %s uses standard annotations to declare it as a component, but also uses the bnd DS annotation: %s. It is an error to mix these two types of annotations", componentName, e.getKey()).details(errorDetails);
}
}
}
return;
}
// Check if we are doing a super class
if (component.implementation != null)
return;
component.implementation = clazz.getClassName();
component.name = comp.name();
component.factory = comp.factory();
component.configurationPolicy = comp.configurationPolicy();
if (annotation.get("enabled") != null)
component.enabled = comp.enabled();
if (annotation.get("factory") != null)
component.factory = comp.factory();
if (annotation.get("immediate") != null)
component.immediate = comp.immediate();
if (annotation.get("servicefactory") != null)
component.scope = comp.servicefactory() ? ServiceScope.BUNDLE : ServiceScope.SINGLETON;
if (annotation.get("scope") != null && comp.scope() != ServiceScope.DEFAULT) {
component.scope = comp.scope();
if (comp.scope() == ServiceScope.PROTOTYPE) {
component.updateVersion(V1_3);
}
}
if (annotation.get("configurationPid") != null) {
component.configurationPid = comp.configurationPid();
if (component.configurationPid.length > 1) {
component.updateVersion(V1_3);
} else {
component.updateVersion(V1_2);
}
}
if (annotation.get("xmlns") != null)
component.xmlns = comp.xmlns();
String[] properties = comp.properties();
if (properties != null)
for (String entry : properties) {
if (entry.contains("=")) {
analyzer.error("Found an = sign in an OSGi DS Component annotation on %s. In the bnd annotation " + "this is an actual property but in the OSGi, this element must refer to a path with Java properties. " + "However, found a path with an '=' sign which looks like a mixup (%s) with the 'property' element.", clazz, entry).details(new DeclarativeServicesAnnotationError(className.getFQN(), null, null, ErrorType.COMPONENT_PROPERTIES_ERROR));
}
component.properties.add(entry);
}
doProperty(comp.property());
Object[] x = annotation.get("service");
if (x == null) {
// fqn.
if (interfaces != null) {
List<TypeRef> result = new ArrayList<TypeRef>();
for (int i = 0; i < interfaces.length; i++) {
if (!interfaces[i].equals(analyzer.getTypeRef("scala/ScalaObject")))
result.add(interfaces[i]);
}
component.service = result.toArray(EMPTY);
}
} else {
// We have explicit interfaces set
component.service = new TypeRef[x.length];
for (int i = 0; i < x.length; i++) {
TypeRef typeRef = (TypeRef) x[i];
Clazz service = analyzer.findClass(typeRef);
if (!analyzer.assignable(clazz, service)) {
analyzer.error("Class %s is not assignable to specified service %s", clazz.getFQN(), typeRef.getFQN()).details(new DeclarativeServicesAnnotationError(className.getFQN(), null, null, ErrorType.INCOMPATIBLE_SERVICE));
}
component.service[i] = typeRef;
}
}
// make sure reference processing knows this is a Reference in Component
member = null;
Object[] refAnnotations = annotation.get("reference");
if (refAnnotations != null) {
for (Object o : refAnnotations) {
Annotation refAnnotation = (Annotation) o;
Reference ref = refAnnotation.getAnnotation();
doReference(ref, refAnnotation);
}
}
}
Aggregations