-
Notifications
You must be signed in to change notification settings - Fork 325
Expand file tree
/
Copy pathConfigUtil.java
More file actions
253 lines (208 loc) · 7.56 KB
/
Copy pathConfigUtil.java
File metadata and controls
253 lines (208 loc) · 7.56 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
package org.jbake.app;
import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* Provides Configuration related functions.
*
* @author Jonathan Bullock <jonbullock@gmail.com>
*/
public class ConfigUtil {
/**
* Set of config keys used by JBake
* @author ndx
*
*/
public static interface Keys {
/**
* Output filename for archive file, is only used when {@link #RENDER_ARCHIVE} is true
*/
static final String ARCHIVE_FILE = "archive.file";
/**
* Asciidoctor attributes to be set when processing input
*/
static final String ASCIIDOCTOR_ATTRIBUTES = "asciidoctor.attributes";
/**
* Flag indicating if JBake properties should be made available to Asciidoctor
*/
static final String ASCIIDOCTOR_ATTRIBUTES_EXPORT = "asciidoctor.attributes.export";
/**
* Prefix to be used when exporting JBake properties to Asciidoctor
*/
static final String ASCIIDOCTOR_ATTRIBUTES_EXPORT_PREFIX = "asciidoctor.attributes.export.prefix";
/**
* Asciidoctor options to be set when processing input
*/
static final String ASCIIDOCTOR_OPTION = "asciidoctor.option";
/**
* Folder where assets are stored, they are copied directly in output folder and not processed
*/
static final String ASSET_FOLDER = "asset.folder";
/**
* Flag indicating if hidden asset resources should be ignored
*/
static final String ASSET_IGNORE_HIDDEN = "asset.ignore";
/**
* Timestamp that records when JBake build was made
*/
static final String BUILD_TIMESTAMP = "build.timestamp";
/**
* Folder where content (that's to say files to be transformed) resides in
*/
static final String CONTENT_FOLDER = "content.folder";
/**
* How date is formated
*/
static final String DATE_FORMAT = "date.format";
/**
* Folder to store database files in
*/
static final String DB_PATH = "db.path";
/**
* Flag to identify if database is kept in memory (memory) or persisted to disk (local)
*/
static final String DB_STORE = "db.store";
/**
* Default status to use (in order to avoid putting it in all files)
*/
static final String DEFAULT_STATUS = "default.status";
/**
* Folder where rendered files are output
*/
static final String DESTINATION_FOLDER = "destination.folder";
/**
* Suffix used to identify draft files
*/
static final String DRAFT_SUFFIX = "draft.suffix";
/**
* Output filename for feed file, is only used when {@link #RENDER_FEED} is true
*/
static final String FEED_FILE = "feed.file";
/**
* Flag indicating if index page shows excerpts or full bodies,
* is only used when {@link #RENDER_INDEX} is true
*/
static final String INDEX_SUMMERY = "index.summery";
/**
* Flag indicating if feed page shows excerpts or full bodies,
* is only used when {@link #RENDER_INDEX} is true
*/
static final String FEED_SUMMERY = "feed.summery";
/**
* The max length of an excerpt used as summary.
*
* By default: -1, i.e. no limit.
*/
static final String SUMMERY_MAX_LENGTH = "summary.max.length";
/*
* The unit used to truncate the body, either character, Unicode code point or word.
*
* By default: world
*/
static final String SUMMERY_LENGTH_UNIT = "summary.length.unit";
/**
* The ellipsis used with an excerpt shorter than the page/post body content.
*
* By default: ...
*/
static final String SUMMERY_ELLIPSIS = "summary.ellipsis";
/**
* The readmore label used with an excerpt shorter than the page/post body content.
*
* If a pattern is provided then it will be interpolated with the post/page link.
* By default: empty string
*/
static final String SUMMERY_READMORE = "summary.readmore";
/**
* Output filename for index, is only used when {@link #RENDER_INDEX} is true
*/
static final String INDEX_FILE = "index.file";
/**
* File extension to be used for all output files
*/
static final String OUTPUT_EXTENSION = "output.extension";
/**
* Flag indicating if archive file should be generated
*/
static final String RENDER_ARCHIVE = "render.archive";
/**
* Encoding used when rendering files
*/
static final String RENDER_ENCODING = "render.encoding";
/**
* Flag indicating if feed file should be generated
*/
static final String RENDER_FEED = "render.feed";
/**
* Flag indicating if index file should be generated
*/
static final String RENDER_INDEX = "render.index";
/**
* Flag indicating if sitemap file should be generated
*/
static final String RENDER_SITEMAP = "render.sitemap";
/**
* Flag indicating if tag files should be generated
*/
static final String RENDER_TAGS = "render.tags";
/**
* Port used when running Jetty server
*/
static final String SERVER_PORT = "server.port";
/**
* Sitemap template file name. Used only when {@link #RENDER_SITEMAP} is set to true
*/
static final String SITEMAP_FILE = "sitemap.file";
/**
* Tags output path, used only when {@link #RENDER_TAGS} is true
*/
static final String TAG_PATH = "tag.path";
/**
* Should the tag value be sanitized?
*/
static final String TAG_SANITIZE = "tag.sanitize";
/**
* Encoding to be used for template files
*/
static final String TEMPLATE_ENCODING = "template.encoding";
/**
* Folder where template files are looked for
*/
static final String TEMPLATE_FOLDER = "template.folder";
/**
* Locale used for Thymeleaf template rendering
*/
static final String THYMELEAF_LOCALE = "thymeleaf.locale";
/**
* Version of JBake
*/
static final String VERSION = "version";
}
private final static Logger LOGGER = LoggerFactory.getLogger(ConfigUtil.class);
private final static String LEGACY_CONFIG_FILE = "custom.properties";
private final static String CONFIG_FILE = "jbake.properties";
private final static String DEFAULT_CONFIG_FILE = "default.properties";
private static boolean LEGACY_CONFIG_FILE_WARNING_SHOWN = false;
public static CompositeConfiguration load(File source) throws ConfigurationException {
CompositeConfiguration config = new CompositeConfiguration();
config.setListDelimiter(',');
File customConfigFile = new File(source, LEGACY_CONFIG_FILE);
if (customConfigFile.exists()) {
if (!LEGACY_CONFIG_FILE_WARNING_SHOWN) {
LOGGER.warn(String.format("You have defined a part of your JBake configuration in %s located at: %s", LEGACY_CONFIG_FILE, customConfigFile.getParent()));
LOGGER.warn(String.format("Usage of this file is being deprecated, please rename this file to: %s to remove this warning", CONFIG_FILE));
LEGACY_CONFIG_FILE_WARNING_SHOWN = true;
}
config.addConfiguration(new PropertiesConfiguration(customConfigFile));
}
customConfigFile = new File(source, CONFIG_FILE);
if (customConfigFile.exists()) {
config.addConfiguration(new PropertiesConfiguration(customConfigFile));
}
config.addConfiguration(new PropertiesConfiguration(DEFAULT_CONFIG_FILE));
return config;
}
}