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

devonfw / IDEasy / 20271179405

16 Dec 2025 02:21PM UTC coverage: 70.061% (-0.08%) from 70.142%
20271179405

push

github

web-flow
#1660: status robustness #1475: fix tests to work offline (#1661)

3965 of 6233 branches covered (63.61%)

Branch coverage included in aggregate %.

10162 of 13931 relevant lines covered (72.95%)

3.15 hits per line

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

92.59
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 com.devonfw.tools.ide.cli.CliException;
13
import com.devonfw.tools.ide.context.IdeContext;
14
import com.devonfw.tools.ide.os.SystemInfo;
15
import com.devonfw.tools.ide.tool.ToolCommandlet;
16
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
17
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
18
import com.devonfw.tools.ide.url.model.folder.UrlTool;
19
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
20
import com.devonfw.tools.ide.version.GenericVersionRange;
21
import com.devonfw.tools.ide.version.VersionIdentifier;
22

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

28
  private final IdeContext context;
29

30
  private final UrlRepository repository;
31

32
  private final Map<String, List<VersionIdentifier>> toolEdition2VersionMap;
33

34
  /**
35
   * The constructor.
36
   *
37
   * @param context the owning {@link IdeContext}.
38
   */
39
  public UrlMetadata(IdeContext context) {
40

41
    this(context, createRepository(context));
5✔
42
  }
1✔
43

44
  /**
45
   * The constructor.
46
   *
47
   * @param context the owning {@link IdeContext}.
48
   * @param urlRepository the {@link UrlRepository} to use for loading tool metadata.
49
   */
50
  public UrlMetadata(IdeContext context, UrlRepository urlRepository) {
51

52
    super();
2✔
53
    this.context = context;
3✔
54
    this.repository = urlRepository;
3✔
55
    this.toolEdition2VersionMap = new HashMap<>();
5✔
56
  }
1✔
57

58
  private static UrlRepository createRepository(IdeContext context) {
59
    Path urlsPath = context.getUrlsPath();
3✔
60
    if (urlsPath == null) {
2!
61
      urlsPath = Paths.get("urls");
×
62
    }
63
    return new UrlRepository(urlsPath);
5✔
64
  }
65

66
  /**
67
   * @param tool the name of the {@link UrlTool}.
68
   * @param edition the name of the {@link UrlEdition}.
69
   * @return the {@link UrlEdition}. Will be lazily loaded.
70
   */
71
  public UrlEdition getEdition(String tool, String edition) {
72

73
    UrlTool urlTool = this.repository.getOrCreateChild(tool);
6✔
74
    return urlTool.getOrCreateChild(edition);
5✔
75
  }
76

77
  @Override
78
  public List<String> getSortedEditions(String tool) {
79

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

93
  @Override
94
  public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) {
95

96
    String key = tool + "/" + edition;
4✔
97
    return this.toolEdition2VersionMap.computeIfAbsent(key, k -> computeSortedVersions(tool, edition));
15✔
98
  }
99

100
  private List<VersionIdentifier> computeSortedVersions(String tool, String edition) {
101

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

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

130
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
131
    return VersionIdentifier.resolveVersionPattern(version, versions, this.context);
6✔
132
  }
133

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

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

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