Converted dependencies from a Set to a List, so the order of dependencies
can be used to help select between multiple provides.  More specifically,
stop an unordered Set allowing one dependency to trigger a default provider
when an earlier specified dependency enables a specific provider.
This commit is contained in:
Greg Wilkins 2017-04-21 14:24:22 +10:00
parent a584646c82
commit 68c7a1d960
8 changed files with 46 additions and 10 deletions

View File

@ -116,7 +116,7 @@ public class Module implements Comparable<Module>
private final List<String> _license=new ArrayList<>();
/** Dependencies */
private final Set<String> _depends=new HashSet<>();
private final List<String> _depends=new ArrayList<>();
/** Optional */
private final Set<String> _optional=new HashSet<>();
@ -183,10 +183,10 @@ public class Module implements Comparable<Module>
{
Function<String,String> expander = d->{return props.expand(d);};
Set<String> tmp=_depends.stream().map(expander).collect(Collectors.toSet());
List<String> tmp=_depends.stream().map(expander).collect(Collectors.toList());
_depends.clear();
_depends.addAll(tmp);
tmp=_optional.stream().map(expander).collect(Collectors.toSet());
tmp=_optional.stream().map(expander).collect(Collectors.toList());
_optional.clear();
_optional.addAll(tmp);
}
@ -329,7 +329,8 @@ public class Module implements Comparable<Module>
break;
case "DEPEND":
case "DEPENDS":
_depends.add(line);
if (!_depends.contains(line))
_depends.add(line);
break;
case "FILE":
case "FILES":
@ -437,9 +438,9 @@ public class Module implements Comparable<Module>
return str.toString();
}
public Set<String> getDepends()
public List<String> getDepends()
{
return new HashSet<>(_depends);
return new ArrayList<>(_depends);
}
public Set<String> getProvides()

View File

@ -335,12 +335,13 @@ public class Modules implements Iterable<Module>
}
// Process module dependencies (always processed as may be dynamic)
StartLog.debug("Enabled module %s depends on %s",module.getName(),module.getDepends());
for(String dependsOn:module.getDepends())
{
// Look for modules that provide that dependency
Set<Module> providers = getAvailableProviders(dependsOn);
StartLog.debug("Module %s depends on %s provided by ",module,dependsOn,providers);
StartLog.debug("Module %s depends on %s provided by %s",module,dependsOn,providers);
// If there are no known providers of the module
if (providers.isEmpty())
@ -381,11 +382,11 @@ public class Modules implements Iterable<Module>
private Set<Module> getAvailableProviders(String name)
{
// Get all available providers
Set<Module> providers = _provided.get(name);
StartLog.debug("Providers of %s are %s",name,providers);
if (providers==null || providers.isEmpty())
return Collections.emptySet();
providers = new HashSet<>(providers);
// find all currently provided names by other modules
@ -409,13 +410,15 @@ public class Modules implements Iterable<Module>
{
if (provided.contains(p))
{
StartLog.debug("Removing provider %s because %s already enabled",provider,p);
i.remove();
break;
}
}
}
}
StartLog.debug("Available providers of %s are %s",name,providers);
return providers;
}

View File

@ -0,0 +1,12 @@
## The XMLs we expect (order is important)
XML|${jetty.home}/etc/base.xml
XML|${jetty.home}/etc/main.xml
# The LIBs we expect (order is irrelevant)
LIB|${jetty.home}/lib/base.jar
LIB|${jetty.home}/lib/main.jar
LIB|${jetty.home}/lib/other.jar
# The Properties we expect (order is irrelevant)
PROP|main.prop=value0
PROP|impl=replacement

View File

@ -0,0 +1,2 @@
--module=main,convenience

View File

@ -0,0 +1,4 @@
[depends]
replacement
something-else

View File

@ -0,0 +1,4 @@
[ini]
impl=original

View File

@ -0,0 +1,7 @@
[provides]
original
[ini]
impl=replacement

View File

@ -0,0 +1,3 @@
[depends]
original