Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 1 | package aQute.bnd.build; |
| 2 | |
| 3 | import java.io.*; |
| 4 | import java.util.*; |
| 5 | |
| 6 | import aQute.lib.osgi.*; |
| 7 | |
| 8 | public class ProjectBuilder extends Builder { |
| 9 | Project project; |
| 10 | boolean initialized; |
| 11 | |
| 12 | public ProjectBuilder(Project project) { |
| 13 | super(project); |
| 14 | this.project = project; |
| 15 | } |
| 16 | |
| 17 | public ProjectBuilder(ProjectBuilder builder) { |
| 18 | super(builder); |
| 19 | this.project = builder.project; |
| 20 | } |
| 21 | |
| 22 | @Override |
| 23 | public long lastModified() { |
| 24 | return Math.max(project.lastModified(), super.lastModified()); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * We put our project and our workspace on the macro path. |
| 29 | */ |
| 30 | protected Object[] getMacroDomains() { |
| 31 | return new Object[] { project, project.getWorkspace() }; |
| 32 | } |
| 33 | |
| 34 | public Builder getSubBuilder() throws Exception { |
| 35 | return project.getBuilder(this); |
| 36 | } |
| 37 | |
| 38 | public Project getProject() { |
| 39 | return project; |
| 40 | } |
| 41 | |
| 42 | public void init() { |
| 43 | try { |
| 44 | if (!initialized) { |
| 45 | initialized = true; |
| 46 | for (Container file : project.getClasspath()) { |
| 47 | addClasspath(file.getFile()); |
| 48 | } |
| 49 | |
| 50 | for (Container file : project.getBuildpath()) { |
| 51 | addClasspath(file.getFile()); |
| 52 | } |
| 53 | |
| 54 | for (Container file : project.getBootclasspath()) { |
| 55 | addClasspath(file.getFile()); |
| 56 | } |
| 57 | |
| 58 | for (File file : project.getAllsourcepath()) { |
| 59 | addSourcepath(file); |
| 60 | } |
| 61 | |
| 62 | } |
| 63 | } catch (Exception e) { |
| 64 | error("init project builder fails", e); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public List<Jar> getClasspath() { |
| 69 | init(); |
| 70 | return super.getClasspath(); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | protected void changedFile(File f) { |
| 75 | project.getWorkspace().changedFile(f); |
| 76 | } |
| 77 | } |