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

devonfw / IDEasy / 17065240915

19 Aug 2025 09:20AM UTC coverage: 68.713% (-0.4%) from 69.087%
17065240915

Pull #1201

github

web-flow
Merge d344ad69c into 42204c624
Pull Request #1201: #103: introduce security module

3379 of 5385 branches covered (62.75%)

Branch coverage included in aggregate %.

8812 of 12357 relevant lines covered (71.31%)

3.13 hits per line

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

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

3
import java.util.ArrayList;
4
import java.util.Collections;
5
import java.util.Comparator;
6
import java.util.HashMap;
7
import java.util.List;
8
import java.util.Map;
9

10
import com.devonfw.tools.ide.cli.CliException;
11
import com.devonfw.tools.ide.context.IdeContext;
12
import com.devonfw.tools.ide.os.SystemInfo;
13
import com.devonfw.tools.ide.tool.ToolCommandlet;
14
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
15
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
16
import com.devonfw.tools.ide.url.model.folder.UrlTool;
17
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
18
import com.devonfw.tools.ide.version.GenericVersionRange;
19
import com.devonfw.tools.ide.version.VersionIdentifier;
20

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

26
  private final IdeContext context;
27

28
  private final UrlRepository repository;
29

30
  private final Map<String, List<VersionIdentifier>> toolEdition2VersionMap;
31

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

39
    this(context, new UrlRepository(context.getUrlsPath()));
8✔
40
  }
1✔
41

42
  public UrlMetadata(IdeContext context, UrlRepository urlRepository) {
43

44
    super();
2✔
45
    this.context = context;
3✔
46
    this.repository = urlRepository;
3✔
47
    this.toolEdition2VersionMap = new HashMap<>();
5✔
48
  }
1✔
49

50
  /**
51
   * @param tool the name of the {@link UrlTool}.
52
   * @param edition the name of the {@link UrlEdition}.
53
   * @return the {@link UrlEdition}. Will be lazily loaded.
54
   */
55
  public UrlEdition getEdition(String tool, String edition) {
56

57
    UrlTool urlTool = this.repository.getOrCreateChild(tool);
6✔
58
    return urlTool.getOrCreateChild(edition);
5✔
59
  }
60

61
  @Override
62
  public List<String> getSortedEditions(String tool) {
63

64
    List<String> list = new ArrayList<>();
4✔
65
    UrlTool urlTool = this.repository.getChild(tool);
6✔
66
    if (urlTool == null) {
2✔
67
      this.context.warning("Can't get sorted editions for tool {} because it does not exist in {}.", tool, this.repository.getPath());
17✔
68
    } else {
69
      for (UrlEdition urlEdition : urlTool.getChildren()) {
11✔
70
        list.add(urlEdition.getName());
5✔
71
      }
1✔
72
    }
73
    Collections.sort(list);
2✔
74
    return Collections.unmodifiableList(list);
3✔
75
  }
76

77
  @Override
78
  public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) {
79

80
    String key = tool + "/" + edition;
4✔
81
    return this.toolEdition2VersionMap.computeIfAbsent(key, k -> computeSortedVersions(tool, edition));
15✔
82
  }
83

84
  private List<VersionIdentifier> computeSortedVersions(String tool, String edition) {
85

86
    List<VersionIdentifier> list = new ArrayList<>();
4✔
87
    UrlEdition urlEdition = getEdition(tool, edition);
5✔
88
    urlEdition.load(false);
3✔
89
    for (UrlVersion urlVersion : urlEdition.getChildren()) {
11✔
90
      VersionIdentifier versionIdentifier = urlVersion.getVersionIdentifier();
3✔
91
      SystemInfo sys = this.context.getSystemInfo();
4✔
92
      try {
93
        urlVersion.getMatchingUrls(sys.getOs(), sys.getArchitecture());
7✔
94
        list.add(versionIdentifier);
4✔
95
      } catch (CliException e) {
1✔
96
        // ignore, but do not add versionIdentifier as there is no download available for the current system
97
      }
1✔
98
    }
1✔
99
    list.sort(Comparator.reverseOrder());
3✔
100
    return Collections.unmodifiableList(list);
3✔
101
  }
102

103
  /**
104
   * @param tool the name of the {@link UrlTool}.
105
   * @param edition the name of the {@link UrlEdition}.
106
   * @param version the {@link GenericVersionRange} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for
107
   *     the latest version.
108
   * @param toolCommandlet the {@link ToolCommandlet}.
109
   * @return the latest matching {@link VersionIdentifier} for the given {@code tool} and {@code edition}.
110
   */
111
  @Override
112
  public VersionIdentifier resolveVersion(String tool, String edition, GenericVersionRange version, ToolCommandlet toolCommandlet) {
113

114
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
115
    return VersionIdentifier.resolveVersionPattern(version, versions, this.context);
6✔
116
  }
117

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

128
    VersionIdentifier resolvedVersion = resolveVersion(tool, edition, version, toolCommandlet);
7✔
129
    UrlVersion urlVersion = getEdition(tool, edition).getChild(resolvedVersion.toString());
9✔
130
    if (urlVersion == null) {
2!
131
      throw new CliException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + ".");
×
132
    }
133
    return urlVersion;
2✔
134
  }
135

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