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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

0.0
cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlSecurityFile.java
1
package com.devonfw.tools.ide.url.model.file;
2

3
import java.io.BufferedReader;
4
import java.io.BufferedWriter;
5
import java.io.IOException;
6
import java.nio.file.Files;
7
import java.nio.file.Path;
8
import java.nio.file.StandardOpenOption;
9
import java.util.Set;
10
import java.util.TreeSet;
11

12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

15
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
16
import com.devonfw.tools.ide.version.VersionIdentifier;
17
import com.devonfw.tools.ide.version.VersionRange;
18

19
/**
20
 * {@link UrlFile} with the security information for an {@link UrlEdition}.
21
 */
22
public class UrlSecurityFile extends AbstractUrlFile<UrlEdition> {
23

24
  /** {@link #getName() Name} of security file. */
25
  public static final String FILENAME_SECURITY = "security";
26

27
  private static final Logger LOG = LoggerFactory.getLogger(UrlSecurityFile.class);
×
28

29
  private final Set<VersionRange> versionRanges;
30

31
  /**
32
   * The constructor.
33
   *
34
   * @param parent the {@link #getParent() parent folder}.
35
   */
36
  public UrlSecurityFile(UrlEdition parent) {
37

38
    super(parent, FILENAME_SECURITY);
×
39
    this.versionRanges = new TreeSet<>();
×
40
  }
×
41

42
  /**
43
   * @return the number of #getUrl
44
   */
45
  public int getVersionRangeCount() {
46

47
    return this.versionRanges.size();
×
48
  }
49

50
  /**
51
   * @param versionRange the {@link VersionRange} add.
52
   */
53
  public void addVersionRange(VersionRange versionRange) {
54

55
    boolean added = this.versionRanges.add(versionRange);
×
56
    if (added) {
×
57
      this.modified = true;
×
58
    }
59
  }
×
60

61
  /**
62
   * @param versionRange the {@link VersionRange} to remove.
63
   */
64
  public void removeVersionRange(VersionRange versionRange) {
65

66
    boolean removed = this.versionRanges.remove(versionRange);
×
67
    if (removed) {
×
68
      this.modified = true;
×
69
    }
70
  }
×
71

72
  /**
73
   * @param version the {@link VersionIdentifier} to check.
74
   * @return {@code true} if the given {@link VersionIdentifier} is contained in this {@link UrlSecurityFile}, {@code false} otherwise.
75
   */
76
  public boolean contains(VersionIdentifier version) {
77

78
    for (VersionRange range : this.versionRanges) {
×
79
      if (range.contains(version)) {
×
80
        return true;
×
81
      }
82
    }
×
83
    return false;
×
84
  }
85

86
  @Override
87
  protected void doLoad() {
88

89
    this.versionRanges.clear();
×
90
    Path path = getPath();
×
91
    if (!Files.exists(path)) {
×
92
      return;
×
93
    }
94
    try (BufferedReader br = Files.newBufferedReader(path)) {
×
95
      String line;
96
      do {
97
        line = br.readLine();
×
98
        if (line != null) {
×
99
          line = line.trim();
×
100
          VersionRange range = VersionRange.of(line);
×
101
          if (range == null) {
×
102
            LOG.warn("Invalid line in file " + path + ": " + line);
×
103
          } else {
104
            this.versionRanges.add(range);
×
105
          }
106
        }
107
      } while (line != null);
×
108
    } catch (IOException e) {
×
109
      throw new IllegalStateException("Failed to load file " + path, e);
×
110
    }
×
111
  }
×
112

113
  @Override
114
  protected void doSave() {
115

116
    Path path = getPath();
×
117
    if (this.versionRanges.isEmpty() && !Files.exists(path)) {
×
118
      return;
×
119
    }
120
    try (BufferedWriter bw = Files.newBufferedWriter(path, StandardOpenOption.TRUNCATE_EXISTING,
×
121
        StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
122
      for (VersionRange range : this.versionRanges) {
×
123
        bw.write(range + "\n");
×
124
      }
×
125
    } catch (IOException e) {
×
126
      throw new IllegalStateException("Failed to save file " + path, e);
×
127
    }
×
128
  }
×
129
}
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