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 | |
| 6 | public abstract class ProjectTester { |
| 7 | final Project project; |
| 8 | final Collection<Container> testbundles; |
| 9 | final ProjectLauncher launcher; |
| 10 | final List<String> tests = new ArrayList<String>(); |
| 11 | File reportDir; |
| 12 | boolean continuous = true; |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 13 | |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 14 | public ProjectTester(Project project) throws Exception { |
| 15 | this.project = project; |
| 16 | launcher = project.getProjectLauncher(); |
| 17 | testbundles = project.getTestpath(); |
| 18 | for (Container c : testbundles) { |
| 19 | launcher.addClasspath(c); |
| 20 | } |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 21 | reportDir = new File(project.getTarget(), project.getProperty("test-reports", "test-reports")); |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 22 | } |
| 23 | |
| 24 | public ProjectLauncher getProjectLauncher() { |
| 25 | return launcher; |
| 26 | } |
| 27 | |
| 28 | public void addTest(String test) { |
| 29 | tests.add(test); |
| 30 | } |
| 31 | |
| 32 | public Collection<String> getTests() { |
| 33 | return tests; |
| 34 | } |
| 35 | |
| 36 | public Collection<File> getReports() { |
| 37 | List<File> reports = new ArrayList<File>(); |
| 38 | for (File report : reportDir.listFiles()) { |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 39 | if (report.isFile()) |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 40 | reports.add(report); |
| 41 | } |
| 42 | return reports; |
| 43 | } |
| 44 | |
| 45 | public File getReportDir() { |
| 46 | return reportDir; |
| 47 | } |
| 48 | |
| 49 | public void setReportDir(File reportDir) { |
| 50 | this.reportDir = reportDir; |
| 51 | } |
| 52 | |
| 53 | public Project getProject() { |
| 54 | return project; |
| 55 | } |
| 56 | |
| 57 | public boolean getContinuous() { |
| 58 | return continuous; |
| 59 | } |
| 60 | |
| 61 | public void setContinuous(boolean b) { |
| 62 | this.continuous = b; |
| 63 | } |
| 64 | |
| 65 | public boolean prepare() throws Exception { |
Stuart McCulloch | 2929e2d | 2012-08-07 10:57:21 +0000 | [diff] [blame] | 66 | if (!reportDir.exists() && !reportDir.mkdirs()) { |
| 67 | throw new IOException("Could not create directory " + reportDir); |
| 68 | } |
Stuart McCulloch | 4482c70 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 69 | for (File file : reportDir.listFiles()) { |
Stuart McCulloch | f317322 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 70 | file.delete(); |
| 71 | } |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | public abstract int test() throws Exception; |
| 76 | } |