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

devonfw / IDEasy / 22317391561

23 Feb 2026 05:30PM UTC coverage: 70.257% (-0.2%) from 70.474%
22317391561

Pull #1714

github

web-flow
Merge 5be048514 into 379acdc9d
Pull Request #1714: #404: #1713: advanced logging

4066 of 6384 branches covered (63.69%)

Branch coverage included in aggregate %.

10598 of 14488 relevant lines covered (73.15%)

3.08 hits per line

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

58.33
cli/src/main/java/com/devonfw/tools/ide/os/WindowsHelperImpl.java
1
package com.devonfw.tools.ide.os;
2

3
import java.util.List;
4

5
import org.slf4j.Logger;
6
import org.slf4j.LoggerFactory;
7

8
import com.devonfw.tools.ide.context.IdeContext;
9
import com.devonfw.tools.ide.log.IdeLogLevel;
10
import com.devonfw.tools.ide.process.ProcessErrorHandling;
11
import com.devonfw.tools.ide.process.ProcessMode;
12
import com.devonfw.tools.ide.process.ProcessResult;
13

14
/**
15
 * Implementation of {@link WindowsHelper}.
16
 */
17
public class WindowsHelperImpl implements WindowsHelper {
18

19
  private static final Logger LOG = LoggerFactory.getLogger(WindowsHelperImpl.class);
4✔
20

21
  /** Registry key for the users environment variables. */
22
  public static final String HKCU_ENVIRONMENT = "HKCU\\Environment";
23

24
  private final IdeContext context;
25

26
  /**
27
   * The constructor.
28
   *
29
   * @param context the {@link IdeContext}.
30
   */
31
  public WindowsHelperImpl(IdeContext context) {
2✔
32

33
    this.context = context;
3✔
34
  }
1✔
35

36
  @Override
37
  public void setUserEnvironmentValue(String key, String value) {
38

39
    ProcessResult result = this.context.newProcess().executable("setx").addArgs(key, value).run(ProcessMode.DEFAULT_SILENT);
×
40
    assert (result.isSuccessful());
×
41
  }
×
42

43
  @Override
44
  public void removeUserEnvironmentValue(String key) {
45
    ProcessResult result = this.context.newProcess().executable("reg").addArgs("delete", HKCU_ENVIRONMENT, "/v", key, "/f")
×
46
        .errorHandling(ProcessErrorHandling.LOG_WARNING).run(ProcessMode.DEFAULT_CAPTURE);
×
47
    if (result.isSuccessful()) {
×
48
      LOG.debug("Removed environment variable {}", key);
×
49
    } else {
50
      result.log(IdeLogLevel.WARNING);
×
51
    }
52
  }
×
53

54
  @Override
55
  public String getUserEnvironmentValue(String key) {
56

57
    return getRegistryValue(HKCU_ENVIRONMENT, key);
×
58
  }
59

60
  @Override
61
  public String getRegistryValue(String path, String key) {
62

63
    ProcessResult result = this.context.newProcess().errorHandling(ProcessErrorHandling.LOG_WARNING).executable("reg").addArgs("query", path, "/v", key)
×
64
        .run(ProcessMode.DEFAULT_CAPTURE);
×
65
    if (!result.isSuccessful()) {
×
66
      return null;
×
67
    }
68
    List<String> out = result.getOut();
×
69
    return retrieveRegString(key, out);
×
70
  }
71

72
  /**
73
   * Parses the result of a registry query and outputs the given key.
74
   *
75
   * @param key the key to look for.
76
   * @param out List of keys from registry query result.
77
   * @return the registry value.
78
   */
79
  protected String retrieveRegString(String key, List<String> out) {
80
    for (String line : out) {
10✔
81
      int i = line.indexOf(key);
4✔
82
      if (i >= 0) {
2✔
83
        assert (i == 4);
4!
84
        i += key.length();
5✔
85
        i = skipWhitespaces(line, i);
4✔
86
        i = skipNonWhitespaces(line, i); // the type (e.g. "REG_SZ")
4✔
87
        i = skipWhitespaces(line, i);
4✔
88
        line = line.substring(i);
4✔
89
        return line;
2✔
90
      }
91
    }
1✔
92
    return null;
2✔
93
  }
94

95
  private static int skipWhitespaces(String string, int i) {
96

97
    int len = string.length();
3✔
98
    while ((i < len) && Character.isWhitespace(string.charAt(i))) {
8!
99
      i++;
2✔
100
    }
101
    return i;
2✔
102
  }
103

104
  private static int skipNonWhitespaces(String string, int i) {
105

106
    int len = string.length();
3✔
107
    while ((i < len) && !Character.isWhitespace(string.charAt(i))) {
8!
108
      i++;
2✔
109
    }
110
    return i;
2✔
111
  }
112

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