Refine search
@Override protected void processFile(InputFile inputFile, SensorContext context, RuleKey ruleKey, String languageKey) { NewIssue newIssue = context.newIssue() .forRule(ruleKey); newIssue.at(newIssue.newLocation() .on(inputFile) .message("This issue is generated on each file with a debt of one day")) .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(); } }
@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(); }
@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; }
@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); } } }
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 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(); } } }
NewIssue newIssue = context.newIssue().forRule(ruleKey); Integer issueId = entry.getKey(); NewIssueLocation primaryLocation = newIssue.newLocation() .on(file) .at(file.newRange(entry.getValue(), endPositions.get(issueId))); newIssue.at(primaryLocation.message("Primary location")); if (startFlowsPositions.containsKey(issueId)) { Table<Integer, Integer, TextPointer> flows = startFlowsPositions.get(issueId); TextPointer end = endFlowsPositions.get(issueId).row(flowId).get(flowNum); NewIssueLocation newLocation = newIssue.newLocation() .on(file) .at(file.newRange(start, end)) .message("Flow step #" + flowNum); flowLocations.add(newLocation);
private static void createIssues(InputFile file, SensorContext context) { ActiveRule rule = context.activeRules().findByInternalKey(XooRulesDefinition.XOO_REPOSITORY, context.settings().getString(INTERNAL_KEY_PROPERTY)); if (rule != null) { NewIssue newIssue = context.newIssue(); newIssue .forRule(rule.ruleKey()) .at(newIssue.newLocation() .on(file) .message("This issue is generated on each file")) .save(); } } }
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); }
public JavaIssue setPrimaryLocationOnFile(InputPath file, String message) { newIssue.at( newIssue.newLocation() .on(file) .message(message)); return this; }
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; }
private static void saveFileIssue(SensorContext sensorContext, InputFile inputFile, RuleKey ruleKey, FileIssue issue) { NewIssue newIssue = sensorContext.newIssue(); NewIssueLocation primaryLocation = newIssue.newLocation() .message(issue.message()) .on(inputFile); saveIssue(newIssue, primaryLocation, ruleKey, issue); }
@Override public Issue build() { if (newIssue.primaryLocation() == null) { NewIssueLocation newLocation = newIssue.newLocation().on(primaryComponent); if (primaryMessage != null) { newLocation.message(primaryMessage); } if (primaryComponent.isFile() && primaryRange != null) { newLocation.at(primaryRange); } newIssue.at(newLocation); } return new DeprecatedIssueWrapper(newIssue); }
private static void setSecondaryLocation(NewIssueLocation newSecondaryLocation, SecondaryLocation secondaryLocation, InputFile inputFile) { newSecondaryLocation.at(inputFile.newRange( secondaryLocation.startLine + 1, secondaryLocation.startCol, secondaryLocation.endLine + 1, secondaryLocation.endCol)); if (secondaryLocation.message != null) { newSecondaryLocation.message(secondaryLocation.message); } }
@Test public void testExternalIssues() { assertThat(tester.allExternalIssues()).isEmpty(); NewExternalIssue newExternalIssue = tester.newExternalIssue(); newExternalIssue .at(newExternalIssue.newLocation().message("message").on(new TestInputFileBuilder("foo", "src/Foo.java").build())) .forRule(RuleKey.of("repo", "rule")) .type(RuleType.BUG) .severity(Severity.BLOCKER) .save(); newExternalIssue = tester.newExternalIssue(); newExternalIssue .at(newExternalIssue.newLocation().message("message").on(new TestInputFileBuilder("foo", "src/Foo.java").build())) .type(RuleType.BUG) .severity(Severity.BLOCKER) .forRule(RuleKey.of("repo", "rule")) .save(); assertThat(tester.allExternalIssues()).hasSize(2); }
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 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(); } } }
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) .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();
private static void createIssues(InputFile file, SensorContext context) { ActiveRule rule = context.activeRules().findByInternalKey(XooRulesDefinition.XOO_REPOSITORY, context.settings().getString(INTERNAL_KEY_PROPERTY)); if (rule != null) { NewIssue newIssue = context.newIssue(); newIssue .forRule(rule.ruleKey()) .at(newIssue.newLocation() .on(file) .message("This issue is generated on each file")) .save(); } } }