Merge pull request #4633 from eclipse/jetty-9.4.x-4628-start-module-non-required

Issue #4628 - Ensuring checkEnabledModules is conditional dependency aware
This commit is contained in:
Simone Bordet 2020-03-31 11:10:53 +02:00 committed by GitHub
commit 81c13f08d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 19 deletions

View File

@ -195,14 +195,14 @@ public class Module implements Comparable<Module>
process(basehome); process(basehome);
} }
public static boolean isRequiredDependency(String depends) public static boolean isConditionalDependency(String depends)
{ {
return (depends != null) && (depends.charAt(0) != '?'); return (depends != null) && (depends.charAt(0) == '?');
} }
public static String normalizeModuleName(String name) public static String normalizeModuleName(String name)
{ {
if (!isRequiredDependency(name)) if (isConditionalDependency(name))
return name.substring(1); return name.substring(1);
return name; return name;
} }

View File

@ -91,8 +91,8 @@ public class Modules implements Iterable<Module>
_modules.stream() _modules.stream()
.filter(m -> .filter(m ->
{ {
boolean included = all || m.getTags().stream().anyMatch(t -> include.contains(t)); boolean included = all || m.getTags().stream().anyMatch(include::contains);
boolean excluded = m.getTags().stream().anyMatch(t -> exclude.contains(t)); boolean excluded = m.getTags().stream().anyMatch(exclude::contains);
return included && !excluded; return included && !excluded;
}) })
.sorted() .sorted()
@ -135,9 +135,9 @@ public class Modules implements Iterable<Module>
{ {
parent = Module.normalizeModuleName(parent); parent = Module.normalizeModuleName(parent);
System.out.printf(label, parent); System.out.printf(label, parent);
if (!Module.isRequiredDependency(parent)) if (Module.isConditionalDependency(parent))
{ {
System.out.print(" [not-required]"); System.out.print(" [conditional]");
} }
label = ", %s"; label = ", %s";
} }
@ -219,11 +219,7 @@ public class Modules implements Iterable<Module>
Module module = new Module(_baseHome, file); Module module = new Module(_baseHome, file);
_modules.add(module); _modules.add(module);
_names.put(module.getName(), module); _names.put(module.getName(), module);
module.getProvides().forEach(n -> module.getProvides().forEach(n -> _provided.computeIfAbsent(n, k -> new HashSet<>()).add(module));
{
_provided.computeIfAbsent(n, k -> new HashSet<Module>()).add(module);
});
return module; return module;
} }
catch (Error | RuntimeException t) catch (Error | RuntimeException t)
@ -258,7 +254,7 @@ public class Modules implements Iterable<Module>
public List<Module> getEnabled() public List<Module> getEnabled()
{ {
List<Module> enabled = _modules.stream().filter(m -> m.isEnabled()).collect(Collectors.toList()); List<Module> enabled = _modules.stream().filter(Module::isEnabled).collect(Collectors.toList());
TopologicalSort<Module> sort = new TopologicalSort<>(); TopologicalSort<Module> sort = new TopologicalSort<>();
for (Module module : enabled) for (Module module : enabled)
@ -360,7 +356,7 @@ public class Modules implements Iterable<Module>
StartLog.debug("Enabled module %s depends on %s", module.getName(), module.getDepends()); StartLog.debug("Enabled module %s depends on %s", module.getName(), module.getDepends());
for (String dependsOnRaw : module.getDepends()) for (String dependsOnRaw : module.getDepends())
{ {
boolean isRequired = Module.isRequiredDependency(dependsOnRaw); boolean isConditional = Module.isConditionalDependency(dependsOnRaw);
// Final to allow lambda's below to use name // Final to allow lambda's below to use name
final String dependentModule = Module.normalizeModuleName(dependsOnRaw); final String dependentModule = Module.normalizeModuleName(dependsOnRaw);
@ -376,7 +372,7 @@ public class Modules implements Iterable<Module>
if (dependentModule.contains("/")) if (dependentModule.contains("/"))
{ {
Path file = _baseHome.getPath("modules/" + dependentModule + ".mod"); Path file = _baseHome.getPath("modules/" + dependentModule + ".mod");
if (isRequired || Files.exists(file)) if (!isConditional || Files.exists(file))
{ {
registerModule(file).expandDependencies(_args.getProperties()); registerModule(file).expandDependencies(_args.getProperties());
providers = _provided.get(dependentModule); providers = _provided.get(dependentModule);
@ -387,10 +383,10 @@ public class Modules implements Iterable<Module>
continue; continue;
} }
} }
// is this a non-required module // is this a conditional module
if (!isRequired) if (isConditional)
{ {
StartLog.debug("Skipping non-required module [%s]: doesn't exist", dependentModule); StartLog.debug("Skipping conditional module [%s]: it does not exist", dependentModule);
continue; continue;
} }
// throw an exception (not a dynamic module and a required dependency) // throw an exception (not a dynamic module and a required dependency)
@ -488,7 +484,7 @@ public class Modules implements Iterable<Module>
{ {
// Check dependencies // Check dependencies
m.getDepends().stream() m.getDepends().stream()
.filter(Module::isRequiredDependency) .filter(depends -> !Module.isConditionalDependency(depends))
.forEach(d -> .forEach(d ->
{ {
Set<Module> providers = getAvailableProviders(d); Set<Module> providers = getAvailableProviders(d);

View File

@ -234,6 +234,7 @@ public class ModulesTest
// Collect active module list // Collect active module list
List<Module> active = modules.getEnabled(); List<Module> active = modules.getEnabled();
modules.checkEnabledModules();
// Assert names are correct, and in the right order // Assert names are correct, and in the right order
List<String> expectedNames = new ArrayList<>(); List<String> expectedNames = new ArrayList<>();
@ -282,6 +283,7 @@ public class ModulesTest
// Collect active module list // Collect active module list
List<Module> active = modules.getEnabled(); List<Module> active = modules.getEnabled();
modules.checkEnabledModules();
// Assert names are correct, and in the right order // Assert names are correct, and in the right order
List<String> expectedNames = new ArrayList<>(); List<String> expectedNames = new ArrayList<>();
@ -331,6 +333,7 @@ public class ModulesTest
// Collect active module list // Collect active module list
List<Module> active = modules.getEnabled(); List<Module> active = modules.getEnabled();
modules.checkEnabledModules();
// Assert names are correct, and in the right order // Assert names are correct, and in the right order
List<String> expectedNames = new ArrayList<>(); List<String> expectedNames = new ArrayList<>();