Skip to content

Commit 4d6766c

Browse files
devonfw#103: fixed NPEs and other issues
adjusted getCpeVendor and getCpeProduct to return the tool name instead of an empty string removed unused urlEdition param from getCpeEdition added workaround for intellij #1378 fixed NPE's (added checks for missing UrlUpdaters)
1 parent 69e1fdd commit 4d6766c

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

cli/src/main/java/com/devonfw/tools/ide/url/updater/AbstractUrlUpdater.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,23 @@ protected final String getToolWithEdition() {
103103
*/
104104
public String getCpeVendor() {
105105

106-
return "";
106+
return getTool();
107107
}
108108

109109
/**
110110
* @return the product name of the tool as specified in the CPE (Common Platform Enumeration)
111111
*/
112112
public String getCpeProduct() {
113113

114-
return "";
114+
return getTool();
115115
}
116116

117117
/**
118-
* @param urlEdition the {@link UrlEdition} to get the CPE (Common Platform Enumeration) edition for.
119118
* @return the edition as specified in the CPE.
120119
*/
121-
public String getCpeEdition(String urlEdition) {
120+
public String getCpeEdition() {
122121

123-
return "";
122+
return getTool();
124123
}
125124

126125
/**

cli/src/main/java/com/devonfw/tools/ide/url/updater/UpdateManager.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,16 @@ public void updateAll() {
108108
*/
109109
public AbstractUrlUpdater retrieveUrlUpdater(String tool, String edition) {
110110

111-
return updaters.stream().filter(updater -> updater.getTool().equals(tool) && updater.getEdition().equals(edition))
112-
.findFirst().orElse(null);
111+
for (AbstractUrlUpdater updater : updaters) {
112+
// TODO: fix this ugly hack for intellij see: https://github.com/devonfw/ide/issues/1378
113+
if (updater.getTool().equals(tool) && edition.equals("intellij")) {
114+
return updater;
115+
}
116+
if (updater.getTool().equals(tool) && updater.getEdition().equals(edition)) {
117+
return updater;
118+
}
119+
}
120+
return null;
113121
}
114122

115123
public UrlRepository getUrlRepository() {

security/src/main/java/com/devonfw/tools/security/BuildSecurityJsonFiles.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.nio.file.Files;
66
import java.nio.file.Path;
77
import java.nio.file.Paths;
8+
import java.util.Arrays;
89
import java.util.HashSet;
910
import java.util.List;
1011
import java.util.Locale;
@@ -111,14 +112,17 @@ private static void run() {
111112

112113
initCvesToIgnore();
113114
UpdateManager updateManager = new UpdateManager(context.getUrlsPath(), null);
114-
Dependency[] dependencies = getDependenciesWithVulnerabilities(updateManager);
115+
List<Dependency> dependencies = getDependenciesWithVulnerabilities(updateManager);
115116
Set<Pair<String, String>> foundToolsAndEditions = new HashSet<>();
116117
for (Dependency dependency : dependencies) {
117118
String filePath = dependency.getFilePath();
118119
Path parent = Paths.get(filePath).getParent();
119120
String tool = parent.getParent().getParent().getFileName().toString();
120121
String edition = parent.getParent().getFileName().toString();
121122
AbstractUrlUpdater urlUpdater = updateManager.retrieveUrlUpdater(tool, edition);
123+
if (urlUpdater == null) {
124+
continue;
125+
}
122126
UrlSecurityJsonFile securityFile = context.getUrls().getEdition(tool, edition).getSecurityJsonFile();
123127
boolean newlyAdded = foundToolsAndEditions.add(new Pair<>(tool, edition));
124128
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
153157

154158
List<String> sortedVersions = context.getUrls().getSortedVersions(tool, edition).stream()
155159
.map(VersionIdentifier::toString).toList();
160+
156161
List<String> sortedCpeVersions = sortedVersions.stream().map(urlUpdater::mapUrlVersionToCpeVersion)
157162
.collect(Collectors.toList());
158163
Map<String, String> cpeToUrlVersion = MapUtil.createMapfromLists(sortedCpeVersions, sortedVersions);
@@ -163,13 +168,13 @@ private static Map<String, String> buildCpeToUrlVersionMap(String tool, String e
163168
* Uses the {@link Engine OWASP engine} to scan the {@link AbstractIdeContext#getUrlsPath() ide-url} folder for
164169
* dependencies and then runs {@link Engine#analyzeDependencies() analyzes} them to get the {@link Vulnerability
165170
* vulnerabilities}.
166-
*
171+
*
167172
* @param updateManager the {@link UpdateManager} to use to get the {@link AbstractUrlUpdater} of the tool to get CPE
168173
* Vendor, CPE Product and CPE edition of the tool, as well as the
169174
* {@link AbstractUrlUpdater#mapCpeVersionToUrlVersion(String) CPE naming of its version}
170175
* @return the {@link Dependency dependencies} with associated {@link Vulnerability vulnerabilities}.
171176
*/
172-
private static Dependency[] getDependenciesWithVulnerabilities(UpdateManager updateManager) {
177+
private static List<Dependency> getDependenciesWithVulnerabilities(UpdateManager updateManager) {
173178

174179
Settings settings = new Settings();
175180
Engine engine = new Engine(settings);
@@ -189,8 +194,11 @@ private static Dependency[] getDependenciesWithVulnerabilities(UpdateManager upd
189194
throw new RuntimeException(e);
190195
}
191196
Dependency[] dependencies = engine.getDependencies();
197+
// remove dependencies without vulnerabilities
198+
List<Dependency> dependenciesFiltered = Arrays.stream(dependencies)
199+
.filter(dependency -> !dependency.getVulnerabilities().isEmpty()).toList();
192200
engine.close();
193-
return dependencies;
201+
return dependenciesFiltered;
194202
}
195203

196204
/**

security/src/main/java/com/devonfw/tools/security/UrlAnalyzer.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.devonfw.tools.security;
22

3-
import com.devonfw.tools.ide.url.updater.AbstractUrlUpdater;
4-
import com.devonfw.tools.ide.url.updater.UpdateManager;
3+
import java.io.FileFilter;
4+
import java.nio.file.Path;
5+
import java.nio.file.Paths;
6+
57
import org.owasp.dependencycheck.Engine;
68
import org.owasp.dependencycheck.analyzer.AbstractFileTypeAnalyzer;
79
import org.owasp.dependencycheck.analyzer.AnalysisPhase;
@@ -11,9 +13,8 @@
1113
import org.owasp.dependencycheck.dependency.EvidenceType;
1214
import org.owasp.dependencycheck.exception.InitializationException;
1315

14-
import java.io.FileFilter;
15-
import java.nio.file.Path;
16-
import java.nio.file.Paths;
16+
import com.devonfw.tools.ide.url.updater.AbstractUrlUpdater;
17+
import com.devonfw.tools.ide.url.updater.UpdateManager;
1718

1819
/**
1920
* Analyzes file paths to detect tool, edition and version of software listed in a directory structure like this:
@@ -56,9 +57,13 @@ protected void analyzeDependency(Dependency dependency, Engine engine) {
5657

5758
AbstractUrlUpdater urlUpdater = this.updateManager.retrieveUrlUpdater(tool, edition);
5859

60+
if (urlUpdater == null) {
61+
return;
62+
}
63+
5964
String cpeVendor = urlUpdater.getCpeVendor();
6065
String cpeProduct = urlUpdater.getCpeProduct();
61-
String cpeEdition = urlUpdater.getCpeEdition(edition);
66+
String cpeEdition = urlUpdater.getCpeEdition();
6267
String cpeVersion = urlUpdater.mapUrlVersionToCpeVersion(versionFolder.getFileName().toString());
6368

6469
if (cpeVendor.isBlank() || cpeProduct.isBlank()) {

0 commit comments

Comments
 (0)