blob: 4549624ff1a88717a031db6d9c8a1838998b8ff2 [file] [log] [blame]
Stuart McCullochf3173222012-06-07 21:57:32 +00001package aQute.bnd.build;
2
3import java.io.*;
4import java.util.*;
5
6public 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 McCulloch4482c702012-06-15 13:27:53 +000013
Stuart McCullochf3173222012-06-07 21:57:32 +000014 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 McCulloch4482c702012-06-15 13:27:53 +000021 reportDir = new File(project.getTarget(), project.getProperty("test-reports", "test-reports"));
Stuart McCullochf3173222012-06-07 21:57:32 +000022 }
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 McCulloch4482c702012-06-15 13:27:53 +000039 if (report.isFile())
Stuart McCullochf3173222012-06-07 21:57:32 +000040 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 McCulloch2929e2d2012-08-07 10:57:21 +000066 if (!reportDir.exists() && !reportDir.mkdirs()) {
67 throw new IOException("Could not create directory " + reportDir);
68 }
Stuart McCulloch4482c702012-06-15 13:27:53 +000069 for (File file : reportDir.listFiles()) {
Stuart McCullochf3173222012-06-07 21:57:32 +000070 file.delete();
71 }
72 return true;
73 }
74
75 public abstract int test() throws Exception;
76}