plugin/checkstyle/src/main/java/se/jguru/nazgul/tools/plugin/checkstyle/CheckstyleViolationCheckMojo.java
public void execute()
            throws MojoExecutionException, MojoFailureException {
        if (skip) {
            return;
        }

        if (!skipExec) {
            if (checkstyleRules != null) {
                if (!"sun_checks.xml".equals(configLocation)) {
                    throw new MojoExecutionException("If you use inline configuration for rules, don't specify "
                            + "a configLocation");
                }
                if (checkstyleRules.getChildCount() > 1) {
                    throw new MojoExecutionException("Currently only one root module is supported");
                }

                PlexusConfiguration checkerModule = checkstyleRules.getChild(0);

                try {
                    FileUtils.forceMkdir(rulesFiles.getParentFile());
                    FileUtils.fileWrite(rulesFiles, CHECKSTYLE_FILE_HEADER + checkerModule.toString());
                } catch (final IOException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
                configLocation = rulesFiles.getAbsolutePath();
            }

            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

            try {
                CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
                request.setConsoleListener(getConsoleListener()).setConsoleOutput(consoleOutput)
                        .setExcludes(excludes).setFailsOnError(failsOnError).setIncludes(includes)
                        .setResourceIncludes(resourceIncludes)
                        .setResourceExcludes(resourceExcludes)
                        .setIncludeResources(includeResources)
                        .setIncludeTestResources(includeTestResources)
                        .setIncludeTestSourceDirectory(includeTestSourceDirectory).setListener(getListener())
                        .setProject(project).setSourceDirectories(getSourceDirectories())
                        .setResources(resources).setTestResources(testResources)
                        .setStringOutputStream(stringOutputStream).setSuppressionsLocation(suppressionsLocation)
                        .setTestSourceDirectories(getTestSourceDirectories()).setConfigLocation(configLocation)
                        .setConfigurationArtifacts(collectArtifacts("config"))
                        .setPropertyExpansion(propertyExpansion)
                        .setHeaderLocation(headerLocation).setLicenseArtifacts(collectArtifacts("license"))
                        .setCacheFile(cacheFile).setSuppressionsFileExpression(suppressionsFileExpression)
                        .setEncoding(encoding).setPropertiesLocation(propertiesLocation);
                checkstyleExecutor.executeCheckstyle(request);

            } catch (CheckstyleException e) {
                throw new MojoExecutionException("Failed during checkstyle configuration", e);
            } catch (CheckstyleExecutorException e) {
                throw new MojoExecutionException("Failed during checkstyle execution", e);
            } finally {
                //be sure to restore original context classloader
                Thread.currentThread().setContextClassLoader(currentClassLoader);
            }
        }

        if (!"xml".equals(outputFileFormat)) {
            throw new MojoExecutionException("Output format is '" + outputFileFormat
                    + "', checkstyle:check requires format to be 'xml'.");
        }

        if (!outputFile.exists()) {
            getLog().info("Unable to perform checkstyle:check, unable to find checkstyle:checkstyle outputFile.");
            return;
        }

        Reader reader = null;
        try {
            reader = new BufferedReader(ReaderFactory.newXmlReader(outputFile));

            XmlPullParser xpp = new MXParser();
            xpp.setInput(reader);

            int violations = countViolations(xpp);

            if (violations > maxAllowedViolations) {
                if (failOnViolation) {
                    String msg =
                            "You have " + violations + " Checkstyle violation" + ((violations > 1) ? "s" : "") + ".";
                    if (maxAllowedViolations > 0) {
                        msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
                    }
                    throw new MojoFailureException(msg);
                }

                getLog().warn("checkstyle:check violations detected but failOnViolation set to false");
            }

            reader.close();
            reader = null;
        } catch (IOException | XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read Checkstyle results xml: " + outputFile.getAbsolutePath(),
                    e);
        } finally {
            IOUtil.close(reader);
        }
    }
public void execute()
            throws MojoExecutionException, MojoFailureException {
        if (skip) {
            return;
        }

        if (!skipExec) {
            if (checkstyleRules != null) {
                if (!"sun_checks.xml".equals(configLocation)) {
                    throw new MojoExecutionException("If you use inline configuration for rules, don't specify "
                            + "a configLocation");
                }
                if (checkstyleRules.getChildCount() > 1) {
                    throw new MojoExecutionException("Currently only one root module is supported");
                }

                PlexusConfiguration checkerModule = checkstyleRules.getChild(0);

                try {
                    FileUtils.forceMkdir(rulesFiles.getParentFile());
                    FileUtils.fileWrite(rulesFiles, CHECKSTYLE_FILE_HEADER + checkerModule.toString());
                } catch (final IOException e) {
                    throw new MojoExecutionException(e.getMessage(), e);
                }
                configLocation = rulesFiles.getAbsolutePath();
            }

            ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();

            try {
                CheckstyleExecutorRequest request = new CheckstyleExecutorRequest();
                request.setConsoleListener(getConsoleListener()).setConsoleOutput(consoleOutput)
                        .setExcludes(excludes).setFailsOnError(failsOnError).setIncludes(includes)
                        .setResourceIncludes(resourceIncludes)
                        .setResourceExcludes(resourceExcludes)
                        .setIncludeResources(includeResources)
                        .setIncludeTestResources(includeTestResources)
                        .setIncludeTestSourceDirectory(includeTestSourceDirectory).setListener(getListener())
                        .setProject(project).setSourceDirectories(getSourceDirectories())
                        .setResources(resources).setTestResources(testResources)
                        .setStringOutputStream(stringOutputStream).setSuppressionsLocation(suppressionsLocation)
                        .setTestSourceDirectories(getTestSourceDirectories()).setConfigLocation(configLocation)
                        .setConfigurationArtifacts(collectArtifacts("config"))
                        .setPropertyExpansion(propertyExpansion)
                        .setHeaderLocation(headerLocation).setLicenseArtifacts(collectArtifacts("license"))
                        .setCacheFile(cacheFile).setSuppressionsFileExpression(suppressionsFileExpression)
                        .setEncoding(encoding).setPropertiesLocation(propertiesLocation);
                checkstyleExecutor.executeCheckstyle(request);

            } catch (CheckstyleException e) {
                throw new MojoExecutionException("Failed during checkstyle configuration", e);
            } catch (CheckstyleExecutorException e) {
                throw new MojoExecutionException("Failed during checkstyle execution", e);
            } finally {
                //be sure to restore original context classloader
                Thread.currentThread().setContextClassLoader(currentClassLoader);
            }
        }

        if (!"xml".equals(outputFileFormat)) {
            throw new MojoExecutionException("Output format is '" + outputFileFormat
                    + "', checkstyle:check requires format to be 'xml'.");
        }

        if (!outputFile.exists()) {
            getLog().info("Unable to perform checkstyle:check, unable to find checkstyle:checkstyle outputFile.");
            return;
        }

        Reader reader = null;
        try {
            reader = new BufferedReader(ReaderFactory.newXmlReader(outputFile));

            XmlPullParser xpp = new MXParser();
            xpp.setInput(reader);

            int violations = countViolations(xpp);

            if (violations > maxAllowedViolations) {
                if (failOnViolation) {
                    String msg =
                            "You have " + violations + " Checkstyle violation" + ((violations > 1) ? "s" : "") + ".";
                    if (maxAllowedViolations > 0) {
                        msg += " The maximum number of allowed violations is " + maxAllowedViolations + ".";
                    }
                    throw new MojoFailureException(msg);
                }

                getLog().warn("checkstyle:check violations detected but failOnViolation set to false");
            }

            reader.close();
            reader = null;
        } catch (IOException | XmlPullParserException e) {
            throw new MojoExecutionException("Unable to read Checkstyle results xml: " + outputFile.getAbsolutePath(),
                    e);
        } finally {
            IOUtil.close(reader);
        }
    }
{@inheritDoc}