Skip to content

Commit 2b6161d

Browse files
authored
Merge branch 'develop' into addlib-4.0
2 parents ffabcbe + 4750376 commit 2b6161d

File tree

26 files changed

+375
-221
lines changed

26 files changed

+375
-221
lines changed

.github/settings.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
<servers>
88
<server>
9-
<id>ossrh</id>
10-
<username>${env.OSSRH_TOKEN_USERNAME}</username>
11-
<password>${env.OSSRH_TOKEN_PASSWORD}</password>
9+
<id>sonatype</id>
10+
<username>${env.SONATYPE_TOKEN_USERNAME}</username>
11+
<password>${env.SONATYPE_TOKEN_PASSWORD}</password>
1212
</server>
1313
</servers>
1414
</settings>

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,6 @@ jobs:
128128
restore-keys: cache-deploy-
129129
- name: Run Maven
130130
env: # make secrets available as environment variables
131-
OSSRH_TOKEN_USERNAME: ${{ secrets.OSSRH_TOKEN_USERNAME }}
132-
OSSRH_TOKEN_PASSWORD: ${{ secrets.OSSRH_TOKEN_PASSWORD }}
131+
SONATYPE_TOKEN_USERNAME: ${{ secrets.SONATYPE_TOKEN_USERNAME }}
132+
SONATYPE_TOKEN_PASSWORD: ${{ secrets.SONATYPE_TOKEN_PASSWORD }}
133133
run: mvn -B -s $GITHUB_WORKSPACE/.github/settings.xml -DskipTests deploy

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1414
### Changed
1515

1616
* AutomataLib now requires Java 11 at runtime.
17+
* `ProcessUtil#invokeProcess` now handles consumers for stdout and stderr separately.
1718

1819
### Removed
1920

2021
* `IOUtil#copy(Reader, Writer)` has been removed. Use `Reader#transferTo(Writer)` instead.
22+
* `JVMUtil` has been removed. Use `Runtime.version().feature()` for its previously (only) provided method.
2123

2224

2325
## [0.12.1] - 2025-03-11

commons/util/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@
5050
exports net.automatalib.common.util.ref;
5151
exports net.automatalib.common.util.setting;
5252
exports net.automatalib.common.util.string;
53-
exports net.automatalib.common.util.system;
5453
}

commons/util/src/main/java/net/automatalib/common/util/process/InputStreamConsumer.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.BufferedReader;
1919
import java.io.IOException;
2020
import java.io.InputStream;
21+
import java.io.OutputStream;
2122
import java.util.function.Consumer;
2223

2324
import net.automatalib.common.util.IOUtil;
@@ -30,16 +31,19 @@ interface InputStreamConsumer {
3031
void consume(InputStream is) throws IOException;
3132

3233
/**
33-
* Consumes an input stream by throwing away all of its content.
34+
* Consumes an input stream by copying it to a given output stream.
3435
*/
35-
class NOPConsumer implements InputStreamConsumer {
36+
class CopyConsumer implements InputStreamConsumer {
37+
38+
private final OutputStream outputStream;
39+
40+
CopyConsumer(OutputStream outputStream) {
41+
this.outputStream = outputStream;
42+
}
3643

3744
@Override
3845
public void consume(InputStream inputStream) throws IOException {
39-
final byte[] buf = new byte[IOUtil.DEFAULT_BUFFER_SIZE];
40-
while (inputStream.read(buf) >= 0) {
41-
// do nothing
42-
}
46+
inputStream.transferTo(outputStream);
4347
}
4448
}
4549

commons/util/src/main/java/net/automatalib/common/util/process/ProcessUtil.java

Lines changed: 119 additions & 88 deletions
Large diffs are not rendered by default.

commons/util/src/main/java/net/automatalib/common/util/system/JVMUtil.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* Copyright (C) 2013-2025 TU Dortmund University
2+
* This file is part of AutomataLib <https://automatalib.net>.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package net.automatalib.common.util.process;
17+
18+
import java.io.IOException;
19+
import java.io.StringReader;
20+
import java.net.URISyntaxException;
21+
import java.net.URL;
22+
import java.nio.file.Paths;
23+
import java.util.Objects;
24+
import java.util.StringJoiner;
25+
26+
import org.testng.Assert;
27+
import org.testng.SkipException;
28+
import org.testng.annotations.BeforeTest;
29+
import org.testng.annotations.Test;
30+
31+
@Test
32+
public class ProcessUtilTest {
33+
34+
private final String program;
35+
private final String path;
36+
37+
public ProcessUtilTest() throws URISyntaxException {
38+
this.program = "python";
39+
this.path = getPathToScript();
40+
}
41+
42+
private static String getPathToScript() throws URISyntaxException {
43+
final URL resource = Objects.requireNonNull(ProcessUtilTest.class.getResource("/process.py"));
44+
return Paths.get(resource.toURI()).toFile().getAbsolutePath();
45+
}
46+
47+
@BeforeTest
48+
public void setUp() {
49+
try {
50+
if (ProcessUtil.invokeProcess(new String[] {program, "--version"}) != 0) {
51+
throw new SkipException("python not supported");
52+
}
53+
} catch (IOException | InterruptedException e) {
54+
throw new SkipException("python not supported");
55+
}
56+
}
57+
58+
@Test
59+
public void testReturnValue() throws IOException, InterruptedException {
60+
Assert.assertEquals(ProcessUtil.invokeProcess(new String[] {program, path, "abc"}), 0);
61+
Assert.assertEquals(ProcessUtil.invokeProcess(new String[] {program, path, "abc", "def"}), 1);
62+
63+
Assert.assertEquals(ProcessUtil.invokeProcess(new String[] {program, path}, new StringReader("abc")), 0);
64+
Assert.assertEquals(ProcessUtil.invokeProcess(new String[] {program, path}, new StringReader("abc def")), 1);
65+
}
66+
67+
@Test
68+
public void testProcessOutput() throws IOException, InterruptedException {
69+
StringJoiner stdOutJoiner = new StringJoiner("\n");
70+
StringJoiner stdErrBuilder = new StringJoiner("\n");
71+
72+
int returnCode =
73+
ProcessUtil.invokeProcess(new String[] {program, path, "abc"}, stdOutJoiner::add, stdErrBuilder::add);
74+
Assert.assertEquals(returnCode, 0, stdErrBuilder.toString());
75+
Assert.assertEquals(stdOutJoiner.toString(), "294");
76+
Assert.assertEquals(stdErrBuilder.toString(), "abc");
77+
78+
stdOutJoiner = new StringJoiner("\n");
79+
stdErrBuilder = new StringJoiner("\n");
80+
returnCode = ProcessUtil.invokeProcess(new String[] {program, path, "abc", "def"},
81+
stdOutJoiner::add,
82+
stdErrBuilder::add);
83+
Assert.assertEquals(returnCode, 1, stdErrBuilder.toString());
84+
Assert.assertEquals(stdOutJoiner.toString(), "294\n303");
85+
Assert.assertEquals(stdErrBuilder.toString(), "abc\ndef");
86+
87+
stdOutJoiner = new StringJoiner("\n");
88+
stdErrBuilder = new StringJoiner("\n");
89+
returnCode = ProcessUtil.invokeProcess(new String[] {program, path},
90+
new StringReader("abc"),
91+
stdOutJoiner::add,
92+
stdErrBuilder::add);
93+
Assert.assertEquals(returnCode, 0, stdErrBuilder.toString());
94+
Assert.assertEquals(stdOutJoiner.toString(), "294");
95+
Assert.assertEquals(stdErrBuilder.toString(), "abc");
96+
97+
stdOutJoiner = new StringJoiner("\n");
98+
stdErrBuilder = new StringJoiner("\n");
99+
returnCode = ProcessUtil.invokeProcess(new String[] {program, path},
100+
new StringReader("abc def"),
101+
stdOutJoiner::add,
102+
stdErrBuilder::add);
103+
Assert.assertEquals(returnCode, 1, stdErrBuilder.toString());
104+
Assert.assertEquals(stdOutJoiner.toString(), "294\n303");
105+
Assert.assertEquals(stdErrBuilder.toString(), "abc\ndef");
106+
107+
}
108+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/python
2+
import sys
3+
4+
def main():
5+
argv = len(sys.argv)
6+
7+
if argv > 1: # arg mode
8+
for arg in sys.argv[1:]:
9+
print(sum([ord(c) for c in arg]))
10+
print(arg, file=sys.stderr)
11+
else: # stdin mode
12+
for line in sys.stdin:
13+
for arg in line.split():
14+
argv += 1
15+
print(sum([ord(c) for c in arg]))
16+
print(arg, file=sys.stderr)
17+
18+
sys.exit(argv % 2)
19+
20+
if __name__ == "__main__":
21+
main()

examples/pom.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,6 @@ limitations under the License.
137137
</systemPropertyVariables>
138138
</configuration>
139139
</plugin>
140-
<plugin>
141-
<groupId>org.apache.maven.plugins</groupId>
142-
<artifactId>maven-enforcer-plugin</artifactId>
143-
<configuration>
144-
<rules>
145-
<enforceBytecodeVersion>
146-
<excludes>
147-
<exclude>ch.qos.logback:*</exclude>
148-
</excludes>
149-
</enforceBytecodeVersion>
150-
</rules>
151-
</configuration>
152-
</plugin>
153140
</plugins>
154141
</pluginManagement>
155142
</build>

0 commit comments

Comments
 (0)