Skip to content

Commit fd64100

Browse files
committed
devonfw#103: some final cleanup
1 parent b19b877 commit fd64100

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlSecurityJsonFile.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ public boolean addSecurityWarning(VersionRange versionRange) {
6464
*
6565
* @param versionRange the version range, specifying the versions of the tool to which the security risk applies.
6666
* @param matchedCpe the matched CPE.
67-
* @param interval the interval of vulnerability that was used to determine the {@link VersionRange}. This is used to
68-
* check if the mapping from CPE version to UrlVersion was correct.
67+
* @param interval the interval of vulnerability that was used to determine the {@link VersionRange}. This can be used
68+
* to manually check if the mapping from CPE version to UrlVersion was correct.
6969
* @param severity the severity of the security risk.
7070
* @param severityVersion Indicating from which version the {@code severity} was obtained. As of December 2023, this
7171
* is either v2 or v3.

cli/src/main/java/com/devonfw/tools/ide/util/MapUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class MapUtil {
1414
* Creates a {@link HashMap} with the given {@code keys} and {@code values} which are passed as {@link List lists}.
1515
* The map is populated by iterating through both lists simultaneously until one of the list is exhausted.
1616
*/
17-
public static <K, V> Map<K, V> createMapWithLists(List<K> keys, List<V> values) {
17+
public static <K, V> Map<K, V> createMapfromLists(List<K> keys, List<V> values) {
1818

1919
Map<K, V> resultMap = new HashMap<>();
2020

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

+8-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010
import java.util.Locale;
1111
import java.util.Map;
12-
import java.util.Optional;
12+
import java.util.Objects;
1313
import java.util.Set;
1414
import java.util.stream.Collectors;
1515

@@ -59,6 +59,8 @@
5959
import com.devonfw.tools.ide.version.VersionRange;
6060

6161
// TODO Doesn't yet work with versions defined like this /<tool>/<edition>/latest
62+
// TODO Sometimes when running this class is takes a long time to finish. Maybe this is because of the OWASP package, which
63+
// is updating the vulnerabilities. A dirty fix is to stop the program and restart it.
6264

6365
/**
6466
* This class is used to build the {@link UrlSecurityJsonFile} files for IDEasy. It scans the
@@ -133,7 +135,7 @@ private static void run() {
133135
.map(VersionIdentifier::toString).toList();
134136
List<String> sortedCpeVersions = sortedVersions.stream().map(urlUpdater::mapUrlVersionToCpeVersion)
135137
.collect(Collectors.toList());
136-
Map<String, String> cpeToUrlVersion = MapUtil.createMapWithLists(sortedCpeVersions, sortedVersions);
138+
Map<String, String> cpeToUrlVersion = MapUtil.createMapfromLists(sortedCpeVersions, sortedVersions);
137139

138140
Set<Vulnerability> vulnerabilities = dependency.getVulnerabilities(true);
139141
for (Vulnerability vulnerability : vulnerabilities) {
@@ -174,7 +176,8 @@ private static void addVulnerabilityToSecurityFile(Vulnerability vulnerability,
174176

175177
if (vulnerability.getCvssV2() == null && vulnerability.getCvssV3() == null) {
176178
// TODO if this ever happens, add a case that handles this
177-
throw new RuntimeException("Vulnerability without severity found: " + vulnerability.getName());
179+
throw new RuntimeException("Vulnerability without severity found: " + vulnerability.getName() + "\\n"
180+
+ " Please contact https://github.com/devonfw/IDEasy and make a request to get this feature implemented.");
178181
}
179182
boolean hasV3Severity = vulnerability.getCvssV3() != null;
180183
double severityDouble = hasV3Severity ? vulnerability.getCvssV3().getBaseScore()
@@ -287,15 +290,11 @@ public static VersionRange getVersionRangeFromInterval(String si, String se, Str
287290
}
288291
return VersionRange.of(s + VersionRange.getVersionSeparator() + s);
289292
}
290-
se = Optional.ofNullable(se).orElse("");
291-
si = Optional.ofNullable(si).orElse("");
292-
ee = Optional.ofNullable(ee).orElse("");
293-
ei = Optional.ofNullable(ei).orElse("");
294293

295-
String leftBoundary = se.isEmpty() ? VersionRange.getStartIncludingPrefix() + si
294+
String leftBoundary = se == null ? VersionRange.getStartIncludingPrefix() + Objects.toString(si, "")
296295
: VersionRange.getStartExcludingPrefix() + se;
297296

298-
String rightBoundary = ee.isEmpty() ? ei + VersionRange.getEndIncludingSuffix()
297+
String rightBoundary = ee == null ? Objects.toString(ei, "") + VersionRange.getEndIncludingSuffix()
299298
: ee + VersionRange.getEndExcludingSuffix();
300299

301300
return VersionRange.of(leftBoundary + VersionRange.getVersionSeparator() + rightBoundary);

0 commit comments

Comments
 (0)