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
This commit is contained in:
parent
84269c1dd6
commit
d1d174d5a7
13 changed files with 66 additions and 271 deletions
14
README.md
14
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`.
|
To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`.
|
||||||
The `maven-checkstyle-plugin` will be included automatically.
|
The `maven-checkstyle-plugin` will be included automatically.
|
||||||
|
|
||||||
The following goals implement increasingly strict rulesets:
|
The following levels implement increasingly strict rulesets:
|
||||||
|
|
||||||
* 1-layout
|
* 1-layout
|
||||||
* 2-naming
|
* 2-naming
|
||||||
|
@ -33,6 +33,13 @@ The following goals implement increasingly strict rulesets:
|
||||||
* 4-tweaks
|
* 4-tweaks
|
||||||
* 5-complexity
|
* 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
|
||||||
|
|
||||||
````
|
````
|
||||||
<properties>
|
<properties>
|
||||||
<kemitix-checkstyle-ruleset.version>2.1.0</kemitix-checkstyle-ruleset.version>
|
<kemitix-checkstyle-ruleset.version>2.1.0</kemitix-checkstyle-ruleset.version>
|
||||||
|
@ -45,11 +52,14 @@ The following goals implement increasingly strict rulesets:
|
||||||
<groupId>net.kemitix</groupId>
|
<groupId>net.kemitix</groupId>
|
||||||
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
||||||
<version>${kemitix-checkstyle-ruleset.version}</version>
|
<version>${kemitix-checkstyle-ruleset.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<level>${kemitix-checkstyle-ruleset.level}</level>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>${kemitix-checkstyle-ruleset.level}</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
|
@ -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`.
|
To use this ruleset add the plugin `kemitix-checktyle-ruleset-maven-plugin`.
|
||||||
The `maven-checkstyle-plugin` will be included automatically.
|
The `maven-checkstyle-plugin` will be included automatically.
|
||||||
|
|
||||||
The following goals implement increasingly strict rulesets:
|
The following levels implement increasingly strict rulesets:
|
||||||
|
|
||||||
* 1-layout
|
* 1-layout
|
||||||
* 2-naming
|
* 2-naming
|
||||||
|
@ -33,6 +33,13 @@ The following goals implement increasingly strict rulesets:
|
||||||
* 4-tweaks
|
* 4-tweaks
|
||||||
* 5-complexity
|
* 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
|
||||||
|
|
||||||
````
|
````
|
||||||
<properties>
|
<properties>
|
||||||
<kemitix-checkstyle-ruleset.version>2.1.0</kemitix-checkstyle-ruleset.version>
|
<kemitix-checkstyle-ruleset.version>2.1.0</kemitix-checkstyle-ruleset.version>
|
||||||
|
@ -45,11 +52,14 @@ The following goals implement increasingly strict rulesets:
|
||||||
<groupId>net.kemitix</groupId>
|
<groupId>net.kemitix</groupId>
|
||||||
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
||||||
<version>${kemitix-checkstyle-ruleset.version}</version>
|
<version>${kemitix-checkstyle-ruleset.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<level>${kemitix-checkstyle-ruleset.level}</level>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>${kemitix-checkstyle-ruleset.level}</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
|
@ -48,4 +48,6 @@ class CheckConfiguration {
|
||||||
private String rulesetVersion;
|
private String rulesetVersion;
|
||||||
|
|
||||||
private String sourceDirectory;
|
private String sourceDirectory;
|
||||||
|
|
||||||
|
private String level;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,14 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||||
import org.apache.maven.execution.MavenSession;
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.model.Build;
|
import org.apache.maven.model.Build;
|
||||||
import org.apache.maven.model.Plugin;
|
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.AbstractMojo;
|
||||||
import org.apache.maven.plugin.BuildPluginManager;
|
import org.apache.maven.plugin.BuildPluginManager;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
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.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
|
|
||||||
|
@ -42,13 +45,16 @@ import org.apache.maven.project.MavenProject;
|
||||||
*
|
*
|
||||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
* @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_GROUPID = "net.kemitix";
|
||||||
|
|
||||||
private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset";
|
private static final String KEMITIX_ARTIFACTID = "kemitix-checkstyle-ruleset";
|
||||||
|
|
||||||
private final CheckstyleExecutor checkstyleExecutor;
|
@Setter
|
||||||
|
private CheckstyleExecutor checkstyleExecutor =
|
||||||
|
new DefaultCheckstyleExecutor(new DefaultPluginExecutor(), new MavenXpp3Reader());
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Parameter(defaultValue = "${project}", readonly = true)
|
@Parameter(defaultValue = "${project}", readonly = true)
|
||||||
|
@ -62,22 +68,16 @@ abstract class AbstractCheckMojo extends AbstractMojo {
|
||||||
@Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
|
@Parameter(defaultValue = "${localRepository}", readonly = true, required = true)
|
||||||
private ArtifactRepository artifactRepository;
|
private ArtifactRepository artifactRepository;
|
||||||
|
|
||||||
|
@Parameter(defaultValue = "5-complexity", readonly = true)
|
||||||
|
private String level = "5-complexity";
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@Component
|
@Component
|
||||||
private BuildPluginManager pluginManager;
|
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
|
@Override
|
||||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
public final void execute() throws MojoExecutionException, MojoFailureException {
|
||||||
|
checkstyleExecutor.setLog(getLog());
|
||||||
CheckConfiguration config = getCheckConfiguration();
|
CheckConfiguration config = getCheckConfiguration();
|
||||||
checkstyleExecutor.performCheck(config);
|
checkstyleExecutor.performCheck(config);
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ abstract class AbstractCheckMojo extends AbstractMojo {
|
||||||
.pluginManager(pluginManager)
|
.pluginManager(pluginManager)
|
||||||
.rulesetVersion(rulesetPlugin.getVersion())
|
.rulesetVersion(rulesetPlugin.getVersion())
|
||||||
.sourceDirectory(build.getSourceDirectory())
|
.sourceDirectory(build.getSourceDirectory())
|
||||||
|
.level(level)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -37,12 +37,15 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
import org.apache.maven.plugin.MojoFailureException;
|
import org.apache.maven.plugin.MojoFailureException;
|
||||||
import org.apache.maven.plugin.logging.Log;
|
import org.apache.maven.plugin.logging.Log;
|
||||||
|
import org.codehaus.plexus.util.xml.Xpp3Dom;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
import org.twdata.maven.mojoexecutor.MojoExecutor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,7 +54,7 @@ import java.util.Properties;
|
||||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||||
*/
|
*/
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
class DefaultCheckstyleExecutor implements CheckstyleExecutor {
|
public class DefaultCheckstyleExecutor implements CheckstyleExecutor {
|
||||||
|
|
||||||
private static final String CHECKSTYLE_GROUPID = "com.puppycrawl.tools";
|
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 static final String PLUGIN_ARTIFACT_ID = KEMITIX_ARTIFACTID + "-parent";
|
||||||
|
|
||||||
private final String level;
|
|
||||||
|
|
||||||
private final PluginExecutor pluginExecutor;
|
private final PluginExecutor pluginExecutor;
|
||||||
|
|
||||||
private final MavenXpp3Reader mavenXpp3Reader;
|
private final MavenXpp3Reader mavenXpp3Reader;
|
||||||
|
@ -98,11 +99,13 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor {
|
||||||
// configure
|
// configure
|
||||||
val checkstylePlugin = getPlugin(properties);
|
val checkstylePlugin = getPlugin(properties);
|
||||||
final String sourceDirectory = config.getSourceDirectory();
|
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);
|
final String configFile = String.format("net/kemitix/checkstyle-%s.xml", level);
|
||||||
val configuration = pluginExecutor.configuration(pluginExecutor.element(CONFIG_LOCATION, configFile),
|
final Xpp3Dom configuration = pluginExecutor.configuration(pluginExecutor.element(CONFIG_LOCATION, configFile),
|
||||||
pluginExecutor.element(SOURCE_DIR, sourceDirectory)
|
pluginExecutor.element(SOURCE_DIR, sourceDirectory)
|
||||||
);
|
);
|
||||||
val environment = pluginExecutor.executionEnvironment(config);
|
final MojoExecutor.ExecutionEnvironment environment = pluginExecutor.executionEnvironment(config);
|
||||||
|
|
||||||
// run
|
// run
|
||||||
pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment);
|
pluginExecutor.executeMojo(checkstylePlugin, "check", configuration, environment);
|
||||||
|
@ -120,15 +123,15 @@ class DefaultCheckstyleExecutor implements CheckstyleExecutor {
|
||||||
val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version");
|
val pluginVersion = getProperty(properties, "maven-checkstyle-plugin.version");
|
||||||
val checkstyleVersion = getProperty(properties, "checkstyle.version");
|
val checkstyleVersion = getProperty(properties, "checkstyle.version");
|
||||||
val sevntuVersion = getProperty(properties, "sevntu.version");
|
val sevntuVersion = getProperty(properties, "sevntu.version");
|
||||||
info("Checkstyle %s (plugin: %s, sevntu: %s) with ruleset %s (%s)", checkstyleVersion, pluginVersion,
|
info("Checkstyle %s (plugin: %s, sevntu: %s, ruleset: %s)", checkstyleVersion,
|
||||||
sevntuVersion, level, rulesetVersion
|
pluginVersion, sevntuVersion, rulesetVersion
|
||||||
);
|
);
|
||||||
|
|
||||||
// create checkstyle dependencies
|
// create checkstyle dependencies
|
||||||
val checkstyle = getCheckstyleDependency(checkstyleVersion);
|
val checkstyle = getCheckstyleDependency(checkstyleVersion);
|
||||||
val sevntu = getSevntuDependency(sevntuVersion);
|
val sevntu = getSevntuDependency(sevntuVersion);
|
||||||
val ruleset = getRulesetDependency();
|
val ruleset = getRulesetDependency();
|
||||||
val dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset);
|
final List<Dependency> dependencies = pluginExecutor.dependencies(checkstyle, sevntu, ruleset);
|
||||||
|
|
||||||
return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies);
|
return pluginExecutor.plugin(APACHE_PLUGIN_GROUPID, APACHE_PLUGIN_ARTIFACTID, pluginVersion, dependencies);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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()));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -21,11 +21,11 @@ import static org.mockito.BDDMockito.then;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link AbstractCheckMojo}.
|
* Tests for {@link CheckMojo}.
|
||||||
*
|
*
|
||||||
* @author Paul Campbell (pcampbell@kemitix.net)
|
* @author Paul Campbell (pcampbell@kemitix.net)
|
||||||
*/
|
*/
|
||||||
public class AbstractCheckMojoTest {
|
public class CheckMojoTest {
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private CheckstyleExecutor checkstyleExecutor;
|
private CheckstyleExecutor checkstyleExecutor;
|
||||||
|
@ -59,8 +59,8 @@ public class AbstractCheckMojoTest {
|
||||||
@Test
|
@Test
|
||||||
public void canExecute() throws MojoFailureException, MojoExecutionException {
|
public void canExecute() throws MojoFailureException, MojoExecutionException {
|
||||||
//given
|
//given
|
||||||
final AbstractCheckMojo mojo = new AbstractCheckMojo(checkstyleExecutor) {
|
final CheckMojo mojo = new CheckMojo();
|
||||||
};
|
mojo.setCheckstyleExecutor(checkstyleExecutor);
|
||||||
mojo.setMavenProject(mavenProject);
|
mojo.setMavenProject(mavenProject);
|
||||||
mojo.setMavenSession(mavenSession);
|
mojo.setMavenSession(mavenSession);
|
||||||
mojo.setArtifactRepository(artifactRepository);
|
mojo.setArtifactRepository(artifactRepository);
|
|
@ -41,6 +41,9 @@ import static org.mockito.Matchers.eq;
|
||||||
*/
|
*/
|
||||||
public class DefaultCheckstyleExecutorTest {
|
public class DefaultCheckstyleExecutorTest {
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private PluginExecutor pluginExecutor;
|
private PluginExecutor pluginExecutor;
|
||||||
|
|
||||||
|
@ -71,9 +74,6 @@ public class DefaultCheckstyleExecutorTest {
|
||||||
|
|
||||||
private File artifactFile;
|
private File artifactFile;
|
||||||
|
|
||||||
@Rule
|
|
||||||
public TemporaryFolder folder = new TemporaryFolder();
|
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private MavenXpp3Reader mavenXpp3Reader;
|
private MavenXpp3Reader mavenXpp3Reader;
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ public class DefaultCheckstyleExecutorTest {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
level = "test level";
|
level = "test level";
|
||||||
checkstyleExecutor = new DefaultCheckstyleExecutor(level, pluginExecutor, mavenXpp3Reader);
|
checkstyleExecutor = new DefaultCheckstyleExecutor(pluginExecutor, mavenXpp3Reader);
|
||||||
checkstyleExecutor.setLog(log);
|
checkstyleExecutor.setLog(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +119,7 @@ public class DefaultCheckstyleExecutorTest {
|
||||||
.artifactRepository(artifactRepository)
|
.artifactRepository(artifactRepository)
|
||||||
.pluginManager(pluginManager)
|
.pluginManager(pluginManager)
|
||||||
.rulesetVersion("ruleset version")
|
.rulesetVersion("ruleset version")
|
||||||
|
.level(level)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
artifactFile = folder.newFile("pom.xml");
|
artifactFile = folder.newFile("pom.xml");
|
||||||
|
|
|
@ -51,11 +51,14 @@
|
||||||
<groupId>net.kemitix</groupId>
|
<groupId>net.kemitix</groupId>
|
||||||
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
<artifactId>kemitix-checkstyle-ruleset-maven-plugin</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<level>${kemitix-checkstyle-ruleset-level}</level>
|
||||||
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>validate</phase>
|
<phase>validate</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>${kemitix-checkstyle-ruleset-level}</goal>
|
<goal>check</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
|
Loading…
Reference in a new issue