use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneIssueOnDirPerFileSensor method createIssues.
private static void createIssues(InputFile file, SensorContext context) {
RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY);
InputDir inputDir = context.fileSystem().inputDir(file.file().getParentFile());
if (inputDir != null) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(inputDir).message("This issue is generated for file " + file.relativePath())).save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class TemplateRuleCheck method execute.
@Override
public void execute(SensorContext sensorContext, InputFile file, RuleKey ruleKey) {
NewIssue newIssue = sensorContext.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line))).save();
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class HasTagSensor method processFile.
@Override
protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) {
org.sonar.api.batch.rule.ActiveRule activeRule = activeRules.find(ruleKey);
String tag = activeRule.param("tag");
if (tag == null) {
throw new IllegalStateException("Rule is badly configured. The parameter 'tag' is missing.");
}
try {
int[] lineCounter = { 1 };
Files.lines(inputFile.path(), inputFile.charset()).forEachOrdered(lineStr -> {
int startIndex = -1;
while ((startIndex = lineStr.indexOf(tag, startIndex + 1)) != -1) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)).at(newIssue.newLocation().on(inputFile).at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))).save();
}
lineCounter[0]++;
});
} catch (IOException e) {
throw new IllegalStateException("Fail to process " + inputFile, e);
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneIssuePerLineSensor method createIssues.
private void createIssues(InputFile file, SensorContext context, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
String severity = context.settings().getString(FORCE_SEVERITY_PROPERTY);
for (int line = 1; line <= file.lines(); line++) {
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(file).at(file.selectLine(line)).message("This issue is generated on each line")).overrideSeverity(severity != null ? Severity.valueOf(severity) : null);
if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(5, 5))) {
newIssue.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
} else {
newIssue.effortToFix(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY));
}
newIssue.save();
}
}
use of org.sonar.api.batch.sensor.issue.NewIssue in project sonarqube by SonarSource.
the class OneIssuePerModuleSensor method analyse.
private void analyse(SensorContext context, String language, String repo) {
RuleKey ruleKey = RuleKey.of(repo, RULE_KEY);
NewIssue newIssue = context.newIssue();
newIssue.forRule(ruleKey).at(newIssue.newLocation().on(context.module()).message("This issue is generated on each module")).save();
}
Aggregations