Java Code Examples for org.sonar.api.batch.sensor.SensorContext#config()

The following examples show how to use org.sonar.api.batch.sensor.SensorContext#config() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EsqlSensor.java    From sonar-esql-plugin with Apache License 2.0 6 votes vote down vote up
private void scanFile(SensorContext sensorContext, InputFile inputFile, List<TreeVisitor> visitors, ProgramTree programTree) {
    LOG.debug("scanning file " + inputFile.filename());
    EsqlVisitorContext context = new EsqlVisitorContext(programTree, inputFile, sensorContext.config());

    List<Issue> fileIssues = new ArrayList<>();

    for (TreeVisitor visitor : visitors) {
        if (visitor instanceof EsqlCheck) {
            fileIssues.addAll(((EsqlCheck) visitor).scanFile(context));
        } else {
            visitor.scanTree(context);
        }
    }

    saveFileIssues(sensorContext, fileIssues, inputFile);
    highlightSymbols(inputFile, context, sensorContext);
}
 
Example 2
Source File: CustomAllChecksProvider.java    From sonar-tsql-plugin with GNU General Public License v3.0 5 votes vote down vote up
public CandidateRule[] getChecks(final SensorContext context) {
	final Configuration config = context.config();
	final boolean skipCustomRules = config.getBoolean(Constants.PLUGIN_SKIP_CUSTOM_RULES).orElse(false);
	final String baseDir = context.fileSystem().baseDir().getAbsolutePath();

	final String[] paths = config.getStringArray(Constants.PLUGIN_CUSTOM_RULES_PATH);
	final String rulesPrefix = config.get(Constants.PLUGIN_CUSTOM_RULES_PREFIX).orElse(".customRules");

	final List<SqlRules> rules = new ArrayList<>();

	rules.addAll(provider.getRules(baseDir, rulesPrefix, paths).values());

	if (!skipCustomRules) {
		final SqlRules customRules = pluginChecksProvider.getRules();
		rules.add(customRules);
	}

	for (final SqlRules sqlRules : rules) {
		if (sqlRules.isIsAdhoc()) {
			for (final Rule r : sqlRules.getRule()) {
				context.newAdHocRule().description(r.getDescription()).engineId(sqlRules.getRepoKey())
						.ruleId(r.getKey()).type(RuleType.valueOf(r.getRuleType())).name(r.getName())
						.severity(Severity.valueOf(r.getSeverity())).save();
			}
		}
	}

	final SqlRules[] finalRules = rules.toArray(new SqlRules[0]);

	final CandidateRule[] candidateRules = convert(finalRules);
	LOGGER.info(String.format("Total %s custom rules repositories with total %s checks", rules.size(),
			candidateRules.length));
	return candidateRules;

}
 
Example 3
Source File: CFLintAnalyzer.java    From sonar-coldfusion with Apache License 2.0 4 votes vote down vote up
public CFLintAnalyzer(SensorContext sensorContext) {
    Preconditions.checkNotNull(sensorContext);

    this.settings = sensorContext.config();
    this.fs = sensorContext.fileSystem();
}
 
Example 4
Source File: EsqlSensor.java    From sonar-esql-plugin with Apache License 2.0 3 votes vote down vote up
private static void executeCoverageSensors(SensorContext context, Map<InputFile, Set<Integer>> executableLines) {
    Configuration configuration = context.config();

    String[] traces = configuration.getStringArray(EsqlPlugin.TRACE_PATHS_PROPERTY);

    (new TraceSensor()).execute(context, executableLines, traces);

}