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

devonfw / IDEasy / 13858963404

14 Mar 2025 02:38PM UTC coverage: 67.657% (-1.0%) from 68.619%
13858963404

push

github

web-flow
#1024: Move urls into url-updater module (#1025)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

3036 of 4915 branches covered (61.77%)

Branch coverage included in aggregate %.

7825 of 11138 relevant lines covered (70.25%)

3.07 hits per line

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

56.52
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
   * @return the number of #getUrl
51
   */
52
  public int getUrlCount() {
53

54
    return this.urls.size();
×
55
  }
56

57
  /**
58
   * @param url the download URL to add.
59
   */
60
  public void addUrl(String url) {
61

62
    boolean added = this.urls.add(url);
×
63
    if (added) {
×
64
      this.modified = true;
×
65
    }
66
  }
×
67

68
  /**
69
   * Avoid direct mutation of this {@link Set} and use {@link #addUrl(String)} or {@link #removeUrl(String)} instead.
70
   */
71
  @Override
72
  public Set<String> getUrls() {
73

74
    load(false);
3✔
75
    return this.urls;
3✔
76
  }
77

78
  /**
79
   * @param url the download URL to remove.
80
   */
81
  public void removeUrl(String url) {
82

83
    boolean removed = this.urls.remove(url);
×
84
    if (removed) {
×
85
      this.modified = true;
×
86
    }
87
  }
×
88

89
  @Override
90
  protected void doLoad() {
91

92
    this.urls.clear();
3✔
93
    Path path = getPath();
3✔
94
    try (BufferedReader br = Files.newBufferedReader(path)) {
3✔
95
      String line;
96
      do {
97
        line = br.readLine();
3✔
98
        if (line != null) {
2✔
99
          this.urls.add(line.trim());
6✔
100
        }
101
      } while (line != null);
2✔
102
    } catch (IOException e) {
×
103
      throw new IllegalStateException("Failed to load file " + path, e);
×
104
    }
1✔
105
  }
1✔
106

107
  @Override
108
  protected void doSave() {
109

110
    Path path = getPath();
×
111
    try (BufferedWriter bw = Files.newBufferedWriter(path, StandardOpenOption.TRUNCATE_EXISTING,
×
112
        StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
113
      for (String line : this.urls) {
×
114
        bw.write(line + "\n");
×
115
      }
×
116
    } catch (IOException e) {
×
117
      throw new IllegalStateException("Failed to save file " + path, e);
×
118
    }
×
119
  }
×
120

121
  @Override
122
  public OperatingSystem getOs() {
123

124
    String name = getName();
3✔
125
    if (name.equals(NAME_URLS)) {
4!
126
      return null;
×
127
    }
128
    for (OperatingSystem os : OperatingSystem.values()) {
16!
129
      if (name.startsWith(os.toString())) {
5✔
130
        return os;
2✔
131
      }
132
    }
133
    throw new IllegalStateException("Cannot derive operating-system from " + name);
×
134
  }
135

136
  @Override
137
  public SystemArchitecture getArch() {
138

139
    String name = getName();
3✔
140
    if (name.equals(NAME_URLS)) {
4!
141
      return null;
×
142
    }
143
    int underscore = name.indexOf('_');
4✔
144
    if (underscore < 0) {
2!
145
      return null;
×
146
    }
147
    assert (name.endsWith(EXTENSION_URLS));
5!
148
    // EXTENSION_URLS.length() = ".urls".length() = 5
149
    String archString = name.substring(underscore + 1, name.length() - 5);
10✔
150
    for (SystemArchitecture arch : SystemArchitecture.values()) {
14!
151
      if (archString.equals(arch.toString())) {
5!
152
        return arch;
2✔
153
      }
154
    }
155
    throw new IllegalStateException("Cannot derive system-architecture from " + name);
×
156
  }
157

158
  @Override
159
  public VersionIdentifier getVersion() {
160

161
    UrlVersion version = getParent();
4✔
162
    return version.getVersionIdentifier();
3✔
163
  }
164

165
  @Override
166
  public String getEdition() {
167

168
    UrlEdition edition = getParent().getParent();
6✔
169
    return edition.getName();
3✔
170
  }
171

172
  @Override
173
  public String getTool() {
174

175
    UrlTool tool = getParent().getParent().getParent();
8✔
176
    return tool.getName();
3✔
177
  }
178

179
  @Override
180
  public UrlChecksums getChecksums() {
181

182
    UrlChecksum checksum = getParent().getChecksum(getName());
7✔
183
    if (checksum == null) {
2!
184
      return UrlGenericChecksums.EMPTY;
2✔
185
    }
186
    return checksum;
×
187
  }
188
}
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