InfoLister: new listings: --list-java-properties and --list-environment-variables v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 24 May 2015 19:10:25 +0200
branchv_0
changeset 200 2e351d7c26c4
parent 199 88de2602deb3
child 201 d3db5a72a089
InfoLister: new listings: --list-java-properties and --list-environment-variables
java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
scripts/help_generator.pl
--- 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<String> databaseNamesToTest = new LinkedHashSet<>();
-	private Set<String> databaseNamesToListProperties = new LinkedHashSet<>();
+	private final Set<String> databaseNamesToTest = new LinkedHashSet<>();
+	private final Set<String> 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 {
 
--- 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
--- 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<Object[]> data = new ArrayList<>();
+		for (Entry<Object, Object> 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<Object[]> data = new ArrayList<>();
+		for (Entry<String, String> 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 {
--- 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/);
 }