<commit_before>package brooklyn.launcher

import brooklyn.management.ManagementContext
import org.apache.commons.io.IOUtils
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext

public class WebAppRunner {
    private Server server;
    private int port;
    private String warClasspathPath;
    private ManagementContext managementContext;

    public WebAppRunner(ManagementContext managementContext,  int port=8081, String embeddedWarCP="/web-console.war") throws Exception {
        this.warClasspathPath = embeddedWarCP;
        this.port = port;
        this.managementContext = managementContext;
    }

    /** Starts the embedded web application server. */
    public void start() throws Exception {
        File war = File.createTempFile("embedded", "war");
        war.deleteOnExit();
        InputStream is = null;
        Writer out = null;

        try {
            is = WebAppRunner.class.getResourceAsStream(warClasspathPath);
            out = new FileWriter(war);
            IOUtils.copy(is, out);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(out);
        }

        server = new Server(port);

        WebAppContext context = new WebAppContext();
        context.setAttribute("brooklynManagementContext", managementContext);
        context.war = war.getAbsolutePath();
        context.contextPath = "/";
        context.parentLoaderPriority = true;

        server.handler = context;
        server.start();
    }<commit_msg>WebAppRunner: Fail with sensible message if war not found<commit_after>package brooklyn.launcher

import brooklyn.management.ManagementContext
import org.apache.commons.io.IOUtils
import org.eclipse.jetty.server.Server
import org.eclipse.jetty.webapp.WebAppContext

public class WebAppRunner {
    private Server server;
    private int port;
    private String warClasspathPath;
    private ManagementContext managementContext;

    public WebAppRunner(ManagementContext managementContext,  int port=8081, String embeddedWarCP="/web-console.war") throws Exception {
        this.warClasspathPath = embeddedWarCP;
        this.port = port;
        this.managementContext = managementContext;
    }

    /** Starts the embedded web application server. */
    public void start() throws Exception {
        File war = File.createTempFile("embedded", "war");
        war.deleteOnExit();
        InputStream is = null;
        Writer out = null;

        try {
            is = WebAppRunner.class.getResourceAsStream(warClasspathPath);
            if (!is) {
                throw new IllegalArgumentException("WAR not found on classpath at $warClasspathPath")
            }
            out = new FileWriter(war);
            IOUtils.copy(is, out);
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(out);
        }

        server = new Server(port);

        WebAppContext context = new WebAppContext();
        context.setAttribute("brooklynManagementContext", managementContext);
        context.war = war.getAbsolutePath();
        context.contextPath = "/";
        context.parentLoaderPriority = true;

        server.handler = context;
        server.start();
    }
{'fraction_non_alphanumeric': 0.08809891808346214, 'fraction_numerical': 0.002472952086553323, 'mean_word_length': 2.728110599078341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1370434', 'n_tokens_mistral': 843, 'n_tokens_neox': 836, 'n_words': 199}