Skip to content

Commit

Permalink
Issue #4572 - Process requested enabled modules in topological order
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Mar 10, 2020
1 parent 95c0513 commit ac0e4a7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 16 deletions.
45 changes: 44 additions & 1 deletion jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,50 @@ public List<Module> getEnabled()
return enabled;
}

public List<Module> getSortedAll()
{
List<Module> all = new ArrayList(_modules);

TopologicalSort<Module> sort = new TopologicalSort<>();
for (Module module : all)
{
Consumer<String> add = name ->
{
Module dependency = _names.get(name);
if (dependency != null)
sort.addDependency(module, dependency);

Set<Module> provided = _provided.get(name);
if (provided != null)
for (Module p : provided)
{
sort.addDependency(module, p);
}
};
module.getDepends().forEach(add);
module.getOptional().forEach(add);
}

sort.sort(all);
return all;
}

public List<String> getSortedNames(List<String> enabledModules)
{
List<Module> all = getSortedAll();
List<String> order = new ArrayList<>();
for (Module module : all)
{
String name = module.getName();
if (enabledModules.contains(name))
{
order.add(name);
}
}

return order;
}

/**
* Enable a module
*
Expand Down Expand Up @@ -340,7 +384,6 @@ private void enable(Set<String> newlyEnabled, Module module, String enabledFrom,
throw new UsageException("Module %s provides %s, which is already provided by %s enabled in %s", module.getName(), name, p.getName(), p.getEnableSources());
}
}
;
}
}

Expand Down
31 changes: 18 additions & 13 deletions jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,7 @@ public void testUseCase(String caseName) throws Exception
PrintStream originalStream = StartLog.setStream(new PrintStream(out));
try
{
// If there is a "{caseName}.prepare.txt" then use those
// lines as if you are calling start.jar once to setup
// the base directory.
List<String> prepareArgs = lines(caseName + ".prepare.txt");
if (!prepareArgs.isEmpty())
{
Main main = new Main();
List<String> cmdLine = new ArrayList<>();
cmdLine.add("--testing-mode");
cmdLine.addAll(prepareArgs);

main.start(main.processCommandLine(cmdLine));
}
prepare(caseName);

Main main = new Main();
List<String> cmdLine = new ArrayList<>();
Expand Down Expand Up @@ -135,6 +123,23 @@ public void testUseCase(String caseName) throws Exception
}
}

private void prepare(String caseName) throws Exception
{
// If there is a "{caseName}.prepare.txt" then use those
// lines as if you are calling start.jar once to setup
// the base directory.
List<String> prepareArgs = lines(caseName + ".prepare.txt");
if (!prepareArgs.isEmpty())
{
Main main = new Main();
List<String> cmdLine = new ArrayList<>();
cmdLine.add("--testing-mode");
cmdLine.addAll(prepareArgs);

main.start(main.processCommandLine(cmdLine));
}
}

private List<String> lines(String filename) throws IOException
{
return lines(MavenTestingUtils.getTestResourcesPath().resolve("usecases" + File.separator + filename).toFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ XML|${jetty.base}/etc/logging-a.xml

# The Properties we expect (order is irrelevant)
PROP|logging.prop=a
PROP|logging.a=true

# Files / Directories to create

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ XML|${jetty.base}/etc/logging-b.xml

# The Properties we expect (order is irrelevant)
PROP|logging.prop=b
PROP|logging.b=true

# Files / Directories to create

Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ logging|default
etc/logging-a.xml

[ini]
logging.prop=a
logging.prop=a
logging.a=true
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ etc/logging-b.xml

[ini]
logging.prop=b
logging.b=true
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ logging
etc/logging-c.xml

[ini]
logging.prop=c
logging.prop=c
logging.c=true

0 comments on commit ac0e4a7

Please sign in to comment.