From 7c774a5057a98717c79d7b3c2d934a281155d0c0 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 25 May 2017 16:28:35 +0100 Subject: [PATCH 01/16] {builder,plugin}: pom.xml: upgrades * kemitix-parent: 2.4.0 -> 2.8.0 * spring-boot: 1.5.1 -> 1.5.3 * lombok: 1.16.12 -> 1.16.16 (reverting to kemitix-parent version) * assertj: 3.6.2 -> 3.8.0 * maven: 3.3.9 -> 3.5.0 * mojo-executor: 2.2.0 -> 2.3.0 --- builder/pom.xml | 7 +++---- plugin/pom.xml | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index 808bcbb..eaa04c1 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-parent - 2.4.0 + 2.8.0 @@ -37,9 +37,8 @@ 1.8 UTF-8 UTF-8 - 1.5.1.RELEASE - 1.16.12 - 3.6.2 + 1.5.3.RELEASE + 3.8.0 2.3.5 1.0.0 4.3.0 diff --git a/plugin/pom.xml b/plugin/pom.xml index d8d1911..3d3e238 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -19,7 +19,7 @@ 1.8 UTF-8 UTF-8 - 3.3.9 + 3.5.0 3.6.1 3.5 3.5 @@ -27,8 +27,8 @@ 3.0.1 1.6 2.8.2 - 2.2.0 - 1.16.12 + 2.3.0 + 1.16.16 1.0.0 From 1d0d24c1d37304e6a10ce3cc1da0bb86082059d2 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 09:06:31 +0100 Subject: [PATCH 02/16] plugin: PluginExecutor: add wrapper for static methods on MojoExecutor --- .../ruleset/plugin/DefaultPluginExecutor.java | 83 ++++++++++++ .../ruleset/plugin/PluginExecutor.java | 121 ++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java create mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java new file mode 100644 index 0000000..de01dfe --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java @@ -0,0 +1,83 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.List; + +/** + * Wrapper for {@link org.twdata.maven.mojoexecutor.MojoExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public final class DefaultPluginExecutor implements PluginExecutor { + + @Override + public MojoExecutor.Element element(final String key, final String value) { + return MojoExecutor.element(key, value); + } + + @Override + public Xpp3Dom configuration(final MojoExecutor.Element... elements) { + return MojoExecutor.configuration(elements); + } + + @Override + public MojoExecutor.ExecutionEnvironment executionEnvironment( + final MavenProject mavenProject, final MavenSession mavenSession, final BuildPluginManager pluginManager + ) { + return MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + } + + @Override + public void executeMojo( + final Plugin plugin, final String goal, final Xpp3Dom configuration, + final MojoExecutor.ExecutionEnvironment env + ) throws MojoExecutionException { + MojoExecutor.executeMojo(plugin, goal, configuration, env); + } + + @Override + public Dependency dependency(final String groupid, final String artifactid, final String version) { + return MojoExecutor.dependency(groupid, artifactid, version); + } + + @Override + public List dependencies(final Dependency... dependencies) { + return MojoExecutor.dependencies(dependencies); + } + + @Override + public Plugin plugin( + final String groupid, final String artifactid, final String version, final List dependencies + ) { + return MojoExecutor.plugin(groupid, artifactid, version, dependencies); + } +} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java new file mode 100644 index 0000000..1747f3f --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java @@ -0,0 +1,121 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.List; + +/** + * Interface for wrapping calls to static methods on {@link org.twdata.maven.mojoexecutor.MojoExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public interface PluginExecutor { + + /** + * Constructs the element with a textual body. + * + * @param name The element name + * @param value The element text value + * + * @return The element object + */ + MojoExecutor.Element element(String name, String value); + + /** + * Builds the configuration for the goal using Elements. + * + * @param elements A list of elements for the configuration section + * + * @return The elements transformed into the Maven-native XML format + */ + Xpp3Dom configuration(MojoExecutor.Element... elements); + + /** + * Constructs the {@link MojoExecutor.ExecutionEnvironment} instance fluently. + * + * @param mavenProject The current Maven project + * @param mavenSession The current Maven session + * @param pluginManager The Build plugin manager + * + * @return The execution environment + */ + MojoExecutor.ExecutionEnvironment executionEnvironment( + MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager + ); + + /** + * Entry point for executing a mojo. + * + * @param plugin The plugin to execute + * @param goal The goal to execute + * @param configuration The execution configuration + * @param env The execution environment + * + * @throws MojoExecutionException If there are any exceptions locating or executing the mojo + */ + void executeMojo( + Plugin plugin, String goal, Xpp3Dom configuration, MojoExecutor.ExecutionEnvironment env + ) throws MojoExecutionException; + + /** + * Defines a dependency. + * + * @param groupId The group id + * @param artifactId The artifact id + * @param version The plugin version + * + * @return the dependency instance + */ + Dependency dependency(String groupId, String artifactId, String version); + + /** + * Creates a list of dependencies. + * + * @param dependencies the dependencies + * + * @return A list of dependencies + */ + List dependencies(Dependency... dependencies); + + /** + * Defines a plugin. + * + * @param groupId The group id + * @param artifactId The artifact id + * @param version The plugin version + * @param dependencies The plugin dependencies + * + * @return The plugin instance + */ + Plugin plugin( + String groupId, String artifactId, String version, List dependencies + ); +} From abe72514533e444a99fac70446907809a0fc6497 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 09:16:09 +0100 Subject: [PATCH 03/16] plugin: AbstractCheckMojo: use PluginExecutor --- .../ruleset/plugin/AbstractCheckMojo.java | 27 +++++++++++-------- .../ruleset/plugin/ComplexityCheckMojo.java | 9 ++++++- .../ruleset/plugin/JavadocCheckMojo.java | 9 ++++++- .../ruleset/plugin/LayoutCheckMojo.java | 9 ++++++- .../ruleset/plugin/NamingCheckMojo.java | 9 ++++++- .../ruleset/plugin/TweaksCheckMojo.java | 9 ++++++- 6 files changed, 56 insertions(+), 16 deletions(-) diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index b3a3102..e4dcbf8 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -40,7 +40,6 @@ import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.twdata.maven.mojoexecutor.MojoExecutor; import java.io.FileReader; import java.io.IOException; @@ -89,6 +88,12 @@ abstract class AbstractCheckMojo extends AbstractMojo { @Component private BuildPluginManager pluginManager = null; + private final PluginExecutor pluginExecutor; + + AbstractCheckMojo(final PluginExecutor pluginExecutor) { + this.pluginExecutor = pluginExecutor; + } + /** * Execute Checkstyle Check. * @@ -111,17 +116,17 @@ abstract class AbstractCheckMojo extends AbstractMojo { // configure val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); - val configuration = MojoExecutor.configuration( - MojoExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), - MojoExecutor.element(SOURCE_DIR, mavenProject.getBuild().getSourceDirectory()) + val configuration = pluginExecutor.configuration( + pluginExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), + pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild().getSourceDirectory()) ); - val environment = MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + val environment = pluginExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); // run info("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, sevntuVersion, level, rulesetVersion ); - MojoExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); + pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); info("Checkstyle complete"); } @@ -133,12 +138,12 @@ abstract class AbstractCheckMojo extends AbstractMojo { private Plugin getPlugin(final String pluginVersion, final String checkstyleVersion, final String sevntuVersion) { // create checkstyle dependencies - 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 dependencies = MojoExecutor.dependencies(checkstyle, sevntu, ruleset); + val checkstyle = pluginExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); + val sevntu = pluginExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); + val ruleset = pluginExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); + val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); - return MojoExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); + return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); } private Properties getProperties() throws MojoFailureException { 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 index 94090c8..ec4706d 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java @@ -35,7 +35,14 @@ import org.apache.maven.plugins.annotations.Mojo; * @author Paul Campbell (pcampbell@kemitix.net) */ @Mojo(name = "5-complexity", defaultPhase = LifecyclePhase.VALIDATE) -public class ComplexityCheckMojo extends AbstractCheckMojo { +public final class ComplexityCheckMojo extends AbstractCheckMojo { + + /** + * Create the Mojo. + */ + ComplexityCheckMojo() { + super(new DefaultPluginExecutor()); + } @Override public void execute() throws MojoExecutionException, MojoFailureException { 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 index 2952110..e3cd51f 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java @@ -35,7 +35,14 @@ import org.apache.maven.plugins.annotations.Mojo; * @author Paul Campbell (pcampbell@kemitix.net) */ @Mojo(name = "3-javadoc", defaultPhase = LifecyclePhase.VALIDATE) -public class JavadocCheckMojo extends AbstractCheckMojo { +public final class JavadocCheckMojo extends AbstractCheckMojo { + + /** + * Create the Mojo. + */ + JavadocCheckMojo() { + super(new DefaultPluginExecutor()); + } @Override public void execute() throws MojoExecutionException, MojoFailureException { 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 index e6aee8e..3a76973 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java @@ -35,7 +35,14 @@ import org.apache.maven.plugins.annotations.Mojo; * @author Paul Campbell (pcampbell@kemitix.net) */ @Mojo(name = "1-layout", defaultPhase = LifecyclePhase.VALIDATE) -public class LayoutCheckMojo extends AbstractCheckMojo { +public final class LayoutCheckMojo extends AbstractCheckMojo { + + /** + * Create the Mojo. + */ + LayoutCheckMojo() { + super(new DefaultPluginExecutor()); + } @Override public void execute() throws MojoExecutionException, MojoFailureException { 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 index a650885..bd11151 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java @@ -35,7 +35,14 @@ import org.apache.maven.plugins.annotations.Mojo; * @author Paul Campbell (pcampbell@kemitix.net) */ @Mojo(name = "2-naming", defaultPhase = LifecyclePhase.VALIDATE) -public class NamingCheckMojo extends AbstractCheckMojo { +public final class NamingCheckMojo extends AbstractCheckMojo { + + /** + * Create the Mojo. + */ + NamingCheckMojo() { + super(new DefaultPluginExecutor()); + } @Override public void execute() throws MojoExecutionException, MojoFailureException { 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 index 6cb2144..c7d8c54 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java @@ -35,7 +35,14 @@ import org.apache.maven.plugins.annotations.Mojo; * @author Paul Campbell (pcampbell@kemitix.net) */ @Mojo(name = "4-tweaks", defaultPhase = LifecyclePhase.VALIDATE) -public class TweaksCheckMojo extends AbstractCheckMojo { +public final class TweaksCheckMojo extends AbstractCheckMojo { + + /** + * Create the Mojo. + */ + TweaksCheckMojo() { + super(new DefaultPluginExecutor()); + } @Override public void execute() throws MojoExecutionException, MojoFailureException { From 6f9f07709f3386edc575b9c692f8f3e99003635a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 09:17:29 +0100 Subject: [PATCH 04/16] README.md,application.yml: fix typo ArrayTrailingCommand and FinalLocalVariable had typo in level (TWEAK when it should have been TWEAKS) --- README.md | 4 ++-- builder/src/main/resources/application.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 98bcdf0..6916e5f 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,7 @@ Rule|Level|Source|Enabled|Suppressable [AnnotationLocation](#annotationlocation)|layout|checkstyle|Yes| [AnnotationUseStyle](#annotationusestyle)|layout|checkstyle|Yes| [AnonInnerLength](#anoninnerlength)|complexity|checkstyle|Yes| -[ArrayTrailingComma](#arraytrailingcomma)|unspecified|checkstyle|| +[ArrayTrailingComma](#arraytrailingcomma)|tweaks|checkstyle|| [ArrayTypeStyle](#arraytypestyle)|layout|checkstyle|Yes| [AtclauseOrder](#atclauseorder)|javadoc|checkstyle|Yes| [AvoidConditionInversion](#avoidconditioninversion)|complexity|sevntu|| @@ -125,7 +125,7 @@ Rule|Level|Source|Enabled|Suppressable [FileTabCharacter](#filetabcharacter)|layout|checkstyle|Yes| [FinalClass](#finalclass)|complexity|checkstyle|Yes| [FinalizeImplementation](#finalizeimplementation)|unspecified|sevntu|| -[FinalLocalVariable](#finallocalvariable)|unspecified|checkstyle|| +[FinalLocalVariable](#finallocalvariable)|tweaks|checkstyle|| [FinalParameters](#finalparameters)|tweaks|checkstyle|Yes| [ForbidAnnotation](#forbidannotation)|unspecified|sevntu|| [ForbidCCommentsInMethods](#forbidccommentsinmethods)|layout|sevntu|Yes| diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 8d331fe..3380f3a 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -1182,7 +1182,7 @@ rules: - name: ArrayTrailingComma parent: TREEWALKER - level: TWEAK + level: TWEAKS enabled: false source: CHECKSTYLE uri: http://checkstyle.sourceforge.net/config_coding.html#ArrayTrailingComma @@ -1190,7 +1190,7 @@ rules: - name: FinalLocalVariable parent: TREEWALKER - level: TWEAK + level: TWEAKS enabled: false source: CHECKSTYLE uri: http://checkstyle.sourceforge.net/config_coding.html#FinalLocalVariable From e46f8d5d1fa29cfcfda49ffc97f89f6c43290f77 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 12:03:03 +0100 Subject: [PATCH 05/16] plugin: AbstractCheckMojo: replace abstract execute() with getLevel() Child classes don't need to implement the execute() method now, but a getLevel() method instead. --- .../checkstyle/ruleset/plugin/AbstractCheckMojo.java | 12 ++++++++++-- .../ruleset/plugin/ComplexityCheckMojo.java | 10 +++++----- .../checkstyle/ruleset/plugin/JavadocCheckMojo.java | 10 +++++----- .../checkstyle/ruleset/plugin/LayoutCheckMojo.java | 10 +++++----- .../checkstyle/ruleset/plugin/NamingCheckMojo.java | 10 +++++----- .../checkstyle/ruleset/plugin/TweaksCheckMojo.java | 10 +++++----- 6 files changed, 35 insertions(+), 27 deletions(-) diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index e4dcbf8..31e4ed8 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -94,6 +94,13 @@ abstract class AbstractCheckMojo extends AbstractMojo { this.pluginExecutor = pluginExecutor; } + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + performCheck(getLevel()); + } + + abstract String getLevel(); + /** * Execute Checkstyle Check. * @@ -118,8 +125,9 @@ abstract class AbstractCheckMojo extends AbstractMojo { val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); val configuration = pluginExecutor.configuration( pluginExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), - pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild().getSourceDirectory()) - ); + pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild() + .getSourceDirectory()) + ); val environment = pluginExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); // run 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 index ec4706d..c34a0c0 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java @@ -24,8 +24,6 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -37,15 +35,17 @@ import org.apache.maven.plugins.annotations.Mojo; @Mojo(name = "5-complexity", defaultPhase = LifecyclePhase.VALIDATE) public final class ComplexityCheckMojo extends AbstractCheckMojo { + private static final String LEVEL = "5-complexity"; + /** * Create the Mojo. */ - ComplexityCheckMojo() { + public ComplexityCheckMojo() { super(new DefaultPluginExecutor()); } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck("5-complexity"); + String getLevel() { + return LEVEL; } } 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 index e3cd51f..98a0fb5 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java @@ -24,8 +24,6 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -37,15 +35,17 @@ import org.apache.maven.plugins.annotations.Mojo; @Mojo(name = "3-javadoc", defaultPhase = LifecyclePhase.VALIDATE) public final class JavadocCheckMojo extends AbstractCheckMojo { + private static final String LEVEL = "3-javadoc"; + /** * Create the Mojo. */ - JavadocCheckMojo() { + public JavadocCheckMojo() { super(new DefaultPluginExecutor()); } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck("3-javadoc"); + String getLevel() { + return LEVEL; } } 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 index 3a76973..2336864 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java @@ -24,8 +24,6 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -37,15 +35,17 @@ import org.apache.maven.plugins.annotations.Mojo; @Mojo(name = "1-layout", defaultPhase = LifecyclePhase.VALIDATE) public final class LayoutCheckMojo extends AbstractCheckMojo { + private static final String LEVEL = "1-layout"; + /** * Create the Mojo. */ - LayoutCheckMojo() { + public LayoutCheckMojo() { super(new DefaultPluginExecutor()); } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck("1-layout"); + String getLevel() { + return LEVEL; } } 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 index bd11151..1042538 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java @@ -24,8 +24,6 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -37,15 +35,17 @@ import org.apache.maven.plugins.annotations.Mojo; @Mojo(name = "2-naming", defaultPhase = LifecyclePhase.VALIDATE) public final class NamingCheckMojo extends AbstractCheckMojo { + private static final String LEVEL = "2-naming"; + /** * Create the Mojo. */ - NamingCheckMojo() { + public NamingCheckMojo() { super(new DefaultPluginExecutor()); } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck("2-naming"); + String getLevel() { + return LEVEL; } } 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 index c7d8c54..0bb56fe 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java @@ -24,8 +24,6 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; @@ -37,15 +35,17 @@ import org.apache.maven.plugins.annotations.Mojo; @Mojo(name = "4-tweaks", defaultPhase = LifecyclePhase.VALIDATE) public final class TweaksCheckMojo extends AbstractCheckMojo { + private static final String LEVEL = "4-tweaks"; + /** * Create the Mojo. */ - TweaksCheckMojo() { + public TweaksCheckMojo() { super(new DefaultPluginExecutor()); } @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck("4-tweaks"); + String getLevel() { + return LEVEL; } } From 337524ed970b60bf28f2bcdcc27bc494f0c66a56 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 12:14:09 +0100 Subject: [PATCH 06/16] plugin: CheckstyleExecutor: extracted from AbstractCheckMojo --- .../ruleset/plugin/AbstractCheckMojo.java | 119 +------------- .../ruleset/plugin/CheckstyleExecutor.java | 53 ++++++ .../plugin/DefaultCheckstyleExecutor.java | 153 ++++++++++++++++++ 3 files changed, 211 insertions(+), 114 deletions(-) create mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java create mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index 31e4ed8..1c9f5e1 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -25,13 +25,8 @@ SOFTWARE. package net.kemitix.checkstyle.ruleset.plugin; import lombok.Setter; -import lombok.val; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; -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; @@ -39,11 +34,6 @@ import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; - -import java.io.FileReader; -import java.io.IOException; -import java.util.Properties; /** * Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset. @@ -52,28 +42,6 @@ import java.util.Properties; */ abstract class AbstractCheckMojo 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 SOURCE_DIR = "sourceDirectory"; - - private String rulesetVersion; - @Setter @Parameter(defaultValue = "${project}", readonly = true) private MavenProject mavenProject; @@ -88,93 +56,16 @@ abstract class AbstractCheckMojo extends AbstractMojo { @Component private BuildPluginManager pluginManager = null; - private final PluginExecutor pluginExecutor; + private final CheckstyleExecutor checkstyleExecutor; AbstractCheckMojo(final PluginExecutor pluginExecutor) { - this.pluginExecutor = pluginExecutor; - } - - @Override - public void execute() throws MojoExecutionException, MojoFailureException { - performCheck(getLevel()); + checkstyleExecutor = new DefaultCheckstyleExecutor(getLog(), getLevel(), pluginExecutor); } abstract String getLevel(); - /** - * Execute Checkstyle Check. - * - * @param level The level of config file to use. - * - * @throws MojoExecutionException on execution error - * @throws MojoFailureException on execution failure - */ - final void performCheck(final String level) throws MojoExecutionException, MojoFailureException { - rulesetVersion = mavenProject.getPlugin(KEMITIX_GROUPID + ":" + KEMITIX_ARTIFACTID + "-maven-plugin") - .getVersion(); - debug("rulesetVersion: %s", rulesetVersion); - val properties = getProperties(); - debug("properties: %s", properties); - - // get versions from pom.xml properties - val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version"); - val checkstyleVersion = getProperty(properties, "checkstyle.version"); - val sevntuVersion = getProperty(properties, "sevntu.version"); - - // configure - val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); - val configuration = pluginExecutor.configuration( - pluginExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), - pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild() - .getSourceDirectory()) - ); - val environment = pluginExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); - - // run - info("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, sevntuVersion, level, - rulesetVersion - ); - pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); - info("Checkstyle complete"); - } - - private String getProperty(final Properties properties, final String key) { - val property = properties.getProperty(key); - debug(key + ": %s", property); - return property; - } - - private Plugin getPlugin(final String pluginVersion, final String checkstyleVersion, final String sevntuVersion) { - // create checkstyle dependencies - val checkstyle = pluginExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); - val sevntu = pluginExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); - val ruleset = pluginExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); - val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); - - return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); - } - - private Properties getProperties() throws MojoFailureException { - // load properties from the plugin pom.xml - val pluginArtifactId = KEMITIX_ARTIFACTID + "-parent"; - val pluginArtifact = new DefaultArtifact(KEMITIX_GROUPID, pluginArtifactId, rulesetVersion, null, "", null, - new DefaultArtifactHandler("pom") - ); - try { - val pomReader = new FileReader(artifactRepository.find(pluginArtifact) - .getFile()); - return new MavenXpp3Reader().read(pomReader) - .getProperties(); - } catch (XmlPullParserException | IOException e) { - throw new MojoFailureException("Can't load properties from plugin's pom.xml", e); - } - } - - private void info(final String format, final Object... args) { - getLog().info(String.format(format, args)); - } - - private void debug(final String format, final Object... args) { - getLog().debug(String.format(format, args)); + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + checkstyleExecutor.performCheck(mavenProject, mavenSession, artifactRepository, pluginManager); } } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java new file mode 100644 index 0000000..c13645d --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java @@ -0,0 +1,53 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; + +/** + * Executes the Checkstyle plugin. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +interface CheckstyleExecutor { + + /** + * Execute Checkstyle Check. + * + * @param mavenProject The Maven Project + * @param mavenSession The Maven Session + * @param artifactRepository The Artifact Repository + * @param pluginManager The Maven Plugin Manager + * + * @throws MojoExecutionException on execution error + * @throws MojoFailureException on execution failure + */ + void performCheck( + final MavenProject mavenProject, final MavenSession mavenSession, + final ArtifactRepository artifactRepository, final BuildPluginManager pluginManager + ) throws MojoExecutionException, MojoFailureException; +} 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 new file mode 100644 index 0000000..26dc547 --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutor.java @@ -0,0 +1,153 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.Getter; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.DefaultArtifactHandler; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.FileReader; +import java.io.IOException; +import java.util.Properties; + +/** + * Default implementation of {@link CheckstyleExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +@RequiredArgsConstructor +class DefaultCheckstyleExecutor implements CheckstyleExecutor { + + 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 SOURCE_DIR = "sourceDirectory"; + + @Getter + private final Log log; + + private final String level; + + private final PluginExecutor pluginExecutor; + + private String rulesetVersion; + + @Override + public final void performCheck( + final MavenProject mavenProject, final MavenSession mavenSession, + final ArtifactRepository artifactRepository, final BuildPluginManager pluginManager + ) throws MojoExecutionException, MojoFailureException { + rulesetVersion = mavenProject.getPlugin(KEMITIX_GROUPID + ":" + KEMITIX_ARTIFACTID + "-maven-plugin") + .getVersion(); + debug("rulesetVersion: %s", rulesetVersion); + val properties = getProperties(artifactRepository); + debug("properties: %s", properties); + + // get versions from pom.xml properties + val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version"); + val checkstyleVersion = getProperty(properties, "checkstyle.version"); + val sevntuVersion = getProperty(properties, "sevntu.version"); + + // configure + val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); + val configuration = pluginExecutor.configuration( + pluginExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), + pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild() + .getSourceDirectory()) + ); + val environment = pluginExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + + // run + info("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, sevntuVersion, level, + rulesetVersion + ); + pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); + info("Checkstyle complete"); + } + + private String getProperty(final Properties properties, final String key) { + val property = properties.getProperty(key); + debug(key + ": %s", property); + return property; + } + + private Plugin getPlugin(final String pluginVersion, final String checkstyleVersion, final String sevntuVersion) { + // create checkstyle dependencies + val checkstyle = pluginExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); + val sevntu = pluginExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); + val ruleset = pluginExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); + val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); + + return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); + } + + private Properties getProperties(final ArtifactRepository artifactRepository) throws MojoFailureException { + // load properties from the plugin pom.xml + val pluginArtifactId = KEMITIX_ARTIFACTID + "-parent"; + val pluginArtifact = new DefaultArtifact(KEMITIX_GROUPID, pluginArtifactId, rulesetVersion, null, "", null, + new DefaultArtifactHandler("pom") + ); + try { + val pomReader = new FileReader(artifactRepository.find(pluginArtifact) + .getFile()); + return new MavenXpp3Reader().read(pomReader) + .getProperties(); + } catch (XmlPullParserException | IOException e) { + throw new MojoFailureException("Can't load properties from plugin's pom.xml", e); + } + } + + private void info(final String format, final Object... args) { + getLog().info(String.format(format, args)); + } + + private void debug(final String format, final Object... args) { + getLog().debug(String.format(format, args)); + } +} From d91f392bf13274b417fb4973db9b870f054fbb49 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 15:42:02 +0100 Subject: [PATCH 07/16] plugin: add assertj and mockito test dependencies --- plugin/pom.xml | 10 ++++++++++ pom.xml | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/plugin/pom.xml b/plugin/pom.xml index 3d3e238..7f2cf6c 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -65,6 +65,16 @@ map-builder ${map-builder.version} + + org.assertj + assertj-core + test + + + org.mockito + mockito-core + test + diff --git a/pom.xml b/pom.xml index a256b1a..082404e 100644 --- a/pom.xml +++ b/pom.xml @@ -23,6 +23,8 @@ 2.17 7.6.1 1.23.1 + 1.10.19 + 3.8.0 @@ -133,6 +135,21 @@ + + + + org.mockito + mockito-core + ${mockito.version} + + + org.assertj + assertj-core + ${assertj.version} + + + + sonatype-nexus-snapshots From 92e9a289fa87f943c6f62a857eed633d4308f246 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 17:08:44 +0100 Subject: [PATCH 08/16] plugin: extract CheckConfiguration and variour other refactorings --- .../ruleset/plugin/AbstractCheckMojo.java | 35 +++++- .../ruleset/plugin/CheckConfiguration.java | 51 ++++++++ .../ruleset/plugin/CheckstyleExecutor.java | 17 +-- .../ruleset/plugin/ComplexityCheckMojo.java | 8 +- .../plugin/DefaultCheckstyleExecutor.java | 111 +++++++++++------- .../ruleset/plugin/DefaultPluginExecutor.java | 10 +- .../ruleset/plugin/JavadocCheckMojo.java | 8 +- .../ruleset/plugin/LayoutCheckMojo.java | 8 +- .../ruleset/plugin/NamingCheckMojo.java | 8 +- .../ruleset/plugin/PluginExecutor.java | 11 +- .../ruleset/plugin/TweaksCheckMojo.java | 8 +- 11 files changed, 171 insertions(+), 104 deletions(-) create mode 100644 plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index 1c9f5e1..46bc726 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -27,6 +27,8 @@ package net.kemitix.checkstyle.ruleset.plugin; import lombok.Setter; 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.plugin.AbstractMojo; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; @@ -42,6 +44,10 @@ import org.apache.maven.project.MavenProject; */ abstract class AbstractCheckMojo extends AbstractMojo { + private static final String KEMITIX_GROUPID = "net.kemitix"; + + private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset"; + @Setter @Parameter(defaultValue = "${project}", readonly = true) private MavenProject mavenProject; @@ -50,22 +56,41 @@ abstract class AbstractCheckMojo extends AbstractMojo { @Parameter(defaultValue = "${session}", readonly = true) private MavenSession mavenSession; + @Setter @Parameter(defaultValue = "${localRepository}", readonly = true, required = true) private ArtifactRepository artifactRepository = null; + @Setter @Component private BuildPluginManager pluginManager = null; private final CheckstyleExecutor checkstyleExecutor; - AbstractCheckMojo(final PluginExecutor pluginExecutor) { - checkstyleExecutor = new DefaultCheckstyleExecutor(getLog(), getLevel(), pluginExecutor); + AbstractCheckMojo(final CheckstyleExecutor checkstyleExecutor) { + this.checkstyleExecutor = checkstyleExecutor; + checkstyleExecutor.setLog(getLog()); } - abstract String getLevel(); - @Override public void execute() throws MojoExecutionException, MojoFailureException { - checkstyleExecutor.performCheck(mavenProject, mavenSession, artifactRepository, pluginManager); + CheckConfiguration config = getCheckConfiguration(); + checkstyleExecutor.performCheck(config); + } + + private CheckConfiguration getCheckConfiguration() { + final Plugin rulesetPlugin = getRulesetPlugin(); + final Build build = mavenProject.getBuild(); + return CheckConfiguration.builder() + .mavenProject(mavenProject) + .mavenSession(mavenSession) + .artifactRepository(artifactRepository) + .pluginManager(pluginManager) + .rulesetVersion(rulesetPlugin.getVersion()) + .sourceDirectory(build.getSourceDirectory()) + .build(); + } + + private Plugin getRulesetPlugin() { + return mavenProject.getPlugin(KEMITIX_GROUPID + ":" + KEMITIX_ARTIFACTID + "-maven-plugin"); } } 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 new file mode 100644 index 0000000..84d51b6 --- /dev/null +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfiguration.java @@ -0,0 +1,51 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2017 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.Builder; +import lombok.Getter; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.project.MavenProject; + +/** + * Configuration for performing a Checkstyle Check. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +@Getter +@Builder +class CheckConfiguration { + + private MavenProject mavenProject; + + private MavenSession mavenSession; + + private ArtifactRepository artifactRepository; + + private BuildPluginManager pluginManager; + + private String rulesetVersion; + + private String sourceDirectory; +} diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java index c13645d..212f3bf 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/CheckstyleExecutor.java @@ -21,12 +21,9 @@ package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.project.MavenProject; +import org.apache.maven.plugin.logging.Log; /** * Executes the Checkstyle plugin. @@ -38,16 +35,12 @@ interface CheckstyleExecutor { /** * Execute Checkstyle Check. * - * @param mavenProject The Maven Project - * @param mavenSession The Maven Session - * @param artifactRepository The Artifact Repository - * @param pluginManager The Maven Plugin Manager + * @param configuration The Configuration * * @throws MojoExecutionException on execution error * @throws MojoFailureException on execution failure */ - void performCheck( - final MavenProject mavenProject, final MavenSession mavenSession, - final ArtifactRepository artifactRepository, final BuildPluginManager pluginManager - ) throws MojoExecutionException, MojoFailureException; + void performCheck(CheckConfiguration configuration) throws MojoExecutionException, MojoFailureException; + + void setLog(Log log); } 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 index c34a0c0..4c12bc0 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/ComplexityCheckMojo.java @@ -24,6 +24,7 @@ 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; @@ -41,11 +42,6 @@ public final class ComplexityCheckMojo extends AbstractCheckMojo { * Create the Mojo. */ public ComplexityCheckMojo() { - super(new DefaultPluginExecutor()); - } - - @Override - String getLevel() { - return LEVEL; + 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 26dc547..dbb32e5 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 @@ -23,22 +23,26 @@ package net.kemitix.checkstyle.ruleset.plugin; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.Setter; import lombok.val; +import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.DefaultArtifact; +import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import java.io.File; import java.io.FileReader; import java.io.IOException; +import java.io.Reader; import java.util.Properties; /** @@ -69,80 +73,105 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor { private static final String SOURCE_DIR = "sourceDirectory"; - @Getter - private final Log log; + private static final ArtifactHandler POM_ARTIFACT_HANDLER = new DefaultArtifactHandler("pom"); + + private static final String PLUGIN_ARTIFACT_ID = KEMITIX_ARTIFACTID + "-parent"; private final String level; private final PluginExecutor pluginExecutor; + private final MavenXpp3Reader mavenXpp3Reader; + + @Setter + @Getter + private Log log; + private String rulesetVersion; @Override - public final void performCheck( - final MavenProject mavenProject, final MavenSession mavenSession, - final ArtifactRepository artifactRepository, final BuildPluginManager pluginManager - ) throws MojoExecutionException, MojoFailureException { - rulesetVersion = mavenProject.getPlugin(KEMITIX_GROUPID + ":" + KEMITIX_ARTIFACTID + "-maven-plugin") - .getVersion(); - debug("rulesetVersion: %s", rulesetVersion); - val properties = getProperties(artifactRepository); - debug("properties: %s", properties); - - // get versions from pom.xml properties - val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version"); - val checkstyleVersion = getProperty(properties, "checkstyle.version"); - val sevntuVersion = getProperty(properties, "sevntu.version"); + public final void performCheck(final CheckConfiguration config) + throws MojoExecutionException, MojoFailureException { + rulesetVersion = config.getRulesetVersion(); + val properties = getProperties(config.getArtifactRepository()); // configure - val checkstylePlugin = getPlugin(pluginVersion, checkstyleVersion, sevntuVersion); - val configuration = pluginExecutor.configuration( - pluginExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level)), - pluginExecutor.element(SOURCE_DIR, mavenProject.getBuild() - .getSourceDirectory()) + val checkstylePlugin = getPlugin(properties); + final String sourceDirectory = config.getSourceDirectory(); + 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(mavenProject, mavenSession, pluginManager); + val environment = pluginExecutor.executionEnvironment(config); // run - info("Running Checkstyle %s (sevntu: %s) with ruleset %s (%s)", checkstyleVersion, sevntuVersion, level, - rulesetVersion - ); pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment); info("Checkstyle complete"); } private String getProperty(final Properties properties, final String key) { val property = properties.getProperty(key); - debug(key + ": %s", property); + debug("%s: %s", key, property); return property; } - private Plugin getPlugin(final String pluginVersion, final String checkstyleVersion, final String sevntuVersion) { + private Plugin getPlugin(final Properties properties) { + // get versions from pom.xml properties + 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 + ); + // create checkstyle dependencies - val checkstyle = pluginExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); - val sevntu = pluginExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); - val ruleset = pluginExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); + val checkstyle = getCheckstyleDependency(checkstyleVersion); + val sevntu = getSevntuDependency(sevntuVersion); + val ruleset = getRulesetDependency(); val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset); return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies); } + private Dependency getRulesetDependency() { + return pluginExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion); + } + + private Dependency getSevntuDependency(final String sevntuVersion) { + return pluginExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion); + } + + private Dependency getCheckstyleDependency(final String checkstyleVersion) { + return pluginExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion); + } + private Properties getProperties(final ArtifactRepository artifactRepository) throws MojoFailureException { // load properties from the plugin pom.xml - val pluginArtifactId = KEMITIX_ARTIFACTID + "-parent"; - val pluginArtifact = new DefaultArtifact(KEMITIX_GROUPID, pluginArtifactId, rulesetVersion, null, "", null, - new DefaultArtifactHandler("pom") - ); + final Artifact pluginArtifact = getPluginArtifact(artifactRepository); try { - val pomReader = new FileReader(artifactRepository.find(pluginArtifact) - .getFile()); - return new MavenXpp3Reader().read(pomReader) - .getProperties(); + final File pomFile = pluginArtifact.getFile(); + return parsePomFile(pomFile).getProperties(); } catch (XmlPullParserException | IOException e) { throw new MojoFailureException("Can't load properties from plugin's pom.xml", e); } } + private Model parsePomFile(final File pomFile) throws IOException, XmlPullParserException { + final Reader pomReader = new FileReader(pomFile); + return mavenXpp3Reader.read(pomReader); + } + + private Artifact getPluginArtifact(final ArtifactRepository artifactRepository) { + final Artifact templateArtifact = getRulesetArtifactTemplate(); + return artifactRepository.find(templateArtifact); + } + + private DefaultArtifact getRulesetArtifactTemplate() { + return new DefaultArtifact(KEMITIX_GROUPID, PLUGIN_ARTIFACT_ID, rulesetVersion, null, "", null, + POM_ARTIFACT_HANDLER + ); + } + private void info(final String format, final Object... args) { getLog().info(String.format(format, args)); } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java index de01dfe..b176c2d 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutor.java @@ -21,12 +21,9 @@ package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.twdata.maven.mojoexecutor.MojoExecutor; @@ -50,10 +47,9 @@ public final class DefaultPluginExecutor implements PluginExecutor { } @Override - public MojoExecutor.ExecutionEnvironment executionEnvironment( - final MavenProject mavenProject, final MavenSession mavenSession, final BuildPluginManager pluginManager - ) { - return MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager); + public MojoExecutor.ExecutionEnvironment executionEnvironment(final CheckConfiguration config) { + return MojoExecutor.executionEnvironment( + config.getMavenProject(), config.getMavenSession(), config.getPluginManager()); } @Override 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 index 98a0fb5..f0a64f2 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/JavadocCheckMojo.java @@ -24,6 +24,7 @@ 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; @@ -41,11 +42,6 @@ public final class JavadocCheckMojo extends AbstractCheckMojo { * Create the Mojo. */ public JavadocCheckMojo() { - super(new DefaultPluginExecutor()); - } - - @Override - String getLevel() { - return LEVEL; + 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 index 2336864..1883ecc 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/LayoutCheckMojo.java @@ -24,6 +24,7 @@ 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; @@ -41,11 +42,6 @@ public final class LayoutCheckMojo extends AbstractCheckMojo { * Create the Mojo. */ public LayoutCheckMojo() { - super(new DefaultPluginExecutor()); - } - - @Override - String getLevel() { - return LEVEL; + 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 index 1042538..27081b9 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/NamingCheckMojo.java @@ -24,6 +24,7 @@ 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; @@ -41,11 +42,6 @@ public final class NamingCheckMojo extends AbstractCheckMojo { * Create the Mojo. */ public NamingCheckMojo() { - super(new DefaultPluginExecutor()); - } - - @Override - String getLevel() { - return LEVEL; + super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); } } diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java index 1747f3f..91caeaf 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/PluginExecutor.java @@ -21,12 +21,9 @@ package net.kemitix.checkstyle.ruleset.plugin; -import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Plugin; -import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.project.MavenProject; import org.codehaus.plexus.util.xml.Xpp3Dom; import org.twdata.maven.mojoexecutor.MojoExecutor; @@ -61,15 +58,11 @@ public interface PluginExecutor { /** * Constructs the {@link MojoExecutor.ExecutionEnvironment} instance fluently. * - * @param mavenProject The current Maven project - * @param mavenSession The current Maven session - * @param pluginManager The Build plugin manager + * @param configuration The Configuration * * @return The execution environment */ - MojoExecutor.ExecutionEnvironment executionEnvironment( - MavenProject mavenProject, MavenSession mavenSession, BuildPluginManager pluginManager - ); + MojoExecutor.ExecutionEnvironment executionEnvironment(CheckConfiguration configuration); /** * Entry point for executing a mojo. 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 index 0bb56fe..6c2c6b8 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/TweaksCheckMojo.java @@ -24,6 +24,7 @@ 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; @@ -41,11 +42,6 @@ public final class TweaksCheckMojo extends AbstractCheckMojo { * Create the Mojo. */ public TweaksCheckMojo() { - super(new DefaultPluginExecutor()); - } - - @Override - String getLevel() { - return LEVEL; + super(new DefaultCheckstyleExecutor(LEVEL, new DefaultPluginExecutor(), new MavenXpp3Reader())); } } From 3549014a03c4549d5e53c80cd245189a3bd5a1f7 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 17:13:34 +0100 Subject: [PATCH 09/16] plugin: pom.xml: enable jacoco support --- plugin/pom.xml | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/plugin/pom.xml b/plugin/pom.xml index 7f2cf6c..885e378 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -30,6 +30,10 @@ 2.3.0 1.16.16 1.0.0 + 0.7.9 + 0.50 + 0.80 + 0 @@ -106,6 +110,58 @@ 1.8 + + org.jacoco + jacoco-maven-plugin + ${jacoco-maven-plugin.version} + + + + prepare-agent + + + + report + prepare-package + + report + + + + default-check + + check + + + + + + + CLASS + + *HelpMojo + + + + LINE + COVEREDRATIO + ${jacoco-class-line-covered-ratio} + + + INSTRUCTION + COVEREDRATIO + ${jacoco-class-instruction-covered-ratio} + + + CLASS + MISSEDCOUNT + ${jacoco-class-missed-count-maximum} + + + + + + From c9258fcdc5a56dc11eeea11b8f3430b8781cde1e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 17:14:13 +0100 Subject: [PATCH 10/16] plugin: AbstractCheckMojoTest: added --- .../ruleset/plugin/AbstractCheckMojoTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java new file mode 100644 index 0000000..adcced5 --- /dev/null +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojoTest.java @@ -0,0 +1,80 @@ +package net.kemitix.checkstyle.ruleset.plugin; + +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.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Matchers.any; + +/** + * Tests for {@link AbstractCheckMojo}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class AbstractCheckMojoTest { + + @Mock + private CheckstyleExecutor checkstyleExecutor; + + @Mock + private MavenProject mavenProject; + + @Mock + private MavenSession mavenSession; + + @Mock + private ArtifactRepository artifactRepository; + + @Mock + private BuildPluginManager pluginManager; + + @Captor + private ArgumentCaptor configuration; + + @Mock + private Plugin rulesetPlugin; + + @Mock + private Build build; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void canExecute() throws MojoFailureException, MojoExecutionException { + //given + final AbstractCheckMojo mojo = new AbstractCheckMojo(checkstyleExecutor) { + }; + mojo.setMavenProject(mavenProject); + mojo.setMavenSession(mavenSession); + mojo.setArtifactRepository(artifactRepository); + mojo.setPluginManager(pluginManager); + given(mavenProject.getPlugin(any())).willReturn(rulesetPlugin); + given(mavenProject.getBuild()).willReturn(build); + //when + mojo.execute(); + //then + then(checkstyleExecutor).should() + .performCheck(configuration.capture()); + assertThat(configuration.getValue()).returns(mavenProject, CheckConfiguration::getMavenProject) + .returns(mavenSession, CheckConfiguration::getMavenSession) + .returns(artifactRepository, CheckConfiguration::getArtifactRepository) + .returns(pluginManager, CheckConfiguration::getPluginManager); + } +} From e3e38f90eb689817dbedd1207861ec53bc04f025 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 17:14:25 +0100 Subject: [PATCH 11/16] plugin: DefaultCheckstyleExecutorTest: added --- .../plugin/DefaultCheckstyleExecutorTest.java | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java 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 new file mode 100644 index 0000000..f784f54 --- /dev/null +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultCheckstyleExecutorTest.java @@ -0,0 +1,162 @@ +package net.kemitix.checkstyle.ruleset.plugin; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.logging.Log; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; + +/** + * Tests for {@link DefaultCheckstyleExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultCheckstyleExecutorTest { + + @Mock + private PluginExecutor pluginExecutor; + + @Mock + private MavenProject mavenProject; + + @Mock + private MavenSession mavenSession; + + @Mock + private ArtifactRepository artifactRepository; + + @Mock + private BuildPluginManager pluginManager; + + @Mock + private Plugin rulesetPlugin; + + @Mock + private Log log; + + private DefaultCheckstyleExecutor checkstyleExecutor; + + private String level; + + @Mock + private Artifact artifact; + + private File artifactFile; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Mock + private MavenXpp3Reader mavenXpp3Reader; + + @Mock + private Model pomModel; + + @Mock + private MojoExecutor.Element configElement; + + @Mock + private MojoExecutor.Element sourceElement; + + @Mock + private Xpp3Dom pluginConfig; + + @Mock + private MojoExecutor.ExecutionEnvironment env; + + @Mock + private Dependency checkstyle; + + @Mock + private Dependency sevntu; + + @Mock + private Dependency ruleset; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + level = "test level"; + checkstyleExecutor = new DefaultCheckstyleExecutor(level, pluginExecutor, mavenXpp3Reader); + checkstyleExecutor.setLog(log); + } + + @Test + public void canPerformCheck() + throws MojoFailureException, MojoExecutionException, IOException, XmlPullParserException { + //given + final CheckConfiguration configuration = CheckConfiguration.builder() + .mavenProject(mavenProject) + .mavenSession(mavenSession) + .artifactRepository(artifactRepository) + .pluginManager(pluginManager) + .rulesetVersion("ruleset version") + .build(); + + artifactFile = folder.newFile("pom.xml"); + given(artifactRepository.find(any())).willReturn(artifact); + given(artifact.getFile()).willReturn(artifactFile); + given(mavenXpp3Reader.read(any(FileReader.class))).willReturn(pomModel); + final Properties properties = new Properties(); + given(pomModel.getProperties()).willReturn(properties); + given(pluginExecutor.element(eq("configLocation"), any())).willReturn(configElement); + given(pluginExecutor.element(eq("sourceDirectory"), any())).willReturn(sourceElement); + given(pluginExecutor.configuration(configElement, sourceElement)).willReturn(pluginConfig); + given(pluginExecutor.executionEnvironment(configuration)).willReturn(env); + final List dependencies = new ArrayList<>(); + dependencies.add(checkstyle); + dependencies.add(sevntu); + dependencies.add(ruleset); + final String pluginVersion = "plugin version"; + final String checkstyleVersion = "checkstyle version"; + final String sevntuVersion = "sevntu version"; + final String rulesetVersion = "ruleset version"; + given(pluginExecutor.dependencies(checkstyle, sevntu, ruleset)).willReturn(dependencies); + given(pluginExecutor.dependency("com.puppycrawl.tools", "checkstyle", checkstyleVersion)).willReturn( + checkstyle); + given(pluginExecutor.dependency( + "com.github.sevntu.checkstyle", "sevntu-checkstyle-maven-plugin", sevntuVersion)).willReturn(sevntu); + given(pluginExecutor.dependency("net.kemitix", "kemtiix-checkstyle-ruleset", rulesetVersion)).willReturn( + ruleset); + properties.setProperty("maven-checkstyle-plugin.version", pluginVersion); + properties.setProperty("checkstyle.version", checkstyleVersion); + properties.setProperty("sevntu.version", sevntuVersion); + given(pluginExecutor.plugin( + eq("org.apache.maven.plugins"), eq("maven-checkstyle-plugin"), eq(pluginVersion), any())).willReturn( + rulesetPlugin); + //when + checkstyleExecutor.performCheck(configuration); + //then + + then(pluginExecutor).should() + .executeMojo(rulesetPlugin, "check", pluginConfig, env); + } +} From 981893d1a1d758a8e66359950d81c7306cd057fb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 18:19:36 +0100 Subject: [PATCH 12/16] plugin: DefaultPluginExecutorTest: added --- .../plugin/DefaultPluginExecutorTest.java | 177 ++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100644 plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutorTest.java diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutorTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutorTest.java new file mode 100644 index 0000000..9ce752c --- /dev/null +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/DefaultPluginExecutorTest.java @@ -0,0 +1,177 @@ +package net.kemitix.checkstyle.ruleset.plugin; + +import org.apache.maven.execution.MavenSession; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Plugin; +import org.apache.maven.plugin.BuildPluginManager; +import org.apache.maven.plugin.InvalidPluginDescriptorException; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugin.PluginConfigurationException; +import org.apache.maven.plugin.PluginDescriptorParsingException; +import org.apache.maven.plugin.PluginManagerException; +import org.apache.maven.plugin.PluginNotFoundException; +import org.apache.maven.plugin.PluginResolutionException; +import org.apache.maven.plugin.descriptor.MojoDescriptor; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.configuration.PlexusConfiguration; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.twdata.maven.mojoexecutor.MojoExecutor; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.then; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; + +/** + * Tests for {@link DefaultPluginExecutor}. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +public class DefaultPluginExecutorTest { + + private PluginExecutor pluginExecutor; + + @Mock + private MavenProject mavenProject; + + @Mock + private MavenSession mavenSession; + + @Mock + private BuildPluginManager pluginManager; + + @Mock + private Plugin plugin; + + @Mock + private Xpp3Dom configuration; + + @Mock + private PluginDescriptor pluginDescriptor; + + @Mock + private MojoDescriptor mojoDescriptor; + + @Mock + private PlexusConfiguration mojoConfiguration; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + pluginExecutor = new DefaultPluginExecutor(); + } + + @Test + public void canElement() { + //when + final MojoExecutor.Element element = pluginExecutor.element("name", "value"); + //then + assertThat(element.toDom()).returns("name", Xpp3Dom::getName) + .returns("value", Xpp3Dom::getValue); + } + + @Test + public void canConfiguration() { + //given + final MojoExecutor.Element alpha = pluginExecutor.element("alpha", "first"); + final MojoExecutor.Element beta = pluginExecutor.element("beta", "second"); + //when + final Xpp3Dom configuration = pluginExecutor.configuration(alpha, beta); + //then + assertThat(configuration.getChild("alpha")).returns("alpha", Xpp3Dom::getName) + .returns("first", Xpp3Dom::getValue); + assertThat(configuration.getChild("beta")).returns("beta", Xpp3Dom::getName) + .returns("second", Xpp3Dom::getValue); + } + + @Test + public void canExecutionEnvironment() { + //given + final CheckConfiguration configuration = createCheckConfiguration(); + //when + final MojoExecutor.ExecutionEnvironment environment = pluginExecutor.executionEnvironment(configuration); + //then + assertThat(environment).returns(mavenProject, MojoExecutor.ExecutionEnvironment::getMavenProject) + .returns(mavenSession, MojoExecutor.ExecutionEnvironment::getMavenSession) + .returns(pluginManager, MojoExecutor.ExecutionEnvironment::getPluginManager); + } + + private CheckConfiguration createCheckConfiguration() { + return CheckConfiguration.builder() + .mavenProject(mavenProject) + .mavenSession(mavenSession) + .pluginManager(pluginManager) + .build(); + } + + @Test + public void canExecuteMojo() + throws MojoExecutionException, InvalidPluginDescriptorException, PluginResolutionException, + PluginDescriptorParsingException, PluginNotFoundException, PluginManagerException, + PluginConfigurationException, MojoFailureException { + //given + final String goal = "check"; + final MojoExecutor.ExecutionEnvironment environment = + pluginExecutor.executionEnvironment(createCheckConfiguration()); + given(mavenSession.getCurrentProject()).willReturn(mavenProject); + given(pluginManager.loadPlugin(eq(plugin), any(), any())).willReturn(pluginDescriptor); + given(pluginDescriptor.getMojo(goal)).willReturn(mojoDescriptor); + given(mojoDescriptor.getMojoConfiguration()).willReturn(mojoConfiguration); + given(mojoConfiguration.getAttributeNames()).willReturn(new String[]{}); + given(mojoConfiguration.getChildren()).willReturn(new PlexusConfiguration[]{}); + //when + pluginExecutor.executeMojo(plugin, goal, configuration, environment); + //then + then(pluginManager).should() + .executeMojo(eq(mavenSession), any()); + } + + @Test + public void canDependency() { + //given + final String groupId = "groupId"; + final String artifactId = "artifactId"; + final String version = "version"; + //when + final Dependency dependency = pluginExecutor.dependency(groupId, artifactId, version); + //then + assertThat(dependency).returns(groupId, Dependency::getGroupId) + .returns(artifactId, Dependency::getArtifactId) + .returns(version, Dependency::getVersion); + } + + @Test + public void canDependencies() { + //given + final Dependency dependency = pluginExecutor.dependency("groupId", "artifactId", "version"); + //when + final List dependencies = pluginExecutor.dependencies(dependency); + //then + assertThat(dependencies).containsExactly(dependency); + } + + @Test + public void canPlugin() { + //given + final String groupId = "groupId"; + final String artifactId = "artifactId"; + final String version = "version"; + final List dependencies = pluginExecutor.dependencies(pluginExecutor.dependency("pg", "pa", "pv")); + //when + final Plugin plugin = pluginExecutor.plugin(groupId, artifactId, version, dependencies); + //then + assertThat(plugin).returns(groupId, Plugin::getGroupId) + .returns(artifactId, Plugin::getArtifactId) + .returns(version, Plugin::getVersion) + .returns(dependencies, Plugin::getDependencies); + } +} From a67a64e851c0618e1b6e016b072524288dbe5a07 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 22:26:43 +0100 Subject: [PATCH 13/16] plugin: CheckConfiguration: simple builder toString coverage test --- .../plugin/CheckConfigurationTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfigurationTest.java diff --git a/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfigurationTest.java b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfigurationTest.java new file mode 100644 index 0000000..3fb2448 --- /dev/null +++ b/plugin/src/test/java/net/kemitix/checkstyle/ruleset/plugin/CheckConfigurationTest.java @@ -0,0 +1,27 @@ +package net.kemitix.checkstyle.ruleset.plugin; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Paul Campbell (pcampbell@kemitix.net). + */ +public class CheckConfigurationTest { + + @Test + public void toStringCoverage() { + //given + final String rulesetVersion = "ruleset version"; + final String sourceDirectory = "source directory"; + //when + final String result = CheckConfiguration.builder() + .rulesetVersion(rulesetVersion) + .sourceDirectory(sourceDirectory) + .toString(); + //then + System.out.println("result = " + result); + assertThat(result).contains("rulesetVersion=ruleset version") + .contains("sourceDirectory=source directory"); + } +} From 84269c1dd64026bf5e279795007c7df5078e2098 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 22:31:23 +0100 Subject: [PATCH 14/16] plugin: AbstractCheckMojo: minor tidy-up --- .../ruleset/plugin/AbstractCheckMojo.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java index 46bc726..946b893 100644 --- a/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java +++ b/plugin/src/main/java/net/kemitix/checkstyle/ruleset/plugin/AbstractCheckMojo.java @@ -48,6 +48,8 @@ abstract class AbstractCheckMojo extends AbstractMojo { private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset"; + private final CheckstyleExecutor checkstyleExecutor; + @Setter @Parameter(defaultValue = "${project}", readonly = true) private MavenProject mavenProject; @@ -58,14 +60,17 @@ abstract class AbstractCheckMojo extends AbstractMojo { @Setter @Parameter(defaultValue = "${localRepository}", readonly = true, required = true) - private ArtifactRepository artifactRepository = null; + private ArtifactRepository artifactRepository; @Setter @Component - private BuildPluginManager pluginManager = null; - - private final CheckstyleExecutor checkstyleExecutor; + 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()); From d1d174d5a7097184ececfaf371e8b0356c51f27b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 27 May 2017 08:53:56 +0100 Subject: [PATCH 15/16] 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 From 1b27a84bd6fb31db57a99c59327f57305a8be959 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 27 May 2017 08:58:11 +0100 Subject: [PATCH 16/16] version: set to 3.0.0-SNAPSHOT --- builder/pom.xml | 2 +- plugin-sample/pom.xml | 4 ++-- plugin/pom.xml | 2 +- pom.xml | 2 +- regressions/pom.xml | 2 +- ruleset/pom.xml | 4 ++-- sample-parent/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/builder/pom.xml b/builder/pom.xml index eaa04c1..7c54c6a 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -12,7 +12,7 @@ kemitix-checkstyle-ruleset-builder - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT jar Kemitix Checkstyle Ruleset Builder diff --git a/plugin-sample/pom.xml b/plugin-sample/pom.xml index ff704ae..3bbb3ca 100644 --- a/plugin-sample/pom.xml +++ b/plugin-sample/pom.xml @@ -8,12 +8,12 @@ net.kemitix kemitix-checkstyle-ruleset-sample-parent - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT ../sample-parent kemitix-checkstyle-ruleset-plugin-sample - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT Kemitix Checkstyle Ruleset Plugin Sample Sample usage of the Kemitix Checkstyle Ruleset Plugin diff --git a/plugin/pom.xml b/plugin/pom.xml index 885e378..ec79301 100644 --- a/plugin/pom.xml +++ b/plugin/pom.xml @@ -7,7 +7,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT kemitix-checkstyle-ruleset-maven-plugin diff --git a/pom.xml b/pom.xml index 082404e..2efb852 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT pom Kemitix Checkstyle Ruleset (Parent) diff --git a/regressions/pom.xml b/regressions/pom.xml index abb2165..6b40b05 100644 --- a/regressions/pom.xml +++ b/regressions/pom.xml @@ -5,7 +5,7 @@ kemitix-checkstyle-ruleset-sample-parent net.kemitix - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT ../sample-parent 4.0.0 diff --git a/ruleset/pom.xml b/ruleset/pom.xml index 2490ece..3a9e63c 100644 --- a/ruleset/pom.xml +++ b/ruleset/pom.xml @@ -7,11 +7,11 @@ net.kemitix kemitix-checkstyle-ruleset-parent - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT kemitix-checkstyle-ruleset - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT jar Kemitix Checkstyle Ruleset diff --git a/sample-parent/pom.xml b/sample-parent/pom.xml index a50101c..3bc2b2d 100644 --- a/sample-parent/pom.xml +++ b/sample-parent/pom.xml @@ -8,7 +8,7 @@ kemitix-checkstyle-ruleset-sample-parent pom - 2.4.0-SNAPSHOT + 3.0.0-SNAPSHOT Kemitix Checkstyle Ruleset Sample Parent Sample parent for modules that use kemitix-checkstyle-ruleset-maven-plugin