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(); } }
/** * @return ServerID based on the SonarQube version */ public static String getServerId(SensorContext context) { String str = context.config().get(context.getSonarQubeVersion().isGreaterThanOrEqual(Version.parse("6.7")) ? CoreProperties.SERVER_ID : CoreProperties.PERMANENT_SERVER_ID).orElse(""); int dashIndex = str.indexOf('-'); return (dashIndex == 8) && (str.length() >= 20) ? str.substring(dashIndex + 1) : str; }
private static void importReport(File reportPath, SensorContext context, Set<String> unresolvedInputFiles) { try (InputStream in = new FileInputStream(reportPath)) { LOG.info("Importing {}", reportPath); boolean engineIdIsSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 4)); BanditJsonReportReader.read(in, issue -> saveIssue(context, issue, unresolvedInputFiles, engineIdIsSupported)); } catch (IOException | ParseException | RuntimeException e) { LOG.error("No issues information will be saved as the report file '{}' can't be read. " + e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e); } }
private static void importReport(File reportPath, SensorContext context, Set<String> unresolvedInputFiles) { try (InputStream in = new FileInputStream(reportPath)) { LOG.info("Importing {}", reportPath); boolean engineIdIsSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 4)); BanditJsonReportReader.read(in, issue -> saveIssue(context, issue, unresolvedInputFiles, engineIdIsSupported)); } catch (IOException | ParseException | RuntimeException e) { LOG.error("No issues information will be saved as the report file '{}' can't be read. " + e.getClass().getSimpleName() + ": " + e.getMessage(), reportPath, e); } }
public static List<File> getReportFiles(SensorContext context, String externalReportsProperty) { boolean externalIssuesSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 2)); String[] reportPaths = context.config().getStringArray(externalReportsProperty); if (reportPaths.length == 0) { return Collections.emptyList(); } if (!externalIssuesSupported) { LOG.error("Import of external issues requires SonarQube 7.2 or greater."); return Collections.emptyList(); } List<File> result = new ArrayList<>(); for (String reportPath : reportPaths) { File report = getIOFile(context.fileSystem().baseDir(), reportPath); result.add(report); } return result; }
@Override public void execute(SensorContext context) { boolean externalIssuesSupported = context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(7, 2)); String[] reportPaths = context.config().getStringArray(reportsPropertyName()); if (reportPaths.length == 0) { return; } if (!externalIssuesSupported) { LOG.error(logPrefix() + "Import of external issues requires SonarQube 7.2 or greater."); return; } for (String reportPath : reportPaths) { File report = getIOFile(context.fileSystem().baseDir(), reportPath); importReport(context, report); } }
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(); } }