blob: f3840f35a15ef3ed0dcf04147bbe2214e43d5645 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.bnd.component;
2
3import java.util.*;
4
Stuart McCulloch42151ee2012-07-16 13:43:38 +00005import aQute.bnd.header.*;
6import aQute.bnd.osgi.*;
Stuart McCullochf3173222012-06-07 21:57:32 +00007import aQute.bnd.service.*;
Stuart McCullochf3173222012-06-07 21:57:32 +00008
9/**
10 * Analyze the class space for any classes that have an OSGi annotation for DS.
Stuart McCullochf3173222012-06-07 21:57:32 +000011 */
12public class DSAnnotations implements AnalyzerPlugin {
13
14 public boolean analyzeJar(Analyzer analyzer) throws Exception {
Stuart McCulloch4482c702012-06-15 13:27:53 +000015 Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.DSANNOTATIONS));
16 if (header.size() == 0)
Stuart McCullochf3173222012-06-07 21:57:32 +000017 return false;
Stuart McCulloch4482c702012-06-15 13:27:53 +000018
Stuart McCullochf3173222012-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 McCulloch4482c702012-06-15 13:27:53 +000023 if (sc != null && sc.trim().length() > 0)
Stuart McCullochf3173222012-06-07 21:57:32 +000024 names.add(sc);
Stuart McCulloch4482c702012-06-15 13:27:53 +000025
Stuart McCulloch5515a832012-07-22 00:19:13 +000026 for (Clazz c: list) {
Stuart McCullochf3173222012-06-07 21:57:32 +000027 for (Instruction instruction : instructions.keySet()) {
Stuart McCullochf3173222012-06-07 21:57:32 +000028
29 if (instruction.matches(c.getFQN())) {
30 if (instruction.isNegated())
Stuart McCulloch5515a832012-07-22 00:19:13 +000031 break;
Stuart McCulloch2929e2d2012-08-07 10:57:21 +000032 ComponentDef definition = AnnotationReader.getDefinition(c, analyzer);
33 if (definition != null) {
34 definition.sortReferences();
35 definition.prepare(analyzer);
36 String name = "OSGI-INF/" + definition.name + ".xml";
37 names.add(name);
38 analyzer.getJar().putResource(name, new TagResource(definition.getTag()));
Stuart McCullochf3173222012-06-07 21:57:32 +000039 }
40 }
41 }
42 }
43 sc = Processor.append(names.toArray(new String[names.size()]));
44 analyzer.setProperty(Constants.SERVICE_COMPONENT, sc);
45 return false;
46 }
47}