Search in sources :

Example 1 with IRefactorSessionEnv

use of org.sonar.plugins.openedge.foundation.IRefactorSessionEnv in project sonar-openedge by Riverside-Software.

the class OpenEdgeCPDSensor method execute.

@Override
public void execute(SensorContext context) {
    if ((context.runtime().getProduct() == SonarProduct.SONARLINT) || !settings.useSimpleCPD())
        return;
    settings.init();
    IRefactorSessionEnv sessions = settings.getProparseSessions();
    for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) {
        LOG.debug("CPD on {}", file);
        IProparseEnvironment session = sessions.getSession(file.relativePath());
        try {
            processFile(context, session, file);
        } catch (UncheckedIOException | ProparseRuntimeException caught) {
            if (caught.getCause() instanceof XCodedFileException) {
                LOG.error("Unable to process xcode'd file '{}", file);
            } else {
                LOG.error("Unable to lex file '{}'", file, caught);
            }
        }
    }
}
Also used : ProparseRuntimeException(org.prorefactor.core.ProparseRuntimeException) IProparseEnvironment(org.prorefactor.proparse.support.IProparseEnvironment) XCodedFileException(org.prorefactor.proparse.XCodedFileException) IRefactorSessionEnv(org.sonar.plugins.openedge.foundation.IRefactorSessionEnv) UncheckedIOException(java.io.UncheckedIOException) InputFile(org.sonar.api.batch.fs.InputFile)

Example 2 with IRefactorSessionEnv

use of org.sonar.plugins.openedge.foundation.IRefactorSessionEnv in project sonar-openedge by Riverside-Software.

the class OpenEdgeCodeColorizer method execute.

@Override
public void execute(SensorContext context) {
    if (context.runtime().getProduct() == SonarProduct.SONARLINT)
        return;
    settings.init();
    IRefactorSessionEnv sessions = settings.getProparseSessions();
    for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguage(Constants.LANGUAGE_KEY))) {
        LOG.debug("Syntax highlight on {}", file);
        IProparseEnvironment session = sessions.getSession(file.relativePath());
        try {
            highlightFile(context, session, file);
        } catch (UncheckedIOException | ProparseRuntimeException caught) {
            if (caught.getCause() instanceof XCodedFileException) {
                LOG.error("Unable to highlight xcode'd file '{}", file);
            } else {
                LOG.error("Unable to lex file '{}'", file, caught);
            }
        }
    }
}
Also used : ProparseRuntimeException(org.prorefactor.core.ProparseRuntimeException) IProparseEnvironment(org.prorefactor.proparse.support.IProparseEnvironment) XCodedFileException(org.prorefactor.proparse.XCodedFileException) IRefactorSessionEnv(org.sonar.plugins.openedge.foundation.IRefactorSessionEnv) UncheckedIOException(java.io.UncheckedIOException) InputFile(org.sonar.api.batch.fs.InputFile)

Example 3 with IRefactorSessionEnv

use of org.sonar.plugins.openedge.foundation.IRefactorSessionEnv in project sonar-openedge by Riverside-Software.

the class OpenEdgeProparseSensor method execute.

@Override
public void execute(SensorContext context) {
    if (settings.skipProparseSensor())
        return;
    settings.init();
    components.init(context);
    for (Map.Entry<ActiveRule, OpenEdgeProparseCheck> entry : components.getProparseRules().entrySet()) {
        ruleTime.put(entry.getKey().ruleKey().toString(), 0L);
    }
    IRefactorSessionEnv sessions = settings.getProparseSessions();
    FilePredicates predicates = context.fileSystem().predicates();
    // Counting total number of files
    long totFiles = StreamSupport.stream(context.fileSystem().inputFiles(predicates.and(predicates.hasLanguage(Constants.LANGUAGE_KEY), predicates.hasType(Type.MAIN))).spliterator(), false).count();
    long prevMessage = System.currentTimeMillis();
    for (InputFile file : context.fileSystem().inputFiles(predicates.and(predicates.hasLanguage(Constants.LANGUAGE_KEY), predicates.hasType(Type.MAIN)))) {
        LOG.debug("Parsing {}", file);
        numFiles++;
        if (System.currentTimeMillis() - prevMessage > 30000L) {
            prevMessage = System.currentTimeMillis();
            LOG.info("{}/{} - Current file: {}", numFiles, totFiles, file.relativePath());
        }
        IProparseEnvironment session = sessions.getSession(file.relativePath());
        if (settings.isIncludeFile(file.filename())) {
            parseIncludeFile(context, file, session);
        } else {
            parseMainFile(context, file, session);
        }
        if (context.isCancelled()) {
            LOG.info("Analysis cancelled...");
            return;
        }
    }
    computeAnalytics(context);
    logStatistics();
    context.addContextProperty("sonar.oe.ncloc", Integer.toString(ncLocs));
    generateProparseDebugIndex();
}
Also used : OpenEdgeProparseCheck(org.sonar.plugins.openedge.api.checks.OpenEdgeProparseCheck) IProparseEnvironment(org.prorefactor.proparse.support.IProparseEnvironment) ActiveRule(org.sonar.api.batch.rule.ActiveRule) FilePredicates(org.sonar.api.batch.fs.FilePredicates) IRefactorSessionEnv(org.sonar.plugins.openedge.foundation.IRefactorSessionEnv) Map(java.util.Map) HashMap(java.util.HashMap) InputFile(org.sonar.api.batch.fs.InputFile)

Aggregations

IProparseEnvironment (org.prorefactor.proparse.support.IProparseEnvironment)3 InputFile (org.sonar.api.batch.fs.InputFile)3 IRefactorSessionEnv (org.sonar.plugins.openedge.foundation.IRefactorSessionEnv)3 UncheckedIOException (java.io.UncheckedIOException)2 ProparseRuntimeException (org.prorefactor.core.ProparseRuntimeException)2 XCodedFileException (org.prorefactor.proparse.XCodedFileException)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 FilePredicates (org.sonar.api.batch.fs.FilePredicates)1 ActiveRule (org.sonar.api.batch.rule.ActiveRule)1 OpenEdgeProparseCheck (org.sonar.plugins.openedge.api.checks.OpenEdgeProparseCheck)1