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

devonfw / IDEasy / 19337626462

13 Nov 2025 03:59PM UTC coverage: 68.927% (+0.05%) from 68.878%
19337626462

push

github

web-flow
#1188: Use WindowsHelper to find bash (#1568)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

3495 of 5557 branches covered (62.89%)

Branch coverage included in aggregate %.

9158 of 12800 relevant lines covered (71.55%)

3.14 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 com.devonfw.tools.ide.context.IdeContext;
6
import com.devonfw.tools.ide.log.IdeLogLevel;
7
import com.devonfw.tools.ide.process.ProcessErrorHandling;
8
import com.devonfw.tools.ide.process.ProcessMode;
9
import com.devonfw.tools.ide.process.ProcessResult;
10

11
/**
12
 * Implementation of {@link WindowsHelper}.
13
 */
14
public class WindowsHelperImpl implements WindowsHelper {
1✔
15

16
  /** Registry key for the users environment variables. */
17
  public static final String HKCU_ENVIRONMENT = "HKCU\\Environment";
18

19
  private final IdeContext context;
20

21
  /**
22
   * The constructor.
23
   *
24
   * @param context the {@link IdeContext}.
25
   */
26
  public WindowsHelperImpl(IdeContext context) {
2✔
27

28
    this.context = context;
3✔
29
  }
1✔
30

31
  @Override
32
  public void setUserEnvironmentValue(String key, String value) {
33

34
    ProcessResult result = this.context.newProcess().executable("setx").addArgs(key, value).run(ProcessMode.DEFAULT_SILENT);
×
35
    assert (result.isSuccessful());
×
36
  }
×
37

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

49
  @Override
50
  public String getUserEnvironmentValue(String key) {
51

52
    return getRegistryValue(HKCU_ENVIRONMENT, key);
×
53
  }
54

55
  @Override
56
  public String getRegistryValue(String path, String key) {
57

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

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

90
  private static int skipWhitespaces(String string, int i) {
91

92
    int len = string.length();
3✔
93
    while ((i < len) && Character.isWhitespace(string.charAt(i))) {
8!
94
      i++;
2✔
95
    }
96
    return i;
2✔
97
  }
98

99
  private static int skipNonWhitespaces(String string, int i) {
100

101
    int len = string.length();
3✔
102
    while ((i < len) && !Character.isWhitespace(string.charAt(i))) {
8!
103
      i++;
2✔
104
    }
105
    return i;
2✔
106
  }
107

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