Skip to content

Commit

Permalink
JUnit tag support
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jvalkeal committed Sep 15, 2024
1 parent 5cd1b45 commit 29b3c6d
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
class JavaConventions {

private static final String SOURCE_AND_TARGET_COMPATIBILITY = "17";
private static final String INCLUDE_TAGS = "shellIncludeTags";
private static final String EXCLUDE_TAGS = "shellExcludeTags";
private static final String[] DEFAULT_EXCLUDE_TAGS = new String[] { };

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

private void configureTestConventions(Project project) {
project.getTasks().withType(Test.class, test -> {
test.useJUnitPlatform();
boolean hasIncludeTags = project.hasProperty(INCLUDE_TAGS);
boolean hasExcludeTags = project.hasProperty(EXCLUDE_TAGS);
test.useJUnitPlatform(options -> {
if (!hasIncludeTags && !hasExcludeTags) {
options.excludeTags(DEFAULT_EXCLUDE_TAGS);
}
else {
if (hasIncludeTags) {
Object includeTagsProperty = project.property(INCLUDE_TAGS);
if (includeTagsProperty instanceof String p) {
if (p.length() > 0) {
options.includeTags(p.split(","));
}
}
}
if (hasExcludeTags) {
Object excludeTagsProperty = project.property(EXCLUDE_TAGS);
if (excludeTagsProperty instanceof String p) {
if (p.length() > 0) {
options.excludeTags(p.split(","));
}
}
}
}
});
});
}

Expand Down

0 comments on commit 29b3c6d

Please sign in to comment.