package me.zhex;

import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.HandlerCollection;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.webapp.WebAppContext;

import java.util.Collections;
import java.util.List;


public class Application {

    static final String INCLUDE_JAR_PATTERN = "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern";
    static final String JSP_PATTERN = ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$";


    public static void main(String[] args) throws Exception {
        final int port = Integer.getInteger("server.port", 8080);
        String viewPath = System.getProperty("viewpath");

        Server server = createServer(viewPath, port);

        server.start();
        server.join();
    }

    public static Server createServer(String viewPath, int port) {
        final String ctx = "/r/";

        Server server = new Server(port);

        final ServletContextHandler servletContextHandler = new ServletContextHandler(null, "/", false, false);
        servletContextHandler.addServlet(new ServletHolder(new CustomServlet(ctx)), "/");
//        final URL url = Application.class.getProtectionDomain().getCodeSource().getLocation();

//        File tempDir = new File(System.getProperty("java.io.tmpdir"));
//        File scratchDir = new File(tempDir.toString(), "jtr");
//        if (!scratchDir.exists()) {
//            if (!scratchDir.mkdirs()) {
//                throw new RuntimeException("Unable to create scratch directory: " + scratchDir);
//            }
//        }


        WebAppContext context = new WebAppContext(viewPath, ctx);

//        if (url != null) {
//            context.getMetaData().addWebInfJar(Resource.newResource(url));
//            String descriptor = "jar:" + url + "!/empty-web.xml";
//            context.setDescriptor(descriptor);
//        }


        context.setAttribute(INCLUDE_JAR_PATTERN, JSP_PATTERN);
//        context.setAttribute("javax.servlet.context.tempdir", scratchDir);
        context.setAttribute("org.eclipse.jetty.containerInitializers", jspInitializers());
        context.addBean(new ServletContainerInitializersStarter(context), true);
//        context.setClassLoader(new URLClassLoader(new URL[0], Application.class.getClassLoader()));

        final HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[]{
                servletContextHandler,
                context
        });
        server.setHandler(handlers);

        return server;
    }

    static List<ContainerInitializer> jspInitializers() {
        JettyJasperInitializer sci = new JettyJasperInitializer();
        ContainerInitializer initializer = new ContainerInitializer(sci, null);
        return Collections.singletonList(initializer);
    }


}

@@ -481,30 +481,121 @@
 tty.
-webapp.WebAppContext;%0A
+util.resource.Resource;%0Aimport org.eclipse.jetty.webapp.WebAppContext;%0A%0Aimport java.io.File;%0Aimport java.net.URL;
 %0Aimp
@@ -918,16 +918,116 @@
 jar$%22;%0A%0A
+    static %7B%0A        System.setProperty(%22org.apache.jasper.compiler.disablejsr199%22, %22false%22);%0A    %7D%0A
 %0A    pub
@@ -1658,26 +1658,24 @@
 tx)), %22/%22);%0A
-//
         fina
@@ -2168,26 +2168,24 @@
 ath, ctx);%0A%0A
-//
         if (
@@ -2195,26 +2195,24 @@
  != null) %7B%0A
-//
             
@@ -2270,26 +2270,24 @@
 urce(url));%0A
-//
             
@@ -2340,18 +2340,16 @@
 b.xml%22;%0A
-//
         
@@ -2383,26 +2383,24 @@
 escriptor);%0A
-//
         %7D%0A%0A%0A
@@ -3071,24 +3071,32 @@
 %0A    %7D%0A%0A    
+private 
 static List%3C

fix sjtl issue