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

devonfw / IDEasy / 16992639699

15 Aug 2025 02:54PM UTC coverage: 69.372% (-0.1%) from 69.51%
16992639699

push

github

web-flow
#1451: fix merge:id default for single attribute (#1452)

3362 of 5289 branches covered (63.57%)

Branch coverage included in aggregate %.

8731 of 12143 relevant lines covered (71.9%)

3.16 hits per line

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

66.2
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
            throw new CliException("No download was found for OS " + os + "@" + arch + " in " + getPath());
12✔
114
          }
115
        }
116
      }
117
    }
118
    return urls;
2✔
119
  }
120

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

207
    return true;
2✔
208
  }
209

210
  @Override
211
  public void save() {
212

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

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