16
16
*/
17
17
package fr .cnes .sonar .plugins .icode .check ;
18
18
19
- import com .google .common .collect .Lists ;
20
- import com .google .common .collect .Maps ;
21
- import fr .cnes .icode .data .AbstractChecker ;
19
+ import fr .cnes .icode .Analyzer ;
22
20
import fr .cnes .icode .data .CheckResult ;
23
- import fr .cnes .icode .logger .ICodeLogger ;
24
- import fr .cnes .icode .services .checkers .CheckerContainer ;
25
- import fr .cnes .icode .services .checkers .CheckerService ;
26
- import fr .cnes .icode .services .languages .ILanguage ;
27
21
import fr .cnes .icode .services .languages .LanguageService ;
28
22
import fr .cnes .sonar .plugins .icode .exceptions .ICodeException ;
29
23
import fr .cnes .sonar .plugins .icode .languages .Fortran77Language ;
52
46
import java .io .FileInputStream ;
53
47
import java .io .FileNotFoundException ;
54
48
import java .io .IOException ;
55
- import java .net .URI ;
56
49
import java .nio .file .Paths ;
57
50
import java .util .*;
58
51
@@ -176,6 +169,7 @@ protected void executeExternalResultsImport(final SensorContext sensorContext) {
176
169
*/
177
170
private void executeEmbeddedICode (final SensorContext sensorContext ) {
178
171
// Initialisation of tools for analysis.
172
+ final Analyzer analyzer = new Analyzer ();
179
173
final FileSystem fileSystem = sensorContext .fileSystem ();
180
174
final FilePredicates predicates = fileSystem .predicates ();
181
175
final ActiveRules activeRules = sensorContext .activeRules ();
@@ -190,7 +184,7 @@ private void executeEmbeddedICode(final SensorContext sensorContext) {
190
184
}
191
185
192
186
// Run all checkers on all files.
193
- final List <CheckResult > results = sonarCheck (files , LanguageService .getLanguagesIds (), null );
187
+ final List <CheckResult > results = analyzer . stableCheck (files , LanguageService .getLanguagesIds (), null );
194
188
195
189
// Add each issue to SonarQube.
196
190
for (final CheckResult result : results ) {
@@ -209,87 +203,6 @@ private void executeEmbeddedICode(final SensorContext sensorContext) {
209
203
210
204
}
211
205
212
- /**
213
- * This method apply all rules of the different contributions set in
214
- * parameter except the one excluded. File in parameters are being analyzed
215
- * by each contribution able to handle it or none if it isn't.
216
- *
217
- * Important: Default configurations to run analysis are
218
- * available when setting parameters.
219
- *
220
- * @param pInputFiles
221
- * to analyze
222
- * @param pLanguageIds
223
- * to include in the analysis. <strong>Set null</strong> to run
224
- * an analysis including all contributions.
225
- * @param pExcludedCheckIds
226
- * rules identifier to exclude from the analysis. <strong>Set
227
- * null</strong> run analysis with every rules.
228
- * @return list of {@link CheckResult} found by the analysis.
229
- */
230
- public List <CheckResult > sonarCheck (final Set <File > pInputFiles , final List <String > pLanguageIds ,
231
- final List <String > pExcludedCheckIds ) {
232
- final String methodName = "check" ;
233
- ICodeLogger .entering (this .getClass ().getName (), methodName );
234
-
235
- List <String > languageIds = pLanguageIds ;
236
- if (languageIds == null ) {
237
- languageIds = LanguageService .getLanguagesIds ();
238
- }
239
- List <String > excludedCheckIds = pExcludedCheckIds ;
240
- if (pExcludedCheckIds == null ) {
241
- excludedCheckIds = new ArrayList <>();
242
- }
243
- final List <CheckResult > analysisResultCheckResult = new ArrayList <>();
244
-
245
- // Contains checkers by language.
246
- final Map <String ,List <CheckerContainer >> checkers = Maps .newHashMap ();
247
- // Contains files by language.
248
- final Map <String , List <File >> inputs = Maps .newLinkedHashMap ();
249
- // Get languages to check during the analysis.
250
- final List <ILanguage > languages = LanguageService .getLanguages (languageIds );
251
- // Get checkers to run during analysis.
252
- for (final ILanguage language : languages ) {
253
- checkers .put (language .getId (), CheckerService .getCheckers (language .getId (), excludedCheckIds ));
254
- }
255
-
256
- // Sort files by language.
257
- for (final File file : pInputFiles ) {
258
- final String languageId = LanguageService .getLanguageId (getFileExtension (file .getAbsolutePath ()));
259
- final List <File > tempList = inputs .getOrDefault (languageId , Lists .newArrayList ());
260
- tempList .add (file );
261
- inputs .put (languageId , tempList );
262
- }
263
- // For each selected language, run selected checkers on selected files.
264
- for (final ILanguage language : languages ) {
265
- for (final File input : inputs .getOrDefault (language .getId (), Lists .newArrayList ())) {
266
- for (final CheckerContainer checker : checkers .get (language .getId ())) {
267
- try {
268
- AbstractChecker check = checker .getChecker ();
269
- check .setInputFile (input );
270
- analysisResultCheckResult .addAll (check .run ());
271
- } catch (final Exception e ) {
272
- // Set the error message.
273
- final String errorMessage = String .format ("Internal i-Code error: exception [%s] thrown while checking [%s] on file [%s] - %s" ,
274
- e .getClass ().getSimpleName (), checker .getName (), input .getPath (), e .getMessage ());
275
- // Log the error in i-Code and SonarQube logger.
276
- LOGGER .error (errorMessage , e );
277
- // Create an issue to be displayed in SonarQube.
278
- final CheckResult exception = new CheckResult ("Parsing Error" , "Parsing Error" , input );
279
- exception .setLangageId (language .getId ());
280
- exception .setLocation ("unknown" );
281
- exception .setLine (0 );
282
- exception .setMessage (errorMessage );
283
- // Add the exception as a Parsing Error result.
284
- analysisResultCheckResult .add (exception );
285
- }
286
- }
287
- }
288
- }
289
-
290
- return analysisResultCheckResult ;
291
- }
292
-
293
206
/**
294
207
* Return the file extension without the final point '.'.
295
208
*
0 commit comments