blob: e66ad0c466bd5b0dbc802157bfb0bd6a668271a9 [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 McCulloch4b9de8e2012-07-22 00:19:13 +000026 for (Clazz c: list) {
Stuart McCullochbb014372012-06-07 21:57:32 +000027 for (Instruction instruction : instructions.keySet()) {
Stuart McCullochbb014372012-06-07 21:57:32 +000028
29 if (instruction.matches(c.getFQN())) {
30 if (instruction.isNegated())
Stuart McCulloch4b9de8e2012-07-22 00:19:13 +000031 break;
Stuart McCullochbb014372012-06-07 21:57:32 +000032 else {
33 ComponentDef definition = AnnotationReader.getDefinition(c, analyzer);
34 if (definition != null) {
Stuart McCulloch4b9de8e2012-07-22 00:19:13 +000035 definition.sortReferences();
Stuart McCullochbb014372012-06-07 21:57:32 +000036 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}