@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); }
private void onViolationStartElement(StartElement element) { try { TextRange textRange = textRange(element); RuleKey ruleKey = RuleKey.of(PmdSensor.LINTER_KEY, getAttributeValue(element, "rule")); issue = context.newExternalIssue() .forRule(ruleKey) .type(RuleType.CODE_SMELL) .severity(SEVERITIES.get(getAttributeAsInt(element, "priority"))) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(ruleKey.rule())); issueLocation = issue.newLocation() .on(inputFile) .at(textRange); issueMessage = new StringBuilder(); } catch (RuntimeException e) { int lineNumber = element.getLocation().getLineNumber(); LOG.warn("Can't import issue at line " + lineNumber + " in " + reportFile + ": " + e.getMessage()); issue = null; } }
private void onViolationStartElement(StartElement element) { try { TextRange textRange = textRange(element); RuleKey ruleKey = RuleKey.of(PmdSensor.LINTER_KEY, getAttributeValue(element, "rule")); issue = context.newExternalIssue() .forRule(ruleKey) .type(RuleType.CODE_SMELL) .severity(SEVERITIES.get(getAttributeAsInt(element, "priority"))) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(ruleKey.rule())); issueLocation = issue.newLocation() .on(inputFile) .at(textRange); issueMessage = new StringBuilder(); } catch (RuntimeException e) { int lineNumber = element.getLocation().getLineNumber(); LOG.warn("Can't import issue at line " + lineNumber + " in " + reportFile + ": " + e.getMessage()); issue = null; } }
public static void saveIssue(SensorContext context, ExternalRuleLoader ruleLoader, InputFile inputFile, RuleKey ruleKey, String line, String message) { NewExternalIssue newExternalIssue = context.newExternalIssue(); newExternalIssue .type(ruleLoader.ruleType(ruleKey.rule())) .severity(ruleLoader.ruleSeverity(ruleKey.rule())) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(ruleKey.rule())); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(message) .on(inputFile); if (!line.isEmpty() && !line.equals("0")) { primaryLocation.at(inputFile.selectLine(Integer.parseInt(line))); } newExternalIssue .at(primaryLocation) .forRule(ruleKey) .save(); }
public static void saveIssue(SensorContext context, ExternalRuleLoader ruleLoader, InputFile inputFile, RuleKey ruleKey, String line, String message) { NewExternalIssue newExternalIssue = context.newExternalIssue(); newExternalIssue .type(ruleLoader.ruleType(ruleKey.rule())) .severity(ruleLoader.ruleSeverity(ruleKey.rule())) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(ruleKey.rule())); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(message) .on(inputFile); if (!line.isEmpty() && !line.equals("0")) { primaryLocation.at(inputFile.selectLine(Integer.parseInt(line))); } newExternalIssue .at(primaryLocation) .forRule(ruleKey) .save(); }
private void saveTslintError(SensorContext context, TslintError tslintError) { String tslintKey = tslintError.ruleName; if (activatedRules.containsKey(tslintKey)) { String message = "TSLint issue for rule '{}' is skipped because this rule is activated in your SonarQube profile for TypeScript (rule key in SQ {})"; LOG.debug(message, tslintKey, activatedRules.get(tslintKey)); return; } InputFile inputFile = getInputFile(context, tslintError.name); if (inputFile == null) { return; } NewExternalIssue newExternalIssue = context.newExternalIssue(); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(tslintError.failure) .on(inputFile) .at(getLocation(tslintError, inputFile)); newExternalIssue .at(primaryLocation) .forRule(RuleKey.of(REPOSITORY, tslintKey)) .type(TSLintRulesDefinition.ruleType(tslintKey)) .severity(DEFAULT_SEVERITY) .remediationEffortMinutes(DEFAULT_REMEDIATION_COST) .save(); }
private static void saveIssue(SensorContext context, Issue issue, Set<String> unresolvedInputFiles, boolean engineIdIsSupported) { if (isEmpty(issue.ruleKey) || isEmpty(issue.filePath) || isEmpty(issue.message)) { LOG.debug("Missing information for ruleKey:'{}', filePath:'{}', message:'{}'", issue.ruleKey, issue.filePath, issue.message); return; } InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(issue.filePath)); if (inputFile == null) { unresolvedInputFiles.add(issue.filePath); return; } NewExternalIssue newExternalIssue = context.newExternalIssue(); newExternalIssue .type(RuleType.VULNERABILITY) .severity(toSonarQubeSeverity(issue.severity, issue.confidence)) .remediationEffortMinutes(DEFAULT_CONSTANT_DEBT_MINUTES); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(issue.message) .on(inputFile); if (issue.lineNumber != null) { primaryLocation.at(inputFile.selectLine(issue.lineNumber)); } newExternalIssue.at(primaryLocation); if (engineIdIsSupported) { newExternalIssue.engineId(LINTER_KEY).ruleId(issue.ruleKey); } else { // Call the deprecated "forRule" method to support SQ 7.2 newExternalIssue.forRule(RuleKey.of(LINTER_KEY, issue.ruleKey)); } newExternalIssue.save(); }
private static void saveIssue(SensorContext context, Issue issue, Set<String> unresolvedInputFiles, boolean engineIdIsSupported) { if (isEmpty(issue.ruleKey) || isEmpty(issue.filePath) || isEmpty(issue.message)) { LOG.debug("Missing information for ruleKey:'{}', filePath:'{}', message:'{}'", issue.ruleKey, issue.filePath, issue.message); return; } InputFile inputFile = context.fileSystem().inputFile(context.fileSystem().predicates().hasPath(issue.filePath)); if (inputFile == null) { unresolvedInputFiles.add(issue.filePath); return; } NewExternalIssue newExternalIssue = context.newExternalIssue(); newExternalIssue .type(RuleType.VULNERABILITY) .severity(toSonarQubeSeverity(issue.severity, issue.confidence)) .remediationEffortMinutes(DEFAULT_CONSTANT_DEBT_MINUTES); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(issue.message) .on(inputFile); if (issue.lineNumber != null) { primaryLocation.at(inputFile.selectLine(issue.lineNumber)); } newExternalIssue.at(primaryLocation); if (engineIdIsSupported) { newExternalIssue.engineId(LINTER_KEY).ruleId(issue.ruleKey); } else { // Call the deprecated "forRule" method to support SQ 7.2 newExternalIssue.forRule(RuleKey.of(LINTER_KEY, issue.ruleKey)); } newExternalIssue.save(); }
void addLineIssue(SensorContext context, ExternalIssue issue) { InputFile inputFile = getInputFile(context, issue.filename); if (inputFile != null) { NewExternalIssue newExternalIssue = context.newExternalIssue(); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(issue.message) .on(inputFile) .at(inputFile.selectLine(issue.lineNumber)); newExternalIssue .at(primaryLocation) .forRule(RuleKey.of(issue.linter, issue.ruleKey)) .type(issue.type) .severity(DEFAULT_SEVERITY) .remediationEffortMinutes(DEFAULT_REMEDIATION_COST) .save(); } }
private static void saveEslintError(SensorContext context, EslintError eslintError, InputFile inputFile) { String eslintKey = eslintError.ruleId; if (eslintKey == null) { LOG.warn("Parse error issue from ESLint will not be imported, file " + inputFile.uri()); return; } NewExternalIssue newExternalIssue = context.newExternalIssue(); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(eslintError.message) .on(inputFile) .at(getLocation(eslintError, inputFile)); ExternalRuleLoader ruleLoader = EslintRulesDefinition.loader(eslintKey); newExternalIssue .at(primaryLocation) .forRule(RuleKey.of(REPO_KEY, eslintKey)) .type(ruleLoader.ruleType(eslintKey)) .severity(ruleLoader.ruleSeverity(eslintKey)) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(eslintKey)) .save(); }
private static void saveEslintError(SensorContext context, EslintError eslintError, InputFile inputFile) { String eslintKey = eslintError.ruleId; if (eslintKey == null) { LOG.warn("Parse error issue from ESLint will not be imported, file " + inputFile.uri()); return; } NewExternalIssue newExternalIssue = context.newExternalIssue(); NewIssueLocation primaryLocation = newExternalIssue.newLocation() .message(eslintError.message) .on(inputFile) .at(getLocation(eslintError, inputFile)); ExternalRuleLoader ruleLoader = EslintRulesDefinition.loader(eslintKey); newExternalIssue .at(primaryLocation) .forRule(RuleKey.of(REPO_KEY, eslintKey)) .type(ruleLoader.ruleType(eslintKey)) .severity(ruleLoader.ruleSeverity(eslintKey)) .remediationEffortMinutes(ruleLoader.ruleConstantDebtMinutes(eslintKey)) .save(); }