237 } else { |
237 } else { |
238 log.log(Level.FINER, "Not writing Bash completion helper file: {0} because configuration {1} has not been changed", new Object[]{target, Constants.CONFIG_FILE}); |
238 log.log(Level.FINER, "Not writing Bash completion helper file: {0} because configuration {1} has not been changed", new Object[]{target, Constants.CONFIG_FILE}); |
239 } |
239 } |
240 } |
240 } |
241 |
241 |
242 private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException { |
242 private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException, FileNotFoundException { |
243 if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) { |
243 if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) { |
244 // TODO: delete old directory |
244 // TODO: delete old directory |
245 formattersDir.mkdir(); |
245 formattersDir.mkdir(); |
246 for (FormatterDefinition fd : configuration.getAllFormatters()) { |
246 for (FormatterDefinition fd : configuration.getAllFormatters()) { |
247 File formatterDir = new File(formattersDir, fd.getName()); |
247 File formatterDir = new File(formattersDir, fd.getName()); |
248 formatterDir.mkdir(); |
248 formatterDir.mkdir(); |
249 |
249 |
250 Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName()); |
250 Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName()); |
251 List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class); |
251 List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class); |
252 Collections.reverse(hierarchy); |
252 Collections.reverse(hierarchy); |
253 hierarchy.stream().forEach((c) -> { |
253 for (Class<? extends Formatter> c : hierarchy) { |
254 for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) { |
254 for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) { |
255 File propertyDir = new File(formatterDir, p.name()); |
255 File propertyDir = new File(formatterDir, p.name()); |
256 propertyDir.mkdir(); |
256 propertyDir.mkdir(); |
|
257 File choicesFile = new File(propertyDir, "choices"); |
|
258 try (PrintWriter fw = new PrintWriter(choicesFile)) { |
|
259 // TODO: refactor, move |
|
260 if (p.type() == Boolean.class) { |
|
261 fw.println("true"); |
|
262 fw.println("false"); |
|
263 } |
|
264 } |
257 } |
265 } |
258 }); |
266 } |
259 } |
267 } |
260 log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir); |
268 log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir); |
261 } else { |
269 } else { |
262 log.log(Level.FINER, "Not writing Bash completion helper directory: {0} because configuration {1} has not been changed", new Object[]{formattersDir, Constants.CONFIG_FILE}); |
270 log.log(Level.FINER, "Not writing Bash completion helper directory: {0} because configuration {1} has not been changed", new Object[]{formattersDir, Constants.CONFIG_FILE}); |
263 } |
271 } |