// Path: appengine-jetty-managed-runtime/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java
// public static final String JETTY_HOME_PATTERN = ""//TestUtil.getRunfilesDir()
//     + "com/google/apphosting/vmruntime/jetty9/" + HOME_FOLDER;


import static com.google.apphosting.vmruntime.jetty9.VmRuntimeTestBase.JETTY_HOME_PATTERN;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.jsp.JspFactory;
import org.apache.jasper.runtime.JspFactoryImpl;
import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.Assert;
import com.google.apphosting.vmruntime.VmRuntimeLogHandler;
    finally
    {
      Log.getLogger(Server.class).info("Started!");
      started.countDown();
    }

    try {
      if (Log.getLogger(Server.class).isDebugEnabled())
        server.dumpStdErr();
      server.join(); 
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

  /**
   * Sets the system properties expected by jetty.xml.
   *
   * @throws IOException
   */
  protected void setSystemProperties(File logs) throws IOException {

    String log_file_pattern = logs.getAbsolutePath()+"/log.%g";
    
    System.setProperty(
            "com.google.apphosting.vmruntime.VmRuntimeFileLogHandler.pattern", log_file_pattern);
    System.setProperty("jetty.appengineport", me.alexpanov.net.FreePortFinder.findFreeLocalPort() + "");
    System.setProperty("jetty.appenginehost", "localhost");
    System.setProperty("jetty.appengine.forwarded", "true");
// Path: appengine-jetty-managed-runtime/src/test/java/com/google/apphosting/vmruntime/jetty9/VmRuntimeTestBase.java
// public static final String JETTY_HOME_PATTERN = ""//TestUtil.getRunfilesDir()
//     + "com/google/apphosting/vmruntime/jetty9/" + HOME_FOLDER;


// Path: appengine-jetty-managed-runtime/src/test/java/com/google/apphosting/vmruntime/jetty9/JettyRunner.java
import static com.google.apphosting.vmruntime.jetty9.VmRuntimeTestBase.JETTY_HOME_PATTERN;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.servlet.jsp.JspFactory;
import org.apache.jasper.runtime.JspFactoryImpl;
import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.SimpleInstanceManager;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.NCSARequestLog;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.server.handler.RequestLogHandler;
import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.Assert;
import com.google.apphosting.vmruntime.VmRuntimeLogHandler;

    finally
    {
      Log.getLogger(Server.class).info("Started!");
      started.countDown();
    }

    try {
      if (Log.getLogger(Server.class).isDebugEnabled())
        server.dumpStdErr();
      server.join(); 
    } catch (Exception e) {
      e.printStackTrace();
    }

  }

  /**
   * Sets the system properties expected by jetty.xml.
   *
   * @throws IOException
   */
  protected void setSystemProperties(File logs) throws IOException {

    String log_file_pattern = logs.getAbsolutePath()+"/log.%g";
    
    System.setProperty(
            "com.google.apphosting.vmruntime.VmRuntimeFileLogHandler.pattern", log_file_pattern);
    System.setProperty("jetty.appengineport", me.alexpanov.net.FreePortFinder.findFreeLocalPort() + "");
    System.setProperty("jetty.appenginehost", "localhost");
    System.setProperty("jetty.appengine.forwarded", "true");
    System.setProperty("jetty.home", JETTY_HOME_PATTERN);