Search in sources :

Example 1 with OpenEdgeDumpFileCheck

use of org.sonar.plugins.openedge.api.checks.OpenEdgeDumpFileCheck in project sonar-openedge by Riverside-Software.

the class OpenEdgeDBRulesSensor method execute.

@Override
public void execute(SensorContext context) {
    Map<String, Long> ruleTime = new HashMap<>();
    long parseTime = 0L;
    components.init(context);
    for (Map.Entry<ActiveRule, OpenEdgeDumpFileCheck> entry : components.getDumpFileRules().entrySet()) {
        ruleTime.put(entry.getKey().ruleKey().toString(), 0L);
    }
    FilePredicates predicates = context.fileSystem().predicates();
    for (InputFile file : context.fileSystem().inputFiles(predicates.and(predicates.hasLanguage(Constants.DB_LANGUAGE_KEY), predicates.hasType(Type.MAIN)))) {
        try {
            LOG.debug("Generating ParseTree for dump file {}", file);
            long time = System.currentTimeMillis();
            ParseTree tree = DumpFileUtils.getDumpFileParseTree(file.inputStream(), file.charset());
            parseTime += (System.currentTimeMillis() - time);
            for (Map.Entry<ActiveRule, OpenEdgeDumpFileCheck> entry : components.getDumpFileRules().entrySet()) {
                LOG.debug("ActiveRule - Internal key {} - Repository {} - Rule {}", entry.getKey().internalKey(), entry.getKey().ruleKey().repository(), entry.getKey().ruleKey().rule());
                long startTime = System.currentTimeMillis();
                entry.getValue().execute(file, tree);
                ruleTime.put(entry.getKey().ruleKey().toString(), ruleTime.get(entry.getKey().ruleKey().toString()) + System.currentTimeMillis() - startTime);
            }
        } catch (IOException caught) {
            LOG.error("Unable to analyze {}", file, caught);
        }
    }
    LOG.info("AST Generation | time={} ms", parseTime);
    for (Entry<String, Long> entry : ruleTime.entrySet()) {
        LOG.info("Rule {} | time={} ms", entry.getKey(), entry.getValue());
    }
}
Also used : HashMap(java.util.HashMap) ActiveRule(org.sonar.api.batch.rule.ActiveRule) IOException(java.io.IOException) InputFile(org.sonar.api.batch.fs.InputFile) OpenEdgeDumpFileCheck(org.sonar.plugins.openedge.api.checks.OpenEdgeDumpFileCheck) FilePredicates(org.sonar.api.batch.fs.FilePredicates) HashMap(java.util.HashMap) Map(java.util.Map) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 InputFile (org.sonar.api.batch.fs.InputFile)1 ActiveRule (org.sonar.api.batch.rule.ActiveRule)1 OpenEdgeDumpFileCheck (org.sonar.plugins.openedge.api.checks.OpenEdgeDumpFileCheck)1