Commit c9ef9d1b authored by Tom Evans's avatar Tom Evans

OF-850: Improve default initialization state

Minor changes to system utility classes to improve initial state of the
system, particularly during unit testing.
parent 2f2f5ba5
......@@ -29,6 +29,7 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.MissingResourceException;
import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.JiveGlobals;
......@@ -619,6 +620,9 @@ public class DbConnectionManager {
// Check to see if the database schema needs to be upgraded.
schemaManager.checkOpenfireSchema(con);
}
catch (MissingResourceException mre) {
Log.error(mre.getMessage());
}
catch (Exception e) {
Log.error(e.getMessage(), e);
}
......
......@@ -28,7 +28,6 @@ import java.sql.SQLException;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -316,12 +315,6 @@ public class JiveGlobals {
if (openfireProperties == null) {
loadOpenfireProperties();
}
// home not loaded?
if (openfireProperties == null) {
return null;
}
return openfireProperties.getProperty(name);
}
......@@ -349,11 +342,6 @@ public class JiveGlobals {
loadOpenfireProperties();
}
// home not loaded?
if (openfireProperties == null) {
return defaultValue;
}
String value = openfireProperties.getProperty(name);
if (value == null) {
value = defaultValue;
......@@ -445,11 +433,7 @@ public class JiveGlobals {
if (openfireProperties == null) {
loadOpenfireProperties();
}
// jiveHome not loaded?
if (openfireProperties != null) {
openfireProperties.setProperty(name, value);
}
openfireProperties.setProperty(name, value);
}
/**
......@@ -472,10 +456,7 @@ public class JiveGlobals {
if (openfireProperties == null) {
loadOpenfireProperties();
}
if (openfireProperties != null) {
openfireProperties.setProperties(propertyMap);
}
openfireProperties.setProperties(propertyMap);
}
/**
......@@ -505,11 +486,6 @@ public class JiveGlobals {
loadOpenfireProperties();
}
// jiveHome not loaded?
if (openfireProperties == null) {
return Collections.EMPTY_LIST;
}
String[] propNames = openfireProperties.getChildrenProperties(parent);
List<String> values = new ArrayList<String>();
for (String propName : propNames) {
......@@ -518,7 +494,6 @@ public class JiveGlobals {
values.add(value);
}
}
return values;
}
......@@ -531,12 +506,6 @@ public class JiveGlobals {
if (openfireProperties == null) {
loadOpenfireProperties();
}
// jiveHome not loaded?
if (openfireProperties == null) {
return Collections.emptyList();
}
return openfireProperties.getAllPropertyNames();
}
......@@ -797,6 +766,9 @@ public class JiveGlobals {
if (isSetupMode()) {
return;
}
if (openfireProperties == null) {
loadOpenfireProperties();
}
openfireProperties.migrateProperty(name);
}
......@@ -969,10 +941,18 @@ public class JiveGlobals {
openfireProperties = new XMLProperties(home + File.separator + getConfigName());
}
catch (IOException ioe) {
Log.error(ioe.getMessage(), ioe);
Log.error(ioe.getMessage());
failedLoading = true;
}
}
// create a default/empty XML properties set (helpful for unit testing)
if (openfireProperties == null) {
try {
openfireProperties = new XMLProperties();
} catch (IOException e) {
Log.error("Failed to setup default openfire properties", e);
}
}
}
}
......@@ -989,12 +969,6 @@ public class JiveGlobals {
msg.append("Critical Error! The home directory has not been configured, \n");
msg.append("which will prevent the application from working correctly.\n\n");
System.err.println(msg.toString());
try {
securityProperties = new XMLProperties();
} catch (IOException ioe) {
Log.error("Failed to setup default secuirty properties", ioe);
}
}
// Create a manager with the full path to the security XML file.
else {
......@@ -1014,10 +988,18 @@ public class JiveGlobals {
}, 1000);
}
catch (IOException ioe) {
Log.error(ioe.getMessage(), ioe);
Log.error(ioe.getMessage());
failedLoading = true;
}
}
// create a default/empty XML properties set (helpful for unit testing)
if (securityProperties == null) {
try {
securityProperties = new XMLProperties();
} catch (IOException e) {
Log.error("Failed to setup default security properties", e);
}
}
}
}
......
......@@ -741,6 +741,10 @@ public class XMLProperties {
* used during the writing process for maximum safety.
*/
private synchronized void saveProperties() {
if (file == null) {
Log.error("Unable to save XML properties; no file specified");
return;
}
boolean error = false;
// Write data out to a temporary file first.
File tempFile = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment