@Test public void test_fail_input() throws IOException { InputFile inputFile = createInputFile("fakeFile.slang", ""); InputFile spyInputFile = spy(inputFile); when(spyInputFile.contents()).thenThrow(IOException.class); context.fileSystem().add(spyInputFile); CheckFactory checkFactory = checkFactory("S1764"); sensor(checkFactory).execute(context); Collection<AnalysisError> analysisErrors = context.allAnalysisErrors(); assertThat(analysisErrors).hasSize(1); AnalysisError analysisError = analysisErrors.iterator().next(); assertThat(analysisError.inputFile()).isEqualTo(spyInputFile); assertThat(analysisError.message()).isEqualTo("Unable to parse file: fakeFile.slang"); assertThat(analysisError.location()).isNull(); assertThat(logTester.logs()).contains(String.format("Unable to parse file: %s. ", inputFile.uri())); }
@Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext sensorContext); }
SlangSensor implements Sensor { @Override public void execute(SensorContext sensorContext) { DurationStatistics statistics = new DurationStatistics(sensorContext.config()); FileSystem fileSystem = sensorContext.fileSystem(); FilePredicate mainFilePredicate = fileSystem.predicates().and( fileSystem.predicates().hasLanguage(language.getKey()), fileSystem.predicates().hasType(InputFile.Type.MAIN)); Iterable<InputFile> inputFiles = fileSystem.inputFiles(mainFilePredicate); List<String> filenames = StreamSupport.stream(inputFiles.spliterator(), false).map(InputFile::toString).collect(Collectors.toList()); ProgressReport progressReport = new ProgressReport("Progress of the " + language.getName() + " analysis", TimeUnit.SECONDS.toMillis(10)); progressReport.start(filenames); boolean success = false; ASTConverter converter = ASTConverterValidation.wrap(astConverter(sensorContext), sensorContext.config()); try { success = analyseFiles(converter, sensorContext, inputFiles, progressReport, visitors(sensorContext, statistics), statistics); } finally { if (success) { progressReport.stop(); } else { progressReport.cancel(); } converter.terminate(); } statistics.log(); } SlangSensor(NoSonarFilter noSonarFilter, FileLinesContextFactory fileLinesContextFactory, Language language); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext sensorContext);  }