Search in sources :

Example 1 with CliExecutionException

use of com.buschmais.jqassistant.commandline.CliExecutionException in project jqa-commandline-tool by jQAssistant.

the class AnalyzeTask method getRuleParameters.

/**
 * Reads the given rule parameters file.
 *
 * @return The map containing the rule parameters.
 * @throws CliExecutionException
 *             If the file cannot be read.
 */
private Map<String, String> getRuleParameters() throws CliExecutionException {
    Map<String, String> ruleParameters;
    if (ruleParametersFile == null) {
        ruleParameters = emptyMap();
    } else {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(ruleParametersFile));
        } catch (IOException e) {
            throw new CliExecutionException("Cannot read rule parameters file '" + ruleParametersFile.getPath() + "'.");
        }
        ruleParameters = new TreeMap<>();
        for (String name : properties.stringPropertyNames()) {
            ruleParameters.put(name, properties.getProperty(name));
        }
    }
    return ruleParameters;
}
Also used : IOException(java.io.IOException) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 2 with CliExecutionException

use of com.buschmais.jqassistant.commandline.CliExecutionException 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 3 with CliExecutionException

use of com.buschmais.jqassistant.commandline.CliExecutionException 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 4 with CliExecutionException

use of com.buschmais.jqassistant.commandline.CliExecutionException in project jqa-commandline-tool by jQAssistant.

the class ReportTask method run.

@Override
public void run(Configuration configuration) throws CliExecutionException {
    File xmlReportFile = new File(reportDirectory, REPORT_FILE_XML);
    if (!xmlReportFile.exists()) {
        LOGGER.error(xmlReportFile.getName() + " does not exist.");
    } else {
        LOGGER.info("Transforming " + xmlReportFile.getAbsolutePath() + ".");
        File htmlReportFile = new File(reportDirectory, REPORT_FILE_HTML);
        Source xmlSource = new StreamSource(xmlReportFile);
        FileWriter writer;
        try {
            writer = new FileWriter(htmlReportFile);
        } catch (IOException e) {
            throw new CliExecutionException("Cannot create HTML report file.", e);
        }
        Result htmlTarget = new StreamResult(writer);
        ReportTransformer transformer = new HtmlReportTransformer();
        try {
            transformer.toStandalone(xmlSource, htmlTarget);
        } catch (ReportTransformerException e) {
            throw new CliExecutionException("Cannot transform report.", e);
        }
    }
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) HtmlReportTransformer(com.buschmais.jqassistant.core.report.impl.HtmlReportTransformer) ReportTransformer(com.buschmais.jqassistant.core.report.api.ReportTransformer) ReportTransformerException(com.buschmais.jqassistant.core.report.api.ReportTransformerException) StreamSource(javax.xml.transform.stream.StreamSource) FileWriter(java.io.FileWriter) HtmlReportTransformer(com.buschmais.jqassistant.core.report.impl.HtmlReportTransformer) IOException(java.io.IOException) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) File(java.io.File) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 5 with CliExecutionException

use of com.buschmais.jqassistant.commandline.CliExecutionException in project jqa-commandline-tool by jQAssistant.

the class AbstractAnalyzeTask method getAvailableRules.

protected RuleSet getAvailableRules() throws CliExecutionException {
    List<RuleSource> sources = new ArrayList<>();
    if (rulesUrl != null) {
        sources.add(new UrlRuleSource(rulesUrl));
    } else {
        File selectedDirectory = new File(ruleDirectory);
        // read rules from rules directory
        sources.addAll(readRulesDirectory(selectedDirectory));
        List<RuleSource> ruleSources = pluginRepository.getRulePluginRepository().getRuleSources();
        sources.addAll(ruleSources);
    }
    Collection<RuleParserPlugin> ruleParserPlugins;
    try {
        ruleParserPlugins = pluginRepository.getRulePluginRepository().getRuleParserPlugins(ruleConfiguration);
    } catch (RuleException e) {
        throw new CliExecutionException("Cannot get rule source reader plugins.", e);
    }
    try {
        RuleParser ruleParser = new RuleParser(ruleParserPlugins);
        return ruleParser.parse(sources);
    } catch (RuleException e) {
        throw new CliExecutionException("Cannot read rules.", e);
    }
}
Also used : UrlRuleSource(com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource) FileRuleSource(com.buschmais.jqassistant.core.rule.api.source.FileRuleSource) RuleSource(com.buschmais.jqassistant.core.rule.api.source.RuleSource) RuleParserPlugin(com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin) ArrayList(java.util.ArrayList) UrlRuleSource(com.buschmais.jqassistant.core.rule.api.source.UrlRuleSource) RuleParser(com.buschmais.jqassistant.core.rule.impl.reader.RuleParser) CliExecutionException(com.buschmais.jqassistant.commandline.CliExecutionException) RuleException(com.buschmais.jqassistant.core.rule.api.model.RuleException) File(java.io.File)

Aggregations

CliExecutionException (com.buschmais.jqassistant.commandline.CliExecutionException)11 RuleException (com.buschmais.jqassistant.core.rule.api.model.RuleException)6 IOException (java.io.IOException)5 RuleSet (com.buschmais.jqassistant.core.rule.api.model.RuleSet)4 File (java.io.File)4 CliRuleViolationException (com.buschmais.jqassistant.commandline.CliRuleViolationException)2 Analyzer (com.buschmais.jqassistant.core.analysis.api.Analyzer)2 Analyze (com.buschmais.jqassistant.core.analysis.api.configuration.Analyze)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 ReportTransformer (com.buschmais.jqassistant.core.report.api.ReportTransformer)2 ReportTransformerException (com.buschmais.jqassistant.core.report.api.ReportTransformerException)2 CompositeReportPlugin (com.buschmais.jqassistant.core.report.impl.CompositeReportPlugin)2 HtmlReportTransformer (com.buschmais.jqassistant.core.report.impl.HtmlReportTransformer)2 InMemoryReportPlugin (com.buschmais.jqassistant.core.report.impl.InMemoryReportPlugin)2 ReportContextImpl (com.buschmais.jqassistant.core.report.impl.ReportContextImpl)2 RuleParserPlugin (com.buschmais.jqassistant.core.rule.api.reader.RuleParserPlugin)2 FileRuleSource (com.buschmais.jqassistant.core.rule.api.source.FileRuleSource)2