blob: 5d16b9a8574fb3a9b36f91c70b46f8e8f54bf0dc [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.bnd.component;
2
3import java.util.*;
4
Stuart McCulloch39cc9ac2012-07-16 13:43:38 +00005import aQute.bnd.header.*;
6import aQute.bnd.osgi.*;
Stuart McCullochbb014372012-06-07 21:57:32 +00007import aQute.bnd.service.*;
Stuart McCullochbb014372012-06-07 21:57:32 +00008
9/**
10 * Analyze the class space for any classes that have an OSGi annotation for DS.
Stuart McCullochbb014372012-06-07 21:57:32 +000011 */
12public class DSAnnotations implements AnalyzerPlugin {
13
14 public boolean analyzeJar(Analyzer analyzer) throws Exception {
Stuart McCulloch2286f232012-06-15 13:27:53 +000015 Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.DSANNOTATIONS));
16 if (header.size() == 0)
Stuart McCullochbb014372012-06-07 21:57:32 +000017 return false;
Stuart McCulloch2286f232012-06-15 13:27:53 +000018
Stuart McCullochbb014372012-06-07 21:57:32 +000019 Instructions instructions = new Instructions(header);
20 Set<Clazz> list = new HashSet<Clazz>(analyzer.getClassspace().values());
21 String sc = analyzer.getProperty(Constants.SERVICE_COMPONENT);
22 List<String> names = new ArrayList<String>();
Stuart McCulloch2286f232012-06-15 13:27:53 +000023 if (sc != null && sc.trim().length() > 0)
Stuart McCullochbb014372012-06-07 21:57:32 +000024 names.add(sc);
Stuart McCulloch2286f232012-06-15 13:27:53 +000025
Stuart McCullochbb014372012-06-07 21:57:32 +000026 for (Iterator<Clazz> i = list.iterator(); i.hasNext();) {
27 for (Instruction instruction : instructions.keySet()) {
28 Clazz c = i.next();
29
30 if (instruction.matches(c.getFQN())) {
31 if (instruction.isNegated())
32 i.remove();
33 else {
34 ComponentDef definition = AnnotationReader.getDefinition(c, analyzer);
35 if (definition != null) {
36 definition.prepare(analyzer);
37 String name = "OSGI-INF/" + definition.name + ".xml";
38 names.add(name);
Stuart McCulloch2286f232012-06-15 13:27:53 +000039 analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
Stuart McCullochbb014372012-06-07 21:57:32 +000040 }
41 }
42 }
43 }
44 }
45 sc = Processor.append(names.toArray(new String[names.size()]));
46 analyzer.setProperty(Constants.SERVICE_COMPONENT, sc);
47 return false;
48 }
49}