blob: 5cf4f0e558a7984138d7aecc7df6a08126099f53 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.bnd.build;
2
3import java.io.*;
4import java.util.*;
5
Stuart McCulloch42151ee2012-07-16 13:43:38 +00006import aQute.bnd.osgi.*;
Stuart McCullochf3173222012-06-07 21:57:32 +00007
8public class ProjectBuilder extends Builder {
Stuart McCulloch4482c702012-06-15 13:27:53 +00009 Project project;
10 boolean initialized;
Stuart McCullochf3173222012-06-07 21:57:32 +000011
Stuart McCulloch4482c702012-06-15 13:27:53 +000012 public ProjectBuilder(Project project) {
13 super(project);
14 this.project = project;
15 }
Stuart McCullochf3173222012-06-07 21:57:32 +000016
Stuart McCulloch4482c702012-06-15 13:27:53 +000017 public ProjectBuilder(ProjectBuilder builder) {
18 super(builder);
19 this.project = builder.project;
20 }
Stuart McCullochf3173222012-06-07 21:57:32 +000021
Stuart McCulloch4482c702012-06-15 13:27:53 +000022 @Override
23 public long lastModified() {
24 return Math.max(project.lastModified(), super.lastModified());
25 }
Stuart McCullochf3173222012-06-07 21:57:32 +000026
Stuart McCulloch4482c702012-06-15 13:27:53 +000027 /**
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 McCullochf3173222012-06-07 21:57:32 +000035
Stuart McCulloch4482c702012-06-15 13:27:53 +000036 public Builder getSubBuilder() throws Exception {
37 return project.getBuilder(this);
38 }
Stuart McCullochf3173222012-06-07 21:57:32 +000039
Stuart McCulloch4482c702012-06-15 13:27:53 +000040 public Project getProject() {
41 return project;
42 }
Stuart McCullochf3173222012-06-07 21:57:32 +000043
Stuart McCulloch4482c702012-06-15 13:27:53 +000044 public void init() {
45 try {
46 if (!initialized) {
47 initialized = true;
48 for (Container file : project.getClasspath()) {
49 addClasspath(file.getFile());
50 }
Stuart McCullochf3173222012-06-07 21:57:32 +000051
Stuart McCulloch4482c702012-06-15 13:27:53 +000052 for (Container file : project.getBuildpath()) {
53 addClasspath(file.getFile());
54 }
Stuart McCullochf3173222012-06-07 21:57:32 +000055
Stuart McCulloch4482c702012-06-15 13:27:53 +000056 for (Container file : project.getBootclasspath()) {
57 addClasspath(file.getFile());
58 }
Stuart McCullochf3173222012-06-07 21:57:32 +000059
Stuart McCulloch4482c702012-06-15 13:27:53 +000060 for (File file : project.getAllsourcepath()) {
61 addSourcepath(file);
62 }
Stuart McCullochf3173222012-06-07 21:57:32 +000063
Stuart McCulloch4482c702012-06-15 13:27:53 +000064 }
65 }
66 catch (Exception e) {
67 msgs.Unexpected_Error_("ProjectBuilder init", e);
68 }
69 }
Stuart McCullochf3173222012-06-07 21:57:32 +000070
Stuart McCulloch4482c702012-06-15 13:27:53 +000071 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 McCullochf3173222012-06-07 21:57:32 +000080}