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

devonfw / IDEasy / 9903789173

12 Jul 2024 06:58AM UTC coverage: 61.842% (+0.03%) from 61.812%
9903789173

push

github

web-flow
#428: Improve get version and edition (#455)

2008 of 3567 branches covered (56.29%)

Branch coverage included in aggregate %.

5324 of 8289 relevant lines covered (64.23%)

2.82 hits per line

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

71.43
cli/src/main/java/com/devonfw/tools/ide/property/VersionProperty.java
1
package com.devonfw.tools.ide.property;
2

3
import com.devonfw.tools.ide.commandlet.Commandlet;
4
import com.devonfw.tools.ide.completion.CompletionCandidate;
5
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
6
import com.devonfw.tools.ide.context.IdeContext;
7
import com.devonfw.tools.ide.tool.ToolCommandlet;
8
import com.devonfw.tools.ide.version.VersionIdentifier;
9
import com.devonfw.tools.ide.version.VersionSegment;
10

11
import java.util.Collections;
12
import java.util.List;
13
import java.util.function.Consumer;
14
import java.util.stream.IntStream;
15

16
/**
17
 * {@link Property} for {@link VersionIdentifier} as {@link #getValueType() value type}.
18
 */
19
public class VersionProperty extends Property<VersionIdentifier> {
20

21
  /**
22
   * The constructor.
23
   *
24
   * @param name the {@link #getName() property name}.
25
   * @param required the {@link #isRequired() required flag}.
26
   * @param alias the {@link #getAlias() property alias}.
27
   */
28
  public VersionProperty(String name, boolean required, String alias) {
29

30
    this(name, required, alias, null);
6✔
31
  }
1✔
32

33
  /**
34
   * The constructor.
35
   *
36
   * @param name the {@link #getName() property name}.
37
   * @param required the {@link #isRequired() required flag}.
38
   * @param alias the {@link #getAlias() property alias}.
39
   * @param validator the {@link Consumer} used to {@link #validate() validate} the {@link #getValue() value}.
40
   */
41
  public VersionProperty(String name, boolean required, String alias, Consumer<VersionIdentifier> validator) {
42

43
    super(name, required, alias, false, validator);
7✔
44
  }
1✔
45

46
  @Override
47
  public Class<VersionIdentifier> getValueType() {
48

49
    return VersionIdentifier.class;
×
50
  }
51

52
  @Override
53
  public VersionIdentifier parse(String valueAsString, IdeContext context) {
54

55
    return VersionIdentifier.of(valueAsString);
3✔
56
  }
57

58
  @Override
59
  protected void completeValue(String arg, IdeContext context, Commandlet commandlet, CompletionCandidateCollector collector) {
60

61
    ToolCommandlet tool = commandlet.getToolForVersionCompletion();
3✔
62
    if (tool != null) {
2!
63
      completeVersion(VersionIdentifier.of(arg), tool, context, commandlet, collector);
8✔
64
    }
65
  }
1✔
66

67
  private void completeVersion(VersionIdentifier version2complete, ToolCommandlet tool, IdeContext context, Commandlet commandlet,
68
      CompletionCandidateCollector collector) {
69

70
    collector.disableSorting();
2✔
71
    if (tool != null) {
2!
72
      String text;
73
      if (version2complete == null) {
2!
74
        text = "";
3✔
75
      } else {
76
        text = version2complete.toString();
×
77
        if (version2complete.isPattern()) {
×
78
          collector.add(text, "Given version pattern.", this, commandlet);
×
79
          return;
×
80
        }
81
      }
82
      List<VersionIdentifier> versions = context.getUrls()
3✔
83
          .getSortedVersions(tool.getName(), tool.getConfiguredEdition());
5✔
84
      int size = versions.size();
3✔
85
      String[] sortedCandidates = IntStream.rangeClosed(1, size).mapToObj(i -> versions.get(size - i).toString())
16✔
86
          .toArray(String[]::new);
6✔
87
      collector.addAllMatches(text, sortedCandidates, this, commandlet);
7✔
88
      List<CompletionCandidate> candidates = collector.getCandidates();
3✔
89
      Collections.reverse(candidates);
2✔
90
      CompletionCandidate latest = collector.createCandidate(text + VersionSegment.PATTERN_MATCH_ANY_STABLE_VERSION,
8✔
91
          "Latest stable matching version", this, commandlet);
92
      if (candidates.isEmpty()) {
3!
93
        candidates.add(latest);
×
94
      } else {
95
        candidates.add(1, latest);
4✔
96
      }
97
      collector.add(text + VersionSegment.PATTERN_MATCH_ANY_VERSION, "Latest matching version including unstable versions", this, commandlet);
7✔
98
    }
99
  }
1✔
100
}
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