|
28 | 28 | import java.beans.XMLEncoder;
|
29 | 29 | import java.io.BufferedInputStream;
|
30 | 30 | import java.io.BufferedOutputStream;
|
31 |
| -import java.io.BufferedReader; |
32 | 31 | import java.io.ByteArrayInputStream;
|
33 | 32 | import java.io.ByteArrayOutputStream;
|
34 | 33 | import java.io.File;
|
35 | 34 | import java.io.FileInputStream;
|
36 | 35 | import java.io.FileOutputStream;
|
37 |
| -import java.io.FileReader; |
38 | 36 | import java.io.IOException;
|
39 | 37 | import java.io.InputStream;
|
40 | 38 | import java.io.OutputStream;
|
|
62 | 60 | import org.opengrok.indexer.index.IgnoredNames;
|
63 | 61 | import org.opengrok.indexer.logger.LoggerFactory;
|
64 | 62 |
|
| 63 | + |
65 | 64 | /**
|
66 |
| - * Placeholder class for all configuration variables. Due to the multithreaded |
| 65 | + * Placeholder class for all configuration variables. Due to the multi-threaded |
67 | 66 | * nature of the web application, each thread will use the same instance of the
|
68 | 67 | * configuration object for each page request. Class and methods should have
|
69 | 68 | * package scope, but that didn't work with the XMLDecoder/XMLEncoder.
|
| 69 | + * |
| 70 | + * This should be as close to POJO (https://en.wikipedia.org/wiki/Plain_old_Java_object) as possible. |
70 | 71 | */
|
71 | 72 | public final class Configuration {
|
72 | 73 |
|
@@ -102,6 +103,9 @@ public final class Configuration {
|
102 | 103 | private static final String NONPOSITIVE_NUMBER_ERROR =
|
103 | 104 | "Invalid value for \"%s\" - \"%s\". Expected value greater than 0";
|
104 | 105 |
|
| 106 | + /** |
| 107 | + * Path to {@code ctags} binary. |
| 108 | + */ |
105 | 109 | private String ctags;
|
106 | 110 |
|
107 | 111 | /**
|
@@ -235,7 +239,6 @@ public final class Configuration {
|
235 | 239 | * contains definition tags.
|
236 | 240 | */
|
237 | 241 | public static final String EFTAR_DTAGS_NAME = "dtags.eftar";
|
238 |
| - private transient File dtagsEftar = null; |
239 | 242 |
|
240 | 243 | /**
|
241 | 244 | * Revision messages will be collapsible if they exceed this many number of
|
@@ -1088,167 +1091,38 @@ public void setListDirsFirst(boolean flag) {
|
1088 | 1091 | listDirsFirst = flag;
|
1089 | 1092 | }
|
1090 | 1093 |
|
1091 |
| - /** |
1092 |
| - * Get the contents of a file or empty string if the file cannot be read. |
1093 |
| - */ |
1094 |
| - private static String getFileContent(File file) { |
1095 |
| - if (file == null || !file.canRead()) { |
1096 |
| - return ""; |
1097 |
| - } |
1098 |
| - FileReader fin = null; |
1099 |
| - BufferedReader input = null; |
1100 |
| - try { |
1101 |
| - fin = new FileReader(file); |
1102 |
| - input = new BufferedReader(fin); |
1103 |
| - String line; |
1104 |
| - StringBuilder contents = new StringBuilder(); |
1105 |
| - String EOL = System.getProperty("line.separator"); |
1106 |
| - while ((line = input.readLine()) != null) { |
1107 |
| - contents.append(line).append(EOL); |
1108 |
| - } |
1109 |
| - return contents.toString(); |
1110 |
| - } catch (java.io.FileNotFoundException e) { |
1111 |
| - LOGGER.log(Level.WARNING, "failed to find file: {0}", |
1112 |
| - e.getMessage()); |
1113 |
| - } catch (java.io.IOException e) { |
1114 |
| - LOGGER.log(Level.WARNING, "failed to read file: {0}", |
1115 |
| - e.getMessage()); |
1116 |
| - } finally { |
1117 |
| - if (input != null) { |
1118 |
| - try { |
1119 |
| - input.close(); |
1120 |
| - } catch (Exception e) { |
1121 |
| - /* |
1122 |
| - * nothing we can do about it |
1123 |
| - */ } |
1124 |
| - } else if (fin != null) { |
1125 |
| - try { |
1126 |
| - fin.close(); |
1127 |
| - } catch (Exception e) { |
1128 |
| - /* |
1129 |
| - * nothing we can do about it |
1130 |
| - */ } |
1131 |
| - } |
1132 |
| - } |
1133 |
| - return ""; |
1134 |
| - } |
1135 |
| - |
1136 | 1094 | /**
|
1137 | 1095 | * The name of the file relative to the <var>DATA_ROOT</var>, which should
|
1138 | 1096 | * be included into the footer of generated web pages.
|
1139 | 1097 | */
|
1140 | 1098 | public static final String FOOTER_INCLUDE_FILE = "footer_include";
|
1141 | 1099 |
|
1142 |
| - private transient String footer = null; |
1143 |
| - |
1144 |
| - /** |
1145 |
| - * Get the contents of the footer include file. |
1146 |
| - * |
1147 |
| - * @param force if true, reload even if already set |
1148 |
| - * @return an empty string if it could not be read successfully, the |
1149 |
| - * contents of the file otherwise. |
1150 |
| - * @see #FOOTER_INCLUDE_FILE |
1151 |
| - */ |
1152 |
| - public String getFooterIncludeFileContent(boolean force) { |
1153 |
| - if (footer == null || force) { |
1154 |
| - footer = getFileContent(new File(getIncludeRoot(), FOOTER_INCLUDE_FILE)); |
1155 |
| - } |
1156 |
| - return footer; |
1157 |
| - } |
1158 |
| - |
1159 | 1100 | /**
|
1160 | 1101 | * The name of the file relative to the <var>DATA_ROOT</var>, which should
|
1161 | 1102 | * be included into the header of generated web pages.
|
1162 | 1103 | */
|
1163 | 1104 | public static final String HEADER_INCLUDE_FILE = "header_include";
|
1164 | 1105 |
|
1165 |
| - private transient String header = null; |
1166 |
| - |
1167 |
| - /** |
1168 |
| - * Get the contents of the header include file. |
1169 |
| - * |
1170 |
| - * @param force if true, reload even if already set |
1171 |
| - * @return an empty string if it could not be read successfully, the |
1172 |
| - * contents of the file otherwise. |
1173 |
| - * @see #HEADER_INCLUDE_FILE |
1174 |
| - */ |
1175 |
| - public String getHeaderIncludeFileContent(boolean force) { |
1176 |
| - if (header == null || force) { |
1177 |
| - header = getFileContent(new File(getIncludeRoot(), HEADER_INCLUDE_FILE)); |
1178 |
| - } |
1179 |
| - return header; |
1180 |
| - } |
1181 |
| - |
1182 | 1106 | /**
|
1183 | 1107 | * The name of the file relative to the <var>DATA_ROOT</var>, which should
|
1184 | 1108 | * be included into the body of web app's "Home" page.
|
1185 | 1109 | */
|
1186 | 1110 | public static final String BODY_INCLUDE_FILE = "body_include";
|
1187 | 1111 |
|
1188 |
| - private transient String body = null; |
1189 |
| - |
1190 |
| - /** |
1191 |
| - * Get the contents of the body include file. |
1192 |
| - * |
1193 |
| - * @param force if true, reload even if already set |
1194 |
| - * @return an empty string if it could not be read successfully, the |
1195 |
| - * contents of the file otherwise. |
1196 |
| - * @see Configuration#BODY_INCLUDE_FILE |
1197 |
| - */ |
1198 |
| - public String getBodyIncludeFileContent(boolean force) { |
1199 |
| - if (body == null || force) { |
1200 |
| - body = getFileContent(new File(getIncludeRoot(), BODY_INCLUDE_FILE)); |
1201 |
| - } |
1202 |
| - return body; |
1203 |
| - } |
1204 |
| - |
1205 | 1112 | /**
|
1206 | 1113 | * The name of the file relative to the <var>DATA_ROOT</var>, which should
|
1207 | 1114 | * be included into the error page handling access forbidden errors - HTTP
|
1208 | 1115 | * code 403 Forbidden.
|
1209 | 1116 | */
|
1210 | 1117 | public static final String E_FORBIDDEN_INCLUDE_FILE = "error_forbidden_include";
|
1211 | 1118 |
|
1212 |
| - private transient String eforbidden_content = null; |
1213 |
| - |
1214 |
| - /** |
1215 |
| - * Get the contents of the page for forbidden error page (403 Forbidden) |
1216 |
| - * include file. |
1217 |
| - * |
1218 |
| - * @param force if true, reload even if already set |
1219 |
| - * @return an empty string if it could not be read successfully, the |
1220 |
| - * contents of the file otherwise. |
1221 |
| - * @see Configuration#E_FORBIDDEN_INCLUDE_FILE |
1222 |
| - */ |
1223 |
| - public String getForbiddenIncludeFileContent(boolean force) { |
1224 |
| - if (eforbidden_content == null || force) { |
1225 |
| - eforbidden_content = getFileContent(new File(getIncludeRoot(), E_FORBIDDEN_INCLUDE_FILE)); |
1226 |
| - } |
1227 |
| - return eforbidden_content; |
1228 |
| - } |
1229 |
| - |
1230 | 1119 | /**
|
1231 | 1120 | * @return path to the file holding compiled path descriptions for the web application
|
1232 | 1121 | */
|
1233 | 1122 | public Path getDtagsEftarPath() {
|
1234 | 1123 | return Paths.get(getDataRoot(), "index", EFTAR_DTAGS_NAME);
|
1235 | 1124 | }
|
1236 | 1125 |
|
1237 |
| - /** |
1238 |
| - * Get the eftar file, which contains definition tags for path descriptions. |
1239 |
| - * |
1240 |
| - * @return {@code null} if there is no such file, the file otherwise. |
1241 |
| - */ |
1242 |
| - public File getDtagsEftar() { |
1243 |
| - if (dtagsEftar == null) { |
1244 |
| - File tmp = getDtagsEftarPath().toFile(); |
1245 |
| - if (tmp.canRead()) { |
1246 |
| - dtagsEftar = tmp; |
1247 |
| - } |
1248 |
| - } |
1249 |
| - return dtagsEftar; |
1250 |
| - } |
1251 |
| - |
1252 | 1126 | public String getCTagsExtraOptionsFile() {
|
1253 | 1127 | return CTagsExtraOptionsFile;
|
1254 | 1128 | }
|
@@ -1428,5 +1302,4 @@ public boolean test(Group g) {
|
1428 | 1302 |
|
1429 | 1303 | return conf;
|
1430 | 1304 | }
|
1431 |
| - |
1432 | 1305 | }
|
0 commit comments