[Notice] Announcing the End of Demo Server [Read me]
Yi EungJun 2015-03-03
Revert "config: Fix config error while starting Yobi"
This reverts commit 53920e0315f62917961a5b9fa4f8640997ea35ef.

Copying and creating application.conf from application.conf.default was
done while building but it does not work for standalone distribution
because it does not contain conf directory. The process should be done
at the first starting of Yobi.
@d0e8823a29dd589002477787089d2c8481221bdf
app/Global.java
--- app/Global.java
+++ app/Global.java
@@ -60,14 +60,44 @@
 
 public class Global extends GlobalSettings {
     private static final String[] INITIAL_ENTITY_NAME = {"users", "roles", "siteAdmins"};
+    public static final String APPLICATION_CONF_DEFAULT = "application.conf.default";
+    public static final String APPLICATION_CONF = "application.conf";
+    public static final String CONFIG_DIRNAME = "conf";
     private final String DEFAULT_SECRET = "VA2v:_I=h9>?FYOH:@ZhW]01P<mWZAKlQ>kk>Bo`mdCiA>pDw64FcBuZdDh<47Ew";
 
     private boolean isSecretInvalid = false;
     private boolean isRestartRequired = false;
-
+    private boolean isValidationRequired = false;
     private MailboxService mailboxService = new MailboxService();
 
     @Override
+    public Configuration onLoadConfig(play.Configuration config, File path, ClassLoader classloader) {
+        String basePath = path.getAbsolutePath();
+        Path pathToDefaultConfig = Paths.get(basePath, CONFIG_DIRNAME, APPLICATION_CONF_DEFAULT);
+        Path pathToConfig = Paths.get(basePath, CONFIG_DIRNAME, APPLICATION_CONF);
+        File configFile = pathToConfig.toFile();
+
+        if (!configFile.exists()) {
+            try {
+                Files.copy(pathToDefaultConfig, pathToConfig);
+            } catch (IOException e) {
+                play.Logger.error("Failed to initialize configuration", e);
+                return null;
+            }
+            Config parsedConfig = ConfigFactory.parseFileAnySyntax(configFile);
+            return new Configuration(ConfigFactory.load(classloader, parsedConfig));
+        } else {
+            if (!configFile.isFile()) {
+                play.Logger.error(
+                        "Failed to initialize configuration: " + pathToConfig + " is a directory.");
+                return null;
+            }
+        }
+
+        return null;
+    }
+
+    @Override
     public void onStart(Application app) {
         isSecretInvalid = equalsDefaultSecret();
         insertInitialData();
 
project/BuildConfig.scala (deleted)
--- project/BuildConfig.scala
@@ -1,45 +0,0 @@
-import sbt._
-import java.nio.file.Files
-import java.nio.file.Paths
-import java.nio.file.Path
-import java.io.IOException;
-
-object ApplicationBuild extends Build {
-
-  val APPLICATION_CONF_DEFAULT = "application.conf.default"
-  val APPLICATION_CONF = "application.conf"
-  val LOG_CONF_DEFAULT = "application-logger.xml.default"
-  val LOG_CONF = "application-logger.xml"
-  val CONFIG_DIRNAME = "conf"
-
-  def basePath = new File(System.getProperty("user.dir")).getAbsolutePath()
-
-  def configDirPath = basePath + "/" + CONFIG_DIRNAME
-
-  def initConfig(pathToDefaultConfig: Path, pathToConfig: Path): Unit = {
-    val configFile = pathToConfig.toFile()
-
-    if (!configFile.exists()) {
-        try {
-          Files.copy(pathToDefaultConfig, pathToConfig)
-        } catch {
-            case e: IOException => throw new Exception("Failed to initialize configuration", e)
-        }
-    } else {
-        if (!configFile.isFile()) {
-            throw new Exception("Failed to initialize configuration: '" + pathToConfig + "' is a directory.")
-        }
-    }
-  }
-
-  def initConfig: Unit = {
-    initConfig(
-      Paths.get(configDirPath, APPLICATION_CONF_DEFAULT),
-      Paths.get(configDirPath, APPLICATION_CONF))
-    initConfig(
-      Paths.get(configDirPath, LOG_CONF_DEFAULT),
-      Paths.get(configDirPath, LOG_CONF))
-  }
-
-  val main = initConfig
-}
Add a comment
List