Search in sources :

Example 1 with Analyze

use of com.buschmais.jqassistant.core.analysis.api.configuration.Analyze in project jqa-commandline-tool by jQAssistant.

the class AnalyzeTask method run.

@Override
public void run(CliConfiguration configuration) throws CliExecutionException {
    Analyze analyze = configuration.analyze();
    Severity warnOnSeverity = analyze.report().warnOnSeverity();
    Severity failOnSeverity = analyze.report().failOnSeverity();
    LOGGER.info("Will warn on violations starting from severity '" + warnOnSeverity + "'");
    LOGGER.info("Will fail on violations starting from severity '" + failOnSeverity + "'.");
    LOGGER.info("Executing analysis.");
    withStore(configuration, store -> {
        ReportContext reportContext = new ReportContextImpl(store, reportDirectory, reportDirectory);
        Map<String, ReportPlugin> reportPlugins = getReportPlugins(analyze.report(), reportContext);
        InMemoryReportPlugin inMemoryReportPlugin = new InMemoryReportPlugin(new CompositeReportPlugin(reportPlugins));
        try {
            Analyzer analyzer = new AnalyzerImpl(analyze, store, pluginRepository.getAnalyzerPluginRepository().getRuleInterpreterPlugins(emptyMap()), inMemoryReportPlugin, LOGGER);
            RuleSet availableRules = getAvailableRules(analyze.rule());
            analyzer.execute(availableRules, getRuleSelection(availableRules, analyze));
        } catch (RuleException e) {
            throw new CliExecutionException("Analysis failed.", e);
        }
        if (analyze.report().createArchive()) {
            createReportArchive(reportContext);
        }
        store.beginTransaction();
        LOGGER.info("Verifying results: failOnSeverity=" + failOnSeverity + ", warnOnSeverity=" + warnOnSeverity);
        try {
            final ReportHelper reportHelper = new ReportHelper(configuration.analyze().report(), LOGGER);
            final int conceptViolations = reportHelper.verifyConceptResults(inMemoryReportPlugin);
            final int constraintViolations = reportHelper.verifyConstraintResults(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) Severity(com.buschmais.jqassistant.core.rule.api.model.Severity) 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) Analyze(com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)

Example 2 with Analyze

use of com.buschmais.jqassistant.core.analysis.api.configuration.Analyze in project jqa-maven-plugin by jQAssistant.

the class AnalyzeMojo method aggregate.

@Override
public void aggregate(MojoExecutionContext mojoExecutionContext) throws MojoExecutionException, MojoFailureException {
    MavenConfiguration configuration = mojoExecutionContext.getConfiguration();
    MavenProject rootModule = mojoExecutionContext.getRootModule();
    RuleSet ruleSet = readRules(mojoExecutionContext);
    Analyze analyze = configuration.analyze();
    RuleSelection ruleSelection = RuleSelection.select(ruleSet, analyze.groups(), analyze.constraints(), analyze.concepts());
    File outputDirectory = mojoExecutionContext.getOutputDirectory();
    withStore(store -> analyze(configuration, rootModule, ruleSet, ruleSelection, store, outputDirectory), mojoExecutionContext);
}
Also used : MavenConfiguration(com.buschmais.jqassistant.scm.maven.configuration.MavenConfiguration) RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) MavenProject(org.apache.maven.project.MavenProject) RuleSelection(com.buschmais.jqassistant.core.rule.api.model.RuleSelection) File(java.io.File) Analyze(com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)

Example 3 with Analyze

use of com.buschmais.jqassistant.core.analysis.api.configuration.Analyze in project jqa-maven-plugin by jQAssistant.

the class EffectiveRulesMojo method aggregate.

@Override
public void aggregate(MojoExecutionContext mojoExecutionContext) throws MojoExecutionException, MojoFailureException {
    getLog().info("Effective rules for '" + mojoExecutionContext.getRootModule().getName() + "'.");
    Analyze analyze = mojoExecutionContext.getConfiguration().analyze();
    RuleSet ruleSet = readRules(mojoExecutionContext);
    RuleSelection ruleSelection = RuleSelection.select(ruleSet, analyze.groups(), analyze.constraints(), analyze.concepts());
    RuleHelper ruleHelper = new RuleHelper(LOGGER);
    try {
        ruleHelper.printRuleSet(ruleSet, ruleSelection, analyze.rule());
    } 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) Analyze(com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)

Example 4 with Analyze

use of com.buschmais.jqassistant.core.analysis.api.configuration.Analyze in project jqa-commandline-tool by jQAssistant.

the class EffectiveRulesTask method run.

@Override
public void run(CliConfiguration configuration) throws CliExecutionException {
    try {
        Analyze analyze = configuration.analyze();
        Rule rule = analyze.rule();
        RuleSet availableRules = getAvailableRules(rule);
        ruleHelper.printRuleSet(availableRules, getRuleSelection(availableRules, analyze), rule);
    } catch (RuleException e) {
        throw new CliExecutionException("Cannot print rules.", e);
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) Rule(com.buschmais.jqassistant.core.rule.api.configuration.Rule) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) Analyze(com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)

Example 5 with Analyze

use of com.buschmais.jqassistant.core.analysis.api.configuration.Analyze in project jqa-maven-plugin by jQAssistant.

the class AnalyzeMojo method analyze.

private void analyze(MavenConfiguration configuration, MavenProject rootModule, RuleSet ruleSet, RuleSelection ruleSelection, Store store, File outputDirectory) throws MojoExecutionException, MojoFailureException {
    Analyze analyze = configuration.analyze();
    getLog().info("Executing analysis for '" + rootModule.getName() + "'.");
    getLog().info("Will warn on violations starting from severity '" + analyze.report().warnOnSeverity() + "'");
    getLog().info("Will fail on violations starting from severity '" + analyze.report().failOnSeverity() + "'.");
    ReportContext reportContext = new ReportContextImpl(store, outputDirectory);
    AnalyzerPluginRepository analyzerPluginRepository = getPluginRepository(configuration).getAnalyzerPluginRepository();
    Map<String, ReportPlugin> reportPlugins = analyzerPluginRepository.getReportPlugins(analyze.report(), reportContext);
    InMemoryReportPlugin inMemoryReportPlugin = new InMemoryReportPlugin(new CompositeReportPlugin(reportPlugins, reportTypes.isEmpty() ? null : reportTypes));
    try {
        Analyzer analyzer = new AnalyzerImpl(analyze, store, analyzerPluginRepository.getRuleInterpreterPlugins(emptyMap()), inMemoryReportPlugin, LOGGER);
        analyzer.execute(ruleSet, ruleSelection);
    } catch (RuleException e) {
        throw new MojoExecutionException("Analysis failed.", e);
    }
    if (analyze.report().createArchive()) {
        attachReportArchive(rootModule, reportContext);
    }
    ReportHelper reportHelper = new ReportHelper(analyze.report(), LOGGER);
    store.beginTransaction();
    try {
        verifyAnalysisResults(inMemoryReportPlugin, reportHelper);
    } finally {
        store.commitTransaction();
    }
}
Also used : ReportContextImpl(com.buschmais.jqassistant.core.report.impl.ReportContextImpl) AnalyzerPluginRepository(com.buschmais.jqassistant.core.analysis.spi.AnalyzerPluginRepository) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ReportHelper(com.buschmais.jqassistant.core.report.api.ReportHelper) CompositeReportPlugin(com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin) InMemoryReportPlugin(com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin) 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) XmlReportPlugin(com.buschmais.jqassistant.core.report.impl.XmlReportPlugin) ReportContext(com.buschmais.jqassistant.core.report.api.ReportContext) AnalyzerImpl(com.buschmais.jqassistant.core.analysis.impl.AnalyzerImpl) Analyze(com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)

Aggregations

Analyze (com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)5 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)4 RuleSet (com.buschmais.jqassistant.core.rule.api.model.RuleSet)4 CliExecutionException (com.buschmais.jqassistant.commandline.CliExecutionException)2 Analyzer (com.buschmais.jqassistant.core.analysis.api.Analyzer)2 AnalyzerImpl (com.buschmais.jqassistant.core.analysis.impl.AnalyzerImpl)2 ReportContext (com.buschmais.jqassistant.core.report.api.ReportContext)2 ReportHelper (com.buschmais.jqassistant.core.report.api.ReportHelper)2 ReportPlugin (com.buschmais.jqassistant.core.report.api.ReportPlugin)2 CompositeReportPlugin (com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin)2 InMemoryReportPlugin (com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin)2 ReportContextImpl (com.buschmais.jqassistant.core.report.impl.ReportContextImpl)2 RuleSelection (com.buschmais.jqassistant.core.rule.api.model.RuleSelection)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 CliRuleViolationException (com.buschmais.jqassistant.commandline.CliRuleViolationException)1 AnalyzerPluginRepository (com.buschmais.jqassistant.core.analysis.spi.AnalyzerPluginRepository)1 XmlReportPlugin (com.buschmais.jqassistant.core.report.impl.XmlReportPlugin)1 RuleHelper (com.buschmais.jqassistant.core.rule.api.RuleHelper)1 Rule (com.buschmais.jqassistant.core.rule.api.configuration.Rule)1 Severity (com.buschmais.jqassistant.core.rule.api.model.Severity)1