@Test public void test() throws IOException { File baseFile = folder.newFile("results.txt"); FileUtils.copyURLToFile(getClass().getResource("/external/sqlcheck.txt"), baseFile); SQLCheckIssuesReader sut = new SQLCheckIssuesReader(); SqlIssuesList results = sut.read("-", baseFile); Assert.assertEquals(4, results.getaLLIssues().size()); }
public SqlIssuesList read(String inputFile, File file) throws IOException { SqlIssuesList list = new SqlIssuesList(); List<String> lines = Files.readAllLines(file.toPath()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.startsWith("SQL Statement: ")) { continue; } String severityDescription = lines.get(i + 1).trim(); for (int j = i + 2; j < lines.size(); j++) { String issueName = lines.get(j).trim(); ; if (issueName.isEmpty()) { continue; } if (lines.get(j).startsWith("------") || lines.get(j).startsWith("SQL Statement")) { break; } if (issueName.startsWith("● ")) { try { StringBuilder descriptionSb = new StringBuilder(); for (int z = j + 1; z < lines.size(); z++) { String tempLine = lines.get(z).trim(); if (tempLine.startsWith("● ") || tempLine.isEmpty() || tempLine.startsWith("SQL Statement")) { break; } if (tempLine.equalsIgnoreCase("Problems:")) { continue; } descriptionSb.append(tempLine); } if (descriptionSb.length() == 0 || severityDescription.isEmpty() || issueName.isEmpty()) { continue; } SqlIssue issue = new SqlIssue(); issue.description = descriptionSb.toString().trim(); issue.fileName = inputFile; issue.severity = extractSeverity(severityDescription); issue.message = extractMessage(severityDescription); issue.name = extractName(issueName); issue.repo = Constants.SQL_SQLCHECK_ENGINEID; issue.isAdhoc = true; issue.isExternal = true; list.addIssue(issue); } catch (Exception e) { LOGGER.info("Unexpected error reading: {}. Exception was: {}", line, e); } } } } return list; }
SQLCheckIssuesReader { public SqlIssuesList read(String inputFile, File file) throws IOException { SqlIssuesList list = new SqlIssuesList(); List<String> lines = Files.readAllLines(file.toPath()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.startsWith("SQL Statement: ")) { continue; } String severityDescription = lines.get(i + 1).trim(); for (int j = i + 2; j < lines.size(); j++) { String issueName = lines.get(j).trim(); ; if (issueName.isEmpty()) { continue; } if (lines.get(j).startsWith("------") || lines.get(j).startsWith("SQL Statement")) { break; } if (issueName.startsWith("● ")) { try { StringBuilder descriptionSb = new StringBuilder(); for (int z = j + 1; z < lines.size(); z++) { String tempLine = lines.get(z).trim(); if (tempLine.startsWith("● ") || tempLine.isEmpty() || tempLine.startsWith("SQL Statement")) { break; } if (tempLine.equalsIgnoreCase("Problems:")) { continue; } descriptionSb.append(tempLine); } if (descriptionSb.length() == 0 || severityDescription.isEmpty() || issueName.isEmpty()) { continue; } SqlIssue issue = new SqlIssue(); issue.description = descriptionSb.toString().trim(); issue.fileName = inputFile; issue.severity = extractSeverity(severityDescription); issue.message = extractMessage(severityDescription); issue.name = extractName(issueName); issue.repo = Constants.SQL_SQLCHECK_ENGINEID; issue.isAdhoc = true; issue.isExternal = true; list.addIssue(issue); } catch (Exception e) { LOGGER.info("Unexpected error reading: {}. Exception was: {}", line, e); } } } } return list; } }
SQLCheckIssuesReader { public SqlIssuesList read(String inputFile, File file) throws IOException { SqlIssuesList list = new SqlIssuesList(); List<String> lines = Files.readAllLines(file.toPath()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.startsWith("SQL Statement: ")) { continue; } String severityDescription = lines.get(i + 1).trim(); for (int j = i + 2; j < lines.size(); j++) { String issueName = lines.get(j).trim(); ; if (issueName.isEmpty()) { continue; } if (lines.get(j).startsWith("------") || lines.get(j).startsWith("SQL Statement")) { break; } if (issueName.startsWith("● ")) { try { StringBuilder descriptionSb = new StringBuilder(); for (int z = j + 1; z < lines.size(); z++) { String tempLine = lines.get(z).trim(); if (tempLine.startsWith("● ") || tempLine.isEmpty() || tempLine.startsWith("SQL Statement")) { break; } if (tempLine.equalsIgnoreCase("Problems:")) { continue; } descriptionSb.append(tempLine); } if (descriptionSb.length() == 0 || severityDescription.isEmpty() || issueName.isEmpty()) { continue; } SqlIssue issue = new SqlIssue(); issue.description = descriptionSb.toString().trim(); issue.fileName = inputFile; issue.severity = extractSeverity(severityDescription); issue.message = extractMessage(severityDescription); issue.name = extractName(issueName); issue.repo = Constants.SQL_SQLCHECK_ENGINEID; issue.isAdhoc = true; issue.isExternal = true; list.addIssue(issue); } catch (Exception e) { LOGGER.info("Unexpected error reading: {}. Exception was: {}", line, e); } } } } return list; }  }
SQLCheckIssuesReader { public SqlIssuesList read(String inputFile, File file) throws IOException { SqlIssuesList list = new SqlIssuesList(); List<String> lines = Files.readAllLines(file.toPath()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.startsWith("SQL Statement: ")) { continue; } String severityDescription = lines.get(i + 1).trim(); for (int j = i + 2; j < lines.size(); j++) { String issueName = lines.get(j).trim(); ; if (issueName.isEmpty()) { continue; } if (lines.get(j).startsWith("------") || lines.get(j).startsWith("SQL Statement")) { break; } if (issueName.startsWith("● ")) { try { StringBuilder descriptionSb = new StringBuilder(); for (int z = j + 1; z < lines.size(); z++) { String tempLine = lines.get(z).trim(); if (tempLine.startsWith("● ") || tempLine.isEmpty() || tempLine.startsWith("SQL Statement")) { break; } if (tempLine.equalsIgnoreCase("Problems:")) { continue; } descriptionSb.append(tempLine); } if (descriptionSb.length() == 0 || severityDescription.isEmpty() || issueName.isEmpty()) { continue; } SqlIssue issue = new SqlIssue(); issue.description = descriptionSb.toString().trim(); issue.fileName = inputFile; issue.severity = extractSeverity(severityDescription); issue.message = extractMessage(severityDescription); issue.name = extractName(issueName); issue.repo = Constants.SQL_SQLCHECK_ENGINEID; issue.isAdhoc = true; issue.isExternal = true; list.addIssue(issue); } catch (Exception e) { LOGGER.info("Unexpected error reading: {}. Exception was: {}", line, e); } } } } return list; }  SqlIssuesList read(String inputFile, File file); }
SQLCheckIssuesReader { public SqlIssuesList read(String inputFile, File file) throws IOException { SqlIssuesList list = new SqlIssuesList(); List<String> lines = Files.readAllLines(file.toPath()); for (int i = 0; i < lines.size(); i++) { String line = lines.get(i); if (!line.startsWith("SQL Statement: ")) { continue; } String severityDescription = lines.get(i + 1).trim(); for (int j = i + 2; j < lines.size(); j++) { String issueName = lines.get(j).trim(); ; if (issueName.isEmpty()) { continue; } if (lines.get(j).startsWith("------") || lines.get(j).startsWith("SQL Statement")) { break; } if (issueName.startsWith("● ")) { try { StringBuilder descriptionSb = new StringBuilder(); for (int z = j + 1; z < lines.size(); z++) { String tempLine = lines.get(z).trim(); if (tempLine.startsWith("● ") || tempLine.isEmpty() || tempLine.startsWith("SQL Statement")) { break; } if (tempLine.equalsIgnoreCase("Problems:")) { continue; } descriptionSb.append(tempLine); } if (descriptionSb.length() == 0 || severityDescription.isEmpty() || issueName.isEmpty()) { continue; } SqlIssue issue = new SqlIssue(); issue.description = descriptionSb.toString().trim(); issue.fileName = inputFile; issue.severity = extractSeverity(severityDescription); issue.message = extractMessage(severityDescription); issue.name = extractName(issueName); issue.repo = Constants.SQL_SQLCHECK_ENGINEID; issue.isAdhoc = true; issue.isExternal = true; list.addIssue(issue); } catch (Exception e) { LOGGER.info("Unexpected error reading: {}. Exception was: {}", line, e); } } } } return list; }  SqlIssuesList read(String inputFile, File file);  }