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

devonfw / IDEasy / 8144002629

04 Mar 2024 04:56PM UTC coverage: 58.928% (+0.7%) from 58.254%
8144002629

push

github

web-flow
#208: improve test infrastructure # 219: fix wrong executable (#238)

* Add first implementation

* Add javadoc

* Add javadoc

* Using target path instead of ressource path to make sure one-to-one copy of set up folders is used

* Add JavaDoc and mac mock program

* Add support for multiple dependencies while testing

* Minor changes

* Modify mock programs for testing

* Refactored example JmcTest

* Add possibility to set execution path by using the context

* Reenable test after related issue 228 has been merged

* Replace ternary with regular if

* Add missing javadoc

* Add missing javadoc

* remove unnecessary semicolon

* Fix spelling typo

* Minor test changes

* Refactoring FileExtractor class for more modularity

* using const

* Add missing extensions

* Remove unnecessary execption declaration and minor rename

* Fix spelling

* Add javadoc

* Forget dot

* minor change

* Revert "minor change"

This reverts commit ec81c3ce6.

* Revert "Merge branch 'main' into feature/208-MockOutToolRepoRefactorTestInfra"

This reverts commit d58847230, reversing
changes made to f38b3105f.

* Revert "Revert "Merge branch 'main' into feature/208-MockOutToolRepoRefactorTestInfra""

This reverts commit 3e49a0b3d.

* Revert "Revert "minor change""

This reverts commit 2f7b94624.

* fix typo

* #208: review and complete rework

* #208: improved system path

* #208: found and fixed bug on windows

* #208: improve OS mocking

* #208: improve test logging

reveal logs/errors so the developer actually sees what is happening instead of leaving them in the dark

* #208: improve OS detection

* #208: fixed

found and fixed bug in MacOS app detection for JMC, fixed copy file to folder bug, moved !extract logic back to FileAccess, f... (continued)

1580 of 2930 branches covered (53.92%)

Branch coverage included in aggregate %.

4047 of 6619 relevant lines covered (61.14%)

2.65 hits per line

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

82.46
cli/src/main/java/com/devonfw/tools/ide/environment/EnvironmentVariables.java
1
package com.devonfw.tools.ide.environment;
2

3
import java.nio.file.Path;
4
import java.util.Collection;
5
import java.util.Locale;
6

7
import com.devonfw.tools.ide.context.IdeContext;
8
import com.devonfw.tools.ide.version.VersionIdentifier;
9

10
/**
11
 * Interface for the environment with the variables.
12
 */
13
public interface EnvironmentVariables {
14

15
  /** Filename of the default variable configuration file. {@value} */
16
  String DEFAULT_PROPERTIES = "ide.properties";
17

18
  /** Filename of the legacy variable configuration file. {@value} */
19
  String LEGACY_PROPERTIES = "devon.properties";
20

21
  /**
22
   * @param name the name of the environment variable to get.
23
   * @return the value of the variable with the given {@code name}. Will be {@code null} if no such variable is defined.
24
   */
25
  default String get(String name) {
26

27
    String value = getFlat(name);
4✔
28
    if (value == null) {
2✔
29
      EnvironmentVariables parent = getParent();
3✔
30
      if (parent != null) {
2✔
31
        value = parent.get(name);
4✔
32
      }
33
    }
34
    return value;
2✔
35
  }
36

37
  /**
38
   * @param name the name of the environment variable to get.
39
   * @return the value of the variable with the given {@code name} as {@link Path}. Will be {@code null} if no such
40
   *         variable is defined.
41
   */
42
  default Path getPath(String name) {
43

44
    String value = get(name);
4✔
45
    if (value == null) {
2!
46
      return null;
×
47
    }
48
    return Path.of(value);
5✔
49
  }
50

51
  /**
52
   * @param name the name of the environment variable to get.
53
   * @return the value of the variable with the given {@code name} without {@link #getParent() inheritance from parent}.
54
   *         Will be {@code null} if no such variable is defined.
55
   */
56
  String getFlat(String name);
57

58
  /**
59
   * @param tool the name of the tool (e.g. "java").
60
   * @return the edition of the tool to use.
61
   */
62
  default String getToolEdition(String tool) {
63

64
    String variable = tool.toUpperCase(Locale.ROOT) + "_EDITION";
5✔
65
    String value = get(variable);
4✔
66
    if (value == null) {
2!
67
      value = tool;
2✔
68
    }
69
    return value;
2✔
70
  }
71

72
  /**
73
   * @param tool the name of the tool (e.g. "java").
74
   * @return the {@link VersionIdentifier} with the version of the tool to use. May also be a
75
   *         {@link VersionIdentifier#isPattern() version pattern}. Will be {@link VersionIdentifier#LATEST} if
76
   *         undefined.
77
   */
78
  default VersionIdentifier getToolVersion(String tool) {
79

80
    String variable = getToolVersionVariable(tool);
3✔
81
    String value = get(variable);
4✔
82
    if (value == null) {
2!
83
      return VersionIdentifier.LATEST;
×
84
    }
85
    return VersionIdentifier.of(value);
3✔
86
  }
87

88
  /**
89
   * @return the {@link EnvironmentVariablesType type} of this {@link EnvironmentVariables}.
90
   */
91
  EnvironmentVariablesType getType();
92

93
  /**
94
   * @param type the {@link #getType() type} of the requested {@link EnvironmentVariables}.
95
   * @return the {@link EnvironmentVariables} with the given {@link #getType() type} from this
96
   *         {@link EnvironmentVariables} along the {@link #getParent() parent} hierarchy or {@code null} if not found.
97
   */
98
  default EnvironmentVariables getByType(EnvironmentVariablesType type) {
99

100
    if (type == getType()) {
4✔
101
      return this;
2✔
102
    }
103
    EnvironmentVariables parent = getParent();
3✔
104
    if (parent == null) {
2!
105
      return null;
×
106
    } else {
107
      return parent.getByType(type);
4✔
108
    }
109
  }
110

111
  /**
112
   * @return the {@link Path} to the underlying properties file or {@code null} if not based on such file (e.g. for EVS
113
   *         or {@link EnvironmentVariablesResolved}).
114
   */
115
  Path getPropertiesFilePath();
116

117
  /**
118
   * @return the source identifier describing this {@link EnvironmentVariables} for debugging.
119
   */
120
  String getSource();
121

122
  /**
123
   * @return the parent {@link EnvironmentVariables} to inherit from or {@code null} if this is the
124
   *         {@link EnvironmentVariablesType#SYSTEM root} {@link EnvironmentVariables} instance.
125
   */
126
  default EnvironmentVariables getParent() {
127

128
    return null;
×
129
  }
130

131
  /**
132
   * @param name the {@link com.devonfw.tools.ide.variable.VariableDefinition#getName() name} of the variable to set.
133
   * @param value the new {@link #get(String) value} of the variable to set. May be {@code null} to unset the variable.
134
   * @param export - {@code true} if the variable needs to be exported, {@code false} otherwise.
135
   * @return the old variable value.
136
   */
137
  default String set(String name, String value, boolean export) {
138

139
    throw new UnsupportedOperationException();
×
140
  }
141

142
  /**
143
   * Saves any potential {@link #set(String, String, boolean) changes} of this {@link EnvironmentVariables}.
144
   */
145
  default void save() {
146

147
    throw new UnsupportedOperationException("Not yet implemented!");
×
148
  }
149

150
  /**
151
   * @param name the {@link com.devonfw.tools.ide.variable.VariableDefinition#getName() name} of the variable to search
152
   *        for.
153
   * @return the closest {@link EnvironmentVariables} instance that defines the variable with the given {@code name} or
154
   *         {@code null} if the variable is not defined.
155
   */
156
  default EnvironmentVariables findVariable(String name) {
157

158
    String value = getFlat(name);
4✔
159
    if (value != null) {
2✔
160
      return this;
2✔
161
    }
162
    EnvironmentVariables parent = getParent();
3✔
163
    if (parent == null) {
2✔
164
      return null;
2✔
165
    } else {
166
      return parent.findVariable(name);
4✔
167
    }
168
  }
169

170
  /**
171
   * @return the {@link Collection} of the {@link VariableLine}s defined by this {@link EnvironmentVariables} including
172
   *         inheritance.
173
   */
174
  Collection<VariableLine> collectVariables();
175

176
  /**
177
   * @return the {@link Collection} of the {@link VariableLine#isExport() exported} {@link VariableLine}s defined by
178
   *         this {@link EnvironmentVariables} including inheritance.
179
   */
180
  Collection<VariableLine> collectExportedVariables();
181

182
  /**
183
   * @param string the {@link String} that potentially contains variables in the syntax "${«variable«}". Those will be
184
   *        resolved by this method and replaced with their {@link #get(String) value}.
185
   * @param source the source where the {@link String} to resolve originates from. Should have a reasonable
186
   *        {@link Object#toString() string representation} that will be used in error or log messages if a variable
187
   *        could not be resolved.
188
   * @return the given {@link String} with the variables resolved.
189
   * @see com.devonfw.tools.ide.tool.ide.IdeToolCommandlet
190
   */
191
  String resolve(String string, Object source);
192

193
  /**
194
   * The inverse operation of {@link #resolve(String, Object)}. Please note that the {@link #resolve(String, Object)
195
   * resolve} operation is not fully bijective. There may be multiple variables holding the same {@link #get(String)
196
   * value} or there may be static text that can be equal to a {@link #get(String) variable value}. This method does its
197
   * best to implement the inverse resolution based on some heuristics.
198
   *
199
   * @param string the {@link String} where to find {@link #get(String) variable values} and replace them with according
200
   *        "${«variable«}" expressions.
201
   * @param source the source where the {@link String} to inverse resolve originates from. Should have a reasonable
202
   *        {@link Object#toString() string representation} that will be used in error or log messages if the inverse
203
   *        resolving was not working as expected.
204
   * @return the given {@link String} with {@link #get(String) variable values} replaced with according "${«variable«}"
205
   *         expressions.
206
   * @see com.devonfw.tools.ide.tool.ide.IdeToolCommandlet
207
   */
208
  String inverseResolve(String string, Object source);
209

210
  /**
211
   * @param context the {@link IdeContext}.
212
   * @return the system {@link EnvironmentVariables} building the root of the {@link EnvironmentVariables} hierarchy.
213
   */
214
  static AbstractEnvironmentVariables ofSystem(IdeContext context) {
215

216
    return EnvironmentVariablesSystem.of(context);
3✔
217
  }
218

219
  /**
220
   * @param tool the name of the tool.
221
   * @return the name of the version variable.
222
   */
223
  static String getToolVersionVariable(String tool) {
224

225
    return tool.toUpperCase(Locale.ROOT) + "_VERSION";
5✔
226
  }
227

228
  /**
229
   * @param tool the name of the tool.
230
   * @return the name of the edition variable.
231
   */
232
  static String getToolEditionVariable(String tool) {
233

234
    return tool.toUpperCase(Locale.ROOT) + "_EDITION";
5✔
235
  }
236

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