From e46f8d5d1fa29cfcfda49ffc97f89f6c43290f77 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 26 May 2017 12:03:03 +0100 Subject: [PATCH] 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; } }