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 | 4b9de8e | 2012-07-22 00:19:13 +0000 | [diff] [blame] | 26 | for (Clazz c: list) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 27 | for (Instruction instruction : instructions.keySet()) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 28 | |
| 29 | if (instruction.matches(c.getFQN())) { |
| 30 | if (instruction.isNegated()) |
Stuart McCulloch | 4b9de8e | 2012-07-22 00:19:13 +0000 | [diff] [blame] | 31 | break; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 32 | else { |
| 33 | ComponentDef definition = AnnotationReader.getDefinition(c, analyzer); |
| 34 | if (definition != null) { |
Stuart McCulloch | 4b9de8e | 2012-07-22 00:19:13 +0000 | [diff] [blame] | 35 | definition.sortReferences(); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 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 | } |