5
5
import java .nio .file .Files ;
6
6
import java .nio .file .Path ;
7
7
import java .nio .file .Paths ;
8
+ import java .util .Arrays ;
8
9
import java .util .HashSet ;
9
10
import java .util .List ;
10
11
import java .util .Locale ;
@@ -111,14 +112,17 @@ private static void run() {
111
112
112
113
initCvesToIgnore ();
113
114
UpdateManager updateManager = new UpdateManager (context .getUrlsPath (), null );
114
- Dependency [] dependencies = getDependenciesWithVulnerabilities (updateManager );
115
+ List < Dependency > dependencies = getDependenciesWithVulnerabilities (updateManager );
115
116
Set <Pair <String , String >> foundToolsAndEditions = new HashSet <>();
116
117
for (Dependency dependency : dependencies ) {
117
118
String filePath = dependency .getFilePath ();
118
119
Path parent = Paths .get (filePath ).getParent ();
119
120
String tool = parent .getParent ().getParent ().getFileName ().toString ();
120
121
String edition = parent .getParent ().getFileName ().toString ();
121
122
AbstractUrlUpdater urlUpdater = updateManager .retrieveUrlUpdater (tool , edition );
123
+ if (urlUpdater == null ) {
124
+ continue ;
125
+ }
122
126
UrlSecurityJsonFile securityFile = context .getUrls ().getEdition (tool , edition ).getSecurityJsonFile ();
123
127
boolean newlyAdded = foundToolsAndEditions .add (new Pair <>(tool , edition ));
124
128
if (newlyAdded ) { // to assure that the file is cleared only once per tool and edition
@@ -153,6 +157,7 @@ private static Map<String, String> buildCpeToUrlVersionMap(String tool, String e
153
157
154
158
List <String > sortedVersions = context .getUrls ().getSortedVersions (tool , edition ).stream ()
155
159
.map (VersionIdentifier ::toString ).toList ();
160
+
156
161
List <String > sortedCpeVersions = sortedVersions .stream ().map (urlUpdater ::mapUrlVersionToCpeVersion )
157
162
.collect (Collectors .toList ());
158
163
Map <String , String > cpeToUrlVersion = MapUtil .createMapfromLists (sortedCpeVersions , sortedVersions );
@@ -163,13 +168,13 @@ private static Map<String, String> buildCpeToUrlVersionMap(String tool, String e
163
168
* Uses the {@link Engine OWASP engine} to scan the {@link AbstractIdeContext#getUrlsPath() ide-url} folder for
164
169
* dependencies and then runs {@link Engine#analyzeDependencies() analyzes} them to get the {@link Vulnerability
165
170
* vulnerabilities}.
166
- *
171
+ *
167
172
* @param updateManager the {@link UpdateManager} to use to get the {@link AbstractUrlUpdater} of the tool to get CPE
168
173
* Vendor, CPE Product and CPE edition of the tool, as well as the
169
174
* {@link AbstractUrlUpdater#mapCpeVersionToUrlVersion(String) CPE naming of its version}
170
175
* @return the {@link Dependency dependencies} with associated {@link Vulnerability vulnerabilities}.
171
176
*/
172
- private static Dependency [] getDependenciesWithVulnerabilities (UpdateManager updateManager ) {
177
+ private static List < Dependency > getDependenciesWithVulnerabilities (UpdateManager updateManager ) {
173
178
174
179
Settings settings = new Settings ();
175
180
Engine engine = new Engine (settings );
@@ -189,8 +194,11 @@ private static Dependency[] getDependenciesWithVulnerabilities(UpdateManager upd
189
194
throw new RuntimeException (e );
190
195
}
191
196
Dependency [] dependencies = engine .getDependencies ();
197
+ // remove dependencies without vulnerabilities
198
+ List <Dependency > dependenciesFiltered = Arrays .stream (dependencies )
199
+ .filter (dependency -> !dependency .getVulnerabilities ().isEmpty ()).toList ();
192
200
engine .close ();
193
- return dependencies ;
201
+ return dependenciesFiltered ;
194
202
}
195
203
196
204
/**
0 commit comments