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

devonfw / IDEasy / 15253665702

26 May 2025 12:14PM UTC coverage: 67.716% (-0.003%) from 67.719%
15253665702

push

github

web-flow
#1306 Redirect cleaned up in ProcessContext and ProcessMode (#1330)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>

3158 of 5066 branches covered (62.34%)

Branch coverage included in aggregate %.

8095 of 11552 relevant lines covered (70.07%)

3.07 hits per line

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

88.46
cli/src/main/java/com/devonfw/tools/ide/process/ProcessMode.java
1
package com.devonfw.tools.ide.process;
2

3
import java.lang.ProcessBuilder.Redirect;
4

5
/**
6
 * The ProcessMode defines how to start the command process and how output streams are handled using {@link ProcessBuilder}. Modes that can be used:
7
 * {@link #BACKGROUND} {@link #BACKGROUND_SILENT} {@link #DEFAULT} {@link #DEFAULT_CAPTURE}
8
 */
9
public enum ProcessMode {
3✔
10
  /**
11
   * The process of the command will be run like a background process. Technically the parent process will simply not await its child process and a shell is
12
   * used to start the process. The parent process will get the output of the child process using {@link ProcessBuilder.Redirect#INHERIT}. In Unix systems the
13
   * equivalent of appending an '& disown' is used to detach the subprocess from its parent process. In Unix terms, the shell will not send a SIGHUP signal but
14
   * the process remains connected to the terminal so that output is still received. (Only '&' is not used because it just removes awaiting but not sending of
15
   * SIGHUP. Using nohup would simply result in redirecting output to a nohup.out file.)
16
   */
17
  BACKGROUND {
11✔
18
    @Override
19
    public Redirect getRedirectOutput() {
20
      return Redirect.INHERIT;
2✔
21
    }
22

23
    @Override
24
    public Redirect getRedirectError() {
25
      return Redirect.INHERIT;
2✔
26
    }
27

28
    @Override
29
    public Redirect getRedirectInput() {
30
      return null;
2✔
31
    }
32
  },
33
  /**
34
   * Like {@link #BACKGROUND}. Instead of redirecting the output to the parent process, the output is redirected to the 'null file' using
35
   * {@link ProcessBuilder.Redirect#DISCARD}.
36
   */
37
  BACKGROUND_SILENT {
11✔
38
    @Override
39
    public Redirect getRedirectOutput() {
40
      return Redirect.DISCARD;
2✔
41
    }
42

43
    @Override
44
    public Redirect getRedirectError() {
45
      return Redirect.DISCARD;
2✔
46
    }
47

48
    @Override
49
    public Redirect getRedirectInput() {
50
      return null;
2✔
51
    }
52
  },
53
  /**
54
   * The process will be started according {@link ProcessBuilder.Redirect#INHERIT} without any detaching of parent process and child process. This setting makes
55
   * the child process dependant from the parent process! (If you close the parent process the child process will also be terminated.)
56
   */
57
  DEFAULT {
11✔
58
    @Override
59
    public Redirect getRedirectOutput() {
60
      return Redirect.INHERIT;
2✔
61
    }
62

63
    @Override
64
    public Redirect getRedirectError() {
65
      return Redirect.INHERIT;
2✔
66
    }
67

68
    @Override
69
    public Redirect getRedirectInput() {
70
      return Redirect.INHERIT;
2✔
71
    }
72

73
  },
74
  /**
75
   * The process will be started according {@link ProcessBuilder.Redirect#PIPE} and the standard output and standard error streams will be captured from the
76
   * parent process. In other words, they will be printed in the console of the parent process. This setting makes the child process dependant from the parent
77
   * process! (If you close the parent process the child process will also be terminated.)
78
   */
79
  DEFAULT_CAPTURE {
11✔
80
    @Override
81
    public Redirect getRedirectOutput() {
82
      return Redirect.PIPE;
2✔
83
    }
84

85
    @Override
86
    public Redirect getRedirectError() {
87
      return Redirect.PIPE;
2✔
88
    }
89

90
    @Override
91
    public Redirect getRedirectInput() {
92
      return null;
2✔
93
    }
94

95
  },
96

97
  /**
98
   * Like {@link #DEFAULT} the parent and child process will not be detached, the subprocess output will be discarded (to the operating system "null file" )
99
   * using {@link ProcessBuilder.Redirect#DISCARD}.
100
   */
101
  DEFAULT_SILENT {
11✔
102
    @Override
103
    public Redirect getRedirectOutput() {
104

105
      return Redirect.DISCARD;
×
106
    }
107

108
    @Override
109
    public Redirect getRedirectError() {
110

111
      return Redirect.DISCARD;
×
112
    }
113

114
    @Override
115
    public Redirect getRedirectInput() {
116

117
      return Redirect.INHERIT;
×
118
    }
119
  };
120

121
  /**
122
   * Method to return the {@link ProcessBuilder.Redirect} strategy for the standard output stream of the process. Depending on the mode, the output may be
123
   * inherited from the parent process, discarded, or piped for programmatic access.
124
   *
125
   * @return the {@link ProcessBuilder.Redirect} configuration for standard output, or {@code null} if no redirection is specified.
126
   */
127
  public abstract Redirect getRedirectOutput();
128

129
  /**
130
   * Method to return the {@link ProcessBuilder.Redirect} strategy for the standard error stream of the process. Depending on the mode, the error output may be
131
   * inherited from the parent process, discarded, or piped for programmatic access.
132
   *
133
   * @return the {@link ProcessBuilder.Redirect} configuration for standard error, or {@code null} if no redirection is specified.
134
   */
135
  public abstract Redirect getRedirectError();
136

137
  /**
138
   * Method to return the {@link ProcessBuilder.Redirect} strategy for the standard input stream of the process. Depending on the mode, the input may be
139
   * inherited from the parent process or left unconfigured.
140
   *
141
   * @return the {@link ProcessBuilder.Redirect} configuration for standard input, or {@code null} if no redirection is specified.
142
   */
143
  public abstract Redirect getRedirectInput();
144

145

146
  /**
147
   * Method to check if the ProcessMode is a background process.
148
   *
149
   * @return {@code true} if the {@link ProcessMode} is {@link ProcessMode#BACKGROUND} or {@link ProcessMode#BACKGROUND_SILENT}, {@code false} if not.
150
   */
151
  public boolean isBackground() {
152

153
    return this == BACKGROUND || this == BACKGROUND_SILENT;
10✔
154
  }
155

156
  // TODO ADD EXTERNAL_WINDOW_MODE IN FUTURE Issue: https://github.com/devonfw/IDEasy/issues/218
157

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