blob: 29e5353806bb17137f4619fdab719d447e7e0ba7 [file] [log] [blame]
Stuart McCullochbb014372012-06-07 21:57:32 +00001package aQute.bnd.make;
2
3import java.io.*;
4import java.util.*;
5import java.util.regex.*;
6
7import aQute.bnd.build.*;
8import aQute.bnd.service.*;
9import aQute.lib.osgi.*;
10
11public class MakeBnd implements MakePlugin, Constants {
Stuart McCulloch2286f232012-06-15 13:27:53 +000012 final static Pattern JARFILE = Pattern.compile("(.+)\\.(jar|ipa)");
Stuart McCullochbb014372012-06-07 21:57:32 +000013
Stuart McCulloch2286f232012-06-15 13:27:53 +000014 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 McCullochbb014372012-06-07 21:57:32 +000018
Stuart McCulloch2286f232012-06-15 13:27:53 +000019 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 McCullochbb014372012-06-07 21:57:32 +000031
Stuart McCulloch2286f232012-06-15 13:27:53 +000032 // 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 McCullochbb014372012-06-07 21:57:32 +000062
63}