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

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

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

57.14
cli/src/main/java/com/devonfw/tools/ide/variable/VariableDefinition.java
1
package com.devonfw.tools.ide.variable;
2

3
import java.util.Collection;
4

5
import com.devonfw.tools.ide.context.IdeContext;
6
import com.devonfw.tools.ide.environment.EnvironmentVariables;
7
import com.devonfw.tools.ide.environment.VariableLine;
8

9
/**
10
 * Interface for a definition of a variable.
11
 *
12
 * @param <V> the {@link #getValueType() value type}.
13
 */
14
public interface VariableDefinition<V> {
15

16
  /**
17
   * @return the name of the variable.
18
   */
19
  String getName();
20

21
  /**
22
   * @return the optional legacy name that is still supported for downward compatibility. May be {@code null} if undefined (no legacy support).
23
   */
24
  String getLegacyName();
25

26
  /**
27
   * @return the {@link Class} reflecting the type of the variable value.
28
   */
29
  Class<V> getValueType();
30

31
  /**
32
   * @param context the {@link IdeContext}.
33
   * @return the default value. May be {@code null}.
34
   */
35
  V getDefaultValue(IdeContext context);
36

37
  /**
38
   * @param context the {@link IdeContext}.
39
   * @return the default value as {@link String}. May be {@code null}.
40
   * @see #getDefaultValue(IdeContext)
41
   * @see #toString(Object, IdeContext)
42
   */
43
  default String getDefaultValueAsString(IdeContext context) {
44

45
    V value = getDefaultValue(context);
4✔
46
    if (value == null) {
2✔
47
      return null;
2✔
48
    }
49
    return toString(value, context);
5✔
50
  }
51

52
  /**
53
   * @return {@code true} if the {@link #getDefaultValue(IdeContext) default value} shall be used without any
54
   * {@link EnvironmentVariables#get(String) variable lookup} (to prevent odd overriding of build in variables like IDE_HOME), {@code false} otherwise
55
   * (overriding of default value is allowed and intended).
56
   */
57
  boolean isForceDefaultValue();
58

59
  /**
60
   * @param value the value as {@link String}. May NOT be {@code null}.
61
   * @param context the {@link IdeContext}.
62
   * @return the value converted to the {@link #getValueType() value type}.
63
   */
64
  V fromString(String value, IdeContext context);
65

66
  /**
67
   * @return {@code true} if the variable needs to be exported, {@code false} otherwise.
68
   */
69
  boolean isExport();
70

71
  /**
72
   * @param value the typed value.
73
   * @param context the {@link IdeContext}.
74
   * @return the value converted to {@link String}.
75
   */
76
  default String toString(V value, IdeContext context) {
77

78
    if (value == null) {
2!
79
      return "";
×
80
    } else if (value instanceof Collection<?> collection) {
3!
81
      StringBuilder sb = new StringBuilder();
×
82
      for (Object element : collection) {
×
83
        if (sb.length() > 0) {
×
84
          sb.append(',');
×
85
        }
86
        sb.append(element);
×
87
      }
×
88
      return sb.toString();
×
89
    }
90
    return value.toString();
3✔
91
  }
92

93
  /**
94
   * @param context the {@link IdeContext}.
95
   * @return the value of the variable of this {@link VariableDefinition}.
96
   */
97
  V get(IdeContext context);
98

99
  /**
100
   * @param line the {@link VariableLine} that potentially needs to be migrated.
101
   * @return the original {@link VariableLine} or a migrated copy of it.
102
   */
103
  default VariableLine migrateLine(VariableLine line) {
104

105
    String name = line.getName();
3✔
106
    if (name != null) {
2!
107
      String newName = getName();
3✔
108
      if (!name.equals(newName)) {
4✔
109
        return line.withName(newName);
4✔
110
      }
111
    }
112
    return line;
2✔
113
  }
114

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