Skip to content

Commit e608f01

Browse files
committed
Convert PATH crawlers to new process API
1 parent 1c3309a commit e608f01

File tree

5 files changed

+15
-68
lines changed

5 files changed

+15
-68
lines changed

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package io.quarkus.deployment.pkg.steps;
22

3-
import java.io.File;
43
import java.nio.file.Path;
54
import java.util.List;
65
import java.util.stream.Stream;
76

87
import org.apache.commons.lang3.SystemUtils;
98

9+
import io.smallrye.common.process.ProcessUtil;
10+
1011
public class NativeImageBuildLocalRunner extends NativeImageBuildRunner {
1112

1213
private final String nativeImageExecutable;
@@ -43,23 +44,7 @@ protected boolean objcopyExists() {
4344
if (!SystemUtils.IS_OS_LINUX) {
4445
return false;
4546
}
46-
47-
// System path
48-
String systemPath = System.getenv("PATH");
49-
if (systemPath != null) {
50-
String[] pathDirs = systemPath.split(File.pathSeparator);
51-
for (String pathDir : pathDirs) {
52-
File dir = new File(pathDir);
53-
if (dir.isDirectory()) {
54-
File file = new File(dir, "objcopy");
55-
if (file.exists()) {
56-
return true;
57-
}
58-
}
59-
}
60-
}
61-
62-
return false;
47+
return ProcessUtil.pathOfCommand(Path.of("objcopy")).isPresent();
6348
}
6449

6550
private String[] buildCommand(List<String> args) {

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

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import io.quarkus.sbom.ApplicationManifestConfig;
6060
import io.smallrye.common.os.OS;
6161
import io.smallrye.common.process.ProcessBuilder;
62+
import io.smallrye.common.process.ProcessUtil;
6263

6364
public class NativeImageBuildStep {
6465

@@ -75,11 +76,6 @@ public class NativeImageBuildStep {
7576
*/
7677
private static final String JAVA_HOME_ENV = "JAVA_HOME";
7778

78-
/**
79-
* The name of the environment variable containing the system path.
80-
*/
81-
private static final String PATH = "PATH";
82-
8379
private static final int OOM_ERROR_VALUE = 137;
8480
private static final String QUARKUS_XMX_PROPERTY = "quarkus.native.native-image-xmx";
8581
public static final String CONTAINER_BUILD_VOLUME_PATH = "/project";
@@ -547,22 +543,9 @@ private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(Native
547543
}
548544
}
549545

550-
// System path
551-
String systemPath = System.getenv(PATH);
552-
if (systemPath != null) {
553-
String[] pathDirs = systemPath.split(File.pathSeparator);
554-
for (String pathDir : pathDirs) {
555-
File dir = new File(pathDir);
556-
if (dir.isDirectory()) {
557-
File file = new File(dir, executableName);
558-
if (file.exists()) {
559-
return new NativeImageBuildLocalRunner(file.getAbsolutePath());
560-
}
561-
}
562-
}
563-
}
564-
565-
return null;
546+
return ProcessUtil.pathOfCommand(Path.of(executableName))
547+
.map(value -> new NativeImageBuildLocalRunner(value.toString()))
548+
.orElse(null);
566549
}
567550

568551
private static String getNativeImageExecutableName() {

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

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static io.quarkus.deployment.pkg.steps.LinuxIDUtil.getLinuxID;
44

55
import java.io.File;
6+
import java.nio.file.Path;
67
import java.util.ArrayList;
78
import java.util.Collections;
89
import java.util.List;
@@ -24,16 +25,12 @@
2425
import io.quarkus.deployment.util.FileUtil;
2526
import io.smallrye.common.process.AbnormalExitException;
2627
import io.smallrye.common.process.ProcessBuilder;
28+
import io.smallrye.common.process.ProcessUtil;
2729

2830
public class UpxCompressionBuildStep {
2931

3032
private static final Logger log = Logger.getLogger(UpxCompressionBuildStep.class);
3133

32-
/**
33-
* The name of the environment variable containing the system path.
34-
*/
35-
private static final String PATH = "PATH";
36-
3734
@BuildStep(onlyIf = NativeBuild.class)
3835
public void compress(NativeConfig nativeConfig, NativeImageRunnerBuildItem nativeImageRunner,
3936
NativeImageBuildItem image,
@@ -174,21 +171,8 @@ private String getCompressionLevel(int level) {
174171
}
175172

176173
private Optional<File> getUpxFromSystem() {
177-
String exec = getUpxExecutableName();
178-
String systemPath = System.getenv(PATH);
179-
if (systemPath != null) {
180-
String[] pathDirs = systemPath.split(File.pathSeparator);
181-
for (String pathDir : pathDirs) {
182-
File dir = new File(pathDir);
183-
if (dir.isDirectory()) {
184-
File file = new File(dir, exec);
185-
if (file.exists()) {
186-
return Optional.of(file);
187-
}
188-
}
189-
}
190-
}
191-
return Optional.empty();
174+
return ProcessUtil.pathOfCommand(Path.of(getUpxExecutableName()))
175+
.map(Path::toFile);
192176
}
193177

194178
private static String getUpxExecutableName() {

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/exec/Executable.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import java.io.File;
44
import java.nio.file.Path;
5-
import java.nio.file.Paths;
6-
import java.util.regex.Pattern;
7-
import java.util.stream.Stream;
85

96
import io.quarkus.devtools.messagewriter.MessageWriter;
107
import io.smallrye.common.os.OS;
8+
import io.smallrye.common.process.ProcessUtil;
119

1210
public class Executable {
1311

@@ -32,9 +30,7 @@ public static File findExecutableFile(String base) {
3230
}
3331

3432
public static String findExecutable(String exec) {
35-
return Stream.of(System.getenv("PATH").split(Pattern.quote(File.pathSeparator))).map(Paths::get)
36-
.map(path -> path.resolve(exec).toFile()).filter(File::exists).findFirst().map(File::getParent)
37-
.orElse(null);
33+
return ProcessUtil.pathOfCommand(Path.of(exec)).map(Object::toString).orElse(null);
3834
}
3935

4036
public static File findExecutable(String name, String errorMessage, MessageWriter output) {

independent-projects/tools/devtools-common/src/main/java/io/quarkus/devtools/project/update/rewrite/QuarkusUpdateCommand.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.quarkus.qute.Qute;
3131
import io.smallrye.common.os.OS;
3232
import io.smallrye.common.process.ProcessBuilder;
33+
import io.smallrye.common.process.ProcessUtil;
3334

3435
public class QuarkusUpdateCommand {
3536

@@ -308,9 +309,7 @@ private static Path findWrapperOrBinary(Path baseDir, String wrapper, String cmd
308309
* @return A Path to the executable, if found, null otherwise
309310
*/
310311
public static Path searchPath(String cmd) {
311-
String envPath = System.getenv("PATH");
312-
envPath = envPath != null ? envPath : "";
313-
return searchPath(cmd, envPath);
312+
return ProcessUtil.pathOfCommand(Path.of(cmd)).orElse(null);
314313
}
315314

316315
/**

0 commit comments

Comments
 (0)