forked from actframework/actframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntimeDirs.java
More file actions
101 lines (87 loc) · 3.13 KB
/
RuntimeDirs.java
File metadata and controls
101 lines (87 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package act.app;
/*-
* #%L
* ACT Framework
* %%
* Copyright (C) 2014 - 2017 ActFramework
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import act.Act;
import act.app.util.NamedPort;
import org.osgl.util.S;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static act.app.ProjectLayout.Utils.file;
import static act.route.RouteTableRouterBuilder.ROUTES_FILE;
/**
* Define application dir structure at runtime
*/
public enum RuntimeDirs {
;
public static final String CONF = "/conf";
public static final String ASSET = "/asset";
public static final String CLASSES = "/classes";
public static final String LIB = "/lib";
public static File home(App app) {
if (Act.isDev()) {
return app.layout().target(app.base());
} else {
return app.base();
}
}
public static File resource(App app) {
//return Act.isDev() ? app.layout().resource(app.base()) : classes(app);
return app.layout().resource(Act.isDev() ? app.base() : app.home());
}
public static File conf(App app) {
File confBase = app.layout().resource(Act.isDev() ? app.base() : app.home()); //Act.isDev() ? app.layout().resource(app.base()) : classes(app);
File file = new File(confBase, CONF);
return file.exists() ? file : confBase;
}
public static Map<String, List<File>> routes(App app) {
Map<String, List<File>> map = new HashMap();
File classes = classes(app);
map.put(NamedPort.DEFAULT, routes(classes, ROUTES_FILE));
for (NamedPort np : app.config().namedPorts()) {
String npName = np.name();
String routesConfName = S.concat("routes.", npName, ".conf");
map.put(npName, routes(classes, routesConfName));
}
return map;
}
private static List<File> routes(File classes, String name) {
List<File> routes = new ArrayList<>();
routes.add(file(classes, name));
File confRoot = file(classes, CONF);
routes.add(file(confRoot, name));
File profileRooot = file(confRoot, Act.profile());
routes.add(file(profileRooot, name));
return routes;
}
public static File classes(App app) {
File file = new File(app.home(), app.layout().classes());
if (!file.exists()) {
// suppose we starts PROD mode from IDE
file = new File(app.layout().target(app.home()), app.layout().classes());
}
return file;
}
public static File lib(App app) {
return new File(app.home(), LIB);
}
}