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