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