/** * Init the framework * * @param root The application path * @param id The framework id to use */ public static void init(File root, String id) { // Simple things Play.id = id; Play.started = false; Play.applicationPath = root; // load all play.static of exists initStaticStuff(); guessFrameworkPath(); // Read the configuration file readConfiguration(); Play.classes = new ApplicationClasses(); // Configure logs Logger.init(); String logLevel = configuration.getProperty("application.log", "INFO"); // only override log-level if Logger was not configured manually if (!Logger.configuredManually) { Logger.setUp(logLevel); } Logger.recordCaller = Boolean.parseBoolean(configuration.getProperty("application.log.recordCaller", "false")); Logger.info("Starting %s", root.getAbsolutePath()); if (configuration.getProperty("play.tmp", "tmp").equals("none")) { tmpDir = null; Logger.debug("No tmp folder will be used (play.tmp is set to none)"); } else { tmpDir = new File(configuration.getProperty("play.tmp", "tmp")); if (!tmpDir.isAbsolute()) { tmpDir = new File(applicationPath, tmpDir.getPath()); } if (Logger.isTraceEnabled()) { Logger.trace("Using %s as tmp dir", Play.tmpDir); } if (!tmpDir.exists()) { try { if (readOnlyTmp) { throw new Exception("ReadOnly tmp"); } tmpDir.mkdirs(); } catch (Throwable e) { tmpDir = null; Logger.warn("No tmp folder will be used (cannot create the tmp dir)"); } } } // Mode try { mode = Mode.valueOf(configuration.getProperty("application.mode", "DEV").toUpperCase()); } catch (IllegalArgumentException e) { Logger.error( "Illegal mode '%s', use either prod or dev", configuration.getProperty("application.mode")); fatalServerErrorOccurred(); } // Force the Production mode if forceProd or precompile is activate // Set to the Prod mode must be done before loadModules call // as some modules (e.g. DocViewver) is only available in DEV if (usePrecompiled || forceProd || System.getProperty("precompile") != null) { mode = Mode.PROD; } // Context path ctxPath = configuration.getProperty("http.path", ctxPath); // Build basic java source path VirtualFile appRoot = VirtualFile.open(applicationPath); roots.add(appRoot); javaPath = new CopyOnWriteArrayList<VirtualFile>(); javaPath.add(appRoot.child("app")); javaPath.add(appRoot.child("conf")); // Build basic templates path if (appRoot.child("app/views").exists()) { templatesPath = new ArrayList<VirtualFile>(2); templatesPath.add(appRoot.child("app/views")); } else { templatesPath = new ArrayList<VirtualFile>(1); } // Main route file routes = appRoot.child("conf/routes"); // Plugin route files modulesRoutes = new HashMap<String, VirtualFile>(16); // Load modules loadModules(); // Load the templates from the framework after the one from the modules templatesPath.add(VirtualFile.open(new File(frameworkPath, "framework/templates"))); // Enable a first classloader classloader = new ApplicationClassloader(); // Fix ctxPath if ("/".equals(Play.ctxPath)) { Play.ctxPath = ""; } // Default cookie domain Http.Cookie.defaultDomain = configuration.getProperty("application.defaultCookieDomain", null); if (Http.Cookie.defaultDomain != null) { Logger.info("Using default cookie domain: " + Http.Cookie.defaultDomain); } // Plugins pluginCollection.loadPlugins(); // Done ! if (mode == Mode.PROD) { if (preCompile() && System.getProperty("precompile") == null) { start(); } else { return; } } else { Logger.warn("You're running Play! in DEV mode"); } // Plugins pluginCollection.onApplicationReady(); Play.initialized = true; }