-
Notifications
You must be signed in to change notification settings - Fork 365
/
CxxPlugin.java
847 lines (762 loc) · 36.3 KB
/
CxxPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
/*
* Sonar C++ Plugin (Community)
* Copyright (C) 2010-2018 SonarOpenCommunity
* http://github.com/SonarOpenCommunity/sonar-cxx
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.plugins.cxx;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;
import org.sonar.api.Plugin;
import org.sonar.api.PropertyType;
import org.sonar.api.batch.rule.CheckFactory;
import org.sonar.api.batch.sensor.SensorContext;
import org.sonar.api.config.Configuration;
import org.sonar.api.config.PropertyDefinition;
import org.sonar.api.measures.FileLinesContextFactory;
import org.sonar.api.measures.Metric;
import org.sonar.api.measures.Metrics;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.server.rule.RulesDefinitionXmlLoader;
import org.sonar.cxx.AggregateMeasureComputer;
import org.sonar.cxx.CxxMetricsFactory;
import org.sonar.cxx.DensityMeasureComputer;
import org.sonar.cxx.sensors.clangsa.CxxClangSARuleRepository;
import org.sonar.cxx.sensors.clangsa.CxxClangSASensor;
import org.sonar.cxx.sensors.clangtidy.CxxClangTidyRuleRepository;
import org.sonar.cxx.sensors.clangtidy.CxxClangTidySensor;
import org.sonar.cxx.sensors.compiler.gcc.CxxCompilerGccRuleRepository;
import org.sonar.cxx.sensors.compiler.gcc.CxxCompilerGccSensor;
import org.sonar.cxx.sensors.compiler.vc.CxxCompilerVcRuleRepository;
import org.sonar.cxx.sensors.compiler.vc.CxxCompilerVcSensor;
import org.sonar.cxx.sensors.coverage.CxxCoverageCache;
import org.sonar.cxx.sensors.coverage.CxxCoverageSensor;
import org.sonar.cxx.sensors.cppcheck.CxxCppCheckRuleRepository;
import org.sonar.cxx.sensors.cppcheck.CxxCppCheckSensor;
import org.sonar.cxx.sensors.drmemory.CxxDrMemoryRuleRepository;
import org.sonar.cxx.sensors.drmemory.CxxDrMemorySensor;
import org.sonar.cxx.sensors.other.CxxOtherRepository;
import org.sonar.cxx.sensors.other.CxxOtherSensor;
import org.sonar.cxx.sensors.pclint.CxxPCLintRuleRepository;
import org.sonar.cxx.sensors.pclint.CxxPCLintSensor;
import org.sonar.cxx.sensors.rats.CxxRatsRuleRepository;
import org.sonar.cxx.sensors.rats.CxxRatsSensor;
import org.sonar.cxx.sensors.squid.CustomCxxRulesDefinition;
import org.sonar.cxx.sensors.squid.CxxSquidSensor;
import org.sonar.cxx.sensors.tests.dotnet.CxxUnitTestResultsAggregator;
import org.sonar.cxx.sensors.tests.dotnet.CxxUnitTestResultsImportSensor;
import org.sonar.cxx.sensors.tests.dotnet.UnitTestConfiguration;
import org.sonar.cxx.sensors.tests.xunit.CxxXunitSensor;
import org.sonar.cxx.sensors.valgrind.CxxValgrindRuleRepository;
import org.sonar.cxx.sensors.valgrind.CxxValgrindSensor;
import org.sonar.cxx.sensors.veraxx.CxxVeraxxRuleRepository;
import org.sonar.cxx.sensors.veraxx.CxxVeraxxSensor;
import org.sonar.cxx.visitors.CxxFunctionComplexityVisitor;
import org.sonar.cxx.visitors.CxxFunctionSizeVisitor;
import com.google.common.collect.ImmutableList;
/**
* {@inheritDoc}
*/
public final class CxxPlugin implements Plugin {
private static final String USE_ANT_STYLE_WILDCARDS
= " Use <a href='https://ant.apache.org/manual/dirtasks.html'>Ant-style wildcards</a> if neccessary.";
private static final String EXTENDING_THE_CODE_ANALYSIS = " The used format is described <a href='"
+ "https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Extending-the-code-analysis'>here</a>.";
public static final String LANG_PROP_PREFIX = "sonar.cxx.";
public static final String SOURCE_FILE_SUFFIXES_KEY = LANG_PROP_PREFIX + "suffixes.sources";
public static final String HEADER_FILE_SUFFIXES_KEY = LANG_PROP_PREFIX + "suffixes.headers";
public static final String DEFINES_KEY = LANG_PROP_PREFIX + "defines";
public static final String INCLUDE_DIRECTORIES_KEY = LANG_PROP_PREFIX + "includeDirectories";
public static final String ERROR_RECOVERY_KEY = LANG_PROP_PREFIX + "errorRecoveryEnabled";
public static final String FORCE_INCLUDE_FILES_KEY = LANG_PROP_PREFIX + "forceIncludes";
public static final String C_FILES_PATTERNS_KEY = LANG_PROP_PREFIX + "cFilesPatterns";
public static final String MISSING_INCLUDE_WARN = LANG_PROP_PREFIX + "missingIncludeWarnings";
public static final String JSON_COMPILATION_DATABASE_KEY = LANG_PROP_PREFIX + "jsonCompilationDatabase";
public static final String CPD_IGNORE_LITERALS_KEY = LANG_PROP_PREFIX + "cpd.ignoreLiterals";
public static final String CPD_IGNORE_IDENTIFIERS_KEY = LANG_PROP_PREFIX + "cpd.ignoreIdentifiers";
private static List<PropertyDefinition> generalProperties() {
String subcateg = "(1) General";
return new ArrayList<>(Arrays.asList(
PropertyDefinition.builder(SOURCE_FILE_SUFFIXES_KEY)
.multiValues(true)
.defaultValue(CppLanguage.DEFAULT_SOURCE_SUFFIXES)
.name("Source files suffixes")
.description("Comma-separated list of suffixes for source files to analyze. Leave empty to use the default.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(1)
.build(),
PropertyDefinition.builder(HEADER_FILE_SUFFIXES_KEY)
.multiValues(true)
.defaultValue(CppLanguage.DEFAULT_HEADER_SUFFIXES)
.name("Header files suffixes")
.description("Comma-separated list of suffixes for header files to analyze. Leave empty to use the default.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(2)
.build(),
PropertyDefinition.builder(INCLUDE_DIRECTORIES_KEY)
.multiValues(true)
.name("Include directories")
.description("Comma-separated list of directories to search the included files in. "
+ "May be defined either relative to projects root or absolute.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(3)
.build(),
PropertyDefinition.builder(FORCE_INCLUDE_FILES_KEY)
.multiValues(true)
.subCategory(subcateg)
.name("Force includes")
.description("Comma-separated list of files which should to be included implicitly at the "
+ "beginning of each source file.")
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(4)
.build(),
PropertyDefinition.builder(DEFINES_KEY)
.name("Default macros")
.description("Additional macro definitions (one per line) to use when analysing the source code. Use to provide"
+ "macros which cannot be resolved by other means."
+ " Use the 'force includes' setting to inject more complex, multi-line macros.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.TEXT)
.index(5)
.build(),
PropertyDefinition.builder(C_FILES_PATTERNS_KEY)
.defaultValue(CppLanguage.DEFAULT_C_FILES)
.multiValues(true)
.name("C source files patterns")
.description("Comma-separated list of wildcard patterns used to detect C files. When a file matches any of the"
+ "patterns, it is parsed in C-compatibility mode.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(6)
.build(),
PropertyDefinition.builder(CxxPlugin.ERROR_RECOVERY_KEY)
.defaultValue(Boolean.TRUE.toString())
.name("Parse error recovery")
.description("Defines mode for error handling of report files and parsing errors. `False' (strict) breaks after"
+ " an error or 'True' (tolerant=default) continues. See <a href='https://github.com/SonarOpenCommunity/"
+ "sonar-cxx/wiki/Supported-configuration-properties#sonarcxxerrorrecoveryenabled'>"
+ "sonar.cxx.errorRecoveryEnabled</a> for a complete description.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.BOOLEAN)
.index(7)
.build(),
PropertyDefinition.builder(CxxPlugin.MISSING_INCLUDE_WARN)
.defaultValue(Boolean.TRUE.toString())
.name("Missing include warnings")
.description("Enables/disables the warnings when included files could not be found.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.BOOLEAN)
.index(8)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxSquidSensor.REPORT_PATH_KEY)
.name("Path(s) to MSBuild log(s)")
.description("Extract includes, defines and compiler options from the build log. This works only"
+ " if the produced log during compilation adds enough information (MSBuild verbosity set to"
+ " detailed or diagnostic)."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(9)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxSquidSensor.REPORT_CHARSET_DEF)
.defaultValue(CxxSquidSensor.DEFAULT_CHARSET_DEF)
.name("MSBuild log encoding")
.description("The encoding to use when reading a MSBuild log. Leave empty to use default UTF-8.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(10)
.build(),
PropertyDefinition.builder(CxxPlugin.JSON_COMPILATION_DATABASE_KEY)
.subCategory(subcateg)
.name("JSON Compilation Database")
.description("JSON Compilation Database file to use as specification for what defines and includes should be "
+ "used for source files.")
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(11)
.build()
));
}
private static List<PropertyDefinition> codeAnalysisProperties() {
String subcateg = "(2) Code analysis";
return new ArrayList<>(Arrays.asList(PropertyDefinition.builder(LANG_PROP_PREFIX
+ CxxCppCheckSensor.REPORT_PATH_KEY)
.name("Cppcheck report(s)")
.description("Path to a <a href='http://cppcheck.sourceforge.net/'>Cppcheck</a> analysis XML report, relative to"
+ " projects root. Both XML formats (version 1 and version 2) are supported. If neccessary, <a href='https://"
+ "ant.apache.org/manual/dirtasks.html'>Ant-style wildcards</a> are at your service."
)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(1)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCppCheckRuleRepository.CUSTOM_RULES_KEY)
.name("Cppcheck custom rules")
.description("XML definitions of custom Cppcheck rules, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(2)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxValgrindSensor.REPORT_PATH_KEY)
.name("Valgrind report(s)")
.description("Path to <a href='http://valgrind.org/'>Valgrind</a> report(s), relative to projects root."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(3)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxValgrindRuleRepository.CUSTOM_RULES_KEY)
.name("Valgrind custom rules")
.description("XML definitions of custom Valgrind rules, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(4)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxDrMemorySensor.REPORT_PATH_KEY)
.name("Dr Memory report(s)")
.description("Path to <a href='http://drmemory.org/'>Dr. Memory</a> reports(s), relative to projects root."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(5)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxPCLintSensor.REPORT_PATH_KEY)
.name("PC-lint report(s)")
.description("Path to <a href='http://www.gimpel.com/html/pcl.htm'>PC-lint</a> reports(s), relative to projects"
+ " root." + USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(5)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxPCLintRuleRepository.CUSTOM_RULES_KEY)
.name("PC-lint custom rules")
.description("XML definitions of custom PC-lint rules, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(6)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxRatsSensor.REPORT_PATH_KEY)
.name("RATS report(s)")
.description("Path to <a href='https://code.google.com/p/rough-auditing-tool-for-security/'>RATS<a/> reports(s),"
+ " relative to projects root." + USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(7)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxRatsRuleRepository.CUSTOM_RULES_KEY)
.name("RATS custom rules")
.description("XML definitions of custom RATS rules, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(8)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxVeraxxSensor.REPORT_PATH_KEY)
.name("Vera++ report(s)")
.description("Path to <a href='https://bitbucket.org/verateam'>Vera++</a> reports(s), relative to projects root."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(9)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxVeraxxRuleRepository.CUSTOM_RULES_KEY)
.name("Vera++ custom rules")
.description("XML definitions of custom Vera++ rules, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(10)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxOtherSensor.REPORT_PATH_KEY)
.name("External checkers report(s)")
.description("Path to a code analysis report, which is generated by some unsupported code analyser, relative to"
+ "projects root." + USE_ANT_STYLE_WILDCARDS + " See <a href='https://github.com/SonarOpenCommunity/sonar-cxx"
+ "/wiki/Extending-the-code-analysis'>here</a> for details.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(11)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxOtherRepository.RULES_KEY)
.name("External rules")
.description("Rule sets for 'external' code analysers. Use one value per rule set. See <a href='https:"
+ "//github.com/SonarOpenCommunity/sonar-cxx/wiki/Extending-the-code-analysis'>this page</a> for details.")
.type(PropertyType.TEXT)
.multiValues(true)
.subCategory(subcateg)
.index(12)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxClangTidySensor.REPORT_PATH_KEY)
.name("Clang-Tidy analyzer report(s)")
.description("Path to Clang-Tidy reports, relative to projects root. If neccessary, "
+ "<a href='https://ant.apache.org/manual/dirtasks.html'>Ant-style wildcards</a> are at your service.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(13)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxClangTidySensor.REPORT_CHARSET_DEF)
.defaultValue(CxxClangTidySensor.DEFAULT_CHARSET_DEF)
.name("Encoding")
.description("The encoding to use when reading the clang-tidy report. Leave empty to use parser's default UTF-8.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(14)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxClangTidyRuleRepository.CUSTOM_RULES_KEY)
.name("Clang-Tidy custom rules")
.description("XML definitions of custom Clang-Tidy rules, which aren't builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(15)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxClangSASensor.REPORT_PATH_KEY)
.name("Clang Static analyzer analyzer report(s)")
.description("Path to Clang Static Analyzer reports, relative to projects root. If neccessary, "
+ "<a href='https://ant.apache.org/manual/dirtasks.html'>Ant-style wildcards</a> are at your service.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(16)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxClangSARuleRepository.CUSTOM_RULES_KEY)
.name("Clang-SA custom rules")
.description("NO DESC")
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(17)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxFunctionComplexityVisitor.FUNCTION_COMPLEXITY_THRESHOLD_KEY)
.defaultValue("10")
.name("Cyclomatic complexity threshold")
.description("Cyclomatic complexity threshold used to classify a function as complex")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.INTEGER)
.index(18)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxFunctionSizeVisitor.FUNCTION_SIZE_THRESHOLD_KEY)
.defaultValue("20")
.name("Function size threshold")
.description("Function size threshold to consider a function to be too big")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.INTEGER)
.index(19)
.build()
));
}
private static List<PropertyDefinition> compilerWarningsProperties() {
String subcateg = "(4) Compiler warnings";
return new ArrayList<>(Arrays.asList(
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerVcSensor.REPORT_PATH_KEY)
.name("VC Compiler Report(s)")
.description("Path to compilers output (i.e. file(s) containg compiler warnings), relative to projects root."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(1)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerVcSensor.REPORT_CHARSET_DEF)
.defaultValue(CxxCompilerVcSensor.DEFAULT_CHARSET_DEF)
.name("VC Report Encoding")
.description("The encoding to use when reading the compiler report. Leave empty to use parser's default UTF-8.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(2)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerVcSensor.REPORT_REGEX_DEF)
.name("VC Regular Expression")
.description("Regular expression to identify the four named groups of the compiler warning message: <file>, <line>, <id>,"
+ " <message>. Leave empty to use parser's default."
+ " See <a href='https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Compilers'>"
+ "this page</a> for details regarding the different regular expression that can be use per compiler.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(3)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerVcRuleRepository.CUSTOM_RULES_KEY)
.name("VC Custom Rules")
.description("XML definitions of custom rules for Visual C++ warnings, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(4)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerGccSensor.REPORT_PATH_KEY)
.name("GCC Compiler Report(s)")
.description("Path to compilers output (i.e. file(s) containg compiler warnings), relative to projects root."
+ USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(5)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerGccSensor.REPORT_CHARSET_DEF)
.defaultValue(CxxCompilerVcSensor.DEFAULT_CHARSET_DEF)
.name("GCC Report Encoding")
.description("The encoding to use when reading the compiler report. Leave empty to use parser's default UTF-8.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(6)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerGccSensor.REPORT_REGEX_DEF)
.name("GCC Regular Expression")
.description("Regular expression to identify the four named groups of the compiler warning message: <file>, <line>, <id>,"
+ " <message>. Leave empty to use parser's default."
+ " See <a href='https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Compilers'>"
+ "this page</a> for details regarding the different regular expression that can be use per compiler.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(7)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCompilerGccRuleRepository.CUSTOM_RULES_KEY)
.name("GCC Custom Rules")
.description("XML definitions of custom rules for GCC's warnings, which are'nt builtin into the plugin."
+ EXTENDING_THE_CODE_ANALYSIS)
.type(PropertyType.TEXT)
.subCategory(subcateg)
.index(8)
.build()
));
}
private static List<PropertyDefinition> testingAndCoverageProperties() {
String subcateg = "(3) Testing & Coverage";
ImmutableList.Builder<PropertyDefinition> properties = ImmutableList.builder();
properties.add(
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxCoverageSensor.REPORT_PATH_KEY)
.multiValues(true)
.name("Unit test coverage report(s)")
.description("List of paths to reports containing unit test coverage data, relative to projects root."
+ " The values are separated by commas."
+ " See <a href='https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Get-code-coverage-metrics'>"
+ "here</a> for supported formats.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(1)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxXunitSensor.REPORT_PATH_KEY)
.name("Unit test execution report(s)")
.description("Path to unit test execution report(s), relative to projects root."
+ " See <a href='https://github.com/SonarOpenCommunity/sonar-cxx/wiki/Get-test-execution-metrics'>"
+ "here</a> for supported formats." + USE_ANT_STYLE_WILDCARDS)
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(2)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX + CxxXunitSensor.XSLT_URL_KEY)
.name("XSLT transformer")
.description("By default, the unit test execution reports are expected to be in the JUnitReport format."
+ " To import a report in an other format, set this property to an URL to a XSLT stylesheet which is "
+ "able to perform the according transformation.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(3)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX
+ UnitTestConfiguration.VISUAL_STUDIO_TEST_RESULTS_PROPERTY_KEY)
.multiValues(true)
.name("Visual Studio Test Reports Paths")
.description("Example: \"report.trx\", \"report1.trx,report2.trx\" or \"C:/report.trx\"")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(4)
.build(),
PropertyDefinition.builder(LANG_PROP_PREFIX
+ UnitTestConfiguration.XUNIT_TEST_RESULTS_PROPERTY_KEY)
.multiValues(true)
.name("xUnit (MS) Test Reports Paths")
.description("Example: \"report.xml\", \"report1.xml,report2.xml\" or \"C:/report.xml\"")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.index(5)
.build()
);
return properties.build();
}
private static List<PropertyDefinition> duplicationsProperties() {
String subcateg = "(5) Duplications";
return new ArrayList<>(Arrays.asList(
PropertyDefinition.builder(CxxPlugin.CPD_IGNORE_LITERALS_KEY)
.defaultValue(Boolean.FALSE.toString())
.name("Ignores literal value differences when evaluating a duplicate block")
.description("Ignores literal (numbers, characters and strings) value differences when evaluating a duplicate "
+ "block. This means that e.g. foo=42; and foo=43; will be seen as equivalent. Default is 'False'.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.BOOLEAN)
.index(1)
.build(),
PropertyDefinition.builder(CxxPlugin.CPD_IGNORE_IDENTIFIERS_KEY)
.defaultValue(Boolean.FALSE.toString())
.name("Ignores identifier value differences when evaluating a duplicate block")
.description("Ignores identifier value differences when evaluating a duplicate block e.g. variable names, "
+ "methods names, and so forth. Default is 'False'.")
.subCategory(subcateg)
.onQualifiers(Qualifiers.PROJECT, Qualifiers.MODULE)
.type(PropertyType.BOOLEAN)
.index(2)
.build()
));
}
/**
* {@inheritDoc}
*/
@Override
public void define(Context context) {
List<Object> l = new ArrayList<>();
// plugin elements
l.add(CppLanguage.class);
l.add(CxxDefaultProfile.class);
l.add(CxxRuleRepository.class);
// reusable elements
l.addAll(getSensorsImpl());
// properties elements
l.addAll(generalProperties());
l.addAll(codeAnalysisProperties());
l.addAll(testingAndCoverageProperties());
l.addAll(compilerWarningsProperties());
l.addAll(duplicationsProperties());
context.addExtensions(l);
}
public List<Object> getSensorsImpl() {
List<Object> l = new ArrayList<>();
// utility classes
l.add(CxxCoverageAggregator.class);
l.add(CxxUnitTestResultsAggregator.class);
// metrics
l.add(CxxMetricsImp.class);
// ComputeEngine: propagate metrics through all levels (FILE -> MODULE -> PROJECT)
l.add(AggregateMeasureComputerImpl.class);
// ComputeEngine: calculate new metrics from existing ones
l.add(DensityMeasureComputerImpl.class);
// issue sensors
l.add(CxxSquidSensorImpl.class);
l.add(CxxRatsSensorImpl.class);
l.add(CxxCppCheckSensorImpl.class);
l.add(CxxPCLintSensorImpl.class);
l.add(CxxDrMemorySensorImpl.class);
l.add(CxxCompilerGccSensorImpl.class);
l.add(CxxCompilerVcSensorImpl.class);
l.add(CxxVeraxxSensorImpl.class);
l.add(CxxValgrindSensorImpl.class);
l.add(CxxClangTidySensorImpl.class);
l.add(CxxClangSASensorImpl.class);
l.add(CxxExternalRulesSensorImpl.class);
// test sensors
l.add(CxxXunitSensorImpl.class);
l.add(CxxUnitTestResultsImportSensorImpl.class);
l.add(CxxCoverageSensorImpl.class);
// rule provides
l.add(CxxRatsRuleRepositoryImpl.class);
l.add(CxxCppCheckRuleRepositoryImpl.class);
l.add(CxxPCLintRuleRepositoryImpl.class);
l.add(CxxDrMemoryRuleRepositoryImpl.class);
l.add(CxxCompilerVcRuleRepositoryImpl.class);
l.add(CxxCompilerGccRuleRepositoryImpl.class);
l.add(CxxVeraxxRuleRepositoryImpl.class);
l.add(CxxValgrindRuleRepositoryImpl.class);
l.add(CxxExternalRuleRepositoryImpl.class);
l.add(CxxClangTidyRuleRepositoryImpl.class);
l.add(CxxClangSARuleRepositoryImpl.class);
return l;
}
public static class CxxMetricsImp implements Metrics {
private static final List<Metric> METRICS = CxxMetricsFactory.generateList(CppLanguage.KEY, CppLanguage.PROPSKEY);
public CxxMetricsImp(Configuration settings) {
}
@Override
public List<Metric> getMetrics() {
return METRICS;
}
}
public static class AggregateMeasureComputerImpl extends AggregateMeasureComputer {
public AggregateMeasureComputerImpl() {
super(CppLanguage.KEY, CppLanguage.PROPSKEY);
}
}
public static class DensityMeasureComputerImpl extends DensityMeasureComputer {
public DensityMeasureComputerImpl() {
super(CppLanguage.KEY, CppLanguage.PROPSKEY);
}
}
public static class CxxRatsRuleRepositoryImpl extends CxxRatsRuleRepository {
public CxxRatsRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxCppCheckRuleRepositoryImpl extends CxxCppCheckRuleRepository {
public CxxCppCheckRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxPCLintRuleRepositoryImpl extends CxxPCLintRuleRepository {
public CxxPCLintRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxDrMemoryRuleRepositoryImpl extends CxxDrMemoryRuleRepository {
public CxxDrMemoryRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxCompilerVcRuleRepositoryImpl extends CxxCompilerVcRuleRepository {
public CxxCompilerVcRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxCompilerGccRuleRepositoryImpl extends CxxCompilerGccRuleRepository {
public CxxCompilerGccRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxVeraxxRuleRepositoryImpl extends CxxVeraxxRuleRepository {
public CxxVeraxxRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxValgrindRuleRepositoryImpl extends CxxValgrindRuleRepository {
public CxxValgrindRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxExternalRuleRepositoryImpl extends CxxOtherRepository {
public CxxExternalRuleRepositoryImpl(RulesDefinitionXmlLoader xmlRuleLoader, Configuration settings) {
super(xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxClangTidyRuleRepositoryImpl extends CxxClangTidyRuleRepository {
public CxxClangTidyRuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxClangSARuleRepositoryImpl extends CxxClangSARuleRepository {
public CxxClangSARuleRepositoryImpl(ServerFileSystem fileSystem, RulesDefinitionXmlLoader xmlRuleLoader,
Configuration settings) {
super(fileSystem, xmlRuleLoader, new CppLanguage(settings));
}
}
public static class CxxSquidSensorImpl extends CxxSquidSensor {
public CxxSquidSensorImpl(Configuration settings,
FileLinesContextFactory fileLinesContextFactory,
CheckFactory checkFactory) {
super(new CppLanguage(settings), fileLinesContextFactory, checkFactory);
}
public CxxSquidSensorImpl(Configuration settings,
FileLinesContextFactory fileLinesContextFactory,
CheckFactory checkFactory,
@Nullable CustomCxxRulesDefinition[] customRulesDefinition) {
super(new CppLanguage(settings), fileLinesContextFactory, checkFactory, customRulesDefinition);
}
}
public static class CxxRatsSensorImpl extends CxxRatsSensor {
public CxxRatsSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxXunitSensorImpl extends CxxXunitSensor {
public CxxXunitSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxCoverageSensorImpl extends CxxCoverageSensor {
public CxxCoverageSensorImpl(Configuration settings, CxxCoverageAggregator cache, SensorContext context) {
super(cache, new CppLanguage(settings), context);
}
}
public static class CxxCppCheckSensorImpl extends CxxCppCheckSensor {
public CxxCppCheckSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxPCLintSensorImpl extends CxxPCLintSensor {
public CxxPCLintSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxDrMemorySensorImpl extends CxxDrMemorySensor {
public CxxDrMemorySensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxCompilerGccSensorImpl extends CxxCompilerGccSensor {
public CxxCompilerGccSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxCompilerVcSensorImpl extends CxxCompilerVcSensor {
public CxxCompilerVcSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxVeraxxSensorImpl extends CxxVeraxxSensor {
public CxxVeraxxSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxValgrindSensorImpl extends CxxValgrindSensor {
public CxxValgrindSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxClangTidySensorImpl extends CxxClangTidySensor {
public CxxClangTidySensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxClangSASensorImpl extends CxxClangSASensor {
public CxxClangSASensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxExternalRulesSensorImpl extends CxxOtherSensor {
public CxxExternalRulesSensorImpl(Configuration settings) {
super(new CppLanguage(settings));
}
}
public static class CxxUnitTestResultsImportSensorImpl extends CxxUnitTestResultsImportSensor {
public CxxUnitTestResultsImportSensorImpl(Configuration settings,
CxxUnitTestResultsAggregator unitTestResultsAggregator) {
super(unitTestResultsAggregator, new CppLanguage(settings));
}
}
public static class CxxCoverageAggregator extends CxxCoverageCache {
public CxxCoverageAggregator() {
super();
}
}
@Override
public String toString() {
return getClass().getSimpleName();
}
}