plugin: AbstractCheckMojo: replace abstract execute() with getLevel()

Child classes don't need to implement the execute() method now, but a
getLevel() method instead.
This commit is contained in:
Paul Campbell 2017-05-26 12:03:03 +01:00
parent 6f9f07709f
commit e46f8d5d1f
6 changed files with 35 additions and 27 deletions

View file

@ -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

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}