* Issue #7111 - Add support to deprecate jetty-home modules. Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
parent
33c9536d12
commit
1ea012afde
|
@ -153,6 +153,11 @@ public class Module implements Comparable<Module>
|
|||
*/
|
||||
private final List<String> _depends = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Text from {@code [deprecated]} section
|
||||
*/
|
||||
private final List<String> _deprecated = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Module names from {@code [before]} section
|
||||
*/
|
||||
|
@ -398,6 +403,9 @@ public class Module implements Comparable<Module>
|
|||
if (!_depends.contains(line))
|
||||
_depends.add(line);
|
||||
break;
|
||||
case "DEPRECATED":
|
||||
_deprecated.add(line);
|
||||
break;
|
||||
case "FILE":
|
||||
case "FILES":
|
||||
_files.add(line);
|
||||
|
@ -538,6 +546,11 @@ public class Module implements Comparable<Module>
|
|||
return new ArrayList<>(_depends);
|
||||
}
|
||||
|
||||
public List<String> getDeprecated()
|
||||
{
|
||||
return List.copyOf(_deprecated);
|
||||
}
|
||||
|
||||
public Set<String> getProvides()
|
||||
{
|
||||
return new HashSet<>(_provides);
|
||||
|
|
|
@ -186,7 +186,7 @@ public class Modules implements Iterable<Module>
|
|||
excluded.add("internal");
|
||||
|
||||
Predicate<Module> filter = m -> (included.isEmpty() || m.getTags().stream().anyMatch(included::contains)) &&
|
||||
!m.getTags().stream().anyMatch(excluded::contains);
|
||||
m.getTags().stream().noneMatch(excluded::contains);
|
||||
|
||||
Optional<Integer> max = _modules.stream().filter(filter).map(Module::getName).map(String::length).max(Integer::compareTo);
|
||||
if (max.isEmpty())
|
||||
|
@ -219,16 +219,18 @@ public class Modules implements Iterable<Module>
|
|||
List<Module> enabled = getEnabled();
|
||||
for (Module module : enabled)
|
||||
{
|
||||
String name = module.getName();
|
||||
String index = (i++) + ")";
|
||||
String name = module.getName();
|
||||
if (!module.getDeprecated().isEmpty())
|
||||
name += " (deprecated)";
|
||||
for (String s : module.getEnableSources())
|
||||
{
|
||||
out.printf(" %4s %-15s %s%n", index, name, s);
|
||||
out.printf("%4s %-25s %s%n", index, name, s);
|
||||
index = "";
|
||||
name = "";
|
||||
}
|
||||
if (module.isTransitive() && module.hasIniTemplate())
|
||||
out.printf(" init template available with --add-module=%s%n", module.getName());
|
||||
out.printf(" ".repeat(31) + "ini template available with --add-module=%s%n", module.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,6 +424,13 @@ public class Modules implements Iterable<Module>
|
|||
return;
|
||||
}
|
||||
|
||||
List<String> deprecated = module.getDeprecated();
|
||||
if (!deprecated.isEmpty())
|
||||
{
|
||||
String reason = deprecated.stream().collect(Collectors.joining(System.lineSeparator()));
|
||||
StartLog.warn(reason);
|
||||
}
|
||||
|
||||
// Check that this is not already provided by another module!
|
||||
for (String name : module.getProvides())
|
||||
{
|
||||
|
|
|
@ -1056,4 +1056,54 @@ public class DistributionTests extends AbstractJettyHomeTest
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeprecatedModule() throws Exception
|
||||
{
|
||||
String jettyVersion = System.getProperty("jettyVersion");
|
||||
JettyHomeTester distribution = JettyHomeTester.Builder.newInstance()
|
||||
.jettyVersion(jettyVersion)
|
||||
.mavenLocalRepository(System.getProperty("mavenRepoPath"))
|
||||
.build();
|
||||
|
||||
Path jettyBase = distribution.getJettyBase();
|
||||
Path jettyBaseModules = jettyBase.resolve("modules");
|
||||
Files.createDirectories(jettyBaseModules);
|
||||
Path deprecatedModule = jettyBaseModules.resolve("deprecated.mod");
|
||||
String description = "A deprecated module.";
|
||||
String reason = "This module is deprecated.";
|
||||
List<String> lines = List.of(
|
||||
"[description]",
|
||||
description,
|
||||
"[deprecated]",
|
||||
reason,
|
||||
"[tags]",
|
||||
"deprecated"
|
||||
);
|
||||
Files.write(deprecatedModule, lines, StandardOpenOption.CREATE);
|
||||
|
||||
try (JettyHomeTester.Run listConfigRun = distribution.start(List.of("--list-modules=deprecated")))
|
||||
{
|
||||
assertTrue(listConfigRun.awaitFor(10, TimeUnit.SECONDS));
|
||||
assertEquals(0, listConfigRun.getExitValue());
|
||||
|
||||
assertTrue(listConfigRun.getLogs().stream().anyMatch(log -> log.contains(description)));
|
||||
}
|
||||
|
||||
try (JettyHomeTester.Run run1 = distribution.start(List.of("--add-modules=http,deprecated")))
|
||||
{
|
||||
assertTrue(run1.awaitFor(10, TimeUnit.SECONDS));
|
||||
assertEquals(0, run1.getExitValue());
|
||||
|
||||
assertTrue(run1.getLogs().stream().anyMatch(log -> log.contains("WARN") && log.contains(reason)));
|
||||
|
||||
int port = distribution.freePort();
|
||||
try (JettyHomeTester.Run run2 = distribution.start("jetty.http.port=" + port))
|
||||
{
|
||||
assertTrue(run2.awaitConsoleLogsFor("Started Server@", 10, TimeUnit.SECONDS));
|
||||
assertTrue(run2.getLogs().stream()
|
||||
.anyMatch(log -> log.contains("WARN") && log.contains(reason)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue