• 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

42.25
cli/src/main/java/com/devonfw/tools/ide/url/model/folder/UrlVersion.java
1
package com.devonfw.tools.ide.url.model.folder;
2

3
import java.io.IOException;
4
import java.nio.file.Files;
5
import java.nio.file.Path;
6
import java.util.Objects;
7

8
import com.devonfw.tools.ide.os.OperatingSystem;
9
import com.devonfw.tools.ide.os.SystemArchitecture;
10
import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent;
11
import com.devonfw.tools.ide.url.model.file.UrlChecksum;
12
import com.devonfw.tools.ide.url.model.file.UrlDownloadFile;
13
import com.devonfw.tools.ide.url.model.file.UrlFile;
14
import com.devonfw.tools.ide.url.model.file.UrlStatusFile;
15
import com.devonfw.tools.ide.version.VersionIdentifier;
16

17
/**
18
 * An {@link UrlFolder} representing the actual version of an {@link UrlEdition}. Examples for the {@link #getName() name} of such version could be "1.6.2" or
19
 * "17.0.5_8".
20
 */
21
public class UrlVersion extends AbstractUrlFolderWithParent<UrlEdition, UrlFile<?>> {
22

23
  private VersionIdentifier versionIdentifier;
24

25
  /**
26
   * The constructor.
27
   *
28
   * @param parent the {@link #getParent() parent folder}.
29
   * @param name the {@link #getName() filename}.
30
   */
31
  public UrlVersion(UrlEdition parent, String name) {
32

33
    super(parent, name);
4✔
34
  }
1✔
35

36
  /**
37
   * @return the {@link UrlDownloadFile} {@link #getName() named} "urls". Will be created if it does not exist.
38
   */
39
  public UrlDownloadFile getOrCreateUrls() {
40

41
    return getOrCreateUrls(null, null);
×
42
  }
43

44
  /**
45
   * @param os the optional {@link OperatingSystem}.
46
   * @return the {@link UrlDownloadFile} {@link #getName() named} "«os».urls". Will be created if it does not exist.
47
   */
48
  public UrlDownloadFile getOrCreateUrls(OperatingSystem os) {
49

50
    return getOrCreateUrls(os, null);
×
51
  }
52

53
  /**
54
   * @param os the optional {@link OperatingSystem}.
55
   * @param arch the optional {@link SystemArchitecture}.
56
   * @return the {@link UrlDownloadFile} {@link #getName() named} "«os»_«arch».urls". Will be created if it does not exist.
57
   */
58
  public UrlDownloadFile getOrCreateUrls(OperatingSystem os, SystemArchitecture arch) {
59

60
    return (UrlDownloadFile) getOrCreateChild(getUrlsFileName(os, arch));
×
61
  }
62

63
  /**
64
   * @return the {@link UrlDownloadFile} {@link #getName() named} "urls".
65
   */
66
  public UrlDownloadFile getUrls() {
67

68
    return getUrls(null, null);
×
69
  }
70

71
  /**
72
   * @param os the optional {@link OperatingSystem}.
73
   * @return the {@link UrlDownloadFile} {@link #getName() named} "«os».urls".
74
   */
75
  public UrlDownloadFile getUrls(OperatingSystem os) {
76

77
    return getUrls(os, null);
×
78
  }
79

80
  /**
81
   * @param os the optional {@link OperatingSystem}.
82
   * @param arch the optional {@link SystemArchitecture}.
83
   * @return the {@link UrlDownloadFile} {@link #getName() named} "«os»_«arch».urls".
84
   */
85
  public UrlDownloadFile getUrls(OperatingSystem os, SystemArchitecture arch) {
86

87
    return (UrlDownloadFile) getChild(getUrlsFileName(os, arch));
7✔
88
  }
89

90
  /**
91
   * Finds the existing {@link UrlDownloadFile} child matching the given {@link OperatingSystem} and {@link SystemArchitecture} of the current machine.
92
   *
93
   * @param os the current {@link OperatingSystem}.
94
   * @param arch the current {@link SystemArchitecture}.
95
   * @return the matching {@link UrlDownloadFile}.
96
   */
97
  public UrlDownloadFile getMatchingUrls(OperatingSystem os, SystemArchitecture arch) {
98

99
    Objects.requireNonNull(os);
3✔
100
    Objects.requireNonNull(arch);
3✔
101
    UrlDownloadFile urls = getUrls(os, arch);
5✔
102
    if (urls == null) {
2!
103
      urls = getUrls(os);
×
104
      if (urls == null) {
×
105
        urls = getUrls();
×
106
        if (urls == null) {
×
107
          if ((os == OperatingSystem.MAC) && (arch == SystemArchitecture.ARM64)) {
×
108
            // fallback for MacOS to use x64 using rosetta emulation
109
            urls = getUrls(os, SystemArchitecture.X64);
×
110
          }
111
          if (urls == null) {
×
112
            throw new IllegalStateException("No download was found for OS " + os + "@" + arch + " in " + getPath());
×
113
          }
114
        }
115
      }
116
    }
117
    return urls;
2✔
118
  }
119

120
  /**
121
   * @param os the optional {@link OperatingSystem}.
122
   * @param arch the optional {@link SystemArchitecture}.
123
   * @return String of the format "«os»_«arch».urls".
124
   */
125
  public static String getUrlsFileName(OperatingSystem os, SystemArchitecture arch) {
126

127
    if ((os == null) && (arch == null)) {
2!
128
      return UrlDownloadFile.NAME_URLS;
×
129
    }
130
    return os + "_" + SystemArchitecture.orDefault(arch) + UrlDownloadFile.EXTENSION_URLS;
7✔
131
  }
132

133
  /**
134
   * @return the {@link UrlStatusFile}.
135
   */
136
  public UrlStatusFile getStatus() {
137

138
    return (UrlStatusFile) getChild(UrlStatusFile.STATUS_JSON);
×
139
  }
140

141
  /**
142
   * @return the {@link UrlStatusFile}.
143
   */
144
  public UrlStatusFile getOrCreateStatus() {
145

146
    return (UrlStatusFile) getOrCreateChild(UrlStatusFile.STATUS_JSON);
5✔
147
  }
148

149
  /**
150
   * @return the {@link VersionIdentifier}
151
   */
152
  public VersionIdentifier getVersionIdentifier() {
153

154
    if (this.versionIdentifier == null) {
3✔
155
      this.versionIdentifier = VersionIdentifier.of(getName());
5✔
156
    }
157
    return this.versionIdentifier;
3✔
158
  }
159

160
  /**
161
   * @param urlsFilename the {@link #getName() filename} of the URLs file.
162
   * @return String of {@link #getName() filename} of the URLs file with added extension.
163
   */
164
  public String getChecksumFilename(String urlsFilename) {
165

166
    return urlsFilename + UrlChecksum.EXTENSION;
3✔
167
  }
168

169
  /**
170
   * @param urlsFilename the {@link #getName() filename} of the URLs file.
171
   * @return the existing or newly created and added {@link UrlChecksum} file.
172
   */
173
  public UrlChecksum getOrCreateChecksum(String urlsFilename) {
174

175
    return (UrlChecksum) getOrCreateChild(getChecksumFilename(urlsFilename));
×
176
  }
177

178
  /**
179
   * @param urlsFilename the {@link #getName() filename} of the URLs file.
180
   * @return the existing {@link UrlChecksum} file.
181
   */
182
  public UrlChecksum getChecksum(String urlsFilename) {
183

184
    return (UrlChecksum) getChild(getChecksumFilename(urlsFilename));
7✔
185
  }
186

187
  /**
188
   * This method is used to add new children to the children collection of an instance from this class.
189
   *
190
   * @param name The name of the {@link UrlFile} object that should be created.
191
   */
192
  @Override
193
  protected UrlFile<?> newChild(String name) {
194

195
    if (Objects.equals(name, UrlStatusFile.STATUS_JSON)) {
4✔
196
      return new UrlStatusFile(this);
5✔
197
    } else if (name.endsWith(UrlChecksum.EXTENSION)) {
4✔
198
      return new UrlChecksum(this, name);
6✔
199
    }
200
    return new UrlDownloadFile(this, name);
6✔
201
  }
202

203
  @Override
204
  protected boolean isAllowedChild(String name, boolean folder) {
205

206
    return true;
2✔
207
  }
208

209
  @Override
210
  public void save() {
211

212
    if (getChildCount() == 0) {
×
213
      return;
×
214
    }
215
    Path path = getPath();
×
216
    try {
217
      Files.createDirectories(path);
×
218
    } catch (IOException e) {
×
219
      throw new IllegalStateException("Failed to create directory " + path, e);
×
220
    }
×
221
    super.save();
×
222
  }
×
223

224
}
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