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;
}
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();
}
}
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);
}
}
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);
}
}
}
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);
}
}
Aggregations