From 54b04e0a055d1c494ee0a91a9d1759f0795e4778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 24 May 2024 11:28:42 +0300 Subject: [PATCH] Move away of depracated commons-exec apis --- .../launching/internal/DefaultEquinoxLauncher.java | 11 +++++++---- .../tycho/compiler/jdt/JdkLibraryInfoProvider.java | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java index 8444f513c0..8534c15687 100644 --- a/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java +++ b/sisu-osgi/sisu-equinox-launching/src/main/java/org/eclipse/sisu/equinox/launching/internal/DefaultEquinoxLauncher.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2019 Sonatype Inc. and others. + * Copyright (c) 2008, 2024 Sonatype Inc. and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -14,12 +14,14 @@ import java.io.File; import java.io.IOException; +import java.time.Duration; import java.util.Arrays; import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecutor; +import org.apache.commons.exec.DefaultExecutor.Builder; import org.apache.commons.exec.ExecuteException; import org.apache.commons.exec.ExecuteWatchdog; import org.apache.commons.exec.ShutdownHookProcessDestroyer; @@ -57,12 +59,14 @@ public int execute(LaunchConfiguration configuration, int forkedProcessTimeoutIn cli.addArguments(configuration.getProgramArguments(), handleQuotes); - DefaultExecutor executor = new DefaultExecutor(); + Builder executorBuilder = DefaultExecutor.builder(); + executorBuilder.setWorkingDirectory(configuration.getWorkingDirectory()); + DefaultExecutor executor = executorBuilder.get(); ExecuteWatchdog watchdog = null; if (forkedProcessTimeoutInSeconds > 0) { long timeoutInMilliseconds = forkedProcessTimeoutInSeconds * 1000L; cli.addArguments(new String[] { "-timeout ", String.valueOf(timeoutInMilliseconds) }); - watchdog = new ExecuteWatchdog(timeoutInMilliseconds); + watchdog = ExecuteWatchdog.builder().setTimeout(Duration.ofMillis(timeoutInMilliseconds)).get(); executor.setWatchdog(watchdog); } @@ -70,7 +74,6 @@ public int execute(LaunchConfiguration configuration, int forkedProcessTimeoutIn // best effort to avoid orphaned child process executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); - executor.setWorkingDirectory(configuration.getWorkingDirectory()); try { return executor.execute(cli, getMergedEnvironment(configuration)); } catch (ExecuteException e) { diff --git a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java index e3f44b9f38..9b1759ebce 100644 --- a/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java +++ b/tycho-compiler-jdt/src/main/java/org/eclipse/tycho/compiler/jdt/JdkLibraryInfoProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2018 SAP SE and others. + * Copyright (c) 2018, 2024 SAP SE and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -82,8 +83,8 @@ private LibraryInfo generateLibraryInfo(String javaHome) throws ArtifactResoluti CommandLine cli = new CommandLine(executable); cli.addArguments(new String[] { "-classpath", getLibDetectorJar().getAbsolutePath(), "org.eclipse.tycho.libdetector.LibraryDetector" }, false); - DefaultExecutor executor = new DefaultExecutor(); - ExecuteWatchdog watchdog = new ExecuteWatchdog(30 * 1000L); + DefaultExecutor executor = DefaultExecutor.builder().get(); + ExecuteWatchdog watchdog = ExecuteWatchdog.builder().setTimeout(Duration.ofMillis(30 * 1000L)).get(); executor.setWatchdog(watchdog); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); PumpStreamHandler handler = new PumpStreamHandler(outputStream);