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

devonfw / IDEasy / 21013659204

14 Jan 2026 11:29PM UTC coverage: 70.365% (+0.5%) from 69.904%
21013659204

Pull #1675

github

web-flow
Merge 7a3aa598b into fcadaae82
Pull Request #1675: #1298: support ide-extra-tools.json #1658: prevent Jackson reflection

4015 of 6292 branches covered (63.81%)

Branch coverage included in aggregate %.

10440 of 14251 relevant lines covered (73.26%)

3.17 hits per line

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

76.56
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.Map;
11
import java.util.TreeMap;
12
import java.util.function.Predicate;
13

14
import com.devonfw.tools.ide.json.JsonMapping;
15
import com.devonfw.tools.ide.json.JsonObject;
16
import com.devonfw.tools.ide.log.IdeLogger;
17
import com.devonfw.tools.ide.security.ToolVulnerabilities;
18
import com.devonfw.tools.ide.variable.IdeVariables;
19
import com.devonfw.tools.ide.version.VersionIdentifier;
20
import com.devonfw.tools.ide.version.VersionRange;
21
import com.fasterxml.jackson.databind.ObjectMapper;
22

23
/**
24
 * Container representing data from the "security.json" file with all {@link Cve CVE}s of a specific tool.
25
 *
26
 * @see com.devonfw.tools.ide.url.model.file.UrlSecurityFile
27
 */
28
public class ToolSecurity implements JsonObject {
29

30
  static final String PROPERTY_ISSUES = "issues";
31

32
  private static final ObjectMapper MAPPER = JsonMapping.create();
2✔
33

34
  private static final ToolSecurity EMPTY = new ToolSecurity(Map.of());
6✔
35

36
  private final Map<String, Cve> cveMap;
37

38
  private final Collection<Cve> issues;
39

40
  /**
41
   * The constructor.
42
   */
43
  public ToolSecurity() {
44
    this(new TreeMap<>());
5✔
45
  }
1✔
46

47
  /**
48
   * The constructor.
49
   *
50
   * @param issues the list of {@link Cve}s.
51
   */
52
  public ToolSecurity(List<Cve> issues) {
53
    this();
2✔
54
    setIssues(issues);
3✔
55
  }
1✔
56

57
  private ToolSecurity(Map<String, Cve> cveMap) {
58
    super();
2✔
59
    this.cveMap = cveMap;
3✔
60
    this.issues = Collections.unmodifiableCollection(this.cveMap.values());
6✔
61
  }
1✔
62

63
  /**
64
   * @return the {@link Collection} of {@link Cve}s.
65
   */
66
  public Collection<Cve> getIssues() {
67
    return this.issues;
3✔
68
  }
69

70
  /**
71
   * @param issues the list of {@link Cve}s.
72
   */
73
  public void setIssues(List<Cve> issues) {
74

75
    this.cveMap.clear();
3✔
76
    for (Cve issue : issues) {
10✔
77
      addIssue(issue);
4✔
78
    }
1✔
79
  }
1✔
80

81
  /**
82
   * @param issue the {@link Cve} to add.
83
   * @return {@code true} if this {@link ToolSecurity} was modified (issue added or merged), {@code false} otherwise ({@link Cve} was already contained).
84
   */
85
  public boolean addIssue(Cve issue) {
86

87
    Cve newIssue = issue;
2✔
88
    String id = issue.id();
3✔
89
    Cve existingIssue = this.cveMap.get(id);
6✔
90
    if (existingIssue != null) {
2!
91
      newIssue = existingIssue.merge(issue);
×
92
      if (newIssue.equals(existingIssue)) {
×
93
        return false;
×
94
      }
95
    }
96
    this.cveMap.put(id, newIssue);
6✔
97
    return true;
2✔
98
  }
99

100
  /**
101
   * Clears all issues.
102
   */
103
  public void clearIssues() {
104
    this.cveMap.clear();
×
105
  }
×
106

107
  /**
108
   * Finds all {@link Cve}s for the given {@link VersionIdentifier} that also match the given {@link Predicate}.
109
   *
110
   * @param version the {@link VersionIdentifier} to check.
111
   * @param logger the {@link IdeLogger}.
112
   * @param predicate the {@link Predicate} deciding which matching {@link Cve}s are {@link Predicate#test(Object) accepted}.
113
   * @return all {@link Cve}s for the given {@link VersionIdentifier}.
114
   */
115
  public ToolVulnerabilities findCves(VersionIdentifier version, IdeLogger logger, Predicate<Cve> predicate) {
116
    List<Cve> cvesOfVersion = new ArrayList<>();
4✔
117
    for (Cve cve : this.issues) {
11✔
118
      for (VersionRange range : cve.versions()) {
11✔
119
        if (range.contains(version)) {
4✔
120
          if (predicate.test(cve)) {
4!
121
            cvesOfVersion.add(cve);
5✔
122
          } else {
123
            logger.info("Ignoring CVE {} with severity {}", cve.id(), cve.severity());
×
124
          }
125
        }
126
      }
1✔
127
    }
1✔
128
    return ToolVulnerabilities.of(cvesOfVersion);
3✔
129
  }
130

131
  /**
132
   * Finds all {@link Cve}s for the given {@link VersionIdentifier} and {@code minSeverity}.
133
   *
134
   * @param version the {@link VersionIdentifier} to check.
135
   * @param logger the {@link IdeLogger}.
136
   * @param minSeverity the {@link IdeVariables#CVE_MIN_SEVERITY minimum severity}.
137
   * @return the {@link ToolVulnerabilities} for the given {@link VersionIdentifier}.
138
   */
139
  public ToolVulnerabilities findCves(VersionIdentifier version, IdeLogger logger, double minSeverity) {
140
    return findCves(version, logger, cve -> cve.severity() >= minSeverity);
15!
141
  }
142

143
  /**
144
   * @param file the {@link Path} to the JSON file to load.
145
   * @return the loaded {@link ToolSecurity} or the {@link #getEmpty() empty instance} if given {@link Path} does not exist.
146
   */
147
  public static ToolSecurity of(Path file) {
148

149
    if (Files.exists(file)) {
5!
150
      try (BufferedReader reader = Files.newBufferedReader(file)) {
3✔
151
        return MAPPER.readValue(reader, ToolSecurity.class);
8✔
152
      } catch (Exception e) {
×
153
        throw new IllegalStateException("Failed to load " + file, e);
×
154
      }
155
    } else {
156
      return EMPTY;
×
157
    }
158
  }
159

160
  /**
161
   * @return the empty instance of {@link ToolSecurity}.
162
   */
163
  public static ToolSecurity getEmpty() {
164

165
    return EMPTY;
2✔
166
  }
167
}
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