19
19
20
20
#include " abstract-parser.hh"
21
21
#include " cwe-mapper.hh"
22
+ #include " deflookup.hh"
22
23
#include " defqueue.hh"
23
24
#include " instream.hh"
24
25
#include " json-writer.hh"
@@ -85,6 +86,37 @@ bool loadPropsFromIniFile(
85
86
}
86
87
}
87
88
89
+ class ImpFlagDecorator : public GenericAbstractFilter {
90
+ public:
91
+ ImpFlagDecorator (AbstractWriter *writer):
92
+ GenericAbstractFilter (writer)
93
+ {
94
+ }
95
+
96
+ void hashImpDefect (const Defect &);
97
+
98
+ virtual void handleDef (const Defect &def);
99
+
100
+ private:
101
+ DefLookup impSet_;
102
+ };
103
+
104
+ void ImpFlagDecorator::hashImpDefect (const Defect &impDef) {
105
+ impSet_.hashDefect (impDef);
106
+ }
107
+
108
+ void ImpFlagDecorator::handleDef (const Defect &defOrig) {
109
+ if (impSet_.lookup (defOrig)) {
110
+ // found -> set "imp" flag to 1
111
+ Defect def = defOrig;
112
+ def.imp = 1 ;
113
+ slave_->handleDef (def);
114
+ }
115
+ else {
116
+ slave_->handleDef (defOrig);
117
+ }
118
+ }
119
+
88
120
class OrphanWriter {
89
121
public:
90
122
OrphanWriter (AbstractWriter &writer):
@@ -159,6 +191,8 @@ int main(int argc, char *argv[]) {
159
191
desc.add_options ()
160
192
(" cwelist" , po::value<string>(),
161
193
" (re)assign CWE numbers to defects by the given CSV list" )
194
+ (" implist" , po::value<string>(),
195
+ " mark reports from the specified list as important" )
162
196
(" inifile" , po::value<string>(),
163
197
" load scan properties from the given INI file" )
164
198
(" mapfile" , po::value<string>(),
@@ -199,6 +233,7 @@ int main(int argc, char *argv[]) {
199
233
}
200
234
201
235
const string fnCwe = valueOf<string>(vm[" cwelist" ]);
236
+ const string fnImp = valueOf<string>(vm[" implist" ]);
202
237
const string fnIni = valueOf<string>(vm[" inifile" ]);
203
238
const string fnMap = valueOf<string>(vm[" mapfile" ]);
204
239
const bool silent = vm.count (" quiet" );
@@ -213,7 +248,9 @@ int main(int argc, char *argv[]) {
213
248
return 1 ;
214
249
}
215
250
216
- CweMapDecorator writer (new JsonWriter (std::cout), silent);
251
+ AbstractWriter *jsonWriter = new JsonWriter (std::cout);
252
+ ImpFlagDecorator *impDec = new ImpFlagDecorator (jsonWriter);
253
+ CweMapDecorator writer (impDec, silent);
217
254
218
255
DefQueue defQueue;
219
256
@@ -232,6 +269,21 @@ int main(int argc, char *argv[]) {
232
269
}
233
270
}
234
271
272
+ if (!fnImp.empty ()) {
273
+ try {
274
+ // load list of important defects
275
+ InStream strImp (fnImp.c_str ());
276
+ Parser pImp (strImp.str (), fnImp);
277
+ Defect defImp;
278
+ while (pImp.getNext (&defImp))
279
+ impDec->hashImpDefect (defImp);
280
+ }
281
+ catch (const InFileException &e) {
282
+ printError (e);
283
+ hasError = true ;
284
+ }
285
+ }
286
+
235
287
const unsigned filesCnt = files.size ();
236
288
if (!filesCnt && !fnIni.empty () && !loadPropsFromIniFile (writer, fnIni))
237
289
hasError = true ;
0 commit comments