Skip to content

Commit f4c194c

Browse files
feat: add excludeTags flag (#231)
1 parent 4310eb8 commit f4c194c

File tree

1 file changed

+28
-6
lines changed
  • plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions

1 file changed

+28
-6
lines changed

plugins/edc-build/src/main/java/org/eclipse/edc/plugins/edcbuild/conventions/TestConvention.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.gradle.api.Project;
1818
import org.gradle.api.tasks.testing.Test;
1919
import org.gradle.api.tasks.testing.logging.TestExceptionFormat;
20+
import org.jetbrains.annotations.NotNull;
2021

2122
import static java.util.Optional.ofNullable;
2223

@@ -25,24 +26,45 @@
2526
*/
2627
class TestConvention implements EdcConvention {
2728
private static void determineJunitPlatform(Test testTask) {
29+
// parse task exclusion
30+
var excludedTagsProperty = System.getProperty("excludeTags");
31+
var excludedTags = getTags(excludedTagsProperty);
32+
33+
2834
// Target all type of test e.g. -DrunAllTests="true"
2935
var runAllTests = Boolean.parseBoolean(System.getProperty("runAllTests", "false"));
3036
if (runAllTests) {
31-
testTask.useJUnitPlatform();
37+
// honor excluded tags -> blacklisting
38+
if (excludedTags.length > 0) {
39+
testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags));
40+
} else {
41+
testTask.useJUnitPlatform();
42+
}
3243
} else {
3344
var includeTagsProperty = System.getProperty("includeTags");
34-
var tags = ofNullable(includeTagsProperty)
35-
.map(prop -> prop.split(","))
36-
.orElse(new String[0]);
45+
var includedTags = getTags(includeTagsProperty);
3746

38-
if (tags.length > 0) {
39-
testTask.useJUnitPlatform(platform -> platform.includeTags(tags));
47+
// white-list included tags...
48+
if (includedTags.length > 0) {
49+
testTask.useJUnitPlatform(platform -> platform.includeTags(includedTags));
50+
//... and possibly black-list excluded tags
51+
if (excludedTags.length > 0) {
52+
testTask.useJUnitPlatform(platform -> platform.excludeTags(excludedTags));
53+
}
4054
} else {
55+
// no point in evaluating other excluded tags, if only unit tests are run
4156
testTask.useJUnitPlatform(platform -> platform.excludeTags("IntegrationTest"));
4257
}
4358
}
4459
}
4560

61+
@NotNull
62+
private static String[] getTags(String tagsSeparatedByComma) {
63+
return ofNullable(tagsSeparatedByComma)
64+
.map(prop -> prop.split(","))
65+
.orElse(new String[0]);
66+
}
67+
4668
@Override
4769
public void apply(Project target) {
4870
target.getTasks().withType(Test.class, testTask -> {

0 commit comments

Comments
 (0)