// Path: send-notification/src/main/java/fr/jcgay/notification/SendNotificationException.java
// public class SendNotificationException extends RuntimeException {
// 
//     public SendNotificationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SendNotificationException(String message) {
//         super(message);
//     }
// }


import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import fr.jcgay.notification.SendNotificationException;
import org.slf4j.Logger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.slf4j.LoggerFactory.getLogger;
package fr.jcgay.notification.notifier.executor;




public class RuntimeExecutor implements Executor {

    private static final Logger LOGGER = getLogger(RuntimeExecutor.class);
    private static final int DEFAULT_WAIT_PROCESS_TIMEOUT = 500;

    private final ExecutorService executor = Executors.newSingleThreadExecutor();
    private final long timeout;

    public RuntimeExecutor(long timeout) {
        this.timeout = timeout == -1 ? DEFAULT_WAIT_PROCESS_TIMEOUT : timeout;
    }

    @Override
    public void exec(final String[] command) {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Will execute command line: {} (waiting at most: {} milliseconds)", logCommand(command), timeout);
        }

        Future<Integer> task = executor.submit(() -> {
            try {
                Process execution = new ProcessBuilder(command)
                    .redirectErrorStream(true)
                    .start();

                int returnCode = execution.waitFor();
                if (returnCode != 0) {
                    String message = "Command <[" + logCommand(command) + "]> returns code: " + returnCode + ".\n" + asString(execution.getInputStream());
                    LOGGER.debug(message);
// Path: send-notification/src/main/java/fr/jcgay/notification/SendNotificationException.java
// public class SendNotificationException extends RuntimeException {
// 
//     public SendNotificationException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public SendNotificationException(String message) {
//         super(message);
//     }
// }


// Path: send-notification/src/main/java/fr/jcgay/notification/notifier/executor/RuntimeExecutor.java
import com.google.common.base.Joiner;
import com.google.common.base.Throwables;
import fr.jcgay.notification.SendNotificationException;
import org.slf4j.Logger;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static org.slf4j.LoggerFactory.getLogger;

package fr.jcgay.notification.notifier.executor;




public class RuntimeExecutor implements Executor {

    private static final Logger LOGGER = getLogger(RuntimeExecutor.class);
    private static final int DEFAULT_WAIT_PROCESS_TIMEOUT = 500;

    private final ExecutorService executor = Executors.newSingleThreadExecutor();
    private final long timeout;

    public RuntimeExecutor(long timeout) {
        this.timeout = timeout == -1 ? DEFAULT_WAIT_PROCESS_TIMEOUT : timeout;
    }

    @Override
    public void exec(final String[] command) {

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Will execute command line: {} (waiting at most: {} milliseconds)", logCommand(command), timeout);
        }

        Future<Integer> task = executor.submit(() -> {
            try {
                Process execution = new ProcessBuilder(command)
                    .redirectErrorStream(true)
                    .start();

                int returnCode = execution.waitFor();
                if (returnCode != 0) {
                    String message = "Command <[" + logCommand(command) + "]> returns code: " + returnCode + ".\n" + asString(execution.getInputStream());
                    LOGGER.debug(message);
                    throw new SendNotificationException(message);