@Test public void should_cancel_progress_report_and_return_with_no_exception_when_context_cancelled() { JavaScriptCheck check = new DoubleDispatchVisitorCheck() {}; JavaScriptSensor sensor = createSensor(); SensorContextTester cancelledContext = SensorContextTester.create(baseDir); cancelledContext.setCancelled(true); sensor.analyseFiles(cancelledContext, ImmutableList.of((TreeVisitor) check), ImmutableList.of(inputFile("cpd/Person.js")), progressReport); verify(progressReport).cancel(); }
@VisibleForTesting protected void analyseFiles( SensorContext context, List<TreeVisitor> treeVisitors, Iterable<InputFile> inputFiles, ProgressReport progressReport) { boolean success = false; try { for (InputFile inputFile : inputFiles) { if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, treeVisitors); progressReport.nextFile(); } success = true; } catch (CancellationException e) { LOG.info(e.toString()); } finally { stopProgressReport(progressReport, success); } }
JavaScriptSensor { @VisibleForTesting protected void analyseFiles( SensorContext context, List<TreeVisitor> treeVisitors, Iterable<InputFile> inputFiles, ProgressReport progressReport) { boolean success = false; try { for (InputFile inputFile : inputFiles) { if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, treeVisitors); progressReport.nextFile(); } success = true; } catch (CancellationException e) { LOG.info(e.toString()); } finally { stopProgressReport(progressReport, success); } } }
JavaScriptSensor { @VisibleForTesting protected void analyseFiles( SensorContext context, List<TreeVisitor> treeVisitors, Iterable<InputFile> inputFiles, ProgressReport progressReport) { boolean success = false; try { for (InputFile inputFile : inputFiles) { if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, treeVisitors); progressReport.nextFile(); } success = true; } catch (CancellationException e) { LOG.info(e.toString()); } finally { stopProgressReport(progressReport, success); } } JavaScriptSensor(AbstractChecks checks); }
JavaScriptSensor { @VisibleForTesting protected void analyseFiles( SensorContext context, List<TreeVisitor> treeVisitors, Iterable<InputFile> inputFiles, ProgressReport progressReport) { boolean success = false; try { for (InputFile inputFile : inputFiles) { if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, treeVisitors); progressReport.nextFile(); } success = true; } catch (CancellationException e) { LOG.info(e.toString()); } finally { stopProgressReport(progressReport, success); } } JavaScriptSensor(AbstractChecks checks); void execute(SensorContext context); }
JavaScriptSensor { @VisibleForTesting protected void analyseFiles( SensorContext context, List<TreeVisitor> treeVisitors, Iterable<InputFile> inputFiles, ProgressReport progressReport) { boolean success = false; try { for (InputFile inputFile : inputFiles) { if (context.isCancelled()) { throw new CancellationException("Analysis interrupted because the SensorContext is in cancelled state"); } analyse(context, inputFile, treeVisitors); progressReport.nextFile(); } success = true; } catch (CancellationException e) { LOG.info(e.toString()); } finally { stopProgressReport(progressReport, success); } } JavaScriptSensor(AbstractChecks checks); void execute(SensorContext context);  }