• 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

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

3
import java.util.Collections;
4
import java.util.List;
5
import java.util.stream.IntStream;
6

7
import com.devonfw.tools.ide.commandlet.Commandlet;
8
import com.devonfw.tools.ide.completion.CompletionCandidate;
9
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
10
import com.devonfw.tools.ide.context.IdeContext;
11
import com.devonfw.tools.ide.tool.ToolCommandlet;
12
import com.devonfw.tools.ide.tool.repository.ToolRepository;
13
import com.devonfw.tools.ide.validation.PropertyValidator;
14
import com.devonfw.tools.ide.version.VersionIdentifier;
15
import com.devonfw.tools.ide.version.VersionSegment;
16

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

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

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

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

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

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

50
    return VersionIdentifier.class;
×
51
  }
52

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

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

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

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

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

71
    collector.disableSorting();
2✔
72
    if (tool != null) {
2!
73
      String text;
74
      if (version2complete == null) {
2✔
75
        text = "";
3✔
76
      } else {
77
        text = version2complete.toString();
3✔
78
        if (version2complete.isPattern()) {
3!
79
          collector.add(text, "Given version pattern.", this, commandlet);
6✔
80
          return;
1✔
81
        }
82
      }
83
      ToolRepository toolRepository = tool.getToolRepository();
3✔
84
      List<VersionIdentifier> versions = toolRepository.getSortedVersions(tool.getName(), tool.getConfiguredEdition(), tool);
8✔
85
      int size = versions.size();
3✔
86
      String[] sortedCandidates = IntStream.rangeClosed(1, size).mapToObj(i -> versions.get(size - i).toString()).toArray(String[]::new);
22✔
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

© 2025 Coveralls, Inc