Search in sources :

Example 1 with Analyzer

use of com.buschmais.jqassistant.core.analysis.api.Analyzer 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 Analyzer

use of com.buschmais.jqassistant.core.analysis.api.Analyzer 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 3 with Analyzer

use of com.buschmais.jqassistant.core.analysis.api.Analyzer in project jqa-core-framework by jQAssistant.

the class AbstractPluginIT method applyConcept.

/**
 * Applies the concept identified by id.
 *
 * @param id
 *            The id.
 * @param parameters
 *            The rule parameters.
 * @return The result.
 */
protected Result<Concept> applyConcept(String id, Map<String, String> parameters) throws RuleException {
    Analyzer analyzer = getAnalyzer(parameters);
    RuleSelection ruleSelection = RuleSelection.builder().conceptId(id).build();
    Concept concept = ruleSet.getConceptBucket().getById(id);
    assertThat(concept).describedAs("The requested concept cannot be found: " + id).isNotNull();
    analyzer.execute(ruleSet, ruleSelection);
    return reportPlugin.getConceptResults().get(id);
}
Also used : Analyzer(com.buschmais.jqassistant.core.analysis.api.Analyzer)

Example 4 with Analyzer

use of com.buschmais.jqassistant.core.analysis.api.Analyzer 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)

Example 5 with Analyzer

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

the class AnalyzeMojo method aggregate.

@Override
public void aggregate(MavenProject rootModule, List<MavenProject> projects, Store store) throws MojoExecutionException, MojoFailureException {
    getLog().info("Executing analysis for '" + rootModule.getName() + "'.");
    getLog().info("Will warn on violations starting from severity '" + warnOnSeverity + "'");
    getLog().info("Will fail on violations starting from severity '" + failOnSeverity + "'.");
    RuleSet ruleSet = readRules(rootModule);
    RuleSelection ruleSelection = RuleSelection.select(ruleSet, groups, constraints, concepts);
    ReportContext reportContext = new ReportContextImpl(store, ProjectResolver.getOutputDirectory(rootModule));
    Severity effectiveFailOnSeverity = failOnSeverity;
    Map<String, Object> properties = getReportProperties();
    Map<String, ReportPlugin> reportPlugins = getPluginRepository().getAnalyzerPluginRepository().getReportPlugins(reportContext, properties);
    InMemoryReportPlugin inMemoryReportPlugin = new InMemoryReportPlugin(new CompositeReportPlugin(reportPlugins, reportTypes.isEmpty() ? null : reportTypes));
    AnalyzerConfiguration configuration = new AnalyzerConfiguration();
    configuration.setExecuteAppliedConcepts(executeAppliedConcepts);
    try {
        Analyzer analyzer = new AnalyzerImpl(configuration, store, getPluginRepository().getAnalyzerPluginRepository().getRuleInterpreterPlugins(emptyMap()), inMemoryReportPlugin, logger);
        analyzer.execute(ruleSet, ruleSelection, ruleParameters);
    } catch (RuleException e) {
        throw new MojoExecutionException("Analysis failed.", e);
    }
    if (attachReportArchive) {
        attachReportArchive(rootModule, reportContext);
    }
    ReportHelper reportHelper = new ReportHelper(logger);
    store.beginTransaction();
    try {
        verifyAnalysisResults(inMemoryReportPlugin, reportHelper, effectiveFailOnSeverity);
    } finally {
        store.commitTransaction();
    }
}
Also used : RuleSet(com.buschmais.jqassistant.core.rule.api.model.RuleSet) ReportContextImpl(com.buschmais.jqassistant.core.report.impl.ReportContextImpl) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) 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) 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) RuleSelection(com.buschmais.jqassistant.core.rule.api.model.RuleSelection) ReportContext(com.buschmais.jqassistant.core.report.api.ReportContext) AnalyzerImpl(com.buschmais.jqassistant.core.analysis.impl.AnalyzerImpl) AnalyzerConfiguration(com.buschmais.jqassistant.core.analysis.api.AnalyzerConfiguration)

Aggregations

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