Locates the specified configuration file. @param file file to be copied @param root target root directory @return reference to created file @throws IOException I/O exception
(final String file, final String root)
| 198 | * @throws IOException I/O exception |
| 199 | */ |
| 200 | private static IOFile locate(final String file, final String root) throws IOException { |
| 201 | final IOFile target = new IOFile(root, file); |
| 202 | final boolean create = !target.exists(); |
| 203 | |
| 204 | // try to locate file from development branch |
| 205 | final IO io = new IOFile("src/main/webapp", file); |
| 206 | final byte[] data; |
| 207 | if(io.exists()) { |
| 208 | data = io.read(); |
| 209 | // check if resource path exists |
| 210 | IOFile dir = new IOFile("src/main/resources"); |
| 211 | if(dir.exists()) { |
| 212 | dir = new IOFile(dir, file); |
| 213 | // update file in resource path if it has changed |
| 214 | if(!dir.exists() || !Token.eq(data, dir.read())) { |
| 215 | Util.errln("Updating " + dir); |
| 216 | dir.parent().md(); |
| 217 | dir.write(data); |
| 218 | } |
| 219 | } |
| 220 | } else if(create) { |
| 221 | // try to locate file from resource path |
| 222 | try(InputStream is = BaseXHTTP.class.getResourceAsStream('/' + file)) { |
| 223 | if(is == null) throw new BaseXException(io + " not found."); |
| 224 | data = new IOStream(is).read(); |
| 225 | } |
| 226 | } else { |
| 227 | return target; |
| 228 | } |
| 229 | |
| 230 | if(create) { |
| 231 | // create configuration file |
| 232 | Util.errln("Creating " + target); |
| 233 | target.parent().md(); |
| 234 | target.write(data); |
| 235 | } |
| 236 | return target; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Returns a GZIP handler. |