1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.tck.runner;
20
21 import java.io.File;
22 import java.util.Locale;
23
24 import org.apache.chemistry.opencmis.tck.CmisTest;
25 import org.apache.chemistry.opencmis.tck.CmisTestGroup;
26 import org.apache.chemistry.opencmis.tck.CmisTestProgressMonitor;
27 import org.apache.chemistry.opencmis.tck.CmisTestReport;
28 import org.apache.chemistry.opencmis.tck.report.HtmlReport;
29 import org.apache.chemistry.opencmis.tck.report.JsonReport;
30 import org.apache.chemistry.opencmis.tck.report.TextReport;
31 import org.apache.chemistry.opencmis.tck.report.XmlReport;
32 import org.apache.tools.ant.BuildException;
33 import org.apache.tools.ant.Task;
34
35
36
37
38 public class CmisTckAntTask extends Task {
39
40 private static final String REPORT_TEXT = "text";
41 private static final String REPORT_XML = "xml";
42 private static final String REPORT_HTML = "html";
43 private static final String REPORT_JSON = "json";
44
45 private static final String DEFAULT_REPORT_NAME = "cmis-tck-report";
46
47 private File parameters;
48 private File groups;
49 private File output;
50 private String format;
51
52 @Override
53 public void init() {
54 super.init();
55 parameters = null;
56 groups = null;
57 output = null;
58 format = REPORT_TEXT;
59 }
60
61 public void setParameters(File parameters) {
62 this.parameters = parameters;
63 }
64
65 public void setGroups(File groups) {
66 this.groups = groups;
67 }
68
69 public void setOutput(File output) {
70 this.output = output;
71 }
72
73 public void setFormat(String format) {
74 this.format = format;
75 }
76
77 @Override
78 public void execute() {
79 try {
80 AntRunner runner = new AntRunner();
81
82 if (parameters == null) {
83 runner.setParameters(null);
84 } else {
85 runner.loadParameters(parameters);
86 }
87
88 if (groups == null) {
89 runner.loadDefaultTckGroups();
90 } else {
91 runner.loadGroups(groups);
92 }
93
94 CmisTestReport report = null;
95
96 if (format == null) {
97 report = new TextReport();
98 if (output == null) {
99 output = new File(DEFAULT_REPORT_NAME + ".txt");
100 }
101 } else {
102 format = format.trim().toLowerCase(Locale.ENGLISH);
103 if (REPORT_TEXT.equals(format)) {
104 report = new TextReport();
105 if (output == null) {
106 output = new File(DEFAULT_REPORT_NAME + ".txt");
107 }
108 } else if (REPORT_XML.equals(format)) {
109 report = new XmlReport();
110 if (output == null) {
111 output = new File(DEFAULT_REPORT_NAME + ".xml");
112 }
113 } else if (REPORT_JSON.equals(format)) {
114 report = new JsonReport();
115 if (output == null) {
116 output = new File(DEFAULT_REPORT_NAME + ".json");
117 }
118 } else if (REPORT_HTML.equals(format)) {
119 report = new HtmlReport();
120 if (output == null) {
121 output = new File(DEFAULT_REPORT_NAME + ".html");
122 }
123 } else {
124 throw new BuildException("Unknown format!");
125 }
126 }
127
128 runner.run(new AntProgressMonitor());
129
130 log("CMIS TCK Report: " + output.getAbsolutePath());
131 report.createReport(runner.getParameters(), runner.getGroups(), output);
132 } catch (Exception e) {
133 throw new BuildException("OpenCMIS TCK run failed!", e);
134 }
135 }
136
137 private static class AntRunner extends AbstractRunner {
138
139 }
140
141 private class AntProgressMonitor implements CmisTestProgressMonitor {
142 @Override
143 public void startGroup(CmisTestGroup group) {
144 log(group.getName() + " (" + group.getTests().size() + " tests)");
145 }
146
147 @Override
148 public void endGroup(CmisTestGroup group) {
149 }
150
151 @Override
152 public void startTest(CmisTest test) {
153 log(" " + test.getName());
154 }
155
156 @Override
157 public void endTest(CmisTest test) {
158 }
159
160 @Override
161 public void message(String msg) {
162 log(msg);
163 }
164 }
165 }