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

devonfw / IDEasy / 13518757257

25 Feb 2025 10:12AM UTC coverage: 68.203% (+0.2%) from 68.046%
13518757257

Pull #1071

github

web-flow
Merge 424a5bd57 into cbacec943
Pull Request #1071: #789: implement uninstall of IDEasy

3025 of 4885 branches covered (61.92%)

Branch coverage included in aggregate %.

7854 of 11066 relevant lines covered (70.97%)

3.08 hits per line

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

0.0
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.ProcessMode;
8
import com.devonfw.tools.ide.process.ProcessResult;
9

10
/**
11
 * Implementation of {@link WindowsHelper}.
12
 */
13
public class WindowsHelperImpl implements WindowsHelper {
×
14

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

18
  private final IdeContext context;
19

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

27
    this.context = context;
×
28
  }
×
29

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

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

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

47
  @Override
48
  public String getUserEnvironmentValue(String key) {
49

50
    return getRegistryValue(HKCU_ENVIRONMENT, key);
×
51
  }
52

53
  @Override
54
  public String getRegistryValue(String path, String key) {
55

56
    ProcessResult result = this.context.newProcess().executable("reg").addArgs("query", path, "/v", key).run(ProcessMode.DEFAULT_CAPTURE);
×
57
    List<String> out = result.getOut();
×
58
    for (String line : out) {
×
59
      int i = line.indexOf(key);
×
60
      if (i >= 0) {
×
61
        assert (i == 4);
×
62
        i += key.length();
×
63
        i = skipWhitespaces(line, i);
×
64
        i = skipNonWhitespaces(line, i); // the type (e.g. "REG_SZ")
×
65
        i = skipWhitespaces(line, i);
×
66
        line = line.substring(i);
×
67
        return line;
×
68
      }
69
    }
×
70
    return null;
×
71
  }
72

73
  private static int skipWhitespaces(String string, int i) {
74

75
    int len = string.length();
×
76
    while ((i < len) && Character.isWhitespace(string.charAt(i))) {
×
77
      i++;
×
78
    }
79
    return i;
×
80
  }
81

82
  private static int skipNonWhitespaces(String string, int i) {
83

84
    int len = string.length();
×
85
    while ((i < len) && !Character.isWhitespace(string.charAt(i))) {
×
86
      i++;
×
87
    }
88
    return i;
×
89
  }
90

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