Skip to content

Commit

Permalink
Merge pull request #1065 from codeborne/init-play-static-fields-early
Browse files Browse the repository at this point in the history
#1064 add default value for static fields to make it easier to write …
  • Loading branch information
xael-fry authored Dec 27, 2016
2 parents a339f2b + 0dd7a28 commit 62b38cf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
26 changes: 13 additions & 13 deletions framework/src/play/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public boolean isProd() {
/**
* The framework ID
*/
public static String id;
public static String id = System.getProperty("play.id", "");
/**
* The application mode
*/
public static Mode mode;
public static Mode mode = Mode.DEV;
/**
* The application root
*/
public static File applicationPath = null;
public static File applicationPath = new File(System.getProperty("application.path", "."));
/**
* tmp dir
*/
Expand Down Expand Up @@ -106,27 +106,27 @@ public boolean isProd() {
/**
* All paths to search for Java files
*/
public static List<VirtualFile> javaPath;
public static List<VirtualFile> javaPath = new CopyOnWriteArrayList<>();
/**
* All paths to search for templates files
*/
public static List<VirtualFile> templatesPath;
public static List<VirtualFile> templatesPath = new ArrayList<>(2);
/**
* Main routes file
*/
public static VirtualFile routes;
/**
* Plugin routes files
*/
public static Map<String, VirtualFile> modulesRoutes;
public static Map<String, VirtualFile> modulesRoutes = new HashMap<>(16);
/**
* The loaded configuration files
*/
public static Set<VirtualFile> confs = new HashSet<>(1);
/**
* The app configuration (already resolved from the framework id)
*/
public static Properties configuration;
public static Properties configuration = new Properties();
/**
* The last time than the application has started
*/
Expand Down Expand Up @@ -262,24 +262,24 @@ public static void init(File root, String id) {

// Build basic java source path
VirtualFile appRoot = VirtualFile.open(applicationPath);
roots.clear();
roots.add(appRoot);
javaPath = new CopyOnWriteArrayList<>();

javaPath.clear();
javaPath.add(appRoot.child("app"));
javaPath.add(appRoot.child("conf"));

// Build basic templates path
templatesPath.clear();
if (appRoot.child("app/views").exists() || (usePrecompiled && appRoot.child("precompiled/templates/app/views").exists())) {
templatesPath = new ArrayList<>(2);
templatesPath.add(appRoot.child("app/views"));
} else {
templatesPath = new ArrayList<>(1);
}

// Main route file
routes = appRoot.child("conf/routes");

// Plugin route files
modulesRoutes = new HashMap<>(16);
modulesRoutes.clear();

// Load modules
loadModules(appRoot);
Expand Down
5 changes: 0 additions & 5 deletions framework/src/play/db/Evolutions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,11 @@ public class Evolutions extends PlayPlugin {

public static void main(String[] args) throws SQLException {
/** Start the DB plugin **/
Play.id = System.getProperty("play.id");
Play.applicationPath = new File(System.getProperty("application.path"));
Play.guessFrameworkPath();
Play.readConfiguration();
Play.javaPath = new ArrayList<>();
Play.classes = new ApplicationClasses();
Play.classloader = new ApplicationClassloader();

Play.templatesPath = new ArrayList<>();
Play.modulesRoutes = new HashMap<>();
Play.loadModules(VirtualFile.open(Play.applicationPath));

if (System.getProperty("modules") != null) {
Expand Down
10 changes: 5 additions & 5 deletions framework/src/play/i18n/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public class Messages {

private static final Object[] NO_ARGS = new Object[] { null };

static public Properties defaults;
public static Properties defaults = new Properties();

static public Map<String, Properties> locales = new HashMap<>();
public static Map<String, Properties> locales = new HashMap<>();

static Pattern recursive = Pattern.compile("&\\{(.*?)\\}");
private static final Pattern recursive = Pattern.compile("&\\{(.*?)\\}");

/**
* Given a message code, translate it using current locale. If there is no
Expand Down Expand Up @@ -107,7 +107,7 @@ public static String getMessage(String locale, Object key, Object... args) {
if (value == null && locale != null && locale.length() == 5 && locales.containsKey(locale.substring(0, 2))) {
value = locales.get(locale.substring(0, 2)).getProperty(key.toString());
}
if (value == null && defaults != null) {
if (value == null) {
value = defaults.getProperty(key.toString());
}
if (value == null) {
Expand Down Expand Up @@ -196,7 +196,7 @@ public static Properties all(String locale) {
return defaults;
Properties mergedMessages = new Properties();
mergedMessages.putAll(defaults);
if (locale != null && locale.length() == 5 && locales.containsKey(locale.substring(0, 2))) {
if (locale.length() == 5 && locales.containsKey(locale.substring(0, 2))) {
mergedMessages.putAll(locales.get(locale.substring(0, 2)));
}
mergedMessages.putAll(locales.get(locale));
Expand Down
4 changes: 2 additions & 2 deletions framework/src/play/jobs/JobsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public class JobsPlugin extends PlayPlugin {

public static ScheduledThreadPoolExecutor executor;
public static List<Job> scheduledJobs;
public static List<Job> scheduledJobs = new ArrayList<>();
private static final ThreadLocal<List<Callable<?>>> afterInvocationActions = new ThreadLocal<>();

@Override
Expand Down Expand Up @@ -183,7 +183,7 @@ private Job<?> createJob(Class<?> clazz) throws InstantiationException, IllegalA
public void onApplicationStart() {
int core = Integer.parseInt(Play.configuration.getProperty("play.jobs.pool", "10"));
executor = new ScheduledThreadPoolExecutor(core, new PThreadFactory("jobs"), new ThreadPoolExecutor.AbortPolicy());
scheduledJobs = new ArrayList<>();
scheduledJobs.clear();
}

public static <V> void scheduleForCRON(Job<V> job) {
Expand Down

0 comments on commit 62b38cf

Please sign in to comment.