Skip to content

Commit 29b3c6d

Browse files
committed
JUnit tag support
- Prepare build so that we can use JUnit tags and define shellIncludeTags/shellExcludeTags from command line to override settings. - Needed for some of a new planned tests which would not work without full build. - Relates #1131
1 parent 5cd1b45 commit 29b3c6d

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

buildSrc/src/main/java/org/springframework/shell/gradle/JavaConventions.java

+28-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
class JavaConventions {
4040

4141
private static final String SOURCE_AND_TARGET_COMPATIBILITY = "17";
42+
private static final String INCLUDE_TAGS = "shellIncludeTags";
43+
private static final String EXCLUDE_TAGS = "shellExcludeTags";
44+
private static final String[] DEFAULT_EXCLUDE_TAGS = new String[] { };
4245

4346
void apply(Project project) {
4447
project.getPlugins().withType(JavaBasePlugin.class, java -> {
@@ -83,7 +86,31 @@ private boolean buildingWithJava17(Project project) {
8386

8487
private void configureTestConventions(Project project) {
8588
project.getTasks().withType(Test.class, test -> {
86-
test.useJUnitPlatform();
89+
boolean hasIncludeTags = project.hasProperty(INCLUDE_TAGS);
90+
boolean hasExcludeTags = project.hasProperty(EXCLUDE_TAGS);
91+
test.useJUnitPlatform(options -> {
92+
if (!hasIncludeTags && !hasExcludeTags) {
93+
options.excludeTags(DEFAULT_EXCLUDE_TAGS);
94+
}
95+
else {
96+
if (hasIncludeTags) {
97+
Object includeTagsProperty = project.property(INCLUDE_TAGS);
98+
if (includeTagsProperty instanceof String p) {
99+
if (p.length() > 0) {
100+
options.includeTags(p.split(","));
101+
}
102+
}
103+
}
104+
if (hasExcludeTags) {
105+
Object excludeTagsProperty = project.property(EXCLUDE_TAGS);
106+
if (excludeTagsProperty instanceof String p) {
107+
if (p.length() > 0) {
108+
options.excludeTags(p.split(","));
109+
}
110+
}
111+
}
112+
}
113+
});
87114
});
88115
}
89116

0 commit comments

Comments
 (0)