429487 - Runner code cleanups
Bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=429487 Also-by: Alexander Orlov <alexander.orlov@loxal.net> Signed-off-by: Greg Wilkins <gregw@intalio.com>
This commit is contained in:
parent
af3f2f4894
commit
93e21c8426
|
@ -5,7 +5,6 @@
|
|||
<version>9.1.3-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-runner</artifactId>
|
||||
<name>Jetty :: Runner</name>
|
||||
|
||||
|
|
|
@ -18,33 +18,12 @@
|
|||
|
||||
package org.eclipse.jetty.runner;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.security.ConstraintMapping;
|
||||
import org.eclipse.jetty.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.security.HashLoginService;
|
||||
import org.eclipse.jetty.security.authentication.BasicAuthenticator;
|
||||
import org.eclipse.jetty.server.AbstractConnector;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.ConnectorStatistics;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.NCSARequestLog;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.ShutdownMonitor;
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
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.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.server.*;
|
||||
import org.eclipse.jetty.server.handler.*;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.servlet.ServletContextHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
@ -57,6 +36,14 @@ import org.eclipse.jetty.util.security.Constraint;
|
|||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.xml.XmlConfiguration;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -102,9 +89,9 @@ public class Runner
|
|||
*/
|
||||
public class Classpath
|
||||
{
|
||||
private List<URL> _classpath = new ArrayList<URL>();
|
||||
private List<URL> _classpath = new ArrayList<>();
|
||||
|
||||
public void addJars (Resource lib) throws MalformedURLException, IOException
|
||||
public void addJars (Resource lib) throws IOException
|
||||
{
|
||||
if (lib == null || !lib.exists())
|
||||
throw new IllegalStateException ("No such lib: "+lib);
|
||||
|
@ -118,7 +105,7 @@ public class Runner
|
|||
if (".".equals(path) || "..".equals(path))
|
||||
continue;
|
||||
|
||||
try(Resource item = lib.addPath(path);)
|
||||
try(Resource item = lib.addPath(path))
|
||||
{
|
||||
if (item.isDirectory())
|
||||
addJars(item);
|
||||
|
@ -215,7 +202,7 @@ public class Runner
|
|||
{
|
||||
if ("--lib".equals(args[i]))
|
||||
{
|
||||
try(Resource lib = Resource.newResource(args[++i]);)
|
||||
try(Resource lib = Resource.newResource(args[++i]))
|
||||
{
|
||||
if (!lib.exists() || !lib.isDirectory())
|
||||
usage("No such lib directory "+lib);
|
||||
|
@ -224,7 +211,7 @@ public class Runner
|
|||
}
|
||||
else if ("--jar".equals(args[i]))
|
||||
{
|
||||
try(Resource jar = Resource.newResource(args[++i]);)
|
||||
try(Resource jar = Resource.newResource(args[++i]))
|
||||
{
|
||||
if (!jar.exists() || jar.isDirectory())
|
||||
usage("No such jar "+jar);
|
||||
|
@ -233,7 +220,7 @@ public class Runner
|
|||
}
|
||||
else if ("--classes".equals(args[i]))
|
||||
{
|
||||
try(Resource classes = Resource.newResource(args[++i]);)
|
||||
try(Resource classes = Resource.newResource(args[++i]))
|
||||
{
|
||||
if (!classes.exists() || !classes.isDirectory())
|
||||
usage("No such classes directory "+classes);
|
||||
|
@ -260,55 +247,59 @@ public class Runner
|
|||
|
||||
for (int i=0;i<args.length;i++)
|
||||
{
|
||||
if ("--port".equals(args[i]))
|
||||
port=Integer.parseInt(args[++i]);
|
||||
else if ("--host".equals(args[i]))
|
||||
host=args[++i];
|
||||
else if ("--stop-port".equals(args[i]))
|
||||
stopPort=Integer.parseInt(args[++i]);
|
||||
else if ("--stop-key".equals(args[i]))
|
||||
stopKey=args[++i];
|
||||
else if ("--log".equals(args[i]))
|
||||
_logFile=args[++i];
|
||||
else if ("--out".equals(args[i]))
|
||||
switch (args[i])
|
||||
{
|
||||
case "--port":
|
||||
port = Integer.parseInt(args[++i]);
|
||||
break;
|
||||
case "--host":
|
||||
host = args[++i];
|
||||
break;
|
||||
case "--stop-port":
|
||||
stopPort = Integer.parseInt(args[++i]);
|
||||
break;
|
||||
case "--stop-key":
|
||||
stopKey = args[++i];
|
||||
break;
|
||||
case "--log":
|
||||
_logFile = args[++i];
|
||||
break;
|
||||
case "--out":
|
||||
String outFile = args[++i];
|
||||
PrintStream out = new PrintStream(new RolloverFileOutputStream(outFile, true, -1));
|
||||
LOG.info("Redirecting stderr/stdout to " + outFile);
|
||||
System.setErr(out);
|
||||
System.setOut(out);
|
||||
}
|
||||
else if ("--path".equals(args[i]))
|
||||
{
|
||||
break;
|
||||
case "--path":
|
||||
contextPath = args[++i];
|
||||
contextPathSet = true;
|
||||
}
|
||||
else if ("--config".equals(args[i]))
|
||||
{
|
||||
break;
|
||||
case "--config":
|
||||
if (_configFiles == null)
|
||||
_configFiles = new ArrayList<String>();
|
||||
_configFiles = new ArrayList<>();
|
||||
_configFiles.add(args[++i]);
|
||||
}
|
||||
else if ("--lib".equals(args[i]))
|
||||
{
|
||||
break;
|
||||
case "--lib":
|
||||
++i;//skip
|
||||
}
|
||||
else if ("--jar".equals(args[i]))
|
||||
{
|
||||
|
||||
break;
|
||||
case "--jar":
|
||||
++i; //skip
|
||||
}
|
||||
else if ("--classes".equals(args[i]))
|
||||
{
|
||||
|
||||
break;
|
||||
case "--classes":
|
||||
++i;//skip
|
||||
}
|
||||
else if ("--stats".equals( args[i]))
|
||||
{
|
||||
|
||||
break;
|
||||
case "--stats":
|
||||
_enableStats = true;
|
||||
_statsPropFile = args[++i];
|
||||
_statsPropFile = ("unsecure".equalsIgnoreCase(_statsPropFile) ? null : _statsPropFile);
|
||||
}
|
||||
else // process contexts
|
||||
{
|
||||
break;
|
||||
default:
|
||||
// process contexts
|
||||
|
||||
if (!runnerServerInitialized) // log handlers not registered, server maybe not created, etc
|
||||
{
|
||||
if (_server == null) // server not initialized yet
|
||||
|
@ -322,8 +313,7 @@ public class Runner
|
|||
{
|
||||
for (String cfg : _configFiles)
|
||||
{
|
||||
try (Resource resource=Resource.newResource(cfg))
|
||||
{
|
||||
try (Resource resource = Resource.newResource(cfg)) {
|
||||
XmlConfiguration xmlConfiguration = new XmlConfiguration(resource.getURL());
|
||||
xmlConfiguration.configure(_server);
|
||||
}
|
||||
|
@ -350,8 +340,7 @@ public class Runner
|
|||
if (_enableStats)
|
||||
{
|
||||
//if no stats handler already configured
|
||||
if (handlers.getChildHandlerByClass(StatisticsHandler.class) == null)
|
||||
{
|
||||
if (handlers.getChildHandlerByClass(StatisticsHandler.class) == null) {
|
||||
StatisticsHandler statsHandler = new StatisticsHandler();
|
||||
|
||||
|
||||
|
@ -415,9 +404,9 @@ public class Runner
|
|||
{
|
||||
if (_enableStats)
|
||||
{
|
||||
for (int j=0; j<connectors.length; j++)
|
||||
for (Connector connector : connectors)
|
||||
{
|
||||
((AbstractConnector)connectors[j]).addBean(new ConnectorStatistics());
|
||||
((AbstractConnector) connector).addBean(new ConnectorStatistics());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +415,7 @@ public class Runner
|
|||
}
|
||||
|
||||
// Create a context
|
||||
try(Resource ctx = Resource.newResource(args[i]);)
|
||||
try (Resource ctx = Resource.newResource(args[i]))
|
||||
{
|
||||
if (!ctx.exists())
|
||||
usage("Context '" + ctx + "' does not exist");
|
||||
|
@ -458,6 +447,7 @@ public class Runner
|
|||
//reset
|
||||
contextPathSet = false;
|
||||
contextPath = __defaultContextPath;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue