NewIssueLocation primaryLocation = newIssue.newLocation() .on(file) .at(file.newRange(entry.getValue(), endPositions.get(issueId))); newIssue.at(primaryLocation.message("Primary location")); if (startFlowsPositions.containsKey(issueId)) { NewIssueLocation newLocation = newIssue.newLocation() .on(file) .at(file.newRange(start, end)) .message("Flow step #" + flowNum); flowLocations.add(newLocation);
@Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) { try { int[] lineCounter = {1}; try (InputStreamReader isr = new InputStreamReader(inputFile.inputStream(), inputFile.charset()); BufferedReader reader = new BufferedReader(isr)) { reader.lines().forEachOrdered(lineStr -> { int startIndex = -1; while ((startIndex = lineStr.indexOf(TAG, startIndex + 1)) != -1) { NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) .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); } } }
@CheckForNull private static NewIssueLocation fillLocation(SensorContext context, NewIssueLocation newLocation, Location location) { InputFile file = findFile(context, location.filePath); if (file != null) { newLocation .on(file); if (location.message != null) { newLocation.message(location.message); } if (location.textRange != null) { if (location.textRange.startColumn != null) { TextPointer start = file.newPointer(location.textRange.startLine, location.textRange.startColumn); TextPointer end = file.newPointer(location.textRange.endLine, location.textRange.endColumn); newLocation.at(file.newRange(start, end)); } else { newLocation.at(file.selectLine(location.textRange.startLine)); } } return newLocation; } return null; }
.at(newIssue.newLocation() .on(inputFile) .at(inputFile.newRange(lineCounter[0], startIndex, lineCounter[0], startIndex + tag.length()))) .save();
@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(); }
private static void createIssues(InputFile file, SensorContext context) { RuleKey ruleKey = RuleKey.of(XooRulesDefinition.XOO_REPOSITORY, RULE_KEY); NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) .at(newIssue.newLocation() .on(file) .at(file.selectLine(1)) .message("This issue is generated on each file")) .save(); } }
private static void createIssues(InputFile file, SensorContext context, String repo) { RuleKey ruleKey = RuleKey.of(repo, RULE_KEY); for (int line = 1; line <= file.lines(); line++) { TextRange text = file.selectLine(line); // do not count empty lines, which can be a pain with end-of-file return if (text.end().lineOffset() == 0) { continue; } NewIssue newIssue = context.newIssue(); newIssue .forRule(ruleKey) .at(newIssue.newLocation() .on(file) .at(text) .message("This bug issue is generated on each line")) .save(); } }
private static void createIssues(InputFile file, SensorContext context) { for (int line = 1; line <= file.lines(); line++) { NewExternalIssue newIssue = context.newExternalIssue(); newIssue .engineId(ENGINE_ID) .ruleId(RULE_ID) .at(newIssue.newLocation() .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line and the rule is predefined")) .severity(Severity.valueOf(SEVERITY)) .remediationEffortMinutes(EFFORT) .type(TYPE) .save(); } } }
private static void createIssues(InputFile file, SensorContext context) { for (int line = 1; line <= file.lines(); line++) { NewExternalIssue newIssue = context.newExternalIssue(); newIssue .engineId(ENGINE_ID) .ruleId(RULE_ID) .at(newIssue.newLocation() .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line")) .severity(Severity.valueOf(SEVERITY)) .remediationEffortMinutes(EFFORT) .type(TYPE) .save(); } } }
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.gap(context.settings().getDouble(EFFORT_TO_FIX_PROPERTY)); } newIssue.save(); } }
private static void createIssues(InputFile file, SensorContext context) { for (int line = 1; line <= file.lines(); line++) { NewExternalIssue newIssue = context.newExternalIssue(); newIssue .engineId(OnePredefinedRuleExternalIssuePerLineSensor.ENGINE_ID) .ruleId(OnePredefinedRuleExternalIssuePerLineSensor.RULE_ID) .at(newIssue.newLocation() .on(file) .at(file.selectLine(line)) .message("This issue is generated on each line and the rule is predefined")) .severity(Severity.valueOf(OnePredefinedRuleExternalIssuePerLineSensor.SEVERITY)) .remediationEffortMinutes(OnePredefinedRuleExternalIssuePerLineSensor.EFFORT) .type(OnePredefinedRuleExternalIssuePerLineSensor.TYPE) .save(); // Even if the issue is on a predefined rule, the sensor is declaring an adHoc rule => this info should be ignored context.newAdHocRule() .engineId(OnePredefinedRuleExternalIssuePerLineSensor.ENGINE_ID) .ruleId(OnePredefinedRuleExternalIssuePerLineSensor.RULE_ID) .name("An ad hoc rule") .description("blah blah") .severity(Severity.BLOCKER) .type(RuleType.BUG) .save(); } } }
public JavaIssue addFlow(InputFile file, List<List<AnalyzerMessage>> flows) { for (List<AnalyzerMessage> flow : flows) { newIssue.addFlow(flow.stream() .map(am -> newIssue.newLocation() .on(file) .at(range(file, am.primaryLocation())) .message(am.getMessage())) .collect(Collectors.toList())); } return this; }
public JavaIssue addSecondaryLocation(InputFile file, int startLine, int startLineOffset, int endLine, int endLineOffset, String message) { newIssue.addLocation( newIssue.newLocation() .on(file) .at(file.newRange(startLine, startLineOffset, endLine, endLineOffset)) .message(message)); return this; }
public JavaIssue addSecondaryLocation(InputFile file, int startLine, int startLineOffset, int endLine, int endLineOffset, String message) { newIssue.addLocation( newIssue.newLocation() .on(file) .at(file.newRange(startLine, startLineOffset, endLine, endLineOffset)) .message(message)); return this; }
private static void saveLineIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, LineIssue issue) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(inputFile) .at(inputFile.selectLine(issue.line())); saveIssue(newIssue, primaryLocation, ruleKey, issue); }
/** * Reports an issue on specified file and at given line number */ public void reportIssue(InputFile file, int lineNumber, String msg) { NewIssue issue = context.newIssue(); issue.forRule(getRuleKey()).at(issue.newLocation().on(file).at(file.selectLine(lineNumber)).message(msg)).save(); }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange( location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange( location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }
private static NewIssueLocation newLocation(InputFile inputFile, NewIssue issue, IssueLocation location) { TextRange range = inputFile.newRange(location.startLine(), location.startLineOffset(), location.endLine(), location.endLineOffset()); NewIssueLocation newLocation = issue.newLocation() .on(inputFile) .at(range); if (location.message() != null) { newLocation.message(location.message()); } return newLocation; }