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

devonfw / IDEasy / 13327588889

14 Feb 2025 10:44AM UTC coverage: 67.947% (-0.5%) from 68.469%
13327588889

Pull #1021

github

web-flow
Merge d03159bfe into 52609dacb
Pull Request #1021: #786: support ide upgrade to automatically update to the latest version of IDEasy

2964 of 4791 branches covered (61.87%)

Branch coverage included in aggregate %.

7688 of 10886 relevant lines covered (70.62%)

3.07 hits per line

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

95.24
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.tool.ToolCommandlet;
13
import com.devonfw.tools.ide.url.model.folder.UrlEdition;
14
import com.devonfw.tools.ide.url.model.folder.UrlRepository;
15
import com.devonfw.tools.ide.url.model.folder.UrlTool;
16
import com.devonfw.tools.ide.url.model.folder.UrlVersion;
17
import com.devonfw.tools.ide.version.GenericVersionRange;
18
import com.devonfw.tools.ide.version.VersionIdentifier;
19

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

25
  private final IdeContext context;
26

27
  private final UrlRepository repository;
28

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

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

38
    super();
2✔
39
    this.context = context;
3✔
40
    this.repository = new UrlRepository(this.context.getUrlsPath());
8✔
41
    this.toolEdition2VersionMap = new HashMap<>();
5✔
42
  }
1✔
43

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

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

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

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

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

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

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

80
    List<VersionIdentifier> list = new ArrayList<>();
4✔
81
    UrlEdition urlEdition = getEdition(tool, edition);
5✔
82
    urlEdition.load(false);
3✔
83
    for (UrlVersion urlVersion : urlEdition.getChildren()) {
11✔
84
      VersionIdentifier versionIdentifier = urlVersion.getVersionIdentifier();
3✔
85
      list.add(versionIdentifier);
4✔
86
    }
1✔
87
    list.sort(Comparator.reverseOrder());
3✔
88
    return Collections.unmodifiableList(list);
3✔
89
  }
90

91
  /**
92
   * @param tool the name of the {@link UrlTool}.
93
   * @param edition the name of the {@link UrlEdition}.
94
   * @param version the {@link GenericVersionRange} to match. May be a {@link VersionIdentifier#isPattern() pattern}, a specific version or {@code null} for
95
   *     the latest version.
96
   * @param toolCommandlet the {@link ToolCommandlet}.
97
   * @return the latest matching {@link VersionIdentifier} for the given {@code tool} and {@code edition}.
98
   */
99
  @Override
100
  public VersionIdentifier resolveVersion(String tool, String edition, GenericVersionRange version, ToolCommandlet toolCommandlet) {
101
    List<VersionIdentifier> versions = getSortedVersions(tool, edition, toolCommandlet);
6✔
102
    return VersionIdentifier.resolveVersionPattern(version, versions, this.context);
6✔
103
  }
104

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

115
    VersionIdentifier resolvedVersion = resolveVersion(tool, edition, version, toolCommandlet);
7✔
116
    UrlVersion urlVersion = getEdition(tool, edition).getChild(resolvedVersion.toString());
9✔
117
    if (urlVersion == null) {
2!
118
      throw new CliException("Version " + version + " for tool " + tool + " does not exist in edition " + edition + ".");
×
119
    }
120
    return urlVersion;
2✔
121
  }
122

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