Improve logging modules and listing #984

Avoid sorting all modules. Only sort enabled modules.  This allows for
cycles to exist within all modules, but they are only seen as a problem if they
actually enabled.
This commit is contained in:
Greg Wilkins 2016-10-19 15:00:18 +11:00
parent 08be6aca91
commit b82d4ee2fe
8 changed files with 24 additions and 30 deletions

View File

@ -308,20 +308,9 @@ public class Main
}
}
StartLog.debug("Sorting Modules");
try
{
modules.sort();
}
catch (Exception e)
{
throw new UsageException(ERR_BAD_GRAPH,e);
}
args.setAllModules(modules);
List<Module> activeModules = modules.getEnabled();
final Version START_VERSION = new Version(StartArgs.VERSION);
for(Module enabled: activeModules)
@ -466,8 +455,9 @@ public class Main
{
invokeMain(cl, args);
}
catch (Exception e)
catch (Throwable e)
{
e.printStackTrace();
usageExit(e,ERR_INVOKE_MAIN,startupArgs.isTestingModeEnabled());
}
}

View File

@ -168,7 +168,8 @@ public class Modules implements Iterable<Module>
public void dumpEnabled()
{
int i=0;
for (Module module:getEnabled())
List<Module> enabled = getEnabled();
for (Module module:enabled)
{
String name=module.getName();
String index=(i++)+")";
@ -240,31 +241,31 @@ public class Modules implements Iterable<Module>
return str.toString();
}
public void sort()
public List<Module> getEnabled()
{
List<Module> enabled = _modules.stream().filter(m->{return m.isEnabled();}).collect(Collectors.toList());
TopologicalSort<Module> sort = new TopologicalSort<>();
for (Module module: _modules)
for (Module module: enabled)
{
Consumer<String> add = name ->
{
Module dependency = _names.get(name);
if (dependency!=null)
if (dependency!=null && dependency.isEnabled())
sort.addDependency(module,dependency);
Set<Module> provided = _provided.get(name);
if (provided!=null)
provided.forEach(p->sort.addDependency(module,p));
for (Module p : provided)
if (p.isEnabled())
sort.addDependency(module,p);
};
module.getDepends().forEach(add);
module.getOptional().forEach(add);
}
sort.sort(_modules);
}
public List<Module> getEnabled()
{
return _modules.stream().filter(m->{return m.isEnabled();}).collect(Collectors.toList());
sort.sort(enabled);
return enabled;
}
/** Enable a module
@ -287,6 +288,12 @@ public class Modules implements Iterable<Module>
{
StartLog.debug("enable %s from %s transitive=%b",module,enabledFrom,transitive);
if (newlyEnabled.contains(module.getName()))
{
StartLog.debug("Cycle at %s",module);
return;
}
// Check that this is not already provided by another module!
for (String name:module.getProvides())
{
@ -341,7 +348,6 @@ public class Modules implements Iterable<Module>
{
Path file = _baseHome.getPath("modules/" + dependsOn + ".mod");
registerModule(file).expandProperties(_args.getProperties());
sort();
providers = _provided.get(dependsOn);
if (providers==null || providers.isEmpty())
throw new UsageException("Module %s does not provide %s",_baseHome.toShortForm(file),dependsOn);

View File

@ -81,7 +81,6 @@ Module Management:
Note: this can also be used in the ${jetty.base}/start.ini
or ${jetty.base}/start.d/*.ini files.
--add=<modulename>(,<modulename>)*
--add-to-start=<modulename>(,<modulename>)*
Add the modules to the list of modules enabled at start.
Transitive dependencies are followed and dependent

View File

@ -62,7 +62,6 @@ public class ModuleGraphWriterTest
Modules modules = new Modules(basehome, args);
modules.registerAll();
modules.sort();
Path outputFile = basehome.getBasePath("graph.dot");

View File

@ -168,7 +168,6 @@ public class ModulesTest
// Enable 2 modules
modules.enable("base",TEST_SOURCE);
modules.enable("optional",TEST_SOURCE);
modules.sort();
// Collect active module list
List<Module> active = modules.getEnabled();

View File

@ -1 +1 @@
-module=root
--module=root

View File

@ -1 +1,2 @@
--create-startd --add=tom
--create-startd
--add-to-start=tom

View File

@ -1 +1 @@
-module=root
--module=root