package hudson.plugins.selenium;

import hudson.remoting.Callable;
import hudson.remoting.Channel;

import java.util.logging.Level;
import java.util.logging.Logger;

import org.jfree.util.Log;
import org.openqa.grid.internal.utils.GridHubConfiguration;
import org.openqa.grid.web.Hub;

/**
 * Starts the selenium grid server.
 * 
 * This callable blocks until the server is shut down and thus generally never returns.
 * 
 * @author Kohsuke Kawaguchi
 */
public class HubLauncher implements Callable<Void, Exception> {

    /**
	 * 
	 */
    private static final long serialVersionUID = 5658971914841423874L;

    private final int port;
    private final String[] args;
    private final Level logLevel;

    public HubLauncher(int port, String[] args, Level logLevel) {
        this.port = port;
        this.args = args;
        this.logLevel = logLevel;
    }

    public Void call() {
        try {
            Logger LOG = Logger.getLogger(HubLauncher.class.getName());
            configureLoggers();
            LOG.fine("Grid Hub preparing to start on port " + port);
            GridHubConfiguration c = GridHubConfiguration.build(args);
            c.setPort(port);
            c.setCapabilityMatcher(new JenkinsCapabilityMatcher(Channel.current(), c.getCapabilityMatcher()));
            Hub hub = new Hub(c);
            hub.start();
            HubHolder.hub = hub;

            LOG.fine("Grid Hub started on port " + port);
        } catch (Exception e) {
            Log.error("An error occured while starting the hub", e);
        }

        return null;
    }

    private void configureLoggers() {
        Logger.getLogger("org.openqa").setLevel(logLevel);
        Logger.getLogger("org.seleniumhq").setLevel(logLevel);
        Logger.getLogger("com.thoughtworks.selenium").setLevel(logLevel);
        Logger.getLogger("org.apache.commons.httpclient").setLevel(logLevel);
    }
}

@@ -38,132 +38,131 @@
 ort 
-hudson.remoting.Callable;%0Aimport hudson.remoting.Channel;%0A%0Aimport java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A
+java.util.logging.Level;%0Aimport java.util.logging.Logger;%0A%0Aimport hudson.remoting.Callable;%0Aimport hudson.remoting.Channel;
 %0Aimp
@@ -316,25 +316,24 @@
 d server.%0A *
- 
 %0A * This cal
@@ -411,17 +411,16 @@
 urns.%0A *
- 
 %0A * @aut
@@ -521,17 +521,16 @@
  /**%0A%09 *
- 
 %0A%09 */%0A  
@@ -1005,36 +1005,36 @@
             LOG.
-f
 in
-e
+fo
 (%22Grid Hub prepa
@@ -1370,16 +1370,178 @@
 = hub;%0A%0A
+            StringBuilder arguments = new StringBuilder();%0A            for (String arg : args) %7B%0A                arguments.append(%22 %22).append(arg);%0A            %7D%0A
         
@@ -1552,12 +1552,12 @@
 LOG.
-f
 in
-e
+fo
 (%22Gr
@@ -1579,32 +1579,71 @@
 on port %22 + port
+ + %22 with args:%22 + arguments.toString()
 );%0A        %7D cat
@@ -1698,16 +1698,17 @@
 or occur
+r
 ed while

Make connection info visible in Selenium Hub console at INFO level. Add connection params to log message