From d1d174d5a7097184ececfaf371e8b0356c51f27b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 27 May 2017 08:53:56 +0100 Subject: [PATCH] API Change: plugin: level is specified as a configuration parameter * merge all level-based goals into a single 'check' goal * specify the level to apply as a configuration parameter * add remaining unit tests for plugin --- README.md | 14 +++++- builder/src/main/resources/README-template.md | 14 +++++- .../ruleset/plugin/CheckConfiguration.java | 2 + ...{AbstractCheckMojo.java => CheckMojo.java} | 27 ++++++----- .../ruleset/plugin/ComplexityCheckMojo.java | 47 ------------------- .../plugin/DefaultCheckstyleExecutor.java | 23 +++++---- .../ruleset/plugin/JavadocCheckMojo.java | 47 ------------------- .../ruleset/plugin/LayoutCheckMojo.java | 47 ------------------- .../ruleset/plugin/NamingCheckMojo.java | 47 ------------------- .../ruleset/plugin/TweaksCheckMojo.java | 47 ------------------- ...tCheckMojoTest.java => CheckMojoTest.java} | 8 ++-- .../plugin/DefaultCheckstyleExecutorTest.java | 9 ++-- sample-parent/pom.xml | 5 +- 13 files changed, 66 insertions(+), 271 deletions(-) rename plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/{AbstractCheckMojo.java => CheckMojo.java} (83%) delete mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java delete mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java delete mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java delete mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java delete mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java rename plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/{AbstractCheckMojoTest.java => CheckMojoTest.java} (93%) diff --git a/README.md b/README.md index 6916e5f..a6fd4a2 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The ruleset includes checks from both the core Checkstyle library and from the S To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`. The `maven-checkstyle-plugin` will be included automatically. -The following goals implement increasingly strict rulesets: +The following levels implement increasingly strict rulesets: * 1-layout * 2-naming @@ -33,6 +33,13 @@ The following goals implement increasingly strict rulesets: * 4-tweaks * 5-complexity +### Change from 2.x + +In 2.x, the level was specified as the goal to invoke. In 3.x, there is only the 'check' goal. +The level is now specified as a configuration parameter. See the example below. + +### Example + ```` 2.1.0 @@ -45,11 +52,14 @@ The following goals implement increasingly strict rulesets: net.kemitix kemitix-checkstyle-ruleset-maven-plugin ${kemitix-checkstyle-ruleset.version} + + ${kemitix-checkstyle-ruleset.level} + validate - ${kemitix-checkstyle-ruleset.level} + check diff --git a/builder/src/main/resources/README-template.md b/builder/src/main/resources/README-template.md index 58c64ac..93250af 100644 --- a/builder/src/main/resources/README-template.md +++ b/builder/src/main/resources/README-template.md @@ -25,7 +25,7 @@ The ruleset includes checks from both the core Checkstyle library and from the S To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`. The `maven-checkstyle-plugin` will be included automatically. -The following goals implement increasingly strict rulesets: +The following levels implement increasingly strict rulesets: * 1-layout * 2-naming @@ -33,6 +33,13 @@ The following goals implement increasingly strict rulesets: * 4-tweaks * 5-complexity +### Change from 2.x + +In 2.x, the level was specified as the goal to invoke. In 3.x, there is only the 'check' goal. +The level is now specified as a configuration parameter. See the example below. + +### Example + ```` 2.1.0 @@ -45,11 +52,14 @@ The following goals implement increasingly strict rulesets: net.kemitix kemitix-checkstyle-ruleset-maven-plugin ${kemitix-checkstyle-ruleset.version} + + ${kemitix-checkstyle-ruleset.level} + validate - ${kemitix-checkstyle-ruleset.level} + check diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java index 84d51b6..32572db 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java @@ -48,4 +48,6 @@ class CheckConfiguration { private String rulesetVersion; private String sourceDirectory; + + private String level; } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java similarity index 83% rename from plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java rename to plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java index 946b893..5e01571 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojo.java @@ -29,11 +29,14 @@ import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Build; import org.apache.maven.model.Plugin; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; 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; @@ -42,13 +45,16 @@ import org.apache.maven.project.MavenProject; * * @author Paul Campbell (pcampbell@kemitix.net) */ -abstract class AbstractCheckMojo extends AbstractMojo { +@Mojo(name = "check", defaultPhase = LifecyclePhase.VALIDATE) +public class CheckMojo extends AbstractMojo { private static final String KEMITIX_GROUPID = "net.kemitix"; private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset"; - private final CheckstyleExecutor checkstyleExecutor; + @Setter + private CheckstyleExecutor checkstyleExecutor = + new DefaultCheckstyleExecutor(new DefaultPluginExecutor(), new MavenXpp3Reader()); @Setter @Parameter(defaultValue = "${project}", readonly = true) @@ -62,22 +68,16 @@ abstract class AbstractCheckMojo extends AbstractMojo { @Parameter(defaultValue = "${localRepository}", readonly = true, required = true) private ArtifactRepository artifactRepository; + @Parameter(defaultValue = "5-complexity", readonly = true) + private String level = "5-complexity"; + @Setter @Component private BuildPluginManager pluginManager; - /** - * Create a check mojo. - * - * @param checkstyleExecutor the executor to invoke the checkstyle plugin - */ - AbstractCheckMojo(final CheckstyleExecutor checkstyleExecutor) { - this.checkstyleExecutor = checkstyleExecutor; - checkstyleExecutor.setLog(getLog()); - } - @Override - public void execute() throws MojoExecutionException, MojoFailureException { + public final void execute() throws MojoExecutionException, MojoFailureException { + checkstyleExecutor.setLog(getLog()); CheckConfiguration config = getCheckConfiguration(); checkstyleExecutor.performCheck(config); } @@ -92,6 +92,7 @@ abstract class AbstractCheckMojo extends AbstractMojo { .pluginManager(pluginManager) .rulesetVersion(rulesetPlugin.getVersion()) .sourceDirectory(build.getSourceDirectory()) + .level(level) .build(); } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java deleted file mode 100644 index 4c12bc0..0000000 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset: COMPLEXITY, TWEAKS, JAVADOC, NAMING and LAYOUT. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -@Mojo(name = "5-complexity", defaultPhase = LifecyclePhase.VALIDATE) -public final class ComplexityCheckMojo extends AbstractCheckMojo { - - private static final String LEVEL = "5-complexity"; - - /** - * Create the Mojo. - */ - public ComplexityCheckMojo() { - super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); - } -} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java index dbb32e5..24d8e7d 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java @@ -37,12 +37,15 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; +import org.codehaus.plexus.util.xml.Xpp3Dom; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.twdata.maven.mojoexecutor.MojoExecutor; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.Reader; +import java.util.List; import java.util.Properties; /** @@ -51,7 +54,7 @@ import java.util.Properties; * @author Paul Campbell (pcampbell@kemitix.net) */ @RequiredArgsConstructor -class DefaultCheckstyleExecutor implements CheckstyleExecutor { +public class DefaultCheckstyleExecutor implements CheckstyleExecutor { private static final String CHECKSTYLE_GROUPID = "com.puppycrawl.tools"; @@ -77,8 +80,6 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor { private static final String PLUGIN_ARTIFACT_ID = KEMITIX_ARTIFACTID + "-parent"; - private final String level; - private final PluginExecutor pluginExecutor; private final MavenXpp3Reader mavenXpp3Reader; @@ -98,11 +99,13 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor { // configure val checkstylePlugin = getPlugin(properties); final String sourceDirectory = config.getSourceDirectory(); + final String level = config.getLevel(); + info("Ruleset: %s", level); final String configFile = String.format("net/kemitix/checkstyle-%s.xml", level); - val configuration = pluginExecutor.configuration(pluginExecutor.element(CONFIG_LOCATION, configFile), - pluginExecutor.element(SOURCE_DIR, sourceDirectory) - ); - val environment = pluginExecutor.executionEnvironment(config); + final Xpp3Dom configuration = pluginExecutor.configuration(pluginExecutor.element(CONFIG_LOCATION, configFile), + pluginExecutor.element(SOURCE_DIR, sourceDirectory) + ); + final MojoExecutor.ExecutionEnvironment environment = pluginExecutor.executionEnvironment(config); // run pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); @@ -120,15 +123,15 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor { val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version"); val checkstyleVersion = getProperty(properties, "checkstyle.version"); val sevntuVersion = getProperty(properties, "sevntu.version"); - info("Checkstyle %s (plugin: %s, sevntu: %s) with ruleset %s (%s)", checkstyleVersion, pluginVersion, - sevntuVersion, level, rulesetVersion + info("Checkstyle %s (plugin: %s, sevntu: %s, ruleset: %s)", checkstyleVersion, + pluginVersion, sevntuVersion, rulesetVersion ); // create checkstyle dependencies val checkstyle = getCheckstyleDependency(checkstyleVersion); val sevntu = getSevntuDependency(sevntuVersion); val ruleset = getRulesetDependency(); - val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); + final List dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java deleted file mode 100644 index f0a64f2..0000000 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset: JAVADOC, NAMING and LAYOUT. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -@Mojo(name = "3-javadoc", defaultPhase = LifecyclePhase.VALIDATE) -public final class JavadocCheckMojo extends AbstractCheckMojo { - - private static final String LEVEL = "3-javadoc"; - - /** - * Create the Mojo. - */ - public JavadocCheckMojo() { - super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); - } -} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java deleted file mode 100644 index 1883ecc..0000000 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset: LAYOUT. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -@Mojo(name = "1-layout", defaultPhase = LifecyclePhase.VALIDATE) -public final class LayoutCheckMojo extends AbstractCheckMojo { - - private static final String LEVEL = "1-layout"; - - /** - * Create the Mojo. - */ - public LayoutCheckMojo() { - super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); - } -} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java deleted file mode 100644 index 27081b9..0000000 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Rulesets: NAMING and LAYOUT. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -@Mojo(name = "2-naming", defaultPhase = LifecyclePhase.VALIDATE) -public final class NamingCheckMojo extends AbstractCheckMojo { - - private static final String LEVEL = "2-naming"; - - /** - * Create the Mojo. - */ - public NamingCheckMojo() { - super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); - } -} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java deleted file mode 100644 index 6c2c6b8..0000000 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java +++ /dev/null @@ -1,47 +0,0 @@ -/* -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 org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugins.annotations.LifecyclePhase; -import org.apache.maven.plugins.annotations.Mojo; - -/** - * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset: TWEAKS, JAVADOC, NAMING and LAYOUT. - * - * @author Paul Campbell (pcampbell@kemitix.net) - */ -@Mojo(name = "4-tweaks", defaultPhase = LifecyclePhase.VALIDATE) -public final class TweaksCheckMojo extends AbstractCheckMojo { - - private static final String LEVEL = "4-tweaks"; - - /** - * Create the Mojo. - */ - public TweaksCheckMojo() { - super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); - } -} diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojoTest.java similarity index 93% rename from plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java rename to plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojoTest.java index adcced5..0008532 100644 --- a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckMojoTest.java @@ -21,11 +21,11 @@ import static org.mockito.BDDMockito.then; import static org.mockito.Matchers.any; /** - * Tests for {@link AbstractCheckMojo}. + * Tests for {@link CheckMojo}. * * @author Paul Campbell (pcampbell@kemitix.net) */ -public class AbstractCheckMojoTest { +public class CheckMojoTest { @Mock private CheckstyleExecutor checkstyleExecutor; @@ -59,8 +59,8 @@ public class AbstractCheckMojoTest { @Test public void canExecute() throws MojoFailureException, MojoExecutionException { //given - final AbstractCheckMojo mojo = new AbstractCheckMojo(checkstyleExecutor) { - }; + final CheckMojo mojo = new CheckMojo(); + mojo.setCheckstyleExecutor(checkstyleExecutor); mojo.setMavenProject(mavenProject); mojo.setMavenSession(mavenSession); mojo.setArtifactRepository(artifactRepository); diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java index f784f54..b230eeb 100644 --- a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java @@ -41,6 +41,9 @@ import static org.mockito.Matchers.eq; */ public class DefaultCheckstyleExecutorTest { + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + @Mock private PluginExecutor pluginExecutor; @@ -71,9 +74,6 @@ public class DefaultCheckstyleExecutorTest { private File artifactFile; - @Rule - public TemporaryFolder folder = new TemporaryFolder(); - @Mock private MavenXpp3Reader mavenXpp3Reader; @@ -105,7 +105,7 @@ public class DefaultCheckstyleExecutorTest { public void setUp() { MockitoAnnotations.initMocks(this); level = "test level"; - checkstyleExecutor = new DefaultCheckstyleExecutor(level, pluginExecutor, mavenXpp3Reader); + checkstyleExecutor = new DefaultCheckstyleExecutor(pluginExecutor, mavenXpp3Reader); checkstyleExecutor.setLog(log); } @@ -119,6 +119,7 @@ public class DefaultCheckstyleExecutorTest { .artifactRepository(artifactRepository) .pluginManager(pluginManager) .rulesetVersion("ruleset version") + .level(level) .build(); artifactFile = folder.newFile("pom.xml"); diff --git a/sample-parent/pom.xml b/sample-parent/pom.xml index 08261e9..a50101c 100644 --- a/sample-parent/pom.xml +++ b/sample-parent/pom.xml @@ -51,11 +51,14 @@ net.kemitix kemitix-checkstyle-ruleset-maven-plugin ${project.version} + + ${kemitix-checkstyle-ruleset-level} + validate - ${kemitix-checkstyle-ruleset-level} + check