414635 Modular start.d and jetty.base property
+ Adding --list-config for identifying the configuration
This commit is contained in:
parent
79b2dd781e
commit
1844b4bd3d
|
@ -36,8 +36,10 @@ import java.net.SocketTimeoutException;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Main start class.
|
||||
|
@ -258,9 +260,43 @@ public class Main
|
|||
main.invoke(null,method_params);
|
||||
}
|
||||
|
||||
private void listConfig()
|
||||
public void listConfig(StartArgs args)
|
||||
{
|
||||
// TODO
|
||||
// Dump Jetty Home / Base
|
||||
args.dumpEnvironment();
|
||||
|
||||
// Dump Classpath
|
||||
dumpClasspathWithVersions(args.getClasspath());
|
||||
|
||||
// Dump Enabled Modules
|
||||
System.out.println();
|
||||
System.out.println("Jetty Active Module Tree:");
|
||||
System.out.println("-------------------------");
|
||||
Modules modules = args.getAllModules();
|
||||
modules.dumpEnabledTree();
|
||||
|
||||
// Dump Resolved XMLs
|
||||
System.out.println();
|
||||
System.out.println("Jetty Active XMLs:");
|
||||
System.out.println("------------------");
|
||||
for (File xml : args.getXmlFiles())
|
||||
{
|
||||
System.out.printf(" - %s%n",baseHome.toShortForm(xml.getAbsolutePath()));
|
||||
}
|
||||
|
||||
// Dump Properties
|
||||
System.out.println();
|
||||
System.out.println("Properties:");
|
||||
System.out.println("-----------");
|
||||
Properties props = args.getProperties();
|
||||
@SuppressWarnings("unchecked")
|
||||
Enumeration<String> keyEnum = (Enumeration<String>)props.propertyNames();
|
||||
while (keyEnum.hasMoreElements())
|
||||
{
|
||||
String name = keyEnum.nextElement();
|
||||
String value = props.getProperty(name);
|
||||
System.out.printf(" %s = %s%n",name,value);
|
||||
}
|
||||
}
|
||||
|
||||
private void listModules(StartArgs args)
|
||||
|
@ -353,23 +389,20 @@ public class Main
|
|||
return baseHome;
|
||||
}
|
||||
|
||||
private void showClasspathWithVersions(Classpath classpath)
|
||||
private void dumpClasspathWithVersions(Classpath classpath)
|
||||
{
|
||||
// Iterate through active classpath, and fetch Implementation Version from each entry (if present)
|
||||
// to dump to end user.
|
||||
|
||||
// TODO: modules instead
|
||||
// System.out.println("Active Options: " + _config.getOptions());
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Jetty Server Classpath:");
|
||||
System.out.println("-----------------------");
|
||||
if (classpath.count() == 0)
|
||||
{
|
||||
System.out.println("No version information available show.");
|
||||
System.out.println("No classpath entries and/or version information available show.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Version Information on " + classpath.count() + " entr" + ((classpath.count() > 1)?"ies":"y") + " in the classpath.");
|
||||
System.out.println("Note: order presented here is how they would appear on the classpath.");
|
||||
System.out.println(" changes to the OPTIONS=[option,option,...] command line option will be reflected here.");
|
||||
System.out.println(" changes to the MODULES=[name,name,...] command line option will be reflected here.");
|
||||
|
||||
int i = 0;
|
||||
for (File element : classpath.getElements())
|
||||
|
@ -381,7 +414,7 @@ public class Main
|
|||
public void start(StartArgs args) throws IOException, InterruptedException
|
||||
{
|
||||
StartLog.debug("StartArgs: %s",args);
|
||||
|
||||
|
||||
// Get Desired Classpath based on user provided Active Options.
|
||||
Classpath classpath = args.getClasspath();
|
||||
|
||||
|
@ -406,13 +439,13 @@ public class Main
|
|||
// Show the version information and return
|
||||
if (args.isListClasspath())
|
||||
{
|
||||
showClasspathWithVersions(classpath);
|
||||
dumpClasspathWithVersions(classpath);
|
||||
}
|
||||
|
||||
// Show configuration
|
||||
if (args.isListConfig())
|
||||
{
|
||||
listConfig();
|
||||
listConfig(args);
|
||||
}
|
||||
|
||||
// Show modules
|
||||
|
|
|
@ -21,6 +21,7 @@ package org.eclipse.jetty.start;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -38,6 +39,33 @@ public class Modules implements Iterable<Module>
|
|||
{
|
||||
private Map<String, Module> modules = new HashMap<>();
|
||||
|
||||
private void assertNoCycle(Module module, Stack<String> refs)
|
||||
{
|
||||
for (Module parent : module.getParentEdges())
|
||||
{
|
||||
if (refs.contains(parent.getName()))
|
||||
{
|
||||
// Cycle detected.
|
||||
StringBuilder err = new StringBuilder();
|
||||
err.append("A cyclic reference in the modules has been detected: ");
|
||||
for (int i = 0; i < refs.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
err.append(" -> ");
|
||||
}
|
||||
err.append(refs.get(i));
|
||||
}
|
||||
err.append(" -> ").append(parent.getName());
|
||||
throw new IllegalStateException(err.toString());
|
||||
}
|
||||
|
||||
refs.push(parent.getName());
|
||||
assertNoCycle(parent,refs);
|
||||
refs.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private void bfsCalculateDepth(final Module module, final int depthNow)
|
||||
{
|
||||
int depth = depthNow + 1;
|
||||
|
@ -93,33 +121,6 @@ public class Modules implements Iterable<Module>
|
|||
}
|
||||
}
|
||||
|
||||
private void assertNoCycle(Module module, Stack<String> refs)
|
||||
{
|
||||
for (Module parent : module.getParentEdges())
|
||||
{
|
||||
if (refs.contains(parent.getName()))
|
||||
{
|
||||
// Cycle detected.
|
||||
StringBuilder err = new StringBuilder();
|
||||
err.append("A cyclic reference in the modules has been detected: ");
|
||||
for (int i = 0; i < refs.size(); i++)
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
err.append(" -> ");
|
||||
}
|
||||
err.append(refs.get(i));
|
||||
}
|
||||
err.append(" -> ").append(parent.getName());
|
||||
throw new IllegalStateException(err.toString());
|
||||
}
|
||||
|
||||
refs.push(parent.getName());
|
||||
assertNoCycle(parent,refs);
|
||||
refs.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer count()
|
||||
{
|
||||
return modules.size();
|
||||
|
@ -143,6 +144,51 @@ public class Modules implements Iterable<Module>
|
|||
}
|
||||
}
|
||||
|
||||
public void dumpEnabledTree()
|
||||
{
|
||||
List<Module> ordered = new ArrayList<>();
|
||||
ordered.addAll(modules.values());
|
||||
Collections.sort(ordered,new Module.DepthComparator());
|
||||
|
||||
List<Module> active = resolveEnabled();
|
||||
|
||||
for (Module module : ordered)
|
||||
{
|
||||
if (active.contains(module))
|
||||
{
|
||||
// Show module name
|
||||
String indent = toIndent(module.getDepth());
|
||||
System.out.printf("%s + Module: %s",indent,module.getName());
|
||||
if (module.isEnabled())
|
||||
{
|
||||
System.out.print(" [enabled]");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.print(" [transitive]");
|
||||
}
|
||||
System.out.println();
|
||||
// Dump lib references
|
||||
for (String libRef : module.getLibs())
|
||||
{
|
||||
System.out.printf("%s - LIB | %s%n",indent,libRef);
|
||||
}
|
||||
// Dump xml references
|
||||
for (String xmlRef : module.getXmls())
|
||||
{
|
||||
System.out.printf("%s - XML | %s%n",indent,xmlRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toIndent(int depth)
|
||||
{
|
||||
char indent[] = new char[depth * 2];
|
||||
Arrays.fill(indent,' ');
|
||||
return new String(indent);
|
||||
}
|
||||
|
||||
public void enable(String name)
|
||||
{
|
||||
Module module = modules.get(name);
|
||||
|
@ -196,9 +242,6 @@ public class Modules implements Iterable<Module>
|
|||
return str.toString();
|
||||
}
|
||||
|
||||
// TODO: Resolve LIB names to actual java.io.File references via HomeBase
|
||||
// TODO: Handle ${jetty.version} references here
|
||||
// TODO: Handle *.jar filesystem glob style here
|
||||
public List<String> normalizeLibs(List<Module> active)
|
||||
{
|
||||
List<String> libs = new ArrayList<>();
|
||||
|
@ -215,7 +258,6 @@ public class Modules implements Iterable<Module>
|
|||
return libs;
|
||||
}
|
||||
|
||||
// TODO: Resolve XML names to actual java.io.File references via HomeBase
|
||||
public List<String> normalizeXmls(List<Module> active)
|
||||
{
|
||||
List<String> xmls = new ArrayList<>();
|
||||
|
|
|
@ -57,6 +57,7 @@ public class StartArgs
|
|||
}
|
||||
|
||||
VERSION = ver;
|
||||
System.setProperty("jetty.version",VERSION);
|
||||
}
|
||||
|
||||
// TODO: might make sense to declare this in modules/base.mod
|
||||
|
@ -109,6 +110,37 @@ public class StartArgs
|
|||
}
|
||||
}
|
||||
|
||||
public void dumpEnvironment()
|
||||
{
|
||||
System.out.println();
|
||||
System.out.println("Jetty Environment:");
|
||||
System.out.println("-----------------");
|
||||
|
||||
dumpSystemProperty("jetty.home");
|
||||
dumpSystemProperty("jetty.base");
|
||||
dumpSystemProperty("jetty.version");
|
||||
|
||||
// Java Details
|
||||
System.out.println();
|
||||
System.out.println("Java Environment:");
|
||||
System.out.println("-----------------");
|
||||
dumpSystemProperty("java.home");
|
||||
dumpSystemProperty("java.vm.vendor");
|
||||
dumpSystemProperty("java.vm.version");
|
||||
dumpSystemProperty("java.vm.name");
|
||||
dumpSystemProperty("java.vm.info");
|
||||
dumpSystemProperty("java.runtime.name");
|
||||
dumpSystemProperty("java.runtime.version");
|
||||
|
||||
dumpSystemProperty("java.io.tmpdir");
|
||||
System.out.printf("java.class.path=%s%n",classpath.toString());
|
||||
}
|
||||
|
||||
private void dumpSystemProperty(String key)
|
||||
{
|
||||
System.out.printf("%s=%s%n",key,System.getProperty(key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that the System Properties are set (if defined as a System property, or start.config property, or start.ini property)
|
||||
*
|
||||
|
@ -421,7 +453,7 @@ public class StartArgs
|
|||
run = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ("--list-modules".equals(arg))
|
||||
{
|
||||
listModules = true;
|
||||
|
|
|
@ -50,6 +50,19 @@ public class MainTest
|
|||
ConfigurationAssert.assertConfiguration(baseHome,args,"assert-home.txt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListConfig() throws Exception
|
||||
{
|
||||
List<String> cmdLineArgs = new ArrayList<>();
|
||||
addUseCasesHome(cmdLineArgs);
|
||||
cmdLineArgs.add("jetty.port=9090");
|
||||
cmdLineArgs.add("--list-config");
|
||||
|
||||
Main main = new Main();
|
||||
StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()]));
|
||||
main.listConfig(args);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithCommandLine() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue