// Path: src/main/java/com/danielflower/apprunner/io/OutputToWriterBridge.java
// public class OutputToWriterBridge implements InvocationOutputHandler, LineConsumer {
//     public static final Logger log = LoggerFactory.getLogger(OutputToWriterBridge.class);
//     private final Writer writer;
// 
//     public OutputToWriterBridge(Writer writer) {
//         this.writer = writer;
//     }
// 
//     public void consumeLine(String line) {
//         try {
//             writer.write(line + System.lineSeparator());
//             writer.flush();
//         } catch (InterruptedIOException iox) {
//             Thread.currentThread().interrupt();
//         } catch (Exception e) {
//             log.info("Error while writing", e);
//         }
//     }
// }
// 
// Path: src/test/java/scaffolding/TestConfig.java
// public class TestConfig {
//     public static final Config config;
// 
//     static {
//         try {
//             config = Config.load(new String[]{"sample-config.properties"});
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static Map<String,String> testEnvVars(int port, String appName) throws IOException {
//         File tempDir = new File("target/testapp/" + appName + "/temp");
//         File dataDir = new File("target/testapp/" + appName + "/data/" + UUID.randomUUID());
//         FileUtils.forceMkdir(dataDir);
//         FileUtils.forceMkdir(tempDir);
//         return AppManager.createAppEnvVars(port, appName, dataDir, tempDir);
//     }
// }
// 
// Path: src/main/java/com/danielflower/apprunner/Config.java
// public static String javaExecutableName() {
//     return windowsinize("java");
// }
// 
// Path: src/test/java/scaffolding/RestClient.java
// public static final HttpClient httpClient;


import com.danielflower.apprunner.io.OutputToWriterBridge;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.jetty.client.api.ContentResponse;
import org.hamcrest.Matcher;
import org.junit.Test;
import scaffolding.TestConfig;
import static com.danielflower.apprunner.Config.javaExecutableName;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static scaffolding.RestClient.httpClient;
package com.danielflower.apprunner.runners;



public class ProcessStarterTest {
    static void startAndStop(int attempt, String appName, AppRunner runner, int port, StringBuilderWriter buildLog, StringBuilderWriter consoleLog, Matcher<String> getResponseMatcher, Matcher<String> buildLogMatcher) throws Exception {
        try {
            try (Waiter startupWaiter = Waiter.waitForApp(appName, port)) {
                runner.start(
                    new OutputToWriterBridge(buildLog),
                    new OutputToWriterBridge(consoleLog),
                    TestConfig.testEnvVars(port, appName),
                    startupWaiter);
            }
            try {
                ContentResponse resp = httpClient.GET("http://localhost:" + port + "/" + appName + "/");
                assertThat(resp.getStatus(), is(200));
                assertThat(resp.getContentAsString(), getResponseMatcher);
                assertThat(buildLog.toString(), buildLogMatcher);
            } finally {
                runner.shutdown();
            }
// Path: src/main/java/com/danielflower/apprunner/io/OutputToWriterBridge.java
// public class OutputToWriterBridge implements InvocationOutputHandler, LineConsumer {
//     public static final Logger log = LoggerFactory.getLogger(OutputToWriterBridge.class);
//     private final Writer writer;
// 
//     public OutputToWriterBridge(Writer writer) {
//         this.writer = writer;
//     }
// 
//     public void consumeLine(String line) {
//         try {
//             writer.write(line + System.lineSeparator());
//             writer.flush();
//         } catch (InterruptedIOException iox) {
//             Thread.currentThread().interrupt();
//         } catch (Exception e) {
//             log.info("Error while writing", e);
//         }
//     }
// }
// 
// Path: src/test/java/scaffolding/TestConfig.java
// public class TestConfig {
//     public static final Config config;
// 
//     static {
//         try {
//             config = Config.load(new String[]{"sample-config.properties"});
//         } catch (IOException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     public static Map<String,String> testEnvVars(int port, String appName) throws IOException {
//         File tempDir = new File("target/testapp/" + appName + "/temp");
//         File dataDir = new File("target/testapp/" + appName + "/data/" + UUID.randomUUID());
//         FileUtils.forceMkdir(dataDir);
//         FileUtils.forceMkdir(tempDir);
//         return AppManager.createAppEnvVars(port, appName, dataDir, tempDir);
//     }
// }
// 
// Path: src/main/java/com/danielflower/apprunner/Config.java
// public static String javaExecutableName() {
//     return windowsinize("java");
// }
// 
// Path: src/test/java/scaffolding/RestClient.java
// public static final HttpClient httpClient;


// Path: src/test/java/com/danielflower/apprunner/runners/ProcessStarterTest.java
import com.danielflower.apprunner.io.OutputToWriterBridge;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.io.output.StringBuilderWriter;
import org.apache.commons.lang3.tuple.Pair;
import org.eclipse.jetty.client.api.ContentResponse;
import org.hamcrest.Matcher;
import org.junit.Test;
import scaffolding.TestConfig;
import static com.danielflower.apprunner.Config.javaExecutableName;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static scaffolding.RestClient.httpClient;

package com.danielflower.apprunner.runners;



public class ProcessStarterTest {
    static void startAndStop(int attempt, String appName, AppRunner runner, int port, StringBuilderWriter buildLog, StringBuilderWriter consoleLog, Matcher<String> getResponseMatcher, Matcher<String> buildLogMatcher) throws Exception {
        try {
            try (Waiter startupWaiter = Waiter.waitForApp(appName, port)) {
                runner.start(
                    new OutputToWriterBridge(buildLog),
                    new OutputToWriterBridge(consoleLog),
                    TestConfig.testEnvVars(port, appName),
                    startupWaiter);
            }
            try {
                ContentResponse resp = httpClient.GET("http://localhost:" + port + "/" + appName + "/");
                assertThat(resp.getStatus(), is(200));
                assertThat(resp.getContentAsString(), getResponseMatcher);
                assertThat(buildLog.toString(), buildLogMatcher);
            } finally {
                runner.shutdown();
            }
        } catch (Exception e) {