Don't continue platform startup if Adempiere.properties file is missing.

This commit is contained in:
Heng Sin Low 2010-10-26 19:04:04 +08:00
parent 6f2f78cd11
commit d4be04bd12
2 changed files with 34 additions and 51 deletions

View File

@ -533,7 +533,7 @@ public final class Ini implements Serializable
* @param tryUserHome get user home first
* @return file name
*/
private static String getFileName (boolean tryUserHome)
public static String getFileName (boolean tryUserHome)
{
if (System.getProperty("PropertyFile") != null)
return System.getProperty("PropertyFile");
@ -703,7 +703,7 @@ public final class Ini implements Serializable
*/
public static void setClient (boolean client)
{
s_client = client;
s_client = client;
} // setClient
/**
@ -740,20 +740,24 @@ public final class Ini implements Serializable
public static String getAdempiereHome()
{
String env = System.getProperty (ENV_PREFIX + ADEMPIERE_HOME);
if (env == null)
if (env == null || env.trim().length() == 0)
env = System.getProperty (ADEMPIERE_HOME);
if (env == null && ! isClient()) {
InitialContext context;
try {
context = new InitialContext();
env = (String) context.lookup("java:comp/env/"+ADEMPIERE_HOME);
} catch (NamingException e) {
// teo_sarca: if you uncomment the line below you will get an NPE when generating models
//getLogger().fine( "Not found 'java:comp/env/"+ADEMPIERE_HOME+"' in Initial Context. " +e.getMessage());
if (env == null || env.trim().length() == 0)
{
//client - user home, server - current working directory
String current = isClient() ? System.getProperty("user.home")
: System.getProperty("user.dir");
if (current != null && current.trim().length() > 0)
{
//check directory exists and writable
File file = new File(current);
if (file.exists() && file.canWrite())
{
env = current;
}
}
}
if (env == null || "".equals(env) ) // Fallback
if (env == null || env.trim().length() == 0 ) // Fallback
env = File.separator + "Adempiere";
return env;
} // getAdempiereHome
@ -774,35 +778,7 @@ public final class Ini implements Serializable
*/
public static String findAdempiereHome()
{
String ch = getAdempiereHome();
if (ch != null)
return ch;
File[] roots = File.listRoots();
for (int i = 0; i < roots.length; i++)
{
if (roots[i].getAbsolutePath().startsWith("A:"))
continue;
File[] subs = roots[i].listFiles();
if (subs == null)
continue;
for (int j = 0; j < subs.length; j++)
{
if (!subs[j].isDirectory())
continue;
String fileName = subs[j].getAbsolutePath();
// globalqss, it's leaving log in first directory with lib subdirectory. i.e. Oracle
// if (fileName.indexOf("Adempiere") != 1)
if (fileName.indexOf("Adempiere") != -1)
{
String libDir = fileName + File.separator + "lib";
File lib = new File(libDir);
if (lib.exists() && lib.isDirectory())
return fileName;
}
}
}
return ch;
return getAdempiereHome();
} // findAdempiereHome
/**************************************************************************

View File

@ -16,6 +16,7 @@
*****************************************************************************/
package org.compiere.util;
import java.io.File;
import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.Properties;
@ -126,7 +127,7 @@ public class WebEnv
}
boolean retValue = initWeb (config.getServletContext());
// Logging now initiated
log.info(info.toString());
return retValue;
@ -145,7 +146,7 @@ public class WebEnv
log.info(context.getServletContextName());
return true;
}
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
Enumeration en = context.getInitParameterNames();
StringBuffer info = new StringBuffer("Servlet Context Init Parameters: ")
@ -158,13 +159,19 @@ public class WebEnv
info.append("\n").append(name).append("=").append(value);
}
String propertyFile = Ini.getFileName(false);
File file = new File(propertyFile);
if (!file.exists())
{
throw new java.lang.IllegalStateException("Adempiere.properties is not setup. PropertyFile="+propertyFile);
}
try
{
s_initOK = Adempiere.startup(false);
}
catch (Exception ex)
{
log.log(Level.SEVERE, "startup", ex);
log.log(Level.SEVERE, "startup", ex);
}
if (!s_initOK)
return false;
@ -175,14 +182,14 @@ public class WebEnv
Properties ctx = new Properties();
MClient client = MClient.get(ctx, 0);
MSystem system = MSystem.get(ctx);
client.sendEMail(client.getRequestEMail(),
"Server started: " + system.getName(),
client.sendEMail(client.getRequestEMail(),
"Server started: " + system.getName(),
"ServerInfo: " + context.getServerInfo(), null);
return s_initOK;
} // initWeb
/**************************************************************************
* Get Base Directory entry.
* <br>
@ -251,7 +258,7 @@ public class WebEnv
public static img getLogo()
{
return new img(getLogoURL()).setAlign(AlignType.RIGHT)
.setAlt("&copy; Jorg Janke/adempiere");
.setAlt("&copy; Jorg Janke/adempiere");
} // getLogo
/**
@ -384,7 +391,7 @@ public class WebEnv
+ ", ServletPath=" + request.getServletPath()
+ ", Query=" + request.getQueryString());
log.finer("- From " + request.getRemoteHost() + "/" + request.getRemoteAddr()
// + ":" + request.getRemotePort()
// + ":" + request.getRemotePort()
+ " - User=" + request.getRemoteUser());
log.finer("- URI=" + request.getRequestURI() + ", URL=" + request.getRequestURL());
log.finer("- AuthType=" + request.getAuthType());
@ -467,7 +474,7 @@ public class WebEnv
log.finer("- Class=" + request.getClass().getName());
} // dump (Request)
/**************************************************************************
* Add Footer (with diagnostics)
* @param request request