1515 */
1616package net .codestory .http .misc ;
1717
18+ import com .google .common .annotations .VisibleForTesting ;
1819import net .codestory .http .reload .MasterFolderWatch ;
1920
2021import java .io .File ;
@@ -37,6 +38,7 @@ public class Env implements Serializable {
3738 private final boolean injectLiveReloadScript ;
3839 private final boolean diskCache ;
3940 private final Supplier <MasterFolderWatch > folderWatch ;
41+ private final String appFolder ;
4042
4143 public Env () {
4244 this (
@@ -47,11 +49,12 @@ public Env() {
4749 !getBoolean ("http.disable.gzip" , false ),
4850 getBoolean ("http.livereload.server" , true ),
4951 getBoolean ("http.livereload.script" , true ),
50- getBoolean ("http.cache.disk" , true )
52+ getBoolean ("http.cache.disk" , true ),
53+ get ("APP_FOLDER" , "app" )
5154 );
5255 }
5356
54- private Env (File workingDir , boolean prodMode , boolean classPath , boolean filesystem , boolean gzip , boolean liveReloadServer , boolean injectLiveReloadScript , boolean diskCache ) {
57+ private Env (File workingDir , boolean prodMode , boolean classPath , boolean filesystem , boolean gzip , boolean liveReloadServer , boolean injectLiveReloadScript , boolean diskCache , String appFolder ) {
5558 this .workingDir = workingDir ;
5659 this .prodMode = prodMode ;
5760 this .classPath = classPath ;
@@ -61,50 +64,55 @@ private Env(File workingDir, boolean prodMode, boolean classPath, boolean filesy
6164 this .injectLiveReloadScript = injectLiveReloadScript ;
6265 this .diskCache = diskCache ;
6366 this .folderWatch = memoize (() -> new MasterFolderWatch (this ));
67+ this .appFolder = appFolder ;
6468 }
6569
6670 // helper factories
6771
6872 public static Env prod () {
69- return new Env (new File ("." ), true , true , true , true , false , false , true );
73+ return new Env (new File ("." ), true , true , true , true , false , false , true , "app" );
7074 }
7175
7276 public static Env dev () {
73- return new Env (new File ("." ), false , true , true , false , true , true , true );
77+ return new Env (new File ("." ), false , true , true , false , true , true , true , "app" );
7478 }
7579
76- public static Env dev (File workingDir ) { return new Env (workingDir , false , false , true , false , true , true , true );}
80+ public static Env dev (File workingDir ) { return new Env (workingDir , false , false , true , false , true , true , true , "app" );}
7781
7882 public Env withWorkingDir (File newWorkingDir ) {
79- return new Env (newWorkingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache );
83+ return new Env (newWorkingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache , appFolder );
8084 }
8185
8286 public Env withProdMode (boolean newProdMode ) {
83- return new Env (workingDir , newProdMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache );
87+ return new Env (workingDir , newProdMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache , appFolder );
8488 }
8589
8690 public Env withClassPath (boolean shouldScanCassPath ) {
87- return new Env (workingDir , prodMode , shouldScanCassPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache );
91+ return new Env (workingDir , prodMode , shouldScanCassPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache , appFolder );
8892 }
8993
9094 public Env withFilesystem (boolean shouldScanFilesystem ) {
91- return new Env (workingDir , prodMode , classPath , shouldScanFilesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache );
95+ return new Env (workingDir , prodMode , classPath , shouldScanFilesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache , appFolder );
9296 }
9397
9498 public Env withGzip (boolean shouldGzipResponse ) {
95- return new Env (workingDir , prodMode , classPath , filesystem , shouldGzipResponse , liveReloadServer , injectLiveReloadScript , diskCache );
99+ return new Env (workingDir , prodMode , classPath , filesystem , shouldGzipResponse , liveReloadServer , injectLiveReloadScript , diskCache , appFolder );
96100 }
97101
98102 public Env withLiveReloadServer (boolean shouldStartLiveReloadServer ) {
99- return new Env (workingDir , prodMode , classPath , filesystem , gzip , shouldStartLiveReloadServer , injectLiveReloadScript , diskCache );
103+ return new Env (workingDir , prodMode , classPath , filesystem , gzip , shouldStartLiveReloadServer , injectLiveReloadScript , diskCache , appFolder );
100104 }
101105
102106 public Env withInjectLiveReloadScript (boolean shouldInjectLiveReloadScript ) {
103- return new Env (workingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , shouldInjectLiveReloadScript , diskCache );
107+ return new Env (workingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , shouldInjectLiveReloadScript , diskCache , appFolder );
104108 }
105109
106110 public Env withDiskCache (boolean shouldUseDiskCache ) {
107- return new Env (workingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , shouldUseDiskCache );
111+ return new Env (workingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , shouldUseDiskCache , appFolder );
112+ }
113+
114+ public Env withAppFolder (String shouldAppFolder ) {
115+ return new Env (workingDir , prodMode , classPath , filesystem , gzip , liveReloadServer , injectLiveReloadScript , diskCache , shouldAppFolder );
108116 }
109117
110118 //
@@ -118,7 +126,7 @@ public File workingDir() {
118126 }
119127
120128 public String appFolder () {
121- return "app" ;
129+ return appFolder ;
122130 }
123131
124132 public List <Path > foldersToWatch () {
@@ -165,11 +173,21 @@ public boolean diskCache() {
165173 return diskCache ;
166174 }
167175
176+ @ VisibleForTesting
177+ private static String getenv (String envVar ) {
178+ return System .getenv (envVar );
179+ }
180+
168181 private static String get (String propertyName ) {
169- String env = System . getenv (propertyName );
182+ String env = getenv (propertyName );
170183 return (env != null ) ? env : System .getProperty (propertyName );
171184 }
172185
186+ private static String get (String propertyName , String defaultValue ) {
187+ String env = getenv (propertyName );
188+ return (env != null ) ? env : System .getProperty (propertyName , defaultValue );
189+ }
190+
173191 private static boolean getBoolean (String propertyName , boolean defaultValue ) {
174192 String value = get (propertyName );
175193 return (value == null ) ? defaultValue : Boolean .parseBoolean (value );
0 commit comments