1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sat Aug 15 16:15:30 2015 +0200
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Sun Aug 16 01:25:01 2015 +0200
1.3 @@ -29,6 +29,7 @@
1.4 import info.globalcode.sql.dk.configuration.FormatterDefinition;
1.5 import info.globalcode.sql.dk.configuration.Loader;
1.6 import info.globalcode.sql.dk.configuration.NameIdentified;
1.7 +import info.globalcode.sql.dk.configuration.PropertyDeclaration;
1.8 import info.globalcode.sql.dk.formatting.Formatter;
1.9 import info.globalcode.sql.dk.formatting.FormatterContext;
1.10 import info.globalcode.sql.dk.formatting.FormatterException;
1.11 @@ -41,6 +42,8 @@
1.12 import java.io.PrintWriter;
1.13 import java.sql.SQLException;
1.14 import java.util.Collection;
1.15 +import java.util.Collections;
1.16 +import java.util.List;
1.17 import java.util.logging.Level;
1.18 import java.util.logging.LogRecord;
1.19 import java.util.logging.Logger;
1.20 @@ -215,6 +218,7 @@
1.21 dir.mkdir();
1.22 writeBashCompletionHelperFile(configuration.getDatabases(), new File(dir, "databases"));
1.23 writeBashCompletionHelperFile(configuration.getAllFormatters(), new File(dir, "formatters"));
1.24 + writeBashCompletionHelperFileForFormatterProperties(new File(dir, "formatter-properties"));
1.25 } catch (Exception e) {
1.26 log.log(Level.WARNING, "Unable to generate Bash completion helper files", e);
1.27 }
1.28 @@ -234,4 +238,29 @@
1.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});
1.30 }
1.31 }
1.32 +
1.33 + private void writeBashCompletionHelperFileForFormatterProperties(File formattersDir) throws ClassNotFoundException {
1.34 + if (Constants.CONFIG_FILE.lastModified() > formattersDir.lastModified()) {
1.35 + // TODO: delete old directory
1.36 + formattersDir.mkdir();
1.37 + for (FormatterDefinition fd : configuration.getAllFormatters()) {
1.38 + File formatterDir = new File(formattersDir, fd.getName());
1.39 + formatterDir.mkdir();
1.40 +
1.41 + Class<Formatter> formatterClass = (Class<Formatter>) Class.forName(fd.getClassName());
1.42 + List<Class<? extends Formatter>> hierarchy = Functions.getClassHierarchy(formatterClass, Formatter.class);
1.43 + Collections.reverse(hierarchy);
1.44 + hierarchy.stream().forEach((c) -> {
1.45 + for (PropertyDeclaration p : Functions.getPropertyDeclarations(c)) {
1.46 + File propertyDir = new File(formatterDir, p.name());
1.47 + propertyDir.mkdir();
1.48 + }
1.49 + });
1.50 + }
1.51 + log.log(Level.FINE, "Bash completion helper files was written in: {0}", formattersDir);
1.52 + } else {
1.53 + log.log(Level.FINER, "Not writing Bash completion helper directory: {0} because configuration {1} has not been changed", new Object[]{formattersDir, Constants.CONFIG_FILE});
1.54 + }
1.55 +
1.56 + }
1.57 }