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