Author: adrianc
Date: Sat Mar 26 21:37:00 2011 New Revision: 1085806 URL: http://svn.apache.org/viewvc?rev=1085806&view=rev Log: Final Start class code cleanup - moved remaining Config-specific code to the Config class, simplified some code. Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Config.java ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Config.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Config.java?rev=1085806&r1=1085805&r2=1085806&view=diff ============================================================================== --- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Config.java (original) +++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Config.java Sat Mar 26 21:37:00 2011 @@ -32,6 +32,33 @@ import java.util.TimeZone; public class Config { public static final double REQUIRED_JDK = 1.6; + + private static String getConfigFileName(String command) { + // default command is "start" + if (command == null || command.trim().length() == 0) { + command = "start"; + } + // strip off the leading dash + if (command.startsWith("-")) { + command = command.substring(1); + } + // shutdown & status hack + if (command.equalsIgnoreCase("shutdown")) { + command = "start"; + } else if (command.equalsIgnoreCase("status")) { + command = "start"; + } + return "org/ofbiz/base/start/" + command + ".properties"; + } + + public static Config getInstance(String[] args) throws IOException { + String firstArg = args.length > 0 ? args[0] : ""; + String configFileName = getConfigFileName(firstArg); + Config result = new Config(); + result.readConfig(configFileName); + return result; + } + public InetAddress adminAddress; public String adminKey; public int adminPort; @@ -206,6 +233,53 @@ public class Config { return props; } + public void initClasspath(Classpath classPath) throws IOException { + // load tools.jar + if (this.toolsJar != null) { + classPath.addComponent(this.toolsJar); + } + // load comm.jar + if (this.commJar != null) { + classPath.addComponent(this.commJar); + } + // add OFBIZ_HOME to class path & load libs + classPath.addClasspath(this.ofbizHome); + loadLibs(classPath, this.ofbizHome, false); + // load the lib directory + if (this.baseLib != null) { + loadLibs(classPath, this.baseLib, true); + } + // load the ofbiz-base.jar + if (this.baseJar != null) { + classPath.addComponent(this.baseJar); + } + // load the base schema directory + if (this.baseDtd != null) { + classPath.addComponent(this.baseDtd); + } + // load the config directory + if (this.baseConfig != null) { + classPath.addComponent(this.baseConfig); + } + classPath.instrument(this.instrumenterFile, this.instrumenterClassName); + } + + private void loadLibs(Classpath classPath, String path, boolean recurse) throws IOException { + File libDir = new File(path); + if (libDir.exists()) { + File files[] = libDir.listFiles(); + for (File file: files) { + String fileName = file.getName(); + // FIXME: filter out other files? + if (file.isDirectory() && !"CVS".equals(fileName) && !".svn".equals(fileName) && recurse) { + loadLibs(classPath, file.getCanonicalPath(), recurse); + } else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) { + classPath.addComponent(file); + } + } + } + } + public void readConfig(String config) throws IOException { // check the java_version String javaVersion = System.getProperty("java.version"); @@ -357,51 +431,4 @@ public class Config { } } - public void initClasspath(Classpath classPath) throws IOException { - // load tools.jar - if (this.toolsJar != null) { - classPath.addComponent(this.toolsJar); - } - // load comm.jar - if (this.commJar != null) { - classPath.addComponent(this.commJar); - } - // add OFBIZ_HOME to class path & load libs - classPath.addClasspath(this.ofbizHome); - loadLibs(classPath, this.ofbizHome, false); - // load the lib directory - if (this.baseLib != null) { - loadLibs(classPath, this.baseLib, true); - } - // load the ofbiz-base.jar - if (this.baseJar != null) { - classPath.addComponent(this.baseJar); - } - // load the base schema directory - if (this.baseDtd != null) { - classPath.addComponent(this.baseDtd); - } - // load the config directory - if (this.baseConfig != null) { - classPath.addComponent(this.baseConfig); - } - classPath.instrument(this.instrumenterFile, this.instrumenterClassName); - } - - private void loadLibs(Classpath classPath, String path, boolean recurse) throws IOException { - File libDir = new File(path); - if (libDir.exists()) { - File files[] = libDir.listFiles(); - for (File file: files) { - String fileName = file.getName(); - // FIXME: filter out other files? - if (file.isDirectory() && !"CVS".equals(fileName) && !".svn".equals(fileName) && recurse) { - loadLibs(classPath, file.getCanonicalPath(), recurse); - } else if (fileName.endsWith(".jar") || fileName.endsWith(".zip")) { - classPath.addComponent(file); - } - } - } - } - } Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java?rev=1085806&r1=1085805&r2=1085806&view=diff ============================================================================== --- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java (original) +++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Sat Mar 26 21:37:00 2011 @@ -38,24 +38,6 @@ public class Start { private static final String SHUTDOWN_COMMAND = "SHUTDOWN"; private static final String STATUS_COMMAND = "STATUS"; - private static String getConfigFileName(String command) { - // default command is "start" - if (command == null || command.trim().length() == 0) { - command = "start"; - } - // strip off the leading dash - if (command.startsWith("-")) { - command = command.substring(1); - } - // shutdown & status hack - if (command.equalsIgnoreCase("shutdown")) { - command = "start"; - } else if (command.equalsIgnoreCase("status")) { - command = "start"; - } - return "org/ofbiz/base/start/" + command + ".properties"; - } - public static void main(String[] args) throws IOException { String firstArg = args.length > 0 ? args[0] : ""; Start start = new Start(); @@ -107,13 +89,11 @@ public class Start { } private void createLogDirectory() { - boolean createdDir = false; File logDir = new File(config.logDir); if (!logDir.exists()) { - createdDir = logDir.mkdir(); - } - if (createdDir) { - System.out.println("Created OFBiz log dir [" + logDir.getAbsolutePath() + "]"); + if (logDir.mkdir()) { + System.out.println("Created OFBiz log dir [" + logDir.getAbsolutePath() + "]"); + } } } @@ -130,13 +110,7 @@ public class Start { throw (IOException) new IOException("Couldn't load global system props").initCause(e); } } - String firstArg = args.length > 0 ? args[0] : ""; - String cfgFile = Start.getConfigFileName(firstArg); - - this.config = new Config(); - - // read the default properties first - config.readConfig(cfgFile); + this.config = Config.getInstance(args); // parse the startup arguments if (args.length > 0) { |
Free forum by Nabble | Edit this page |