blob: f2e90d8b4181ce3c43c55ab5c75f20655eec1c3e [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +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 {
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}