Search in sources :

Example 1 with RuleSet

use of com.buschmais.jqassistant.core.rule.api.model.RuleSet in project jqa-commandline-tool by jQAssistant.

the class AnalyzeTask method executeTask.

@Override
protected void executeTask(Configuration configuration, final Store store) throws CliExecutionException {
    LOGGER.info("Will warn on violations starting form severity '" + warnOnSeverity + "'");
    LOGGER.info("Will fail on violations starting from severity '" + failOnSeverity + "'.");
    LOGGER.info("Executing analysis.");
    ReportContext reportContext = new ReportContextImpl(store, reportDirectory, reportDirectory);
    Map<String, ReportPlugin> reportPlugins = getReportPlugins(reportContext);
    InMemoryReportPlugin inMemoryReportPlugin = new InMemoryReportPlugin(new CompositeReportPlugin(reportPlugins));
    AnalyzerConfiguration analyzerConfiguration = new AnalyzerConfiguration();
    analyzerConfiguration.setExecuteAppliedConcepts(executeAppliedConcepts);
    Map<String, String> ruleParameters = getRuleParameters();
    try {
        Analyzer analyzer = new AnalyzerImpl(analyzerConfiguration, store, pluginRepository.getAnalyzerPluginRepository().getRuleInterpreterPlugins(emptyMap()), inMemoryReportPlugin, LOGGER);
        RuleSet availableRules = getAvailableRules();
        analyzer.execute(availableRules, getRuleSelection(availableRules), ruleParameters);
    } catch (RuleException e) {
        throw new CliExecutionException("Analysis failed.", e);
    }
    if (createReportArchive) {
        createReportArchive(reportContext);
    }
    store.beginTransaction();
    LOGGER.info("Verifying results: failOnSeverity=" + failOnSeverity + ", warnOnSeverity=" + warnOnSeverity);
    try {
        final ReportHelper reportHelper = new ReportHelper(LOGGER);
        final int conceptViolations = reportHelper.verifyConceptResults(warnOnSeverity, failOnSeverity, inMemoryReportPlugin);
        final int constraintViolations = reportHelper.verifyConstraintResults(warnOnSeverity, failOnSeverity, inMemoryReportPlugin);
        if (conceptViolations > 0 || constraintViolations > 0) {
            throw new CliRuleViolationException("Failed rules detected: " + conceptViolations + " concepts, " + constraintViolations + " constraints");
        }
    } finally {
        store.commitTransaction();
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) ReportContextImpl(com.buschmais.jqassistant.core.report.impl.ReportContextImpl) ReportHelper(com.buschmais.jqassistant.core.report.api.ReportHelper) CompositeReportPlugin(com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin) InMemoryReportPlugin(com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) Analyzer(com.buschmais.jqassistant.core.analysis.api.Analyzer) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) InMemoryReportPlugin(com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin) ReportPlugin(com.buschmais.jqassistant.core.report.api.ReportPlugin) CompositeReportPlugin(com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin) CliRuleViolationException(com.buschmais.jqassistant.commandline.CliRuleViolationException) ReportContext(com.buschmais.jqassistant.core.report.api.ReportContext) AnalyzerImpl(com.buschmais.jqassistant.core.analysis.impl.AnalyzerImpl) AnalyzerConfiguration(com.buschmais.jqassistant.core.analysis.api.AnalyzerConfiguration)

Example 2 with RuleSet

use of com.buschmais.jqassistant.core.rule.api.model.RuleSet in project jqa-commandline-tool by jQAssistant.

the class EffectiveRulesTask method executeTask.

@Override
protected void executeTask(Configuration configuration, Store store) throws CliExecutionException {
    try {
        RuleSet availableRules = getAvailableRules();
        ruleHelper.printRuleSet(availableRules, getRuleSelection(availableRules));
    } catch (RuleException e) {
        throw new CliExecutionException("Cannot print rules.", e);
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException)

Example 3 with RuleSet

use of com.buschmais.jqassistant.core.rule.api.model.RuleSet in project jqa-maven-plugin by jQAssistant.

the class AvailableRulesMojo method aggregate.

@Override
public void aggregate(MavenProject rootModule, List<MavenProject> projects, Store store) throws MojoExecutionException, MojoFailureException {
    getLog().info("Available rules for '" + rootModule.getName() + "'.");
    RuleSet ruleSet = readRules(rootModule);
    RuleHelper ruleHelper = new RuleHelper(LOGGER);
    try {
        ruleHelper.printRuleSet(ruleSet);
    } catch (RuleException e) {
        throw new MojoExecutionException("Cannot print available rules.", e);
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RuleHelper(com.buschmais.jqassistant.core.rule.api.RuleHelper) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException)

Example 4 with RuleSet

use of com.buschmais.jqassistant.core.rule.api.model.RuleSet in project jqa-maven-plugin by jQAssistant.

the class EffectiveRulesMojo method aggregate.

@Override
public void aggregate(MavenProject rootModule, List<MavenProject> projects, Store store) throws MojoExecutionException, MojoFailureException {
    getLog().info("Effective rules for '" + rootModule.getName() + "'.");
    RuleSet ruleSet = readRules(rootModule);
    RuleSelection ruleSelection = RuleSelection.select(ruleSet, groups, constraints, concepts);
    RuleHelper ruleHelper = new RuleHelper(LOGGER);
    try {
        ruleHelper.printRuleSet(ruleSet, ruleSelection);
    } catch (RuleException e) {
        throw new MojoExecutionException("Cannot print effective rules.", e);
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RuleSelection(com.buschmais.jqassistant.core.rule.api.model.RuleSelection) RuleHelper(com.buschmais.jqassistant.core.rule.api.RuleHelper) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException)

Example 5 with RuleSet

use of com.buschmais.jqassistant.core.rule.api.model.RuleSet in project jqa-maven-plugin by jQAssistant.

the class ExportRulesMojo method aggregate.

@Override
protected void aggregate(MavenProject rootModule, List<MavenProject> projects, Store store) throws MojoExecutionException {
    getLog().info("Exporting rules for '" + rootModule.getName() + "'.");
    final RuleSet ruleSet = readRules(rootModule);
    RuleSetWriter ruleSetWriter = new XmlRuleSetWriter(getRuleConfiguration());
    String exportedRules = rootModule.getBuild().getDirectory() + "/jqassistant/jqassistant-rules.xml";
    Writer writer;
    try {
        writer = new OutputStreamWriter(new FileOutputStream(exportedRules), "UTF-8");
    } catch (IOException e) {
        throw new MojoExecutionException("Cannot create writer for rule export.", e);
    }
    try {
        ruleSetWriter.write(ruleSet, writer);
    } catch (RuleException e) {
        throw new MojoExecutionException("Cannot write rules.", e);
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) XmlRuleSetWriter(com.buschmais.jqassistant.core.rule.impl.writer.XmlRuleSetWriter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) RuleSetWriter(com.buschmais.jqassistant.core.rule.api.writer.RuleSetWriter) XmlRuleSetWriter(com.buschmais.jqassistant.core.rule.impl.writer.XmlRuleSetWriter) RuleSetWriter(com.buschmais.jqassistant.core.rule.api.writer.RuleSetWriter) XmlRuleSetWriter(com.buschmais.jqassistant.core.rule.impl.writer.XmlRuleSetWriter)

Aggregations

RuleSet (com.buschmais.jqassistant.core.rule.api.model.RuleSet)12 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)11 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)7 CliExecutionException (com.buschmais.jqassistant.commandline.CliExecutionException)4 Analyze (com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)4 RuleHelper (com.buschmais.jqassistant.core.rule.api.RuleHelper)4 RuleSelection (com.buschmais.jqassistant.core.rule.api.model.RuleSelection)4 Analyzer (com.buschmais.jqassistant.core.analysis.api.Analyzer)3 AnalyzerImpl (com.buschmais.jqassistant.core.analysis.impl.AnalyzerImpl)3 ReportContext (com.buschmais.jqassistant.core.report.api.ReportContext)3 ReportHelper (com.buschmais.jqassistant.core.report.api.ReportHelper)3 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)3 CompositeReportPlugin (com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin)3 InMemoryReportPlugin (com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin)3 ReportContextImpl (com.buschmais.jqassistant.core.report.impl.ReportContextImpl)3 CliRuleViolationException (com.buschmais.jqassistant.commandline.CliRuleViolationException)2 AnalyzerConfiguration (com.buschmais.jqassistant.core.analysis.api.AnalyzerConfiguration)2 Severity (com.buschmais.jqassistant.core.rule.api.model.Severity)2 RuleSetWriter (com.buschmais.jqassistant.core.rule.api.writer.RuleSetWriter)2 XmlRuleSetWriter (com.buschmais.jqassistant.core.rule.impl.writer.XmlRuleSetWriter)2