diff --git a/README.md b/README.md index 9f019f6..e81a47d 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,10 @@ By default uses [this configuration](./src/main/resources/config/checkstyle/chec * `dk.mada.style.checkstyle.enabled = true` Boolean flag allowing the checkstyle checker to be disabled +* `dk.mada.style.checkstyle.ignore-generated-source = false` + Boolean flag to control scanning of test source files * `dk.mada.style.checkstyle.ignore-test-source = false` - Boolean flag to control scanning of test source + Boolean flag to control scanning of generated source files * `dk.mada.style.checkstyle.config-path = null` Optional path to an alternative checkstyle configuration file @@ -59,11 +61,11 @@ By default uses [this configuration](./src/main/resources/config/checkstyle/chec * `dk.mada.style.errorprone.enabled = true` Boolean flag allowing the error prone checker to be disabled -* `dk.mada.style.errorprone.ignore-test-source = false` - Boolean flag to control scanning of test source * `dk.mada.style.errorprone.ignore-generated-source = false` - Boolean flag to control scanning of generated source + Boolean flag to control scanning of generated source files Note: works poorly with Immutable generated sources (as they cannot be referenced from the main sources when enabled) +* `dk.mada.style.errorprone.ignore-test-source = false` + Boolean flag to control scanning of test source files * `dk.mada.style.errorprone.excluded-paths-regexp = ` Optional regular expression used to exclude files from scanning diff --git a/build.gradle b/build.gradle index 7603349..a954b93 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ plugins { id 'com.gradle.plugin-publish' version '1.2.1' id 'eclipse' - id 'dk.mada.style' version '0.9.1' + id 'dk.mada.style' version '0.9.2' } ext { diff --git a/src/main/java/dk/mada/style/config/PluginConfiguration.java b/src/main/java/dk/mada/style/config/PluginConfiguration.java index c6afb73..9561f18 100644 --- a/src/main/java/dk/mada/style/config/PluginConfiguration.java +++ b/src/main/java/dk/mada/style/config/PluginConfiguration.java @@ -26,13 +26,15 @@ public class PluginConfiguration { /** * Checkstyle configuration. * - * @param enabled flag to activate checkstyle - * @param ignoreFailures flag to ignore failures - * @param ignoreTestSource flag to ignore test sources - * @param toolVersion an optional checkstyle version to use - * @param configPath an optional path to a checkstyle configuration file + * @param enabled flag to activate checkstyle + * @param ignoreFailures flag to ignore failures + * @param ignoreTestSource flag to ignore test source files + * @param ignoreGeneratedSource flag to ignore generated source files + * @param toolVersion an optional checkstyle version to use + * @param configPath an optional path to a checkstyle configuration file */ - public record CheckstyleConfiguration(boolean enabled, boolean ignoreFailures, boolean ignoreTestSource, @Nullable String toolVersion, + public record CheckstyleConfiguration(boolean enabled, boolean ignoreFailures, boolean ignoreTestSource, boolean ignoreGeneratedSource, + @Nullable String toolVersion, @Nullable String configPath) { } @@ -61,8 +63,8 @@ public record NullcheckerConfiguration(boolean enabled, String includePackages, * ErrorProne configuration. * * @param enabled flag to activate error prone - * @param ignoreTestSource flag to ignore test sources - * @param ignoreGeneratedSource flag to ignore generated sources + * @param ignoreTestSource flag to ignore test source files + * @param ignoreGeneratedSource flag to ignore generated source files * @param excludePathsRegexp a regular expression of source paths to ignore * @param disabledRules a comma-separated list of rule names to disable */ @@ -82,6 +84,7 @@ public PluginConfiguration(Project project) { getBoolProperty("checkstyle.enabled", true), getBoolProperty("checkstyle.ignore-failures", true), getBoolProperty("checkstyle.ignore-test-source", false), + getBoolProperty("checkstyle.ignore-generated-source", false), getNullableProperty("checkstyle.config-path", null), getNullableProperty("checkstyle.tool-version", null)); diff --git a/src/main/java/dk/mada/style/configurators/CheckstyleConfigurator.java b/src/main/java/dk/mada/style/configurators/CheckstyleConfigurator.java index c9b9893..162c12e 100644 --- a/src/main/java/dk/mada/style/configurators/CheckstyleConfigurator.java +++ b/src/main/java/dk/mada/style/configurators/CheckstyleConfigurator.java @@ -4,7 +4,9 @@ import java.nio.file.Paths; import org.gradle.api.Project; +import org.gradle.api.Task; import org.gradle.api.logging.Logger; +import org.gradle.api.plugins.quality.Checkstyle; import org.gradle.api.plugins.quality.CheckstyleExtension; import dk.mada.style.config.ConfigFileExtractor; @@ -55,8 +57,20 @@ public void configure(CheckstyleExtension ce) { ce.setToolVersion(toolVersion); } if (checkstyleConfig.ignoreTestSource()) { - project.getTasks().named("checkstyleTest", t -> t.setOnlyIf("disabled by mada style", ta -> false)); + project.getTasks().named("checkstyleTest", this::disableTask); } + + if (checkstyleConfig.ignoreGeneratedSource()) { + project.getTasks().withType(Checkstyle.class, t -> { + if (t.getName().endsWith("Apt")) { + disableTask(t); + } + }); + } + } + + private void disableTask(Task t) { + t.setOnlyIf("disabled by mada style", ta -> false); } private Path getActiveConfigfile() {