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

devonfw / IDEasy / 11559334744

28 Oct 2024 05:26PM UTC coverage: 66.746% (+0.01%) from 66.736%
11559334744

push

github

web-flow
Update ProcessContext.java: fixed crazy bug with pointless vararg for List (#712)

2403 of 3946 branches covered (60.9%)

Branch coverage included in aggregate %.

6270 of 9048 relevant lines covered (69.3%)

3.05 hits per line

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

40.0
cli/src/main/java/com/devonfw/tools/ide/process/ProcessContext.java
1
package com.devonfw.tools.ide.process;
2

3
import java.nio.file.Path;
4
import java.util.List;
5
import java.util.Objects;
6

7
/**
8
 * Wrapper for {@link ProcessBuilder} to simplify its usage and avoid common mistakes and pitfalls.
9
 */
10
public interface ProcessContext extends EnvironmentContext {
11

12
  /**
13
   * @param handling the desired {@link ProcessErrorHandling}.
14
   * @return this {@link ProcessContext} for fluent API calls.
15
   */
16
  ProcessContext errorHandling(ProcessErrorHandling handling);
17

18
  /**
19
   * @param directory the {@link Path} to the working directory from where to execute the command.
20
   * @return this {@link ProcessContext} for fluent API calls.
21
   */
22
  ProcessContext directory(Path directory);
23

24
  /**
25
   * Sets the executable command to be {@link #run()}.
26
   *
27
   * @param executable the {@link Path} to the command to be executed by {@link #run()}. Depending on your operating system and the extension of the
28
   *     executable or OS specific conventions. So e.g. a *.cmd or *.bat file will be called via CMD shell on windows while a *.sh file will be called via Bash,
29
   *     etc.
30
   * @return this {@link ProcessContext} for fluent API calls.
31
   */
32
  ProcessContext executable(Path executable);
33

34
  /**
35
   * Sets the executable command to be {@link #run()}.
36
   *
37
   * @param executable the command to be executed by {@link #run()}.
38
   * @return this {@link ProcessContext} for fluent API calls.
39
   * @see #executable(Path)
40
   */
41
  default ProcessContext executable(String executable) {
42

43
    return executable(Path.of(executable));
7✔
44
  }
45

46
  /**
47
   * Adds a single argument for {@link #executable(Path) command}.
48
   *
49
   * @param arg the next argument for {@link #executable(Path) command} to be added.
50
   * @return this {@link ProcessContext} for fluent API calls.
51
   */
52
  ProcessContext addArg(String arg);
53

54
  /**
55
   * Adds a single argument for {@link #executable(Path) command}.
56
   *
57
   * @param arg the next argument for {@link #executable(Path) command} to be added.
58
   * @return this {@link ProcessContext} for fluent API calls.
59
   */
60
  default ProcessContext addArg(Object arg) {
61

62
    Objects.requireNonNull(arg);
3✔
63
    return addArg(arg.toString());
5✔
64
  }
65

66
  /**
67
   * Adds the given arguments for {@link #executable(Path) command}. E.g. for {@link #executable(Path) command} "mvn" the arguments "clean" and "install" may be
68
   * added here to run "mvn clean install". If this method would be called again with "-Pmyprofile" and "-X" before {@link #run()} gets called then "mvn clean
69
   * install -Pmyprofile -X" would be run.
70
   *
71
   * @param args the arguments for {@link #executable(Path) command} to be added.
72
   * @return this {@link ProcessContext} for fluent API calls.
73
   */
74
  default ProcessContext addArgs(String... args) {
75

76
    for (String arg : args) {
16✔
77
      addArg(arg);
4✔
78
    }
79
    return this;
2✔
80
  }
81

82
  /**
83
   * Adds the given arguments for {@link #executable(Path) command} as arbitrary Java objects. It will add the {@link Object#toString() string representation}
84
   * of these arguments to the command.
85
   *
86
   * @param args the arguments for {@link #executable(Path) command} to be added.
87
   * @return this {@link ProcessContext} for fluent API calls.
88
   */
89
  default ProcessContext addArgs(Object... args) {
90

91
    for (Object arg : args) {
×
92
      addArg(arg);
×
93
    }
94
    return this;
×
95
  }
96

97
  /**
98
   * Adds the given arguments for {@link #executable(Path) command} as arbitrary Java objects. It will add the {@link Object#toString() string representation}
99
   * of these arguments to the command.
100
   *
101
   * @param args the {@link List} of arguments for {@link #executable(Path) command} to be added.
102
   * @return this {@link ProcessContext} for fluent API calls.
103
   */
104
  default ProcessContext addArgs(List<?> args) {
105

106
    for (Object arg : args) {
×
107
      addArg(arg);
×
108
    }
×
109
    return this;
×
110
  }
111

112
  @Override
113
  ProcessContext withEnvVar(String key, String value);
114

115
  @Override
116
  ProcessContext withPathEntry(Path path);
117

118
  /**
119
   * Runs the previously configured {@link #executable(Path) command} with the configured {@link #addArgs(String...) arguments}. Will reset the
120
   * {@link #addArgs(String...) arguments} but not the {@link #executable(Path) command} for sub-sequent calls.
121
   *
122
   * @return the exit code. Will be {@link ProcessResult#SUCCESS} on successful completion of the {@link Process}.
123
   */
124
  default int run() {
125

126
    return run(ProcessMode.DEFAULT).getExitCode();
×
127
  }
128

129
  /**
130
   * Runs the previously configured {@link #executable(Path) command} with the configured {@link #addArgs(String...) arguments}. Will reset the
131
   * {@link #addArgs(String...) arguments} but not the {@link #executable(Path) command} for sub-sequent calls.
132
   *
133
   * @param processMode {@link ProcessMode}
134
   * @return the {@link ProcessResult}.
135
   */
136
  ProcessResult run(ProcessMode processMode);
137

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