• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 19678983659

25 Nov 2025 05:48PM UTC coverage: 69.142% (-0.005%) from 69.147%
19678983659

Pull #1610

github

web-flow
Merge aeaa853d8 into 3e7a75dd9
Pull Request #1610: #1593: #1144: #1145: fix json parsing in graalvm

3641 of 5775 branches covered (63.05%)

Branch coverage included in aggregate %.

9451 of 13160 relevant lines covered (71.82%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.5
cli/src/main/java/com/devonfw/tools/ide/url/model/file/json/ToolSecurity.java
1
package com.devonfw.tools.ide.url.model.file.json;
2

3
import java.io.BufferedReader;
4
import java.nio.file.Files;
5
import java.nio.file.Path;
6
import java.util.ArrayList;
7
import java.util.Collection;
8
import java.util.Collections;
9
import java.util.List;
10
import java.util.function.Predicate;
11

12
import com.devonfw.tools.ide.json.JsonMapping;
13
import com.devonfw.tools.ide.log.IdeLogger;
14
import com.devonfw.tools.ide.variable.IdeVariables;
15
import com.devonfw.tools.ide.version.VersionIdentifier;
16
import com.devonfw.tools.ide.version.VersionRange;
17
import com.fasterxml.jackson.databind.ObjectMapper;
18

19
/**
20
 * Container representing data from the "security.json" file with all {@link Cve CVE}s of a specific tool.
21
 *
22
 * @see com.devonfw.tools.ide.url.model.file.UrlSecurityFile
23
 */
24
public class ToolSecurity {
25

26
  static final String PROPERTY_ISSUES = "issues";
27

28
  private static final ObjectMapper MAPPER = JsonMapping.create();
2✔
29

30
  private static final ToolSecurity EMPTY = new ToolSecurity(Collections.emptyList());
6✔
31

32
  private List<Cve> issues;
33

34
  /**
35
   * The constructor.
36
   */
37
  public ToolSecurity() {
38
    this(new ArrayList<>());
×
39
  }
×
40

41
  /**
42
   * The constructor.
43
   *
44
   * @param issues the {@link List} of {@link Cve CVE}s.
45
   */
46
  public ToolSecurity(List<Cve> issues) {
47

48
    super();
2✔
49
    this.issues = issues;
3✔
50
  }
1✔
51

52
  /**
53
   * @return the list of CVEs
54
   */
55
  public List<Cve> getIssues() {
56
    return issues;
3✔
57
  }
58

59
  /**
60
   * @param issues the list of CVEs
61
   */
62
  public void setIssues(List<Cve> issues) {
63
    this.issues = issues;
×
64
  }
×
65

66
  /**
67
   * Finds all {@link Cve}s for the given {@link VersionIdentifier} that also match the given {@link Predicate}.
68
   *
69
   * @param version the {@link VersionIdentifier} to check.
70
   * @param predicate the {@link Predicate} deciding which matching {@link Cve}s are {@link Predicate#test(Object) accepted}.
71
   * @return all {@link Cve}s for the given {@link VersionIdentifier}.
72
   */
73
  public Collection<Cve> findCves(VersionIdentifier version, IdeLogger logger, Predicate<Cve> predicate) {
74
    List<Cve> cvesOfVersion = new ArrayList<>();
4✔
75
    for (Cve cve : this.issues) {
11✔
76
      for (VersionRange range : cve.versions()) {
11✔
77
        if (range.contains(version)) {
4✔
78
          if (predicate.test(cve)) {
4!
79
            cvesOfVersion.add(cve);
5✔
80
          } else {
81
            logger.info("Ignoring CVE {} with severity {}", cve.id(), cve.severity());
×
82
          }
83
        }
84
      }
1✔
85
    }
1✔
86
    return cvesOfVersion;
2✔
87
  }
88

89
  /**
90
   * Finds all {@link Cve}s for the given {@link VersionIdentifier} and {@code minSeverity}.
91
   *
92
   * @param version the {@link VersionIdentifier} to check.
93
   * @param minSeverity the {@link IdeVariables#CVE_MIN_SEVERITY minimum severity}.
94
   * @return all {@link Cve}s for the given {@link VersionIdentifier}.
95
   */
96
  public Collection<Cve> findCves(VersionIdentifier version, IdeLogger logger, double minSeverity) {
97
    return findCves(version, logger, cve -> cve.severity() >= minSeverity);
15!
98
  }
99

100
  /**
101
   * @param file the {@link Path} to the JSON file to load.
102
   * @return the loaded {@link ToolSecurity} or the {@link #getEmpty() empty instance} if given {@link Path} does not exist.
103
   */
104
  public static ToolSecurity of(Path file) {
105

106
    if (Files.exists(file)) {
5!
107
      try (BufferedReader reader = Files.newBufferedReader(file)) {
3✔
108
        return MAPPER.readValue(reader, ToolSecurity.class);
8✔
109
      } catch (Exception e) {
×
110
        throw new IllegalStateException("Failed to load " + file, e);
×
111
      }
112
    } else {
113
      return EMPTY;
×
114
    }
115
  }
116

117
  /**
118
   * @return the empty instance of {@link ToolSecurity}.
119
   */
120
  public static ToolSecurity getEmpty() {
121

122
    return EMPTY;
2✔
123
  }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc