@Test public void testExecute() throws IOException { Assume.assumeFalse("OS not mac", System.getProperty("os.name").toLowerCase().indexOf("mac") >= 0); SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot()); ctxTester.fileSystem().setWorkDir(folder.getRoot().toPath()); File baseFile = folder.newFile("sample2.sql"); File resFile = folder.newFile("staticcodeanalysis.results.xml"); FileUtils.write(resFile, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<Problems>" + "<Problem>" + "<Line>1</Line>" + "<Rule>S1</Rule>" + "<ProblemDescription>Test</ProblemDescription>" + "<Severity>MAJOR</Severity>" + "<SourceFile>" + baseFile.getAbsolutePath() + "</SourceFile>" + "</Problem></Problems>", Charset.defaultCharset()); FileUtils.copyURLToFile(getClass().getResource("/tsql/sample2.sql"), baseFile); String contents = new String(Files.readAllBytes(baseFile.toPath())); DefaultInputFile ti = new TestInputFileBuilder("test", folder.getRoot(), baseFile).initMetadata(contents) .setLanguage(Constants.languageKey).setContents(contents).build(); ctxTester.fileSystem().add(ti); MSIssuesSensor s = new MSIssuesSensor(); s.execute(ctxTester); Assert.assertEquals(1, ctxTester.allExternalIssues().size()); Assert.assertEquals(0, ctxTester.allIssues().size()); Assert.assertEquals(0, ctxTester.allAdHocRules().size()); }
@Override public void execute(final SensorContext context) { final File baseDir = context.fileSystem().baseDir(); final String filePath = context.config().get(Constants.TSQL_MS_ISSUES).orElse(Constants.TSQL_MS_ISSUES_DEFAULT) .toLowerCase(); try { Files.walk(baseDir.toPath()) .filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(filePath)) .forEach(p -> { LOGGER.debug("Found file with issues {}", p.toString()); try (final BOMInputStream stream = new BOMInputStream(new FileInputStream(p.toFile()))) { final SqlIssuesList issues = read(stream); addIssues(context, issues, null); } catch (IOException e1) { LOGGER.warn("Unexpected IO error: " + p.toString(), e1); } catch (Exception e) { LOGGER.warn("Unexpected error: " + p.toString(), e); } }); } catch (Throwable e) { LOGGER.warn("Unexpected error", e); } }
MSIssuesSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final File baseDir = context.fileSystem().baseDir(); final String filePath = context.config().get(Constants.TSQL_MS_ISSUES).orElse(Constants.TSQL_MS_ISSUES_DEFAULT) .toLowerCase(); try { Files.walk(baseDir.toPath()) .filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(filePath)) .forEach(p -> { LOGGER.debug("Found file with issues {}", p.toString()); try (final BOMInputStream stream = new BOMInputStream(new FileInputStream(p.toFile()))) { final SqlIssuesList issues = read(stream); addIssues(context, issues, null); } catch (IOException e1) { LOGGER.warn("Unexpected IO error: " + p.toString(), e1); } catch (Exception e) { LOGGER.warn("Unexpected error: " + p.toString(), e); } }); } catch (Throwable e) { LOGGER.warn("Unexpected error", e); } } }
MSIssuesSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final File baseDir = context.fileSystem().baseDir(); final String filePath = context.config().get(Constants.TSQL_MS_ISSUES).orElse(Constants.TSQL_MS_ISSUES_DEFAULT) .toLowerCase(); try { Files.walk(baseDir.toPath()) .filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(filePath)) .forEach(p -> { LOGGER.debug("Found file with issues {}", p.toString()); try (final BOMInputStream stream = new BOMInputStream(new FileInputStream(p.toFile()))) { final SqlIssuesList issues = read(stream); addIssues(context, issues, null); } catch (IOException e1) { LOGGER.warn("Unexpected IO error: " + p.toString(), e1); } catch (Exception e) { LOGGER.warn("Unexpected error: " + p.toString(), e); } }); } catch (Throwable e) { LOGGER.warn("Unexpected error", e); } }  }
MSIssuesSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final File baseDir = context.fileSystem().baseDir(); final String filePath = context.config().get(Constants.TSQL_MS_ISSUES).orElse(Constants.TSQL_MS_ISSUES_DEFAULT) .toLowerCase(); try { Files.walk(baseDir.toPath()) .filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(filePath)) .forEach(p -> { LOGGER.debug("Found file with issues {}", p.toString()); try (final BOMInputStream stream = new BOMInputStream(new FileInputStream(p.toFile()))) { final SqlIssuesList issues = read(stream); addIssues(context, issues, null); } catch (IOException e1) { LOGGER.warn("Unexpected IO error: " + p.toString(), e1); } catch (Exception e) { LOGGER.warn("Unexpected error: " + p.toString(), e); } }); } catch (Throwable e) { LOGGER.warn("Unexpected error", e); } }  @Override void describe(SensorDescriptor descriptor); @Override void execute(final SensorContext context); }
MSIssuesSensor extends BaseSensor implements Sensor { @Override public void execute(final SensorContext context) { final File baseDir = context.fileSystem().baseDir(); final String filePath = context.config().get(Constants.TSQL_MS_ISSUES).orElse(Constants.TSQL_MS_ISSUES_DEFAULT) .toLowerCase(); try { Files.walk(baseDir.toPath()) .filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().contains(filePath)) .forEach(p -> { LOGGER.debug("Found file with issues {}", p.toString()); try (final BOMInputStream stream = new BOMInputStream(new FileInputStream(p.toFile()))) { final SqlIssuesList issues = read(stream); addIssues(context, issues, null); } catch (IOException e1) { LOGGER.warn("Unexpected IO error: " + p.toString(), e1); } catch (Exception e) { LOGGER.warn("Unexpected error: " + p.toString(), e); } }); } catch (Throwable e) { LOGGER.warn("Unexpected error", e); } }  @Override void describe(SensorDescriptor descriptor); @Override void execute(final SensorContext context);  }