Skip to content

Commit

Permalink
[#306] Use a custom implementation of Properties for Play.configurati…
Browse files Browse the repository at this point in the history
…on, that guarantee the iteration order.
  • Loading branch information
guillaumebort committed Oct 19, 2010
1 parent 83154ad commit 66fcced
Show file tree
Hide file tree
Showing 3 changed files with 529 additions and 5 deletions.
10 changes: 6 additions & 4 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
Expand All @@ -26,6 +27,7 @@
import play.libs.IO;
import play.mvc.Router;
import play.templates.TemplateLoader;
import play.utils.OrderSafeProperties;
import play.vfs.VirtualFile;

/**
Expand Down Expand Up @@ -287,15 +289,15 @@ static void readConfiguration() {
VirtualFile appRoot = VirtualFile.open(applicationPath);
conf = appRoot.child("conf/application.conf");
try {
configuration = IO.readUtf8Properties(conf.inputstream());
configuration = IO.readUtf8Properties(conf.inputstream());
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
Logger.fatal("Cannot read application.conf");
System.exit(0);
}
}
// Ok, check for instance specifics configuration
Properties newConfiguration = new Properties();
Properties newConfiguration = new OrderSafeProperties();
Pattern pattern = Pattern.compile("^%([a-zA-Z0-9_\\-]+)\\.(.*)$");
for (Object key : configuration.keySet()) {
Matcher matcher = pattern.matcher(key + "");
Expand Down Expand Up @@ -618,8 +620,8 @@ public static void loadModules() {
}
}
}
for (Enumeration<?> e = configuration.propertyNames(); e.hasMoreElements();) {
String pName = e.nextElement().toString();
for (Iterator<?> e = configuration.keySet().iterator(); e.hasNext();) {
String pName = e.next().toString();
if (pName.startsWith("module.")) {
String moduleName = pName.substring(7);
File modulePath = new File(configuration.getProperty(pName));
Expand Down
3 changes: 2 additions & 1 deletion framework/src/play/libs/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.apache.commons.io.IOUtils;
import play.exceptions.UnexpectedException;
import play.utils.OrderSafeProperties;

/**
* IO utils
Expand All @@ -29,7 +30,7 @@ public class IO {
* @return The Properties object
*/
public static Properties readUtf8Properties(InputStream is) {
Properties properties = new Properties();
Properties properties = new OrderSafeProperties();
try {
properties.load(is);
for (Object key : properties.keySet()) {
Expand Down
Loading

0 comments on commit 66fcced

Please sign in to comment.