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

devonfw / IDEasy / 16913925651

12 Aug 2025 03:48PM UTC coverage: 69.496% (+0.03%) from 69.463%
16913925651

push

github

web-flow
#1437: cleanup (#1439)

3365 of 5285 branches covered (63.67%)

Branch coverage included in aggregate %.

8744 of 12139 relevant lines covered (72.03%)

3.16 hits per line

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

62.89
cli/src/main/java/com/devonfw/tools/ide/url/model/file/UrlDownloadFile.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.HashSet;
10
import java.util.Set;
11

12
import com.devonfw.tools.ide.os.OperatingSystem;
13
import com.devonfw.tools.ide.os.SystemArchitecture;
14
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
15
import com.devonfw.tools.ide.url.model.folder.UrlTool;
16
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
17
import com.devonfw.tools.ide.version.VersionIdentifier;
18

19
/**
20
 * {@link UrlFile} with the download URLs. Its {@link #getName() name} has to follow one of the following conventions:
21
 * <ul>
22
 * <li>«os»_«arch».urls</li>
23
 * <li>«os».urls</li>
24
 * <li>urls</li>
25
 * </ul>
26
 */
27
public class UrlDownloadFile extends AbstractUrlFile<UrlVersion> implements UrlDownloadFileMetadata {
1✔
28

29
  /** The name {@value} for OS- and architecture-agnostic URLs. */
30
  public static final String NAME_URLS = "urls";
31

32
  /** The extension {@value}. */
33
  public static final String EXTENSION_URLS = ".urls";
34

35
  private final Set<String> urls;
36

37
  /**
38
   * The constructor.
39
   *
40
   * @param parent the {@link #getParent() parent folder}.
41
   * @param name the {@link #getName() filename}.
42
   */
43
  public UrlDownloadFile(UrlVersion parent, String name) {
44

45
    super(parent, name);
4✔
46
    this.urls = new HashSet<>();
5✔
47
  }
1✔
48

49
  /**
50
   * The constructor.
51
   *
52
   * @param parent the {@link #getParent() parent folder}.
53
   * @param name the {@link #getName() filename}.
54
   * @param urls the predefined {@link Set} of download URLs to prevent loading from disc.
55
   */
56
  public UrlDownloadFile(UrlVersion parent, String name, Set<String> urls) {
57

58
    super(parent, name);
4✔
59
    this.urls = urls;
3✔
60
    this.loaded = true;
3✔
61
    this.modified = false;
3✔
62
  }
1✔
63

64
  /**
65
   * @return the number of #getUrl
66
   */
67
  public int getUrlCount() {
68

69
    return this.urls.size();
×
70
  }
71

72
  /**
73
   * @param url the download URL to add.
74
   */
75
  public void addUrl(String url) {
76

77
    boolean added = this.urls.add(url);
×
78
    if (added) {
×
79
      this.modified = true;
×
80
    }
81
  }
×
82

83
  /**
84
   * Avoid direct mutation of this {@link Set} and use {@link #addUrl(String)} or {@link #removeUrl(String)} instead.
85
   */
86
  @Override
87
  public Set<String> getUrls() {
88

89
    load(false);
3✔
90
    return this.urls;
3✔
91
  }
92

93
  /**
94
   * @param url the download URL to remove.
95
   */
96
  public void removeUrl(String url) {
97

98
    boolean removed = this.urls.remove(url);
×
99
    if (removed) {
×
100
      this.modified = true;
×
101
    }
102
  }
×
103

104
  @Override
105
  protected void doLoad() {
106

107
    this.urls.clear();
3✔
108
    Path path = getPath();
3✔
109
    try (BufferedReader br = Files.newBufferedReader(path)) {
3✔
110
      String line;
111
      do {
112
        line = br.readLine();
3✔
113
        if (line != null) {
2✔
114
          this.urls.add(line.trim());
6✔
115
        }
116
      } while (line != null);
2✔
117
    } catch (IOException e) {
×
118
      throw new IllegalStateException("Failed to load file " + path, e);
×
119
    }
1✔
120
  }
1✔
121

122
  @Override
123
  protected void doSave() {
124

125
    Path path = getPath();
×
126
    try (BufferedWriter bw = Files.newBufferedWriter(path, StandardOpenOption.TRUNCATE_EXISTING,
×
127
        StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
128
      for (String line : this.urls) {
×
129
        bw.write(line + "\n");
×
130
      }
×
131
    } catch (IOException e) {
×
132
      throw new IllegalStateException("Failed to save file " + path, e);
×
133
    }
×
134
  }
×
135

136
  @Override
137
  public OperatingSystem getOs() {
138

139
    String name = getName();
3✔
140
    if (name.equals(NAME_URLS)) {
4✔
141
      return null;
2✔
142
    }
143
    for (OperatingSystem os : OperatingSystem.values()) {
16!
144
      if (name.startsWith(os.toString())) {
5✔
145
        return os;
2✔
146
      }
147
    }
148
    throw new IllegalStateException("Cannot derive operating-system from " + name);
×
149
  }
150

151
  @Override
152
  public SystemArchitecture getArch() {
153

154
    String name = getName();
3✔
155
    if (name.equals(NAME_URLS)) {
4✔
156
      return null;
2✔
157
    }
158
    int underscore = name.indexOf('_');
4✔
159
    if (underscore < 0) {
2!
160
      return null;
×
161
    }
162
    assert (name.endsWith(EXTENSION_URLS));
5!
163
    // EXTENSION_URLS.length() = ".urls".length() = 5
164
    String archString = name.substring(underscore + 1, name.length() - 5);
10✔
165
    for (SystemArchitecture arch : SystemArchitecture.values()) {
14!
166
      if (archString.equals(arch.toString())) {
5!
167
        return arch;
2✔
168
      }
169
    }
170
    throw new IllegalStateException("Cannot derive system-architecture from " + name);
×
171
  }
172

173
  @Override
174
  public VersionIdentifier getVersion() {
175

176
    UrlVersion version = getParent();
4✔
177
    return version.getVersionIdentifier();
3✔
178
  }
179

180
  @Override
181
  public String getEdition() {
182

183
    UrlEdition edition = getParent().getParent();
6✔
184
    return edition.getName();
3✔
185
  }
186

187
  @Override
188
  public String getTool() {
189

190
    UrlTool tool = getParent().getParent().getParent();
8✔
191
    return tool.getName();
3✔
192
  }
193

194
  @Override
195
  public UrlChecksums getChecksums() {
196

197
    UrlChecksum checksum = getParent().getChecksum(getName());
7✔
198
    if (checksum == null) {
2!
199
      return UrlGenericChecksums.EMPTY;
2✔
200
    }
201
    return checksum;
×
202
  }
203
}
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