From c61cbaec2ba6ef2617177cfa6882456f16f4c2d8 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Mon, 26 Aug 2013 14:35:48 -0700 Subject: [PATCH] 415830 - jetty-start / add more TestUseCases for home + base + modules configurations + Adding more complexity to module persistence mechanism test case to demonstrate how it works. --- .../java/org/eclipse/jetty/start/Main.java | 3 +- .../java/org/eclipse/jetty/start/Module.java | 5 ++ .../java/org/eclipse/jetty/start/Modules.java | 59 ++++++++++++++++++- .../org/eclipse/jetty/start/TestUseCases.java | 3 +- .../start.d/requestlog.ini | 2 + .../start.d/websocket.ini | 2 + .../base.with.module.persistence/start.ini | 5 ++ 7 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini create mode 100644 jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java index 8106cd42631..9e7f22e7c2a 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Main.java @@ -410,13 +410,12 @@ public class Main modules.registerAll(baseHome); // 6) Active Module Resolution - modules.enable(loadModulePersistence()); for (String enabledModule : args.getEnabledModules()) { List sources = args.getSources(enabledModule); - StartLog.debug("Enabling module: %s (from %s)",enabledModule,join(sources,", ")); modules.enable(enabledModule,sources); } + modules.enable(loadModulePersistence()); StartLog.debug("Building Module Graph"); modules.buildGraph(); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java index 1aa70a34b79..4f1a3b931ed 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Module.java @@ -288,6 +288,11 @@ public class Module extends TextFile this.sources.addAll(sources); } + public void clearSources() + { + this.sources.clear(); + } + public Set getSources() { return Collections.unmodifiableSet(sources); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index ea5935cc155..90313e77f93 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -204,9 +204,63 @@ public class Modules implements Iterable { List source = new ArrayList<>(); source.add(""); - for (String module : persistence.getEnabled()) + + if (persistence.getEnabled().size() > 0) { - enable(module,source); + // show user warning about module enablement + module persistence + List enabled = new ArrayList<>(); + for (Module module : modules.values()) + { + if (module.isEnabled()) + { + if (!persistence.getEnabled().contains(module.getName())) + { + // only add if not already covered by module persistence + enabled.add(module.getName()); + } + } + } + + if (enabled.size() > 0) + { + StringBuilder err = new StringBuilder(); + err.append("WARNING: Module Persistence Mode is being used.\n"); + err.append("The following "); + if (enabled.size() > 1) + { + err.append(enabled.size()).append(" modules"); + } + else + { + err.append(" module"); + } + err.append(", defined outside of the module persistence mechanism, "); + if (enabled.size() > 1) + { + err.append("are "); + } + else + { + err.append("is "); + } + err.append("being ignored."); + System.err.println(err); + + for (int i = 0; i < enabled.size(); i++) + { + String name = enabled.get(i); + Module module = modules.get(name); + System.err.printf(" [%d] \"%s\" - defined in [%s]%n",i + 1,name,Main.join(module.getSources(),", ")); + module.setEnabled(false); + module.clearSources(); + } + } + + // use module persistence mode + for (String module : persistence.getEnabled()) + { + enable(module,source); + } } } @@ -218,6 +272,7 @@ public class Modules implements Iterable System.err.printf("WARNING: Cannot enable requested module [%s]: not a valid module name.%n",name); return; } + StartLog.debug("Enabling module: %s (via %s)",name,Main.join(sources,", ")); module.setEnabled(true); if (sources != null) { diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java index a4fae59621a..94aa4713826 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/TestUseCases.java @@ -39,8 +39,7 @@ public class TestUseCases List cmdLine = new ArrayList<>(); cmdLine.add("jetty.home=" + homeDir.getAbsolutePath()); cmdLine.add("jetty.base=" + baseDir.getAbsolutePath()); - int len = cmdLine.size(); - StartArgs args = main.processCommandLine(cmdLine.toArray(new String[len])); + StartArgs args = main.processCommandLine(cmdLine); BaseHome baseHome = main.getBaseHome(); ConfigurationAssert.assertConfiguration(baseHome,args,"usecases/" + assertName); } diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini new file mode 100644 index 00000000000..59a4ac4759e --- /dev/null +++ b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/requestlog.ini @@ -0,0 +1,2 @@ + +--module=requestlog diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini new file mode 100644 index 00000000000..1b62c595977 --- /dev/null +++ b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.d/websocket.ini @@ -0,0 +1,2 @@ + +--module=websocket diff --git a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini index 019ed05390e..3e513e792d1 100644 --- a/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini +++ b/jetty-start/src/test/resources/usecases/base.with.module.persistence/start.ini @@ -1,4 +1,9 @@ +# this should not be picked up as there is a module persistence layer present +--module=debug +--module=ipaccess +--module=rewrite + jetty.port=12345 jetty.keystore=etc/keystore