diff --git a/README.md b/README.md index 919171e..075df53 100644 --- a/README.md +++ b/README.md @@ -22,76 +22,45 @@ The ruleset includes checks from both the core Checkstyle library and from the S ## Usage -To use this ruleset in your `maven-checkstyle-plugin` configuration add `checkstyle`, `sevntu-checkstyle-maven-plugin` and `kemitix-checktyle-ruleset` as dependencies of the `maven-checkstyle-plugin`. +To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`. +The `maven-checkstyle-plugin` will be included automatically. -You need to include `checkstyle` as the version bundled with the `maven-checkstyle-plugin` is not up-to-date enough. +Select the level 1-5 of strictness required: -Select the `configLocation` for the level of strictness required: - -* checkstyle-1-layout.xml -* checkstyle-2-naming.xml -* checkstyle-3-javadoc.xml -* checkstyle-4-tweaks.xml -* checkstyle-5-complexity.xml - -Only specify a single `configLocation` as each increasing level includes all the rules -from the previous. +1. layout +2. naming +3. javadoc +4. tweaks +5. complexity ```` - 2.17 - 7.3 - 1.22.0 - 2.0.0 - 5-complexity + 2 + - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven.checkstyle.plugin.version} - - - com.puppycrawl.tools - checkstyle - ${checkstyle.version} - - - com.github.sevntu.checkstyle - sevntu-checkstyle-maven-plugin - ${sevntu-checkstyle-maven-plugin.version} - - - net.kemitix - kemitix-checkstyle-ruleset - ${kemitix-checkstyle-ruleset.version} - - - - net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml - - - - - org.apache.maven.plugins - maven-checkstyle-plugin + net.kemitix + kemitix-checkstyle-ruleset-maven-plugin + 2.0.0 + + ${kemitix-checkstyle-ruleset.level} + - validate validate - check - checkstyle + + check + - + + sevntu-maven diff --git a/builder/src/main/resources/README-template.md b/builder/src/main/resources/README-template.md index 528c337..aff6d61 100644 --- a/builder/src/main/resources/README-template.md +++ b/builder/src/main/resources/README-template.md @@ -22,76 +22,45 @@ The ruleset includes checks from both the core Checkstyle library and from the S ## Usage -To use this ruleset in your `maven-checkstyle-plugin` configuration add `checkstyle`, `sevntu-checkstyle-maven-plugin` and `kemitix-checktyle-ruleset` as dependencies of the `maven-checkstyle-plugin`. +To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`. +The `maven-checkstyle-plugin` will be included automatically. -You need to include `checkstyle` as the version bundled with the `maven-checkstyle-plugin` is not up-to-date enough. +Select the level 1-5 of strictness required: -Select the `configLocation` for the level of strictness required: - -* checkstyle-1-layout.xml -* checkstyle-2-naming.xml -* checkstyle-3-javadoc.xml -* checkstyle-4-tweaks.xml -* checkstyle-5-complexity.xml - -Only specify a single `configLocation` as each increasing level includes all the rules -from the previous. +1. layout +2. naming +3. javadoc +4. tweaks +5. complexity ```` - 2.17 - 7.3 - 1.22.0 - 2.0.0 - 5-complexity + 2 + - - - - org.apache.maven.plugins - maven-checkstyle-plugin - ${maven.checkstyle.plugin.version} - - - com.puppycrawl.tools - checkstyle - ${checkstyle.version} - - - com.github.sevntu.checkstyle - sevntu-checkstyle-maven-plugin - ${sevntu-checkstyle-maven-plugin.version} - - - net.kemitix - kemitix-checkstyle-ruleset - ${kemitix-checkstyle-ruleset.version} - - - - net/kemitix/checkstyle-${kemitix-checkstyle-ruleset.level}.xml - - - - - org.apache.maven.plugins - maven-checkstyle-plugin + net.kemitix + kemitix-checkstyle-ruleset-maven-plugin + 2.0.0 + + ${kemitix-checkstyle-ruleset.level} + - validate validate - check - checkstyle + + check + - + + sevntu-maven diff --git a/plugin/LICENSE.txt b/plugin/LICENSE.txt new file mode 100644 index 0000000..00c515a --- /dev/null +++ b/plugin/LICENSE.txt @@ -0,0 +1,23 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Paul Campbell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ diff --git a/plugin/pom.xml b/plugin/pom.xml new file mode 100644 index 0000000..170d052 --- /dev/null +++ b/plugin/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + + + net.kemitix + kemitix-parent + 2.2.0 + + + + kemitix-checkstyle-ruleset-maven-plugin + + maven-plugin + Kemitix Checkstyle Ruleset Maven Plugin + Checkstyle configuration using the Kemitix Checkstyle Ruleset + + + 1.8 + UTF-8 + UTF-8 + 3.3.9 + 3.5 + 3.5 + 2.17 + 7.3 + 1.23.0 + 2.0.0-SNAPSHOT + 2.2.0 + 1.16.12 + 1.0.0 + + + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.apache.maven + maven-core + ${maven.version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${maven-plugin-annotations.version} + provided + + + org.twdata.maven + mojo-executor + ${mojo-executor.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + + + me.andrz + map-builder + ${map-builder.version} + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + ${maven-plugin-plugin.version} + + + help-goal + + helpmojo + + + + + + + + + sevntu-maven + sevntu-maven + http://sevntu-checkstyle.github.io/sevntu.checkstyle/maven2 + + + diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java new file mode 100644 index 0000000..eca0617 --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java @@ -0,0 +1,150 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Paul Campbell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +package net.kemitix.checkstyle.ruleset.plugin; + +import lombok.Setter; +import lombok.val; +import me.andrz.builder.map.MapBuilder; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.Map; + +/** + * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +@Mojo(name = "check", defaultPhase = LifecyclePhase.VALIDATE) +public class CheckMojo extends AbstractMojo { + + private static final String CHECKSTYLE_GROUPID = "com.puppycrawl.tools"; + + private static final String CHECKSTYLE_ARTIFACTID = "checkstyle"; + + private static final String SEVNTU_GROUPID = "com.github.sevntu.checkstyle"; + + private static final String SEVNTU_ARTIFACTID = "sevntu-checkstyle-maven-plugin"; + + private static final String KEMITIX_GROUPID = "net.kemitix"; + + private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset"; + + private static final String APACHE_PLUGIN_GROUPID = "org.apache.maven.plugins"; + + private static final String APACHE_PLUGIN_ARTIFACTID = "maven-checkstyle-plugin"; + + private static final String CONFIG_LOCATION = "configLocation"; + + + private static final String LAYOUT = "1-layout"; + + private static final String NAMING = "2-naming"; + + private static final String JAVADOC = "3-javadoc"; + + private static final String TWEAKS = "4-tweaks"; + + private static final String COMPLEXITY = "5-complexity"; + + private static Map levelConfig = new MapBuilder().put("1", LAYOUT) + .put("2", NAMING) + .put("3", JAVADOC) + .put("4", TWEAKS) + .put("5", COMPLEXITY) + .build(); + + //@Setter + //@Parameter(defaultValue = "check") + //private String goal; + + @Setter + @Parameter(defaultValue = "2.17") + private String mavenCheckstylePluginVersion; + + @Setter + @Parameter(defaultValue = "7.3") + private String checkstyleVersion; + + @Setter + @Parameter(defaultValue = "1.23.0") + private String sevntuVersion; + + @Setter + @Parameter(defaultValue = "2.0.0-SNAPSHOT") + private String rulesetVersion; + + @Setter + @Parameter(defaultValue = "5") + private String level; + + @Setter + @Parameter(defaultValue = "${project}", readonly = true) + private MavenProject mavenProject; + + @Setter + @Parameter(defaultValue = "${session}", readonly = true) + private MavenSession mavenSession; + + @Component + private BuildPluginManager pluginManager; + + private static String getConfigFile(final String level) { + return String.format("checkstyle-%s.xml", levelConfig.getOrDefault(level, COMPLEXITY)); + } + + /** + * Execute Checkstyle Check. + * + * @throws MojoExecutionException on execution error + * @throws MojoFailureException on execution failure + */ + public final void execute() throws MojoExecutionException, MojoFailureException { + val checkstyle = MojoExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); + val sevntu = MojoExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); + val ruleset = MojoExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); + val checkstylePlugin = + MojoExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, mavenCheckstylePluginVersion, + MojoExecutor.dependencies(checkstyle, sevntu, ruleset) + ); + val configLocation = MojoExecutor.element(CONFIG_LOCATION, "net/kemitix/" + getConfigFile(level)); + + getLog().info( + "Running Checkstyle " + checkstyleVersion + " (sevntu: " + sevntuVersion + ") with " + getConfigFile( + level)); + MojoExecutor.executeMojo(checkstylePlugin, "check", MojoExecutor.configuration(configLocation), + MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager) + ); + } +} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/package-info.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/package-info.java new file mode 100644 index 0000000..af77c05 --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/package-info.java @@ -0,0 +1,31 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 Paul Campbell + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/** + * . + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ + +package net.kemitix.checkstyle.ruleset.plugin; diff --git a/pom.xml b/pom.xml index f22b473..9bb1965 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,7 @@ builder ruleset + plugin