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

devonfw / IDEasy / 17093199286

20 Aug 2025 08:39AM UTC coverage: 68.717% (-0.4%) from 69.087%
17093199286

Pull #1201

github

web-flow
Merge 902765a14 into 6b7da03a8
Pull Request #1201: #103: introduce security module

3379 of 5385 branches covered (62.75%)

Branch coverage included in aggregate %.

8812 of 12356 relevant lines covered (71.32%)

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
  /**
43
   * The constructor.
44
   *
45
   * @param context the owning {@link IdeContext}.
46
   * @param urlRepository the {@link UrlRepository} to use for loading tool metadata.
47
   */
48
  public UrlMetadata(IdeContext context, UrlRepository urlRepository) {
49

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

56
  /**
57
   * @param tool the name of the {@link UrlTool}.
58
   * @param edition the name of the {@link UrlEdition}.
59
   * @return the {@link UrlEdition}. Will be lazily loaded.
60
   */
61
  public UrlEdition getEdition(String tool, String edition) {
62

63
    UrlTool urlTool = this.repository.getOrCreateChild(tool);
6✔
64
    return urlTool.getOrCreateChild(edition);
5✔
65
  }
66

67
  @Override
68
  public List<String> getSortedEditions(String tool) {
69

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

83
  @Override
84
  public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) {
85

86
    String key = tool + "/" + edition;
4✔
87
    return this.toolEdition2VersionMap.computeIfAbsent(key, k -> computeSortedVersions(tool, edition));
15✔
88
  }
89

90
  private List<VersionIdentifier> computeSortedVersions(String tool, String edition) {
91

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

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

120
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
121
    return VersionIdentifier.resolveVersionPattern(version, versions, this.context);
6✔
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 UrlVersion} for the given {@code tool} and {@code edition}.
131
   */
132
  public UrlVersion getVersionFolder(String tool, String edition, GenericVersionRange version, ToolCommandlet toolCommandlet) {
133

134
    VersionIdentifier resolvedVersion = resolveVersion(tool, edition, version, toolCommandlet);
7✔
135
    UrlVersion urlVersion = getEdition(tool, edition).getChild(resolvedVersion.toString());
9✔
136
    if (urlVersion == null) {
2!
137
      throw new CliException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + ".");
×
138
    }
139
    return urlVersion;
2✔
140
  }
141

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