plugin: provide goals for each ruleset level

This commit is contained in:
Paul Campbell 2017-01-14 17:04:18 +00:00
parent 3bed524b27
commit 67557955cc
9 changed files with 248 additions and 75 deletions

View file

@ -25,17 +25,18 @@ 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.
Select the level 1-5 of strictness required:
The following goals implement increasingly strict rulesets:
1. layout
2. naming
3. javadoc
4. tweaks
5. complexity
* 1-layout
* 2-naming
* 3-javadoc
* 4-tweaks
* 5-complexity
````
<properties>
<kemitix-checkstyle-ruleset.level>2</kemitix-checkstyle-ruleset.level>
<kemitix-checkstyle-ruleset.version>2.0.0</kemitix-checkstyle-ruleset.version>
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
</properties>
<build>
@ -43,17 +44,12 @@ Select the level 1-5 of strictness required:
<plugin>
<groupId>net.kemitix</groupId>
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<level>${kemitix-checkstyle-ruleset.level}</level>
</configuration>
<version>${kemitix-checkstyle-ruleset.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>
check
</goal>
<goal>${kemitix-checkstyle-ruleset.level}</goal>
</goals>
</execution>
</executions>

View file

@ -25,17 +25,18 @@ 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.
Select the level 1-5 of strictness required:
The following goals implement increasingly strict rulesets:
1. layout
2. naming
3. javadoc
4. tweaks
5. complexity
* 1-layout
* 2-naming
* 3-javadoc
* 4-tweaks
* 5-complexity
````
<properties>
<kemitix-checkstyle-ruleset.level>2</kemitix-checkstyle-ruleset.level>
<kemitix-checkstyle-ruleset.version>2.0.0</kemitix-checkstyle-ruleset.version>
<kemitix-checkstyle-ruleset.level>5-complexity</kemitix-checkstyle-ruleset.level>
</properties>
<build>
@ -43,17 +44,12 @@ Select the level 1-5 of strictness required:
<plugin>
<groupId>net.kemitix</groupId>
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
<version>2.0.0</version>
<configuration>
<level>${kemitix-checkstyle-ruleset.level}</level>
</configuration>
<version>${kemitix-checkstyle-ruleset.version}</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>
check
</goal>
<goal>${kemitix-checkstyle-ruleset.level}</goal>
</goals>
</execution>
</executions>

View file

@ -22,16 +22,11 @@
<groupId>net.kemitix</groupId>
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
<version>2.0.0-SNAPSHOT</version>
<configuration>
<level>2</level>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>
check
</goal>
<goal>2-naming</goal>
</goals>
</execution>
</executions>

View file

@ -26,28 +26,22 @@ package net.kemitix.checkstyle.ruleset.plugin;
import lombok.Setter;
import lombok.val;
import me.andrz.builder.map.MapBuilder;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.BuildPluginManager;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.twdata.maven.mojoexecutor.MojoExecutor;
import java.util.Map;
/**
* Runs the Checkstyle Maven Plugin with the Kemitix Checkstyle Ruleset.
*
* @author Paul Campbell (pcampbell@kemitix.net)
*/
@Mojo(name = "check", defaultPhase = LifecyclePhase.VALIDATE)
public class CheckMojo extends AbstractMojo {
public abstract class AbstractCheckMojo extends AbstractMojo {
private static final String CHECKSTYLE_GROUPID = "com.puppycrawl.tools";
@ -67,28 +61,6 @@ public class CheckMojo extends AbstractMojo {
private static final String CONFIG_LOCATION = "configLocation";
private static final String LAYOUT = "1-layout";
private static final String NAMING = "2-naming";
private static final String JAVADOC = "3-javadoc";
private static final String TWEAKS = "4-tweaks";
private static final String COMPLEXITY = "5-complexity";
private static Map<String, String> levelConfig = new MapBuilder<String, String>().put("1", LAYOUT)
.put("2", NAMING)
.put("3", JAVADOC)
.put("4", TWEAKS)
.put("5", COMPLEXITY)
.build();
//@Setter
//@Parameter(defaultValue = "check")
//private String goal;
@Setter
@Parameter(defaultValue = "2.17")
private String mavenCheckstylePluginVersion;
@ -105,10 +77,6 @@ public class CheckMojo extends AbstractMojo {
@Parameter(defaultValue = "2.0.0-SNAPSHOT")
private String rulesetVersion;
@Setter
@Parameter(defaultValue = "5")
private String level;
@Setter
@Parameter(defaultValue = "${project}", readonly = true)
private MavenProject mavenProject;
@ -120,17 +88,15 @@ public class CheckMojo extends AbstractMojo {
@Component
private BuildPluginManager pluginManager;
private static String getConfigFile(final String level) {
return String.format("checkstyle-%s.xml", levelConfig.getOrDefault(level, COMPLEXITY));
}
/**
* Execute Checkstyle Check.
*
* @param level The level of config file to use.
*
* @throws MojoExecutionException on execution error
* @throws MojoFailureException on execution failure
*/
public final void execute() throws MojoExecutionException, MojoFailureException {
protected final void performCheck(final String level) throws MojoExecutionException, MojoFailureException {
val checkstyle = MojoExecutor.dependency(CHECKSTYLE_GROUPID, CHECKSTYLE_ARTIFACTID, checkstyleVersion);
val sevntu = MojoExecutor.dependency(SEVNTU_GROUPID, SEVNTU_ARTIFACTID, sevntuVersion);
val ruleset = MojoExecutor.dependency(KEMITIX_GROUPID, KEMITIX_ARTIFACTID, rulesetVersion);
@ -138,11 +104,11 @@ public class CheckMojo extends AbstractMojo {
MojoExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, mavenCheckstylePluginVersion,
MojoExecutor.dependencies(checkstyle, sevntu, ruleset)
);
val configLocation = MojoExecutor.element(CONFIG_LOCATION, "net/kemitix/" + getConfigFile(level));
val configLocation =
MojoExecutor.element(CONFIG_LOCATION, String.format("net/kemitix/checkstyle-%s.xml", level));
getLog().info(
"Running Checkstyle " + checkstyleVersion + " (sevntu: " + sevntuVersion + ") with " + getConfigFile(
level));
String.format("Running Checkstyle %s (sevntu: %s) with %s", checkstyleVersion, sevntuVersion, level));
MojoExecutor.executeMojo(checkstylePlugin, "check", MojoExecutor.configuration(configLocation),
MojoExecutor.executionEnvironment(mavenProject, mavenSession, pluginManager)
);

View file

@ -0,0 +1,44 @@
/*
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.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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 class ComplexityCheckMojo extends AbstractCheckMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
performCheck("5-complexity");
}
}

View file

@ -0,0 +1,44 @@
/*
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.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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 class JavadocCheckMojo extends AbstractCheckMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
performCheck("3-javadoc");
}
}

View file

@ -0,0 +1,44 @@
/*
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.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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 class LayoutCheckMojo extends AbstractCheckMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
performCheck("1-layout");
}
}

View file

@ -0,0 +1,44 @@
/*
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.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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 class NamingCheckMojo extends AbstractCheckMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
performCheck("2-naming");
}
}

View file

@ -0,0 +1,44 @@
/*
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.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
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 class TweaksCheckMojo extends AbstractCheckMojo {
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
performCheck("4-tweaks");
}
}