diff --git a/framework/src/play/Play.java b/framework/src/play/Play.java index 65e22469..f74ea390 100644 --- a/framework/src/play/Play.java +++ b/framework/src/play/Play.java @@ -32,6 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Properties; import static java.nio.charset.StandardCharsets.UTF_8; @@ -158,6 +159,13 @@ public void init(String id) { setupApplicationMode(); VirtualFile appRoot = setupAppRoot(); routes = appRoot.child("conf/routes"); + if (!routes.exists()) { + try { + routes = VirtualFile.open(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("conf/routes")).getFile()); + } catch (NullPointerException e) { + // keep going! VirtualFile's exception is more descriptive + } + } modulesRoutes.clear(); loadModules(appRoot); diff --git a/framework/src/play/PropertiesConfLoader.java b/framework/src/play/PropertiesConfLoader.java index 16d75ba4..4c432fa5 100644 --- a/framework/src/play/PropertiesConfLoader.java +++ b/framework/src/play/PropertiesConfLoader.java @@ -9,6 +9,7 @@ import java.util.HashSet; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.Set; import java.util.regex.Matcher; @@ -33,9 +34,33 @@ public Properties readOneConfigurationFile(String playId, String filename) { } private Properties readOneConfigurationFile(String filename, String playId, String inheritedId, Set confs) { - VirtualFile conf = VirtualFile.open(Play.applicationPath + "/conf/" + filename); + VirtualFile conf = resolveFilenameToVirtualFile(filename); + return readOneConfigurationFile(conf, playId, inheritedId, confs); + } + + protected VirtualFile resolveFilenameToVirtualFile(String filename) { + VirtualFile conf = resolveFileNameWithApplicationPath(filename); + if (!conf.exists()) { + try { + conf = resolveFileNameWithClasspath(filename); + } catch (NullPointerException e) { + // keep going! VirtualFile's exception is more descriptive + } + } + return conf; + } + + protected final VirtualFile resolveFileNameWithApplicationPath(String filename) { + return VirtualFile.open(Play.applicationPath + "/conf/" + filename); + } + + protected final VirtualFile resolveFileNameWithClasspath(String filename) { + return VirtualFile.open(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("conf/" + filename)).getPath()); + } + + private Properties readOneConfigurationFile(VirtualFile conf, String playId, String inheritedId, Set confs) { if (confs.contains(conf)) { - throw new RuntimeException("Detected recursive @include usage. Have seen the file " + filename + " before"); + throw new RuntimeException("Detected recursive @include usage. Have seen the file " + conf.getName() + " before"); } confs.add(conf);