From cf430665b5d978db0b22b03b9aeb72b5f8568b5f Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 4 Apr 2014 14:09:46 +1100 Subject: [PATCH] Fixed start.jar handling of expanded modules during --add-to-start --- .../java/org/eclipse/jetty/start/Main.java | 64 +++++++++++++++---- .../java/org/eclipse/jetty/start/Modules.java | 22 ++++++- .../java/org/eclipse/jetty/start/Props.java | 2 +- .../org/eclipse/jetty/start/PropsTest.java | 1 + 4 files changed, 74 insertions(+), 15 deletions(-) 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 12d64643804..9261397ed8b 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 @@ -41,8 +41,10 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Locale; +import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -333,7 +335,7 @@ public class Main } private void moduleIni(StartArgs args, String name, boolean topLevel, boolean appendStartIni) throws IOException - { + { // Find the start.d relative to the base directory only. File start_d = baseHome.getBaseFile("start.d"); @@ -457,7 +459,9 @@ public class Main { StartLog.info("%-15s initialised in %s",name,short_ini); } - + else + StartLog.info("%-15s initialised transitively",name); + // Also list other places this module is enabled for (String source : module.getSources()) { @@ -473,23 +477,57 @@ public class Main initFile(new FileArg(file)); } - // Process dependencies from top level only + // Process dependencies + module.expandProperties(args.getProperties()); + modules.registerParentsIfMissing(baseHome,args,module); + modules.buildGraph(); + + + // process new ini modules if (topLevel) { - List parents = new ArrayList<>(); - for (String parent : modules.resolveParentModulesOf(name)) + List depends = new ArrayList<>(); + for (String depend : modules.resolveParentModulesOf(name)) { - if (!name.equals(parent)) + if (!name.equals(depend)) { - Module m = modules.get(parent); + Module m = modules.get(depend); m.setEnabled(true); - parents.add(m); + depends.add(m); } } - Collections.sort(parents,Collections.reverseOrder(new Module.DepthComparator())); - for (Module m : parents) + Collections.sort(depends,Collections.reverseOrder(new Module.DepthComparator())); + + Set done = new HashSet<>(0); + while (true) { - moduleIni(args,m.getName(),false,appendStartIni); + // initialize known dependencies + boolean complete=true; + for (Module m : depends) + { + if (!done.contains(m.getName())) + { + complete=false; + moduleIni(args,m.getName(),false,appendStartIni); + done.add(m.getName()); + } + } + + if (complete) + break; + + // look for any new ones resolved via expansion + depends.clear(); + for (String depend : modules.resolveParentModulesOf(name)) + { + if (!name.equals(depend)) + { + Module m = modules.get(depend); + m.setEnabled(true); + depends.add(m); + } + } + Collections.sort(depends,Collections.reverseOrder(new Module.DepthComparator())); } } } @@ -644,13 +682,13 @@ public class Main } } - // Initialize + // Initialize start.ini for (String module : args.getModuleStartIni()) { moduleIni(args,module,true,true); } - // Initialize + // Initialize start.d for (String module : args.getModuleStartdIni()) { moduleIni(args,module,true,false); 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 3c559f9db51..e967abc6b08 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 @@ -118,7 +118,10 @@ public class Modules implements Iterable if (parent == null) { - StartLog.debug("module not found [%s]%n",parentName); + if (parentName.contains("${")) + StartLog.debug("module not found [%s]%n",parentName); + else + StartLog.warn("module not found [%s]%n",parentName); } else { @@ -370,6 +373,23 @@ public class Modules implements Iterable return module; } + public void registerParentsIfMissing(BaseHome basehome, StartArgs args, Module module) throws IOException + { + for (String name : module.getParentNames()) + { + if (!modules.containsKey(name)) + { + File file = basehome.getFile("modules/" + name + ".mod"); + if (FS.canReadFile(file)) + { + Module parent = registerModule(basehome,args,file); + updateParentReferencesTo(parent); + registerParentsIfMissing(basehome, args, parent); + } + } + } + } + public void registerAll(BaseHome basehome, StartArgs args) throws IOException { for (Path path : basehome.getPaths("modules/*.mod")) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java index 69c71c7a0b4..fef34d69404 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Props.java @@ -131,7 +131,7 @@ public final class Props implements Iterable if (value == null) { StartLog.debug("Unable to expand: %s",property); - expanded.append(property); + expanded.append(mat.group(1)); } else { diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java index b9f471f00aa..7837764bdeb 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PropsTest.java @@ -91,6 +91,7 @@ public class PropsTest assertThat(props.expand("port=8080"),is("port=8080")); assertThat(props.expand("jdk=${java.version}"),is("jdk=" + System.getProperty("java.version"))); assertThat(props.expand("id=${name}-${version}"),is("id=jetty-9.1")); + assertThat(props.expand("id=${unknown}-${wibble}"),is("id=${unknown}-${wibble}")); } @Test