package de.saumya.mojo.rubygems;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.log.LoggerLog;
import org.eclipse.jetty.webapp.WebAppContext;
import org.jruby.mains.JettyRunMain;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;


public class JettyRun
{

    public static void main(String[] args)  {
        Properties props = new Properties();
        String filename = args.length == 0 ? "rubygems.properties" : args[ 0 ];
        System.err.println();
        try
        {
            props.load( new FileReader( filename ) );
            System.err.println( "loaded properties from " + filename );
        }
        catch (IOException e)
        {
            System.err.println( "could not load properties from " + filename + " :" + e.getMessage() );
            System.err.println( "      using defaults" );
    	}
        System.err.println();

        String basedir = props.getProperty( "gem.storage.base", "rubygems" );
        
        setProperty( props, "gem.caching.proxy.storage", basedir + "/caching" );
        setProperty( props, "gem.proxy.storage", basedir + "/proxy" );
        setProperty(props, "gem.hosted.storage", basedir + "/hosted");
        setProperty(props, "gem.caching.proxy.url", "https://rubygems.org");
        setProperty(props, "gem.proxy.url", "https://rubygems.org");
    	JettyRunMain.main(props, args);
    }
    
    static private void setProperty( Properties props, String key, String defaultValue ) {
        String result = props.getProperty( key, defaultValue );
        System.setProperty( key, result );
    }
}

@@ -860,18 +860,84 @@
 ing 
-defaults%22 
+system properties and defaults%22 );%0A            props = System.getProperties(
 );%0A 
@@ -1016,17 +1016,16 @@
 roperty(
- 
 %22gem.sto
@@ -1046,17 +1046,16 @@
 ubygems%22
- 
 );%0A     
@@ -1070,33 +1070,32 @@
     setProperty(
- 
 props, %22gem.cach
@@ -1134,17 +1134,16 @@
 caching%22
- 
 );%0A     
@@ -1157,17 +1157,16 @@
 roperty(
- 
 props, %22
@@ -1203,17 +1203,16 @@
 %22/proxy%22
- 
 );%0A     

allow system properties when there is no properties file