From 29b3c6d3f7671176f35c35b6dbb87caf9e1f753e Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Sun, 15 Sep 2024 08:05:10 +0100 Subject: [PATCH] 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 --- .../shell/gradle/JavaConventions.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/buildSrc/src/main/java/org/springframework/shell/gradle/JavaConventions.java b/buildSrc/src/main/java/org/springframework/shell/gradle/JavaConventions.java index cc93ebec..b895aa8e 100644 --- a/buildSrc/src/main/java/org/springframework/shell/gradle/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/shell/gradle/JavaConventions.java @@ -39,6 +39,9 @@ import org.gradle.external.javadoc.CoreJavadocOptions; 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 -> { @@ -83,7 +86,31 @@ class JavaConventions { 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(",")); + } + } + } + } + }); }); }