Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.component; |
| 2 | |
| 3 | import java.util.*; |
| 4 | |
Stuart McCulloch | 39cc9ac | 2012-07-16 13:43:38 +0000 | [diff] [blame] | 5 | import aQute.bnd.header.*; |
| 6 | import aQute.bnd.osgi.*; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 7 | import aQute.bnd.service.*; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 8 | |
| 9 | /** |
| 10 | * Analyze the class space for any classes that have an OSGi annotation for DS. |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 11 | */ |
| 12 | public class DSAnnotations implements AnalyzerPlugin { |
| 13 | |
| 14 | public boolean analyzeJar(Analyzer analyzer) throws Exception { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 15 | Parameters header = OSGiHeader.parseHeader(analyzer.getProperty(Constants.DSANNOTATIONS)); |
| 16 | if (header.size() == 0) |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 17 | return false; |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 18 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 19 | 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 McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 23 | if (sc != null && sc.trim().length() > 0) |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 24 | names.add(sc); |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 25 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 26 | 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 McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 39 | analyzer.getJar().putResource(name, new TagResource(definition.getTag())); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 40 | } |
| 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 | } |