Skip to content

Commit c779b6d

Browse files
authored
Merge pull request #48354 from dmlloyd/process
Conversion to SmallRye Common Process
2 parents e8c4b6e + 6d95873 commit c779b6d

File tree

58 files changed

+712
-1409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+712
-1409
lines changed

core/deployment/pom.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
<groupId>io.smallrye</groupId>
4343
<artifactId>jandex</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>io.smallrye.common</groupId>
47+
<artifactId>smallrye-common-os</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.smallrye.common</groupId>
51+
<artifactId>smallrye-common-process</artifactId>
52+
</dependency>
4553
<dependency>
4654
<groupId>org.ow2.asm</groupId>
4755
<artifactId>asm</artifactId>
@@ -86,10 +94,6 @@
8694
<artifactId>quarkus-bootstrap-gradle-resolver</artifactId>
8795
<scope>provided</scope>
8896
</dependency>
89-
<dependency>
90-
<groupId>io.quarkus</groupId>
91-
<artifactId>quarkus-devtools-utilities</artifactId>
92-
</dependency>
9397
<dependency>
9498
<!-- We don't want the annotation processor to run
9599
as it leaves junk files in the project-->

core/deployment/src/main/java/io/quarkus/deployment/QuarkusAugmentor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import io.quarkus.dev.spi.DevModeType;
3838
import io.quarkus.paths.PathCollection;
3939
import io.quarkus.runtime.LaunchMode;
40-
import io.quarkus.runtime.util.JavaVersionUtil;
4140
import io.smallrye.config.SmallRyeConfigProviderResolver;
4241

4342
public class QuarkusAugmentor {
@@ -91,7 +90,7 @@ public class QuarkusAugmentor {
9190
}
9291

9392
public BuildResult run() throws Exception {
94-
if (!JavaVersionUtil.isJava17OrHigher()) {
93+
if (!(Runtime.version().major() >= 17)) {
9594
throw new IllegalStateException("Quarkus applications require Java 17 or higher to build");
9695
}
9796
long start = System.nanoTime();

core/deployment/src/main/java/io/quarkus/deployment/console/ConsoleProcessor.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import java.io.File;
77
import java.nio.file.Path;
8-
import java.util.ArrayList;
98
import java.util.List;
10-
import java.util.concurrent.TimeUnit;
119
import java.util.concurrent.atomic.AtomicReference;
1210
import java.util.function.BiConsumer;
1311
import java.util.function.Supplier;
@@ -40,6 +38,7 @@
4038
import io.quarkus.deployment.ide.EffectiveIdeBuildItem;
4139
import io.quarkus.deployment.ide.Ide;
4240
import io.quarkus.dev.console.QuarkusConsole;
41+
import io.smallrye.common.process.ProcessBuilder;
4342

4443
public class ConsoleProcessor {
4544

@@ -185,13 +184,8 @@ public void run() {
185184
log.debug("Unable to determine proper launch command for IDE: " + ide);
186185
return;
187186
}
188-
List<String> command = new ArrayList<>();
189-
command.add(effectiveCommand);
190-
command.addAll(args);
191-
log.debugf("Opening IDE with %s", command);
192-
new ProcessBuilder(command).redirectOutput(ProcessBuilder.Redirect.DISCARD)
193-
.redirectError(ProcessBuilder.Redirect.DISCARD).start().waitFor(10,
194-
TimeUnit.SECONDS);
187+
log.debugf("Opening IDE with %s %s", effectiveCommand, args);
188+
ProcessBuilder.exec(effectiveCommand, args);
195189
} catch (Exception e) {
196190
log.error("Failed to open IDE", e);
197191
}

core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeCommandLineBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import io.quarkus.deployment.util.CommandLineUtil;
3939
import io.quarkus.maven.dependency.ArtifactKey;
4040
import io.quarkus.runtime.logging.JBossVersion;
41-
import io.quarkus.utilities.JavaBinFinder;
41+
import io.smallrye.common.process.ProcessUtil;
4242

4343
public class DevModeCommandLineBuilder {
4444

@@ -131,7 +131,7 @@ private static void extensionsDisablingDebugWarning(List<ArtifactKey> extensions
131131
private ExtensionDevModeJvmOptionFilter extDevModeJvmOptionFilter;
132132

133133
protected DevModeCommandLineBuilder(String java) {
134-
final String javaTool = java == null ? JavaBinFinder.findBin() : java;
134+
final String javaTool = java == null ? ProcessUtil.pathOfJava().toString() : java;
135135
log.debugf("Using javaTool: %s", javaTool);
136136
args.add(javaTool);
137137
}

core/deployment/src/main/java/io/quarkus/deployment/dev/DevModeMain.java

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11

22
package io.quarkus.deployment.dev;
33

4-
import java.io.ByteArrayOutputStream;
54
import java.io.Closeable;
65
import java.io.DataInputStream;
76
import java.io.File;
87
import java.io.IOException;
98
import java.io.InputStream;
109
import java.io.ObjectInputStream;
11-
import java.io.PrintStream;
1210
import java.net.URI;
1311
import java.net.URISyntaxException;
1412
import java.net.URL;
15-
import java.nio.file.FileSystemException;
1613
import java.nio.file.Files;
1714
import java.nio.file.Path;
1815
import java.nio.file.Paths;
1916
import java.util.HashMap;
2017
import java.util.Map;
2118
import java.util.Properties;
2219

23-
import org.apache.commons.lang3.SystemUtils;
2420
import org.jboss.logging.Logger;
2521

2622
import io.quarkus.bootstrap.app.CuratedApplication;
2723
import io.quarkus.bootstrap.app.QuarkusBootstrap;
2824
import io.quarkus.bootstrap.model.ApplicationModel;
29-
import io.quarkus.deployment.util.ProcessUtil;
3025
import io.quarkus.dev.appstate.ApplicationStateNotification;
3126
import io.quarkus.dev.spi.DevModeType;
3227
import io.quarkus.maven.dependency.ArtifactKey;
@@ -201,19 +196,8 @@ private void linkDotEnvFile() {
201196
silentDeleteFile(link);
202197
try {
203198
// create a symlink to ensure that user updates to the file have the expected effect in dev-mode
204-
try {
205-
Files.createSymbolicLink(link, dotEnvPath);
206-
} catch (FileSystemException e) {
207-
// on Windows fall back to mklink if symlink cannot be created via Files API (due to insufficient permissions)
208-
// see https://github.com/quarkusio/quarkus/issues/8297
209-
if (SystemUtils.IS_OS_WINDOWS) {
210-
log.debug("Falling back to mklink on Windows after FileSystemException", e);
211-
makeHardLinkWindowsFallback(link, dotEnvPath);
212-
} else {
213-
throw e;
214-
}
215-
}
216-
} catch (IOException | InterruptedException e) {
199+
Files.createSymbolicLink(link, dotEnvPath);
200+
} catch (IOException e) {
217201
log.warn("Unable to link .env file", e);
218202
}
219203
link.toFile().deleteOnExit();
@@ -228,24 +212,6 @@ private void silentDeleteFile(Path path) {
228212
}
229213
}
230214

231-
private void makeHardLinkWindowsFallback(Path link, Path dotEnvPath) throws IOException, InterruptedException {
232-
Process process = new ProcessBuilder("cmd.exe", "/C", "mklink", "/H", link.toString(), dotEnvPath.toString())
233-
.redirectOutput(new File("NUL"))
234-
.redirectError(ProcessBuilder.Redirect.PIPE)
235-
.start();
236-
try {
237-
ByteArrayOutputStream errStream = new ByteArrayOutputStream();
238-
ProcessUtil.streamErrorTo(new PrintStream(errStream), process);
239-
int exitValue = process.waitFor();
240-
if (exitValue > 0) {
241-
throw new IOException(
242-
"mklink /H execution failed with exit code " + exitValue + ": " + new String(errStream.toByteArray()));
243-
}
244-
} finally {
245-
process.destroy();
246-
}
247-
}
248-
249215
@Override
250216
public void close() throws IOException {
251217
if (realCloseable != null) {

core/deployment/src/main/java/io/quarkus/deployment/ide/Ide.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
import java.nio.file.Files;
44
import java.nio.file.Path;
5-
import java.util.ArrayList;
65
import java.util.Collections;
76
import java.util.List;
8-
import java.util.concurrent.TimeUnit;
97
import java.util.stream.Collectors;
108

119
import org.jboss.logging.Logger;
1210

1311
import io.quarkus.dev.console.DevConsoleManager;
12+
import io.smallrye.common.process.ProcessBuilder;
1413

1514
public enum Ide {
1615

@@ -55,14 +54,8 @@ private String doGetEffectiveCommand() {
5554
return defaultCommand;
5655
} else {
5756
try {
58-
List<String> command = new ArrayList<>(1 + markerArgs.size());
59-
command.add(defaultCommand);
60-
command.addAll(markerArgs);
61-
log.debugf("Checking if IDE available with %s", command);
62-
new ProcessBuilder(command).redirectError(ProcessBuilder.Redirect.DISCARD.file())
63-
.redirectOutput(ProcessBuilder.Redirect.DISCARD.file()).start()
64-
.waitFor(10,
65-
TimeUnit.SECONDS);
57+
log.debugf("Checking if IDE available with %s %s", defaultCommand, markerArgs);
58+
ProcessBuilder.exec(defaultCommand, markerArgs);
6659
return defaultCommand;
6760
} catch (Exception e) {
6861
return machineSpecificCommand;

core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/ErrorReplacingProcessReader.java

Lines changed: 38 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import java.io.BufferedReader;
44
import java.io.File;
5-
import java.io.InputStream;
6-
import java.io.InputStreamReader;
7-
import java.nio.charset.StandardCharsets;
5+
import java.io.IOException;
86
import java.util.ArrayDeque;
97
import java.util.Deque;
10-
import java.util.concurrent.CountDownLatch;
118
import java.util.regex.Matcher;
129
import java.util.regex.Pattern;
1310

@@ -17,69 +14,57 @@
1714
* This class intercepts them and prints meaningful output instead, so users don't waste hours going on wild goose
1815
* chases
1916
*/
20-
public final class ErrorReplacingProcessReader implements Runnable {
17+
public final class ErrorReplacingProcessReader {
2118

2219
private static final String LINE_START = "Call path from entry point to ";
23-
private final InputStream inputStream;
20+
private final BufferedReader reader;
2421
private final File reportdir;
25-
private final CountDownLatch doneLatch;
2622

2723
private ReportAnalyzer reportAnalyzer;
2824

29-
public ErrorReplacingProcessReader(InputStream inputStream, File reportdir, CountDownLatch doneLatch) {
30-
this.inputStream = inputStream;
25+
public ErrorReplacingProcessReader(final BufferedReader reader, final File reportdir) {
26+
this.reader = reader;
3127
this.reportdir = reportdir;
32-
this.doneLatch = doneLatch;
3328
}
3429

35-
@Override
36-
public void run() {
37-
try {
38-
Deque<String> fullBuffer = new ArrayDeque<>();
39-
boolean buffering = false;
40-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) {
41-
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
42-
if (line.startsWith(LINE_START)) {
43-
buffering = true;
44-
}
45-
if (buffering) {
46-
fullBuffer.add(line);
47-
} else {
48-
System.err.println(line);
49-
}
50-
}
51-
File reportFile = null;
52-
if (reportdir.exists()) {
53-
File[] files = reportdir.listFiles();
54-
if (files != null) {
55-
for (File j : files) {
56-
if (j.getName().startsWith("call_tree")) {
57-
reportFile = j;
58-
break;
59-
}
60-
}
61-
30+
public void run() throws IOException {
31+
Deque<String> fullBuffer = new ArrayDeque<>();
32+
boolean buffering = false;
33+
for (String line = reader.readLine(); line != null; line = reader.readLine()) {
34+
if (line.startsWith(LINE_START)) {
35+
buffering = true;
36+
}
37+
if (buffering) {
38+
fullBuffer.add(line);
39+
} else {
40+
System.err.println(line);
41+
}
42+
}
43+
File reportFile = null;
44+
if (reportdir.exists()) {
45+
File[] files = reportdir.listFiles();
46+
if (files != null) {
47+
for (File j : files) {
48+
if (j.getName().startsWith("call_tree")) {
49+
reportFile = j;
50+
break;
6251
}
6352
}
64-
if (reportFile == null) {
65-
for (String j : fullBuffer) {
66-
System.err.println(j);
67-
}
53+
}
54+
}
55+
if (reportFile == null) {
56+
for (String j : fullBuffer) {
57+
System.err.println(j);
58+
}
59+
} else {
60+
while (!fullBuffer.isEmpty()) {
61+
String line = fullBuffer.pop();
62+
if (line.startsWith(LINE_START)) {
63+
handleErrorState(reportFile, line, fullBuffer);
6864
} else {
69-
while (!fullBuffer.isEmpty()) {
70-
String line = fullBuffer.pop();
71-
if (line.startsWith(LINE_START)) {
72-
handleErrorState(reportFile, line, fullBuffer);
73-
} else {
74-
System.err.println(line);
75-
}
76-
}
65+
System.err.println(line);
7766
}
78-
} catch (Exception e) {
79-
e.printStackTrace();
8067
}
81-
} finally {
82-
doneLatch.countDown();
8368
}
8469
}
8570

core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/JarResultBuildStep.java

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@
8888
import io.quarkus.paths.PathVisitor;
8989
import io.quarkus.sbom.ApplicationComponent;
9090
import io.quarkus.sbom.ApplicationManifestConfig;
91-
import io.quarkus.utilities.JavaBinFinder;
91+
import io.smallrye.common.process.ProcessBuilder;
92+
import io.smallrye.common.process.ProcessUtil;
9293

9394
/**
9495
* This build step builds both the thin jars and uber jars.
@@ -1631,36 +1632,26 @@ public boolean downloadIfNecessary() {
16311632

16321633
@Override
16331634
public boolean decompile(Path jarToDecompile) {
1634-
int exitCode;
1635+
String jarFileName = jarToDecompile.getFileName().toString();
1636+
int dotIndex = jarFileName.indexOf('.');
1637+
String outputDirectory = jarFileName.substring(0, dotIndex);
1638+
var pb = ProcessBuilder.newBuilder(ProcessUtil.pathOfJava())
1639+
.arguments(
1640+
"-jar",
1641+
decompilerJar.toAbsolutePath().toString(),
1642+
"-rsy=0", // synthetic methods
1643+
"-rbr=0", // bridge methods
1644+
jarToDecompile.toAbsolutePath().toString(),
1645+
context.decompiledOutputDir.resolve(outputDirectory).toAbsolutePath().toString());
1646+
if (log.isDebugEnabled()) {
1647+
pb.output().consumeLinesWith(8192, log::debug);
1648+
}
16351649
try {
1636-
int dotIndex = jarToDecompile.getFileName().toString().indexOf('.');
1637-
String fileName = jarToDecompile.getFileName().toString().substring(0, dotIndex);
1638-
ProcessBuilder processBuilder = new ProcessBuilder(
1639-
Arrays.asList(
1640-
JavaBinFinder.findBin(),
1641-
"-jar",
1642-
decompilerJar.toAbsolutePath().toString(),
1643-
"-rsy=0", // synthetic methods
1644-
"-rbr=0", // bridge methods
1645-
jarToDecompile.toAbsolutePath().toString(),
1646-
context.decompiledOutputDir.resolve(fileName).toAbsolutePath().toString()));
1647-
if (log.isDebugEnabled()) {
1648-
processBuilder.inheritIO();
1649-
} else {
1650-
processBuilder.redirectError(ProcessBuilder.Redirect.DISCARD.file())
1651-
.redirectOutput(ProcessBuilder.Redirect.DISCARD.file());
1652-
}
1653-
exitCode = processBuilder.start().waitFor();
1650+
pb.run();
16541651
} catch (Exception e) {
1655-
log.error("Failed to launch decompiler.", e);
1652+
log.error("Decompilation failed", e);
16561653
return false;
16571654
}
1658-
1659-
if (exitCode != 0) {
1660-
log.errorf("Vineflower decompiler exited with error code: %d.", exitCode);
1661-
return false;
1662-
}
1663-
16641655
return true;
16651656
}
16661657
}

0 commit comments

Comments
 (0)