This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-exec.git
The following commit(s) were added to refs/heads/master by this push:
new 4f9f8d37 Use final
4f9f8d37 is described below
commit 4f9f8d3759297c99369b175ea7a6b47ad42a15f1
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Dec 30 10:20:13 2023 -0500
Use final
- Sort members
- Remove trailing whitespace
- Format
---
.../java/org/apache/commons/exec/CommandLine.java | 4 +--
.../org/apache/commons/exec/DaemonExecutor.java | 20 +++++++-------
.../org/apache/commons/exec/DefaultExecutor.java | 1 +
.../org/apache/commons/exec/ExecuteWatchdog.java | 32 +++++++++++-----------
.../java/org/apache/commons/exec/Executor.java | 15 +++++-----
.../java/org/apache/commons/exec/ThreadUtil.java | 2 +-
.../java/org/apache/commons/exec/Watchdog.java | 25 +++++++++--------
.../org/apache/commons/exec/StandAloneTest.java | 20 +++++++-------
8 files changed, 60 insertions(+), 59 deletions(-)
diff --git a/src/main/java/org/apache/commons/exec/CommandLine.java
b/src/main/java/org/apache/commons/exec/CommandLine.java
index 2289c61f..06284ef2 100644
--- a/src/main/java/org/apache/commons/exec/CommandLine.java
+++ b/src/main/java/org/apache/commons/exec/CommandLine.java
@@ -213,7 +213,7 @@ public class CommandLine {
* Create a command line without any arguments.
*
* @param executable the executable.
- * @throws NullPointerException on null input.
+ * @throws NullPointerException on null input.
* @throws IllegalArgumentException on empty input.
*/
public CommandLine(final String executable) {
@@ -382,7 +382,7 @@ public class CommandLine {
*
* @param dirtyExecutable the executable.
* @return the platform-specific executable string.
- * @throws NullPointerException on null input.
+ * @throws NullPointerException on null input.
* @throws IllegalArgumentException on empty input.
*/
private String toCleanExecutable(final String dirtyExecutable) {
diff --git a/src/main/java/org/apache/commons/exec/DaemonExecutor.java
b/src/main/java/org/apache/commons/exec/DaemonExecutor.java
index 6d3780ef..5a08e667 100644
--- a/src/main/java/org/apache/commons/exec/DaemonExecutor.java
+++ b/src/main/java/org/apache/commons/exec/DaemonExecutor.java
@@ -45,6 +45,16 @@ public class DaemonExecutor extends DefaultExecutor {
}
+ /**
+ * Creates a new builder.
+ *
+ * @return a new builder.
+ * @since 1.4.0
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/**
* Constructs a new instance.
*
@@ -59,16 +69,6 @@ public class DaemonExecutor extends DefaultExecutor {
super(threadFactory, executeStreamHandler, workingDirectory);
}
- /**
- * Creates a new builder.
- *
- * @return a new builder.
- * @since 1.4.0
- */
- public static Builder builder() {
- return new Builder();
- }
-
/**
* Factory method to create a thread waiting for the result of an
asynchronous execution.
*
diff --git a/src/main/java/org/apache/commons/exec/DefaultExecutor.java
b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
index 910c019e..ce06a247 100644
--- a/src/main/java/org/apache/commons/exec/DefaultExecutor.java
+++ b/src/main/java/org/apache/commons/exec/DefaultExecutor.java
@@ -166,6 +166,7 @@ public class DefaultExecutor implements Executor {
*
* The {@code PumpStreamHandler} pumps the output of the subprocess into
our {@code System.out} and {@code System.err} to avoid into our {@code
System.out}
* and {@code System.err} to avoid a blocked or deadlocked subprocess (see
{@link Process Process}).
+ *
* @deprecated Use {@link Builder#get()}.
*/
@Deprecated
diff --git a/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
b/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
index f21b99c3..a10f153b 100644
--- a/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
+++ b/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java
@@ -101,6 +101,16 @@ public class ExecuteWatchdog implements TimeoutObserver {
/** The marker for an infinite timeout. */
public static final Duration INFINITE_TIMEOUT_DURATION =
Duration.ofMillis(INFINITE_TIMEOUT);
+ /**
+ * Creates a new builder.
+ *
+ * @return a new builder.
+ * @since 1.4.0
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/** The process to execute and watch for duration. */
private Process process;
@@ -128,13 +138,14 @@ public class ExecuteWatchdog implements TimeoutObserver {
private final ThreadFactory threadFactory;
/**
- * Creates a new builder.
+ * Creates a new watchdog with a given timeout.
*
- * @return a new builder.
- * @since 1.4.0
+ * @param timeoutMillis the timeout for the process in milliseconds. It
must be greater than 0 or {@code INFINITE_TIMEOUT}.
+ * @deprecated Use {@link Builder#get()}.
*/
- public static Builder builder() {
- return new Builder();
+ @Deprecated
+ public ExecuteWatchdog(final long timeoutMillis) {
+ this(Executors.defaultThreadFactory(),
Duration.ofMillis(timeoutMillis));
}
/**
@@ -157,17 +168,6 @@ public class ExecuteWatchdog implements TimeoutObserver {
}
}
- /**
- * Creates a new watchdog with a given timeout.
- *
- * @param timeoutMillis the timeout for the process in milliseconds. It
must be greater than 0 or {@code INFINITE_TIMEOUT}.
- * @deprecated Use {@link Builder#get()}.
- */
- @Deprecated
- public ExecuteWatchdog(final long timeoutMillis) {
- this(Executors.defaultThreadFactory(),
Duration.ofMillis(timeoutMillis));
- }
-
/**
* This method will rethrow the exception that was possibly caught during
the run of the process. It will only remains valid once the process has been
* terminated either by 'error', timeout or manual intervention.
Information will be discarded once a new process is ran.
diff --git a/src/main/java/org/apache/commons/exec/Executor.java
b/src/main/java/org/apache/commons/exec/Executor.java
index 3c4e1736..0eb0e3cb 100644
--- a/src/main/java/org/apache/commons/exec/Executor.java
+++ b/src/main/java/org/apache/commons/exec/Executor.java
@@ -36,6 +36,7 @@ import java.util.Map;
* <p>
* The following example shows the basic usage:
* </p>
+ *
* <pre>
* Executor exec = DefaultExecutor.builder().get();
* CommandLine cl = new CommandLine("ls -l");
@@ -54,18 +55,17 @@ public interface Executor {
* @param command the command to execute.
* @return process exit value.
* @throws ExecuteException execution of subprocess failed or the
subprocess returned a exit value indicating a failure {@link
Executor#setExitValue(int)}.
- * @throws IOException If an I/O error occurs.
+ * @throws IOException If an I/O error occurs.
*/
int execute(CommandLine command) throws ExecuteException, IOException;
/**
- * Executes a command asynchronously. The child process inherits all
environment variables of the parent process. Result provided to callback
- * handler.
+ * Executes a command asynchronously. The child process inherits all
environment variables of the parent process. Result provided to callback
handler.
*
* @param command the command to execute.
* @param handler capture process termination and exit code.
* @throws ExecuteException execution of subprocess failed.
- * @throws IOException If an I/O error occurs.
+ * @throws IOException If an I/O error occurs.
*/
void execute(CommandLine command, ExecuteResultHandler handler) throws
ExecuteException, IOException;
@@ -76,19 +76,18 @@ public interface Executor {
* @param environment The environment for the new process. If null, the
environment of the current process is used.
* @return process exit value.
* @throws ExecuteException execution of subprocess failed or the
subprocess returned a exit value indicating a failure {@link
Executor#setExitValue(int)}.
- * @throws IOException If an I/O error occurs.
+ * @throws IOException If an I/O error occurs.
*/
int execute(CommandLine command, Map<String, String> environment) throws
ExecuteException, IOException;
/**
- * Executes a command asynchronously. The child process inherits all
environment variables of the parent process. Result provided to callback
- * handler.
+ * Executes a command asynchronously. The child process inherits all
environment variables of the parent process. Result provided to callback
handler.
*
* @param command the command to execute.
* @param environment The environment for the new process. If null, the
environment of the current process is used.
* @param handler capture process termination and exit code.
* @throws ExecuteException execution of subprocess failed.
- * @throws IOException If an I/O error occurs.
+ * @throws IOException If an I/O error occurs.
*/
void execute(CommandLine command, Map<String, String> environment,
ExecuteResultHandler handler) throws ExecuteException, IOException;
diff --git a/src/main/java/org/apache/commons/exec/ThreadUtil.java
b/src/main/java/org/apache/commons/exec/ThreadUtil.java
index f524f1df..324d282b 100644
--- a/src/main/java/org/apache/commons/exec/ThreadUtil.java
+++ b/src/main/java/org/apache/commons/exec/ThreadUtil.java
@@ -33,7 +33,7 @@ final class ThreadUtil {
* @param daemon marks this thread as a daemon thread
* @return constructed thread, or {@code null} if the request to create a
thread is rejected
*/
- static Thread newThread(final ThreadFactory threadFactory, final Runnable
runnable, final String prefix, boolean daemon) {
+ static Thread newThread(final ThreadFactory threadFactory, final Runnable
runnable, final String prefix, final boolean daemon) {
final Thread thread = threadFactory.newThread(runnable);
if (thread == null) {
throw new IllegalStateException(String.format("The ThreadFactory
%s cound not construct a thread for '%s'", threadFactory, prefix));
diff --git a/src/main/java/org/apache/commons/exec/Watchdog.java
b/src/main/java/org/apache/commons/exec/Watchdog.java
index add829aa..e5906f43 100644
--- a/src/main/java/org/apache/commons/exec/Watchdog.java
+++ b/src/main/java/org/apache/commons/exec/Watchdog.java
@@ -96,8 +96,20 @@ public class Watchdog implements Runnable {
/**
* Constructs a new instance.
+ *
+ * @param timeoutMillis the timeout duration.
+ * @deprecated Use {@link #Watchdog(ThreadFactory, Duration)}.
+ */
+ @Deprecated
+ public Watchdog(final long timeoutMillis) {
+ this(null, Duration.ofMillis(timeoutMillis));
+ }
+
+ /**
+ * Constructs a new instance.
+ *
* @param threadFactory the thread factory.
- * @param timeout the timeout duration.
+ * @param timeout the timeout duration.
*/
private Watchdog(final ThreadFactory threadFactory, final Duration
timeout) {
if (timeout.isNegative() || Duration.ZERO.equals(timeout)) {
@@ -107,17 +119,6 @@ public class Watchdog implements Runnable {
this.threadFactory = threadFactory;
}
- /**
- * Constructs a new instance.
- *
- * @param timeoutMillis the timeout duration.
- * @deprecated Use {@link #Watchdog(ThreadFactory, Duration)}.
- */
- @Deprecated
- public Watchdog(final long timeoutMillis) {
- this(null, Duration.ofMillis(timeoutMillis));
- }
-
public void addTimeoutObserver(final TimeoutObserver to) {
observers.addElement(to);
}
diff --git a/src/test/java/org/apache/commons/exec/StandAloneTest.java
b/src/test/java/org/apache/commons/exec/StandAloneTest.java
index ea103112..88cd4f90 100644
--- a/src/test/java/org/apache/commons/exec/StandAloneTest.java
+++ b/src/test/java/org/apache/commons/exec/StandAloneTest.java
@@ -45,10 +45,16 @@ public class StandAloneTest {
}
@Test
- public void testDefaultExecutorDefaultBuilder() throws Exception {
+ public void testDefaultExecutorBuilder() throws Exception {
if (OS.isFamilyUnix()) {
final File testScript =
TestUtil.resolveScriptForOS("./src/test/scripts/standalone");
- final Executor exec = DefaultExecutor.builder().get();
+ // @formatter:off
+ final Executor exec = DefaultExecutor.builder()
+ .setThreadFactory(Executors.defaultThreadFactory())
+ .setExecuteStreamHandler(new PumpStreamHandler())
+ .setWorkingDirectory(new File("."))
+ .get();
+ // @formatter:on
exec.setStreamHandler(new PumpStreamHandler());
final CommandLine cl = new CommandLine(testScript);
exec.execute(cl);
@@ -57,16 +63,10 @@ public class StandAloneTest {
}
@Test
- public void testDefaultExecutorBuilder() throws Exception {
+ public void testDefaultExecutorDefaultBuilder() throws Exception {
if (OS.isFamilyUnix()) {
final File testScript =
TestUtil.resolveScriptForOS("./src/test/scripts/standalone");
- // @formatter:off
- final Executor exec = DefaultExecutor.builder()
- .setThreadFactory(Executors.defaultThreadFactory())
- .setExecuteStreamHandler(new PumpStreamHandler())
- .setWorkingDirectory(new File("."))
- .get();
- // @formatter:on
+ final Executor exec = DefaultExecutor.builder().get();
exec.setStreamHandler(new PumpStreamHandler());
final CommandLine cl = new CommandLine(testScript);
exec.execute(cl);