Skip to content

Commit

Permalink
Improved: Convert ‘Config#ofbizHome’ and ‘Config#logDir’ to a path
Browse files Browse the repository at this point in the history
(OFBIZ-11192)


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/ofbiz-framework/trunk@1867399 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mthl committed Sep 23, 2019
1 parent e3acbf6 commit 6f54d35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void init(List<StartupCommand> ofbizCommands, String name, String configF
// load the components from framework/base/config/component-load.xml (root components)
try {
for (ComponentLoaderConfig.ComponentDef def: ComponentLoaderConfig.getRootComponents()) {
loadComponentFromConfig(Start.getInstance().getConfig().ofbizHome, def);
loadComponentFromConfig(Start.getInstance().getConfig().ofbizHome.toString(), def);
}
} catch (IOException | ComponentException e) {
throw new ContainerException(e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
Expand All @@ -15,13 +15,15 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
*/
package org.apache.ofbiz.base.start;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
Expand All @@ -34,14 +36,16 @@
* one of the properties files in the start component
*/
public final class Config {
/** The default directory where log files are stored. */
public static final Path DEFAULT_LOG_DIRECTORY = Paths.get("runtime", "logs");

public final String ofbizHome;
public final Path ofbizHome;
public final InetAddress adminAddress;
public final String adminKey;
public final int portOffset;
public final int adminPort;
public final List<String> loaders;
public final String logDir;
public final Path logDir;
public final boolean shutdownAfterLoad;
public final boolean useShutdownHook;

Expand All @@ -57,14 +61,14 @@ public final class Config {
portOffset = getPortOffsetValue(ofbizCommands, "0");
adminPort = getAdminPort(props, 0, portOffset);
loaders = Arrays.asList(getProperty(props, "ofbiz.start.loaders", "").split(","));
logDir = getAbsolutePath(props, "ofbiz.log.dir", "runtime/logs", ofbizHome);
logDir = getAbsolutePath(props, "ofbiz.log.dir", DEFAULT_LOG_DIRECTORY, ofbizHome);
shutdownAfterLoad = getProperty(props, "ofbiz.auto.shutdown", "false").equalsIgnoreCase("true");
useShutdownHook = getProperty(props, "ofbiz.enable.hook", "true").equalsIgnoreCase("true");

System.out.println("Set OFBIZ_HOME to - " + ofbizHome);

// set system properties
System.setProperty("ofbiz.home", ofbizHome);
System.setProperty("ofbiz.home", ofbizHome.toString());
System.setProperty("java.awt.headless", getProperty(props, "java.awt.headless", "true"));
System.setProperty("derby.system.home", getProperty(props, "derby.system.home", "runtime/data/derby"));

Expand All @@ -78,12 +82,13 @@ private static String getProperty(Properties props, String key, String defaultVa
.orElse(props.getProperty(key, defaultValue));
}

private static String getOfbizHome(String homeProp) {
return homeProp.equals(".") ? System.getProperty("user.dir").replace('\\', '/') : homeProp;
private static Path getOfbizHome(String homeProp) {
return Paths.get(homeProp).toAbsolutePath().normalize();
}

private static String getAbsolutePath(Properties props, String key, String defaultValue, String ofbizHome) {
return getProperty(props, key, ofbizHome + "/" + props.getProperty(key, defaultValue));
private static Path getAbsolutePath(Properties props, String key, Path defaultValue, Path ofbizHome) {
return Paths.get(getProperty(props, key,
ofbizHome.resolve(props.getProperty(key, defaultValue.toString())).toString()));
}

private Properties getPropertiesFile(List<StartupCommand> ofbizCommands) throws StartupException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static Config init(List<StartupCommand> ofbizCommands) {
*/
static void start(Config config, AtomicReference<ServerState> serverState, List<StartupCommand> ofbizCommands,
ContainerLoader loader) throws StartupException {
createLogDirectoryIfMissing(config.logDir);
createLogDirectoryIfMissing(config.logDir.toString());

if (config.useShutdownHook) {
createRuntimeShutdownHook(loader, serverState);
Expand Down

0 comments on commit 6f54d35

Please sign in to comment.