From 72aba3778ca94448abfa42f920ac2acbf5882512 Mon Sep 17 00:00:00 2001 From: Mathieu Lirzin Date: Sat, 13 Jul 2019 21:37:40 +0000 Subject: [PATCH] =?UTF-8?q?Improved:=20Remove=20support=20for=20=E2=80=9Co?= =?UTF-8?q?fbiz-containers.xml=E2=80=9D=20(OFBIZ-11100)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To extend the containers loaded on startup, it was possible too both edit the “ofbiz-containers.xml” file or alternatively to define a container in a component. This redundancy adds extra complexity in the startup process for no good extensibility reason. The component container loader is more flexible since it allows developper to add new containers without touching the framework so it is better to only rely on this option. The component loader is now hard-coded directly in code. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1863019 13f79535-47bb-0310-9956-ffa450edef68 --- framework/base/config/ofbiz-containers.xml | 27 --------- framework/base/dtd/ofbiz-containers.xsd | 60 ------------------- .../ofbiz/base/container/Container.java | 6 +- .../ofbiz/base/container/ContainerLoader.java | 35 +++++------ .../org/apache/ofbiz/base/start/Config.java | 3 - 5 files changed, 19 insertions(+), 112 deletions(-) delete mode 100644 framework/base/config/ofbiz-containers.xml delete mode 100644 framework/base/dtd/ofbiz-containers.xsd diff --git a/framework/base/config/ofbiz-containers.xml b/framework/base/config/ofbiz-containers.xml deleted file mode 100644 index 726fadc201..0000000000 --- a/framework/base/config/ofbiz-containers.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - diff --git a/framework/base/dtd/ofbiz-containers.xsd b/framework/base/dtd/ofbiz-containers.xsd deleted file mode 100644 index 956b45883a..0000000000 --- a/framework/base/dtd/ofbiz-containers.xsd +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java index baa9eeddcc..39f654ac0d 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/Container.java @@ -45,12 +45,14 @@ public interface Container { * * @param ofbizCommands Command-line arguments. * @param name Unique name of the container's instance. - * @param configFile Location of the configuration file used to load this container. + * @param configFile always {@code null} but used to be the location of the global + * container configuration file which does not exist anymore * @throws ContainerException If an error was encountered. Throwing this exception * will halt container loading, so it should be thrown only when other containers * might depend on this one. */ - public void init(List ofbizCommands, String name, String configFile) throws ContainerException; + void init(List ofbizCommands, String name, String configFile) + throws ContainerException; /** * Start the container process. This method must not block - implementations diff --git a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java index 43efda53b1..79c805b715 100644 --- a/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java +++ b/framework/base/src/main/java/org/apache/ofbiz/base/container/ContainerLoader.java @@ -66,14 +66,17 @@ public class ContainerLoader { // loaders defined in startup (e.g. main, test, load-data, etc ...) List loaders = config.loaders; - // load containers defined in ofbiz-containers.xml - Debug.logInfo("[Startup] Loading containers...", module); - List ofbizContainerConfigs = filterContainersHavingMatchingLoaders( - loaders, retrieveOfbizContainers(config.containerConfig)); - loadedContainers.addAll(loadContainersFromConfigurations(ofbizContainerConfigs, config, ofbizCommands)); + // Load mandatory container providing access to containers from components. + try { + ComponentContainer cc = new ComponentContainer(); + cc.init(ofbizCommands, "component-container", null); + loadedContainers.add(cc); + } catch (ContainerException e) { + throw new StartupException("Cannot init() component-container", e); + } - // load containers defined in components - Debug.logInfo("[Startup] Loading component containers...", module); + // Load containers defined in components. + Debug.logInfo("[Startup] Loading containers...", module); List componentContainerConfigs = filterContainersHavingMatchingLoaders( loaders, ComponentConfig.getAllConfigurations()); loadedContainers.addAll(loadContainersFromConfigurations(componentContainerConfigs, config, ofbizCommands)); @@ -82,15 +85,6 @@ public class ContainerLoader { startLoadedContainers(); } - private static Collection retrieveOfbizContainers(String configFile) - throws StartupException { - try { - return ContainerConfig.getConfigurations(configFile); - } catch (ContainerException e) { - throw new StartupException(e); - } - } - private static List filterContainersHavingMatchingLoaders(List loaders, Collection containerConfigs) { return containerConfigs.stream() @@ -116,15 +110,16 @@ public class ContainerLoader { List loadContainers = new ArrayList<>(); for (ContainerConfig.Configuration containerCfg : containerConfigs) { Debug.logInfo("Loading container: " + containerCfg.name, module); - Container tmpContainer = loadContainer(config.containerConfig, containerCfg, ofbizCommands); + Container tmpContainer = loadContainer(containerCfg, ofbizCommands); loadContainers.add(tmpContainer); Debug.logInfo("Loaded container: " + containerCfg.name, module); } return loadContainers; } - private static Container loadContainer(String configFile, ContainerConfig.Configuration containerCfg, - List ofbizCommands) throws StartupException { + + private static Container loadContainer(ContainerConfig.Configuration containerCfg, List ofbizCommands) + throws StartupException { // load the container class ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class containerClass; @@ -150,7 +145,7 @@ public class ContainerLoader { // initialize the container object try { - containerObj.init(ofbizCommands, containerCfg.name, configFile); + containerObj.init(ofbizCommands, containerCfg.name, null); } catch (ContainerException e) { throw new StartupException("Cannot init() " + containerCfg.name, e); } diff --git a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java index 47ac95b985..15c3730f4b 100644 --- a/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java +++ b/framework/start/src/main/java/org/apache/ofbiz/base/start/Config.java @@ -40,7 +40,6 @@ public final class Config { public final String adminKey; public final int portOffset; public final int adminPort; - public final String containerConfig; public final List loaders; public final String logDir; public final boolean shutdownAfterLoad; @@ -57,8 +56,6 @@ public final class Config { adminKey = getProperty(props, "ofbiz.admin.key", "NA"); portOffset = getPortOffsetValue(ofbizCommands, "0"); adminPort = getAdminPort(props, 0, portOffset); - containerConfig = getAbsolutePath(props, "ofbiz.container.config", - "framework/base/config/ofbiz-containers.xml", ofbizHome); loaders = Arrays.asList(getProperty(props, "ofbiz.start.loaders", "").split(",")); logDir = getAbsolutePath(props, "ofbiz.log.dir", "runtime/logs", ofbizHome); shutdownAfterLoad = getProperty(props, "ofbiz.auto.shutdown", "false").equalsIgnoreCase("true");