Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.make; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.util.*; |
| 5 | import java.util.regex.*; |
| 6 | |
| 7 | import aQute.bnd.build.*; |
| 8 | import aQute.bnd.service.*; |
| 9 | import aQute.lib.osgi.*; |
| 10 | |
| 11 | public class MakeBnd implements MakePlugin, Constants { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 12 | final static Pattern JARFILE = Pattern.compile("(.+)\\.(jar|ipa)"); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 13 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 14 | public Resource make(Builder builder, String destination, Map<String,String> argumentsOnMake) throws Exception { |
| 15 | String type = argumentsOnMake.get("type"); |
| 16 | if (!"bnd".equals(type)) |
| 17 | return null; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 18 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 19 | String recipe = argumentsOnMake.get("recipe"); |
| 20 | if (recipe == null) { |
| 21 | builder.error("No recipe specified on a make instruction for " + destination); |
| 22 | return null; |
| 23 | } |
| 24 | File bndfile = builder.getFile(recipe); |
| 25 | if (bndfile.isFile()) { |
| 26 | // We do not use a parent because then we would |
| 27 | // build ourselves again. So we can not blindly |
| 28 | // inherit the properties. |
| 29 | Builder bchild = builder.getSubBuilder(); |
| 30 | bchild.removeBundleSpecificHeaders(); |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 31 | |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame^] | 32 | // We must make sure that we do not include ourselves again! |
| 33 | bchild.setProperty(Analyzer.INCLUDE_RESOURCE, ""); |
| 34 | bchild.setProperty(Analyzer.INCLUDERESOURCE, ""); |
| 35 | bchild.setProperties(bndfile, builder.getBase()); |
| 36 | |
| 37 | Jar jar = bchild.build(); |
| 38 | Jar dot = builder.getTarget(); |
| 39 | |
| 40 | if (builder.hasSources()) { |
| 41 | for (String key : jar.getResources().keySet()) { |
| 42 | if (key.startsWith("OSGI-OPT/src")) |
| 43 | dot.putResource(key, jar.getResource(key)); |
| 44 | } |
| 45 | } |
| 46 | builder.getInfo(bchild, bndfile.getName() + ": "); |
| 47 | String debug = bchild.getProperty(DEBUG); |
| 48 | if (Processor.isTrue(debug)) { |
| 49 | if (builder instanceof ProjectBuilder) { |
| 50 | ProjectBuilder pb = (ProjectBuilder) builder; |
| 51 | File target = pb.getProject().getTarget(); |
| 52 | String bsn = bchild.getBsn(); |
| 53 | File output = new File(target, bsn + ".jar"); |
| 54 | jar.write(output); |
| 55 | pb.getProject().getWorkspace().changedFile(output); |
| 56 | } |
| 57 | } |
| 58 | return new JarResource(jar); |
| 59 | } else |
| 60 | return null; |
| 61 | } |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 62 | |
| 63 | } |