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

devonfw / IDEasy / 16465009257

23 Jul 2025 08:02AM UTC coverage: 68.467% (+0.002%) from 68.465%
16465009257

Pull #1423

github

web-flow
Merge e60c89856 into 31d427e63
Pull Request #1423: #1387: throw CliException when tool version not supported for OS

3288 of 5206 branches covered (63.16%)

Branch coverage included in aggregate %.

8413 of 11884 relevant lines covered (70.79%)

3.13 hits per line

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

69.44
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.cli.CliException;
9
import com.devonfw.tools.ide.os.OperatingSystem;
10
import com.devonfw.tools.ide.os.SystemArchitecture;
11
import com.devonfw.tools.ide.url.model.AbstractUrlFolderWithParent;
12
import com.devonfw.tools.ide.url.model.file.UrlChecksum;
13
import com.devonfw.tools.ide.url.model.file.UrlDownloadFile;
14
import com.devonfw.tools.ide.url.model.file.UrlFile;
15
import com.devonfw.tools.ide.url.model.file.UrlStatusFile;
16
import com.devonfw.tools.ide.version.VersionIdentifier;
17

18
/**
19
 * 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
20
 * "17.0.5_8".
21
 */
22
public class UrlVersion extends AbstractUrlFolderWithParent<UrlEdition, UrlFile<?>> {
23

24
  private VersionIdentifier versionIdentifier;
25

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

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

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

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

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

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

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

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

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

69
    return getUrls(null, null);
5✔
70
  }
71

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

78
    return getUrls(os, null);
5✔
79
  }
80

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

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

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

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

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

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

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

140
    return (UrlStatusFile) getChild(UrlStatusFile.STATUS_JSON);
×
141
  }
142

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

148
    return (UrlStatusFile) getOrCreateChild(UrlStatusFile.STATUS_JSON);
5✔
149
  }
150

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

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

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

168
    return urlsFilename + UrlChecksum.EXTENSION;
3✔
169
  }
170

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

177
    return (UrlChecksum) getOrCreateChild(getChecksumFilename(urlsFilename));
×
178
  }
179

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

186
    return (UrlChecksum) getChild(getChecksumFilename(urlsFilename));
7✔
187
  }
188

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

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

205
  @Override
206
  protected boolean isAllowedChild(String name, boolean folder) {
207

208
    return true;
2✔
209
  }
210

211
  @Override
212
  public void save() {
213

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

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