package io.purplejs.boot;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;

import io.purplejs.boot.internal.BannerPrinter;
import io.purplejs.boot.internal.config.ConfigBuilder;
import io.purplejs.boot.internal.server.ServerConfigurator;
import io.purplejs.core.settings.Settings;

public final class MainApp
{
    private Server server;

    public void start()
        throws Exception
    {
        System.setProperty( "java.net.preferIPv4Stack", "true" );

        // Print banner
        new BannerPrinter().printBanner();

        // Load settings
        final Settings settings = new ConfigBuilder().build();

        // Configure the server
        final ServerConfigurator serverConfigurator = new ServerConfigurator();
        serverConfigurator.configure( settings );

        // Start the server
        this.server = serverConfigurator.getServer();
        this.server.start();
    }

    public int getPort()
    {
        return ( (ServerConnector) server.getConnectors()[0] ).getLocalPort();
    }

    public void stop()
        throws Exception
    {
        if ( this.server != null )
        {
            this.server.stop();
        }
    }

    public static void main( final String... args )
        throws Exception
    {
        new MainApp().start();
    }
}

@@ -421,32 +421,299 @@
 Exception%0A    %7B%0A
+        // Add shutdown-hook%0A        Runtime.getRuntime().addShutdownHook( new Thread()%0A        %7B%0A            @Override%0A            public void run()%0A            %7B%0A                MainApp.this.stop();%0A            %7D%0A        %7D );%0A%0A        // Set some system properties%0A
         System.s
@@ -1349,35 +1349,36 @@
     
-    throws Exception%0A
+%7B%0A        try%0A    
     %7B%0A
+    
     
@@ -1408,16 +1408,20 @@
  null )%0A
+    
         
@@ -1426,32 +1426,36 @@
   %7B%0A            
+    
 this.server.stop
@@ -1450,32 +1450,124 @@
 .server.stop();%0A
+            %7D%0A        %7D%0A        catch ( final Exception e )%0A        %7B%0A            // Ignore%0A
         %7D%0A    %7D%0A

Add shutdown hook for boot. This fixes #26.