--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat Aug 15 16:15:30 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Aug 16 01:25:01 2015 +0200
@@ -29,6 +29,7 @@
import info.globalcode.sql.dk.configuration.FormatterDefinition;
import info.globalcode.sql.dk.configuration.Loader;
import info.globalcode.sql.dk.configuration.NameIdentified;
+import info.globalcode.sql.dk.configuration.PropertyDeclaration;
import info.globalcode.sql.dk.formatting.Formatter;
import info.globalcode.sql.dk.formatting.FormatterContext;
import info.globalcode.sql.dk.formatting.FormatterException;
@@ -41,6 +42,8 @@
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
@@ -215,6 +218,7 @@
dir.mkdir();
writeBashCompletionHelperFile(configuration.getDatabases(), new File(dir, "databases"));
writeBashCompletionHelperFile(configuration.getAllFormatters(), new File(dir, "formatters"));
+ writeBashCompletionHelperFileForFormatterProperties(new File(dir, "formatter-properties"));
} catch (Exception e) {
log.log(Level.WARNING, "Unable to generate Bash completion helper files", e);
}
@@ -234,4 +238,29 @@
log.log(Level.FINER, "Not writing Bash completion helper file: {0} because configuration {1} has not been changed", new Object[]{target, Constants.CONFIG_FILE});
}
}
+
+ private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException {
+ if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) {
+ // TODO: delete old directory
+ formattersDir.mkdir();
+ for (FormatterDefinition fd : configuration.getAllFormatters()) {
+ File formatterDir = new File(formattersDir, fd.getName());
+ formatterDir.mkdir();
+
+ Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
+ List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
+ Collections.reverse(hierarchy);
+ hierarchy.stream().forEach((c) -> {
+ for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) {
+ File propertyDir = new File(formatterDir, p.name());
+ propertyDir.mkdir();
+ }
+ });
+ }
+ log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir);
+ } else {
+ log.log(Level.FINER, "Not writing Bash completion helper directory: {0} because configuration {1} has not been changed", new Object[]{formattersDir, Constants.CONFIG_FILE});
+ }
+
+ }
}