Skip to content

Commit dfb8585

Browse files
committed
Introduce the process API
1 parent ca191f7 commit dfb8585

29 files changed

+3523
-1
lines changed

function/src/main/java/io/smallrye/common/function/FunctionsLogging.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import org.jboss.logging.annotations.Message;
77
import org.jboss.logging.annotations.MessageLogger;
88

9-
@MessageLogger(projectCode = "SRCFG", length = 5)
9+
@MessageLogger(projectCode = "SRCOM", length = 5)
1010
interface FunctionsLogging {
1111
FunctionsLogging log = Logger.getMessageLogger(FunctionsLogging.class, FunctionsLogging.class.getPackage().getName());
1212

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
<module>io</module>
7777
<module>net</module>
7878
<module>os</module>
79+
<module>process</module>
7980
<module>ref</module>
8081
<module>resource</module>
8182
<module>search</module>
@@ -129,6 +130,11 @@
129130
<artifactId>smallrye-common-net</artifactId>
130131
<version>${project.version}</version>
131132
</dependency>
133+
<dependency>
134+
<groupId>io.smallrye.common</groupId>
135+
<artifactId>smallrye-common-os</artifactId>
136+
<version>${project.version}</version>
137+
</dependency>
132138
<dependency>
133139
<groupId>io.smallrye.common</groupId>
134140
<artifactId>smallrye-common-vertx-context</artifactId>

process/build-release-17

Whitespace-only changes.

process/pom.xml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.smallrye.common</groupId>
8+
<artifactId>smallrye-common-parent</artifactId>
9+
<version>3.0.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>smallrye-common-process</artifactId>
13+
14+
<name>SmallRye Common: Process</name>
15+
<description>Process management utilities</description>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>${project.groupId}</groupId>
20+
<artifactId>smallrye-common-function</artifactId>
21+
</dependency>
22+
<dependency>
23+
<groupId>${project.groupId}</groupId>
24+
<artifactId>smallrye-common-os</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.jboss.logging</groupId>
28+
<artifactId>jboss-logging</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.jboss.logging</groupId>
32+
<artifactId>jboss-logging-annotations</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter-engine</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<configuration>
46+
<annotationProcessorPaths>
47+
<annotationProcessorPath>
48+
<groupId>org.jboss.logging</groupId>
49+
<artifactId>jboss-logging-processor</artifactId>
50+
</annotationProcessorPath>
51+
</annotationProcessorPaths>
52+
</configuration>
53+
</plugin>
54+
<plugin>
55+
<artifactId>maven-javadoc-plugin</artifactId>
56+
<configuration>
57+
<docfilessubdirs>true</docfilessubdirs>
58+
</configuration>
59+
</plugin>
60+
<plugin>
61+
<artifactId>maven-surefire-plugin</artifactId>
62+
<configuration>
63+
<systemPropertyVariables>
64+
<java.util.logging.config.class>io.smallrye.common.process.LoggingConfigurator</java.util.logging.config.class>
65+
</systemPropertyVariables>
66+
</configuration>
67+
</plugin>
68+
</plugins>
69+
</build>
70+
71+
<profiles>
72+
<profile>
73+
<id>coverage</id>
74+
<properties>
75+
<argLine>@{jacocoArgLine}</argLine>
76+
</properties>
77+
<build>
78+
<plugins>
79+
<plugin>
80+
<groupId>org.jacoco</groupId>
81+
<artifactId>jacoco-maven-plugin</artifactId>
82+
<executions>
83+
<execution>
84+
<id>report</id>
85+
<phase>verify</phase>
86+
<goals>
87+
<goal>report</goal>
88+
</goals>
89+
</execution>
90+
</executions>
91+
</plugin>
92+
</plugins>
93+
</build>
94+
</profile>
95+
</profiles>
96+
97+
98+
</project>
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
package io.smallrye.common.process;
2+
3+
import java.io.Serial;
4+
import java.util.List;
5+
6+
import io.smallrye.common.os.OS;
7+
8+
/**
9+
* An exception indicating that a process has exited with an abnormal status.
10+
* Any additional problems will be recorded as suppressed exceptions.
11+
*/
12+
public class AbnormalExitException extends ProcessExecutionException {
13+
@Serial
14+
private static final long serialVersionUID = -2058346021193103167L;
15+
16+
/**
17+
* The process exit code, if known.
18+
*/
19+
private int exitCode = -1;
20+
/**
21+
* Set to {@code true} if the soft timeout was known to have elapsed.
22+
*/
23+
private boolean softTimeoutElapsed;
24+
/**
25+
* Set to {@code true} if the hard timeout was known to have elapsed.
26+
*/
27+
private boolean hardTimeoutElapsed;
28+
/**
29+
* The captured lines of error output.
30+
*/
31+
private List<String> errorOutput = List.of();
32+
33+
/**
34+
* Constructs a new {@code AbnormalExitException} instance. The message is left blank ({@code null}), and no
35+
* cause is specified.
36+
*/
37+
public AbnormalExitException() {
38+
}
39+
40+
/**
41+
* Constructs a new {@code AbnormalExitException} instance with an initial message. No
42+
* cause is specified.
43+
*
44+
* @param msg the message
45+
*/
46+
public AbnormalExitException(final String msg) {
47+
super(msg);
48+
}
49+
50+
/**
51+
* Constructs a new {@code AbnormalExitException} instance with an initial cause. If
52+
* a non-{@code null} cause is specified, its message is used to initialize the message of this
53+
* {@code ProcessException}; otherwise the message is left blank ({@code null}).
54+
*
55+
* @param cause the cause
56+
*/
57+
public AbnormalExitException(final Throwable cause) {
58+
super(cause);
59+
}
60+
61+
/**
62+
* Constructs a new {@code AbnormalExitException} instance with an initial message and cause.
63+
*
64+
* @param msg the message
65+
* @param cause the cause
66+
*/
67+
public AbnormalExitException(final String msg, final Throwable cause) {
68+
super(msg, cause);
69+
}
70+
71+
/**
72+
* {@return the exit code of the process}
73+
*/
74+
public int exitCode() {
75+
return exitCode;
76+
}
77+
78+
/**
79+
* Set the exit code of the process.
80+
*
81+
* @param exitCode the exit code
82+
*/
83+
public void setExitCode(final int exitCode) {
84+
this.exitCode = exitCode;
85+
}
86+
87+
/**
88+
* {@return {@code true} if the soft timeout elapsed before the process exited}
89+
*/
90+
public boolean softTimeoutElapsed() {
91+
return softTimeoutElapsed;
92+
}
93+
94+
/**
95+
* Set whether the soft timeout elapsed before the process exited.
96+
*
97+
* @param softTimeoutElapsed {@code true} if the soft timeout elapsed before the process exited
98+
*/
99+
public void setSoftTimeoutElapsed(final boolean softTimeoutElapsed) {
100+
this.softTimeoutElapsed = softTimeoutElapsed;
101+
}
102+
103+
/**
104+
* {@return {@code true} if the hard timeout elapsed before the process exited}
105+
*/
106+
public boolean hardTimeoutElapsed() {
107+
return hardTimeoutElapsed;
108+
}
109+
110+
/**
111+
* Set whether the hard timeout elapsed before the process exited.
112+
*
113+
* @param hardTimeoutElapsed {@code true} if the hard timeout elapsed before the process exited
114+
*/
115+
public void setHardTimeoutElapsed(final boolean hardTimeoutElapsed) {
116+
this.hardTimeoutElapsed = hardTimeoutElapsed;
117+
}
118+
119+
/**
120+
* {@return the captured error output of the process execution, if any}
121+
*/
122+
public List<String> errorOutput() {
123+
return errorOutput;
124+
}
125+
126+
/**
127+
* Set the captured error output of the process execution.
128+
*
129+
* @param errorOutput the captured error output of the process execution
130+
*/
131+
public void setErrorOutput(final List<String> errorOutput) {
132+
this.errorOutput = List.copyOf(errorOutput);
133+
}
134+
135+
public StringBuilder toString(StringBuilder b) {
136+
super.toString(b);
137+
b.append(" with exit code ").append(exitCode);
138+
if (OS.current() != OS.WINDOWS && exitCode > 128 && exitCode <= 192) {
139+
// todo: add signal names and descriptions to OS module?
140+
b.append(" (possibly due to signal ").append(exitCode - 128).append(')');
141+
}
142+
if (softTimeoutElapsed) {
143+
if (hardTimeoutElapsed) {
144+
b.append(" after soft and hard timeouts elapsed");
145+
} else {
146+
b.append(" after soft timeout elapsed");
147+
}
148+
} else if (hardTimeoutElapsed) {
149+
b.append(" after hard timeout elapsed");
150+
}
151+
List<String> errorOutput = this.errorOutput;
152+
if (!errorOutput.isEmpty()) {
153+
b.append(" with error output:");
154+
for (String line : errorOutput) {
155+
b.append("\n > ").append(line);
156+
}
157+
}
158+
return b;
159+
}
160+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.smallrye.common.process;
2+
3+
import java.io.Serial;
4+
5+
/**
6+
* The base type of all execution exception types.
7+
*/
8+
public abstract class AbstractExecutionException extends RuntimeException {
9+
@Serial
10+
private static final long serialVersionUID = 7071176650961828059L;
11+
12+
/**
13+
* Constructs a new {@code AbstractExecutionException} instance with an initial message and cause,
14+
* and configuring whether the stack trace is writable.
15+
*
16+
* @param msg the message
17+
* @param cause the cause
18+
*/
19+
protected AbstractExecutionException(final String message, final Throwable cause, final boolean writableStackTrace) {
20+
super(message, cause, true, writableStackTrace);
21+
}
22+
23+
/**
24+
* Constructs a new {@code AbstractExecutionException} instance. The message is left blank ({@code null}), and no
25+
* cause is specified.
26+
*/
27+
protected AbstractExecutionException() {
28+
}
29+
30+
/**
31+
* Constructs a new {@code AbstractExecutionException} instance with an initial message. No
32+
* cause is specified.
33+
*
34+
* @param msg the message
35+
*/
36+
protected AbstractExecutionException(final String msg) {
37+
super(msg);
38+
}
39+
40+
/**
41+
* Constructs a new {@code AbstractExecutionException} instance with an initial cause. If
42+
* a non-{@code null} cause is specified, its message is used to initialize the message of this
43+
* {@code AbstractExecutionException}; otherwise the message is left blank ({@code null}).
44+
*
45+
* @param cause the cause
46+
*/
47+
protected AbstractExecutionException(final Throwable cause) {
48+
super(cause);
49+
}
50+
51+
/**
52+
* Constructs a new {@code AbstractExecutionException} instance with an initial message and cause.
53+
*
54+
* @param msg the message
55+
* @param cause the cause
56+
*/
57+
protected AbstractExecutionException(final String msg, final Throwable cause) {
58+
super(msg, cause);
59+
}
60+
61+
/**
62+
* Render this exception to the given string builder.
63+
*
64+
* @param sb the string builder (must not be {@code null})
65+
* @return the same string builder (not {@code null})
66+
*/
67+
public StringBuilder toString(StringBuilder sb) {
68+
String className = getClass().getName();
69+
sb.append(className);
70+
String message = getLocalizedMessage();
71+
if (message != null) {
72+
sb.append(':').append(' ');
73+
sb.append(message);
74+
}
75+
return sb;
76+
}
77+
78+
/**
79+
* {@return a short description of this exception}
80+
*/
81+
public final String toString() {
82+
return toString(new StringBuilder()).toString();
83+
}
84+
}

0 commit comments

Comments
 (0)