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

devonfw / IDEasy / 14494924376

16 Apr 2025 02:13PM UTC coverage: 67.446% (+0.1%) from 67.315%
14494924376

Pull #1244

github

web-flow
Merge 819380b82 into b631f5424
Pull Request #1244: #1229 just list versions with urls for the intended OS

3076 of 4964 branches covered (61.97%)

Branch coverage included in aggregate %.

7915 of 11332 relevant lines covered (69.85%)

3.05 hits per line

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

95.65
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
    super();
2✔
40
    this.context = context;
3✔
41
    this.repository = new UrlRepository(this.context.getUrlsPath());
8✔
42
    this.toolEdition2VersionMap = new HashMap<>();
5✔
43
  }
1✔
44

45
  /**
46
   * @param tool the name of the {@link UrlTool}.
47
   * @param edition the name of the {@link UrlEdition}.
48
   * @return the {@link UrlEdition}. Will be lazily loaded.
49
   */
50
  public UrlEdition getEdition(String tool, String edition) {
51

52
    UrlTool urlTool = this.repository.getOrCreateChild(tool);
6✔
53
    return urlTool.getOrCreateChild(edition);
5✔
54
  }
55

56
  @Override
57
  public List<String> getSortedEditions(String tool) {
58

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

72
  @Override
73
  public List<VersionIdentifier> getSortedVersions(String tool, String edition, ToolCommandlet toolCommandlet) {
74

75
    String key = tool + "/" + edition;
4✔
76
    return this.toolEdition2VersionMap.computeIfAbsent(key, k -> computeSortedVersions(tool, edition));
15✔
77
  }
78

79
  private List<VersionIdentifier> computeSortedVersions(String tool, String edition) {
80

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

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

109
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
110
    return VersionIdentifier.resolveVersionPattern(version, versions, this.context);
6✔
111
  }
112

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

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

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

© 2025 Coveralls, Inc