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

devonfw / IDEasy / 22345446363

24 Feb 2026 09:49AM UTC coverage: 70.247% (-0.2%) from 70.474%
22345446363

Pull #1714

github

web-flow
Merge 5655b6589 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4065 of 6384 branches covered (63.67%)

Branch coverage included in aggregate %.

10597 of 14488 relevant lines covered (73.14%)

3.08 hits per line

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

92.73
cli/src/main/java/com/devonfw/tools/ide/url/model/UrlMetadata.java
1
package com.devonfw.tools.ide.url.model;
2

3
import java.nio.file.Path;
4
import java.nio.file.Paths;
5
import java.util.ArrayList;
6
import java.util.Collections;
7
import java.util.Comparator;
8
import java.util.HashMap;
9
import java.util.List;
10
import java.util.Map;
11

12
import org.slf4j.Logger;
13
import org.slf4j.LoggerFactory;
14

15
import com.devonfw.tools.ide.cli.CliException;
16
import com.devonfw.tools.ide.context.IdeContext;
17
import com.devonfw.tools.ide.os.SystemInfo;
18
import com.devonfw.tools.ide.tool.ToolCommandlet;
19
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
20
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
21
import com.devonfw.tools.ide.url.model.folder.UrlTool;
22
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
23
import com.devonfw.tools.ide.version.GenericVersionRange;
24
import com.devonfw.tools.ide.version.VersionIdentifier;
25

26
/**
27
 * Service to {@link #getEdition(String, String) load} an {@link UrlEdition} to get access to its versions.
28
 */
29
public class UrlMetadata implements AbstractUrlMetadata {
30

31
  private static final Logger LOG = LoggerFactory.getLogger(UrlMetadata.class);
4✔
32

33
  private final IdeContext context;
34

35
  private final UrlRepository repository;
36

37
  private final Map<String, List<VersionIdentifier>> toolEdition2VersionMap;
38

39
  /**
40
   * The constructor.
41
   *
42
   * @param context the owning {@link IdeContext}.
43
   */
44
  public UrlMetadata(IdeContext context) {
45

46
    this(context, createRepository(context));
5✔
47
  }
1✔
48

49
  /**
50
   * The constructor.
51
   *
52
   * @param context the owning {@link IdeContext}.
53
   * @param urlRepository the {@link UrlRepository} to use for loading tool metadata.
54
   */
55
  public UrlMetadata(IdeContext context, UrlRepository urlRepository) {
56

57
    super();
2✔
58
    this.context = context;
3✔
59
    this.repository = urlRepository;
3✔
60
    this.toolEdition2VersionMap = new HashMap<>();
5✔
61
  }
1✔
62

63
  private static UrlRepository createRepository(IdeContext context) {
64
    Path urlsPath = context.getUrlsPath();
3✔
65
    if (urlsPath == null) {
2!
66
      urlsPath = Paths.get("urls");
×
67
    }
68
    return new UrlRepository(urlsPath);
5✔
69
  }
70

71
  /**
72
   * @param tool the name of the {@link UrlTool}.
73
   * @param edition the name of the {@link UrlEdition}.
74
   * @return the {@link UrlEdition}. Will be lazily loaded.
75
   */
76
  public UrlEdition getEdition(String tool, String edition) {
77

78
    UrlTool urlTool = this.repository.getOrCreateChild(tool);
6✔
79
    return urlTool.getOrCreateChild(edition);
5✔
80
  }
81

82
  @Override
83
  public List<String> getSortedEditions(String tool) {
84

85
    List<String> list = new ArrayList<>();
4✔
86
    UrlTool urlTool = this.repository.getChild(tool);
6✔
87
    if (urlTool == null) {
2✔
88
      LOG.warn("Can't get sorted editions for tool {} because it does not exist in {}.", tool, this.repository.getPath());
8✔
89
    } else {
90
      for (UrlEdition urlEdition : urlTool.getChildren()) {
11✔
91
        list.add(urlEdition.getName());
5✔
92
      }
1✔
93
    }
94
    Collections.sort(list);
2✔
95
    return Collections.unmodifiableList(list);
3✔
96
  }
97

98
  @Override
99
  public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) {
100

101
    String key = tool + "/" + edition;
4✔
102
    return this.toolEdition2VersionMap.computeIfAbsent(key, k -> computeSortedVersions(tool, edition));
15✔
103
  }
104

105
  private List<VersionIdentifier> computeSortedVersions(String tool, String edition) {
106

107
    List<VersionIdentifier> list = new ArrayList<>();
4✔
108
    UrlEdition urlEdition = getEdition(tool, edition);
5✔
109
    urlEdition.load(false);
3✔
110
    for (UrlVersion urlVersion : urlEdition.getChildren()) {
11✔
111
      VersionIdentifier versionIdentifier = urlVersion.getVersionIdentifier();
3✔
112
      SystemInfo sys = this.context.getSystemInfo();
4✔
113
      try {
114
        urlVersion.getMatchingUrls(sys.getOs(), sys.getArchitecture());
7✔
115
        list.add(versionIdentifier);
4✔
116
      } catch (CliException e) {
1✔
117
        // ignore, but do not add versionIdentifier as there is no download available for the current system
118
      }
1✔
119
    }
1✔
120
    list.sort(Comparator.reverseOrder());
3✔
121
    return Collections.unmodifiableList(list);
3✔
122
  }
123

124
  /**
125
   * @param tool the name of the {@link UrlTool}.
126
   * @param edition the name of the {@link UrlEdition}.
127
   * @param version the {@link GenericVersionRange} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for
128
   *     the latest version.
129
   * @param toolCommandlet the {@link ToolCommandlet}.
130
   * @return the latest matching {@link VersionIdentifier} for the given {@code tool} and {@code edition}.
131
   */
132
  @Override
133
  public VersionIdentifier resolveVersion(String tool, String edition, GenericVersionRange version, ToolCommandlet toolCommandlet) {
134

135
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
136
    return VersionIdentifier.resolveVersionPattern(version, versions);
4✔
137
  }
138

139
  /**
140
   * @param tool the name of the {@link UrlTool}.
141
   * @param edition the name of the {@link UrlEdition}.
142
   * @param version the {@link GenericVersionRange} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for
143
   *     the latest version.
144
   * @param toolCommandlet the {@link ToolCommandlet}.
145
   * @return the latest matching {@link UrlVersion} for the given {@code tool} and {@code edition}.
146
   */
147
  public UrlVersion getVersionFolder(String tool, String edition, GenericVersionRange version, ToolCommandlet toolCommandlet) {
148

149
    VersionIdentifier resolvedVersion = resolveVersion(tool, edition, version, toolCommandlet);
7✔
150
    UrlVersion urlVersion = getEdition(tool, edition).getChild(resolvedVersion.toString());
9✔
151
    if (urlVersion == null) {
2!
152
      throw new CliException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + ".");
×
153
    }
154
    return urlVersion;
2✔
155
  }
156

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