|
41 | 41 | import java.util.Hashtable;
|
42 | 42 | import java.util.List;
|
43 | 43 | import java.util.Properties;
|
| 44 | +import java.util.StringTokenizer; |
44 | 45 | import java.util.concurrent.TimeoutException;
|
| 46 | +import java.util.stream.Collectors; |
45 | 47 |
|
| 48 | +import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_EXCLUDE_TAGS; |
46 | 49 | import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_HALT_ON_FAILURE;
|
| 50 | +import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_INCLUDE_TAGS; |
47 | 51 | import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ATTR_PRINT_SUMMARY;
|
48 | 52 | import static org.apache.tools.ant.taskdefs.optional.junitlauncher.confined.Constants.LD_XML_ELM_LAUNCH_DEF;
|
49 | 53 |
|
| 54 | + |
50 | 55 | /**
|
51 | 56 | * An Ant {@link Task} responsible for launching the JUnit platform for running tests.
|
52 | 57 | * This requires a minimum of JUnit 5, since that's the version in which the JUnit platform launcher
|
@@ -75,6 +80,8 @@ public class JUnitLauncherTask extends Task {
|
75 | 80 | private boolean printSummary;
|
76 | 81 | private final List<TestDefinition> tests = new ArrayList<>();
|
77 | 82 | private final List<ListenerDefinition> listeners = new ArrayList<>();
|
| 83 | + private List<String> includeTags = new ArrayList<>(); |
| 84 | + private List<String> excludeTags = new ArrayList<>(); |
78 | 85 |
|
79 | 86 | public JUnitLauncherTask() {
|
80 | 87 | }
|
@@ -158,6 +165,32 @@ public void setPrintSummary(final boolean printSummary) {
|
158 | 165 | this.printSummary = printSummary;
|
159 | 166 | }
|
160 | 167 |
|
| 168 | + /** |
| 169 | + * Tags to include. Will trim each tag. |
| 170 | + * |
| 171 | + * @param includes comma separated list of tags to include while running the tests. |
| 172 | + * @since Ant 1.10.7 |
| 173 | + */ |
| 174 | + public void setIncludeTags(final String includes) { |
| 175 | + final StringTokenizer tokens = new StringTokenizer(includes, ","); |
| 176 | + while (tokens.hasMoreTokens()) { |
| 177 | + includeTags.add(tokens.nextToken().trim()); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | + /** |
| 182 | + * Tags to exclude. Will trim each tag. |
| 183 | + * |
| 184 | + * @param excludes comma separated list of tags to exclude while running the tests. |
| 185 | + * @since Ant 1.10.7 |
| 186 | + */ |
| 187 | + public void setExcludeTags(final String excludes) { |
| 188 | + final StringTokenizer tokens = new StringTokenizer(excludes, ","); |
| 189 | + while (tokens.hasMoreTokens()) { |
| 190 | + excludeTags.add(tokens.nextToken().trim()); |
| 191 | + } |
| 192 | + } |
| 193 | + |
161 | 194 | private void preConfigure(final TestDefinition test) {
|
162 | 195 | if (test.getHaltOnFailure() == null) {
|
163 | 196 | test.setHaltOnFailure(this.haltOnFailure);
|
@@ -233,6 +266,12 @@ private void forkTest(final TestDefinition test) {
|
233 | 266 | if (this.haltOnFailure) {
|
234 | 267 | writer.writeAttribute(LD_XML_ATTR_HALT_ON_FAILURE, "true");
|
235 | 268 | }
|
| 269 | + if (this.includeTags.size() > 0) { |
| 270 | + writer.writeAttribute(LD_XML_ATTR_INCLUDE_TAGS, commaSeparatedListElements(includeTags)); |
| 271 | + } |
| 272 | + if (this.excludeTags.size() > 0) { |
| 273 | + writer.writeAttribute(LD_XML_ATTR_EXCLUDE_TAGS, commaSeparatedListElements(excludeTags)); |
| 274 | + } |
236 | 275 | // task level listeners
|
237 | 276 | for (final ListenerDefinition listenerDef : this.listeners) {
|
238 | 277 | if (!listenerDef.shouldUse(getProject())) {
|
@@ -294,6 +333,12 @@ private void forkTest(final TestDefinition test) {
|
294 | 333 | }
|
295 | 334 | }
|
296 | 335 |
|
| 336 | + private static String commaSeparatedListElements(final List<String> stringList) { |
| 337 | + return stringList.stream() |
| 338 | + .map(Object::toString) |
| 339 | + .collect(Collectors.joining(", ")); |
| 340 | + } |
| 341 | + |
297 | 342 | private int executeForkedTest(final ForkDefinition forkDefinition, final CommandlineJava commandlineJava) {
|
298 | 343 | final LogOutputStream outStream = new LogOutputStream(this, Project.MSG_INFO);
|
299 | 344 | final LogOutputStream errStream = new LogOutputStream(this, Project.MSG_WARN);
|
@@ -359,6 +404,16 @@ public boolean isHaltOnFailure() {
|
359 | 404 | return haltOnFailure;
|
360 | 405 | }
|
361 | 406 |
|
| 407 | + @Override |
| 408 | + public List<String> getIncludeTags() { |
| 409 | + return includeTags; |
| 410 | + } |
| 411 | + |
| 412 | + @Override |
| 413 | + public List<String> getExcludeTags() { |
| 414 | + return excludeTags; |
| 415 | + } |
| 416 | + |
362 | 417 | @Override
|
363 | 418 | public ClassLoader getClassLoader() {
|
364 | 419 | return this.executionCL;
|
|
0 commit comments