# HG changeset patch # User František Kučera # Date 1432487425 -7200 # Node ID 2e351d7c26c499488f609590136a0bcf223473cc # Parent 88de2602deb372a0580ee2aa328f461dce726b68 InfoLister: new listings: --list-java-properties and --list-environment-variables diff -r 88de2602deb3 -r 2e351d7c26c4 java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Sun May 24 18:45:46 2015 +0200 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java Sun May 24 19:10:25 2015 +0200 @@ -45,14 +45,14 @@ public static final String DEFAULT_NAME_SUFFIX = "(?=([^\\w]|$))"; private String sql; private String databaseName; - private Set databaseNamesToTest = new LinkedHashSet<>(); - private Set databaseNamesToListProperties = new LinkedHashSet<>(); + private final Set databaseNamesToTest = new LinkedHashSet<>(); + private final Set databaseNamesToListProperties = new LinkedHashSet<>(); private String namePrefix = DEFAULT_NAME_PREFIX; private String nameSuffix = DEFAULT_NAME_SUFFIX; private String formatterName; private boolean batch; - private Properties formatterProperties = new Properties(); - private Properties databaseProperties = new Properties(); + private final Properties formatterProperties = new Properties(); + private final Properties databaseProperties = new Properties(); public enum MODE { diff -r 88de2602deb3 -r 2e351d7c26c4 java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun May 24 18:45:46 2015 +0200 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java Sun May 24 19:10:25 2015 +0200 @@ -129,6 +129,12 @@ case Tokens.INFO_LICENSE: options.addShowInfo(InfoType.LICENSE); break; + case Tokens.INFO_JAVA_PROPERTIES: + options.addShowInfo(InfoType.JAVA_PROPERTIES); + break; + case Tokens.INFO_ENVIRONMENT_VARIABLES: + options.addShowInfo(InfoType.ENVIRONMENT_VARIABLES); + break; case Tokens.INFO_TYPES: options.addShowInfo(InfoType.TYPES); break; @@ -182,6 +188,8 @@ public static final String INFO_HELP = "--help"; // bash-completion:option // help: print this help public static final String INFO_VERSION = "--version"; // bash-completion:option // help: print version info public static final String INFO_LICENSE = "--license"; // bash-completion:option // help: print license + public static final String INFO_JAVA_PROPERTIES = "--list-java-properties"; // bash-completion:option // help: list of Java system properties + public static final String INFO_ENVIRONMENT_VARIABLES = "--list-environment-variables"; // bash-completion:option // help: list of environment variables public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option // help: print list of available formatters public static final String INFO_TYPES = "--list-types"; // bash-completion:option // help: print list of available data types public static final String INFO_JDBC_DRIVERS = "--list-jdbc-drivers"; // bash-completion:option // help: list of available JDBC drivers diff -r 88de2602deb3 -r 2e351d7c26c4 java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sun May 24 18:45:46 2015 +0200 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Sun May 24 19:10:25 2015 +0200 @@ -42,6 +42,7 @@ import java.util.EnumSet; import java.util.HashSet; import java.util.List; +import java.util.Map.Entry; import java.util.ServiceLoader; import java.util.Set; import java.util.concurrent.ExecutorService; @@ -88,6 +89,8 @@ case DATABASES: case FORMATTERS: case TYPES: + case JAVA_PROPERTIES: + case ENVIRONMENT_VARIABLES: formattinNeeded = true; break; } @@ -116,6 +119,24 @@ } } + private void listJavaProperties() throws FormatterException, ConfigurationException { + ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("value", SQLType.VARCHAR)); + List data = new ArrayList<>(); + for (Entry e : System.getProperties().entrySet()) { + data.add(new Object[]{e.getKey(), e.getValue()}); + } + printTable(formatter, header, "-- Java system properties", null, data); + } + + private void listEnvironmentVariables() throws FormatterException, ConfigurationException { + ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("value", SQLType.VARCHAR)); + List data = new ArrayList<>(); + for (Entry e : System.getenv().entrySet()) { + data.add(new Object[]{e.getKey(), e.getValue()}); + } + printTable(formatter, header, "-- environment variables", null, data); + } + private void listFormatters() throws ConfigurationException, FormatterException { ColumnsHeader header = constructHeader( new HeaderField("name", SQLType.VARCHAR), @@ -497,6 +518,18 @@ infoLister.printResource(Constants.LICENSE_FILE); } }, + JAVA_PROPERTIES { + @Override + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { + infoLister.listJavaProperties(); + } + }, + ENVIRONMENT_VARIABLES { + @Override + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { + infoLister.listEnvironmentVariables(); + } + }, FORMATTERS { @Override public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { diff -r 88de2602deb3 -r 2e351d7c26c4 scripts/help_generator.pl --- a/scripts/help_generator.pl Sun May 24 18:45:46 2015 +0200 +++ b/scripts/help_generator.pl Sun May 24 19:10:25 2015 +0200 @@ -32,7 +32,7 @@ '; while (<>) { - print " " . sprintf("%-24s", $1) . "$3\n" if (/"(.*?)".*? \/\/\s*bash-completion:option(\s*\/\/\s*help:(.*))?/); + print " " . sprintf("%-32s", $1) . "$3\n" if (/"(.*?)".*? \/\/\s*bash-completion:option(\s*\/\/\s*help:(.*))?/); last if (/\/\/\s*help:exit-codes/); }