1919
2020import java .io .IOException ;
2121import java .nio .charset .Charset ;
22- import java .util .concurrent .ExecutorService ;
23- import java .util .concurrent .Executors ;
24- import java .util .concurrent .TimeUnit ;
25-
2622import org .sonar .api .batch .fs .FilePredicate ;
2723import org .sonar .api .batch .fs .InputFile ;
2824import org .sonar .api .batch .sensor .Sensor ;
3834import org .sonar .api .utils .log .Logger ;
3935import org .sonar .api .utils .log .Loggers ;
4036
37+ import javax .annotation .Nonnull ;
4138import javax .annotation .ParametersAreNonnullByDefault ;
4239
4340public class DartSensor implements Sensor {
4441
4542 private static final Logger LOGGER = Loggers .get (DartSensor .class );
46- private static final int EXECUTOR_TIMEOUT = 10000 ;
4743
4844 @ Override
49- public void describe (SensorDescriptor sensorDescriptor ) {
45+ public void describe (@ Nonnull SensorDescriptor sensorDescriptor ) {
5046 sensorDescriptor
5147 .onlyOnLanguage (Dart .KEY )
5248 .name ("Dart sensor" )
@@ -63,46 +59,32 @@ public void execute(SensorContext sensorContext) {
6359 FilePredicate dartAndTest = sensorContext .fileSystem ().predicates ().and (hasDart , isTest );
6460 final Charset charset = sensorContext .fileSystem ().encoding ();
6561
66- final ExecutorService executorService = Executors .newWorkStealingPool ();
67-
68- for (InputFile inf : sensorContext .fileSystem ().inputFiles (dartAndMain )){
62+ for (InputFile inf : sensorContext .fileSystem ().inputFiles (dartAndMain )) {
6963
70- executorService .execute (() -> {
71- // Visit source files
72- try {
73- final AntlrContext antlrContext = AntlrContext .fromInputFile (inf , charset );
74- ParseTreeItemVisitor visitor = new CustomTreeVisitor (new HighlighterVisitor (),
75- new SourceLinesVisitor (), new CyclomaticComplexityVisitor ());
76- visitor .fillContext (sensorContext , antlrContext );
77- } catch (IOException e ) {
78- LOGGER .warn ("Unexpected error while analyzing file " + inf .filename (), e );
79- }
80- });
64+ // Visit source files
65+ try {
66+ final AntlrContext antlrContext = AntlrContext .fromInputFile (inf , charset );
67+ ParseTreeItemVisitor visitor = new CustomTreeVisitor (new HighlighterVisitor (),
68+ new SourceLinesVisitor (), new CyclomaticComplexityVisitor ());
69+ visitor .fillContext (sensorContext , antlrContext );
70+ } catch (IOException e ) {
71+ LOGGER .warn ("Unexpected error while analyzing file " + inf .filename (), e );
72+ }
8173
8274 }
8375
84- for (InputFile inf : sensorContext .fileSystem ().inputFiles (dartAndTest )){
76+ for (InputFile inf : sensorContext .fileSystem ().inputFiles (dartAndTest )) {
8577
86- executorService .execute (() -> {
87- // Visit test files (for syntax highlighting only)
88- try {
89- final AntlrContext antlrContext = AntlrContext .fromInputFile (inf , charset );
90- ParseTreeItemVisitor visitor = new CustomTreeVisitor (new HighlighterVisitor ());
91- visitor .fillContext (sensorContext , antlrContext );
92- } catch (IOException e ) {
93- LOGGER .warn ("Unexpected error while analyzing file " + inf .filename (), e );
94- }
95- });
78+ // Visit test files (for syntax highlighting only)
79+ try {
80+ final AntlrContext antlrContext = AntlrContext .fromInputFile (inf , charset );
81+ ParseTreeItemVisitor visitor = new CustomTreeVisitor (new HighlighterVisitor ());
82+ visitor .fillContext (sensorContext , antlrContext );
83+ } catch (IOException e ) {
84+ LOGGER .warn ("Unexpected error while analyzing file " + inf .filename (), e );
85+ }
9686
9787 }
9888
99- try {
100- executorService .shutdown ();
101- executorService .awaitTermination (EXECUTOR_TIMEOUT , TimeUnit .SECONDS );
102- executorService .shutdownNow ();
103- } catch (final InterruptedException e ) {
104- LOGGER .warn ("Unexpected error while running waiting for executor service to finish" , e );
105- Thread .currentThread ().interrupt ();
106- }
10789 }
10890}
0 commit comments