Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.component; |
| 2 | |
| 3 | import java.util.*; |
| 4 | |
| 5 | import aQute.bnd.service.*; |
| 6 | import aQute.lib.osgi.*; |
| 7 | import aQute.libg.header.*; |
| 8 | |
| 9 | /** |
| 10 | * Analyze the class space for any classes that have an OSGi annotation for DS. |
| 11 | * |
| 12 | */ |
| 13 | public class DSAnnotations implements AnalyzerPlugin { |
| 14 | |
| 15 | public boolean analyzeJar(Analyzer analyzer) throws Exception { |
| 16 | Parameters header = OSGiHeader.parseHeader(analyzer |
Stuart McCulloch | 285034f | 2012-06-12 12:41:16 +0000 | [diff] [blame] | 17 | .getProperty(Constants.DSANNOTATIONS)); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 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 | } |