license option: --license v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Mon, 16 Dec 2013 20:20:54 +0100
branchv_0
changeset 17d8ab8aece6f2
parent 16 5b8fcd35d4d6
child 18 7900bb1666f6
license option: --license
java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java
java/sql-dk/src/info/globalcode/sql/dk/Constants.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
java/sql-dk/src/info/globalcode/sql/dk/license.txt
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 16 20:01:37 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java	Mon Dec 16 20:20:54 2013 +0100
     1.3 @@ -38,8 +38,8 @@
     1.4  
     1.5  			/** Show info */
     1.6  			if (!options.getShowInfo().isEmpty()) {
     1.7 -				InfoLister infoLister = new InfoLister();
     1.8 -				infoLister.showInfo(options, System.err);
     1.9 +				InfoLister infoLister = new InfoLister(System.err);
    1.10 +				infoLister.showInfo(options);
    1.11  			}
    1.12  
    1.13  		} catch (CLIParserException e) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/Constants.java	Mon Dec 16 20:20:54 2013 +0100
     2.3 @@ -0,0 +1,30 @@
     2.4 +/**
     2.5 + * SQL-DK
     2.6 + * Copyright © 2013 František Kučera (frantovo.cz)
     2.7 + *
     2.8 + * This program is free software: you can redistribute it and/or modify
     2.9 + * it under the terms of the GNU General Public License as published by
    2.10 + * the Free Software Foundation, either version 3 of the License, or
    2.11 + * (at your option) any later version.
    2.12 + *
    2.13 + * This program is distributed in the hope that it will be useful,
    2.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    2.16 + * GNU General Public License for more details.
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License
    2.19 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
    2.20 + */
    2.21 +package info.globalcode.sql.dk;
    2.22 +
    2.23 +/**
    2.24 + *
    2.25 + * @author Ing. František Kučera (frantovo.cz)
    2.26 + */
    2.27 +public class Constants {
    2.28 +
    2.29 +	public static final String WEBSITE = "https://sql-dk.globalcode.info/";
    2.30 +
    2.31 +	private Constants() {
    2.32 +	}
    2.33 +}
     3.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Mon Dec 16 20:01:37 2013 +0100
     3.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Mon Dec 16 20:20:54 2013 +0100
     3.3 @@ -17,8 +17,12 @@
     3.4   */
     3.5  package info.globalcode.sql.dk;
     3.6  
     3.7 +import java.io.BufferedReader;
     3.8 +import java.io.InputStreamReader;
     3.9  import java.io.PrintStream;
    3.10  import java.util.EnumSet;
    3.11 +import java.util.logging.Level;
    3.12 +import java.util.logging.Logger;
    3.13  
    3.14  /**
    3.15   * Displays info like help, version etc.
    3.16 @@ -27,7 +31,14 @@
    3.17   */
    3.18  public class InfoLister {
    3.19  
    3.20 -	public void showInfo(CLIOptions options, PrintStream out) {
    3.21 +	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
    3.22 +	private PrintStream out;
    3.23 +
    3.24 +	public InfoLister(PrintStream out) {
    3.25 +		this.out = out;
    3.26 +	}
    3.27 +
    3.28 +	public void showInfo(CLIOptions options) {
    3.29  		EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
    3.30  		for (CLIOptions.INFO_TYPE infoType : infoTypes) {
    3.31  			switch (infoType) {
    3.32 @@ -35,29 +46,48 @@
    3.33  				 * TODO: implement show info
    3.34  				 */
    3.35  				case FORMATTERS:
    3.36 -					out.println("TODO: list available formatters");
    3.37 +					println("TODO: list available formatters");
    3.38  					break;
    3.39  				case HELP:
    3.40 -					out.println("TODO: show some help");
    3.41 +					println("TODO: show some help");
    3.42  					break;
    3.43  				case LICENSE:
    3.44 -					out.println("TODO: show license");
    3.45 +					printLicense();
    3.46  					break;
    3.47  				case TYPES:
    3.48 -					out.println("TODO: list supported types");
    3.49 +					println("TODO: list supported types");
    3.50  					break;
    3.51  				case VERSION:
    3.52 -					out.println("TODO: show version");
    3.53 +					println("TODO: show version");
    3.54  					break;
    3.55  				case DATABASES:
    3.56 -					out.println("TODO: list databases");
    3.57 +					println("TODO: list databases");
    3.58  					break;
    3.59  				case CONNECTION:
    3.60 -					out.println("TODO: test database connection: " + options.getDatabaseNameToTest());
    3.61 +					println("TODO: test database connection: " + options.getDatabaseNameToTest());
    3.62  					break;
    3.63  				default:
    3.64  					throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
    3.65  			}
    3.66  		}
    3.67  	}
    3.68 +
    3.69 +	private void printLicense() {
    3.70 +		try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) {
    3.71 +			while (true) {
    3.72 +				String line = license.readLine();
    3.73 +				if (line == null) {
    3.74 +					break;
    3.75 +				} else {
    3.76 +					println(line);
    3.77 +				}
    3.78 +			}
    3.79 +		} catch (Exception e) {
    3.80 +			log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e);
    3.81 +		}
    3.82 +	}
    3.83 +
    3.84 +	private void println(String line) {
    3.85 +		out.println(line);
    3.86 +	}
    3.87  }
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/license.txt	Mon Dec 16 20:20:54 2013 +0100
     4.3 @@ -0,0 +1,1 @@
     4.4 +../../../../../../../license/gpl.txt
     4.5 \ No newline at end of file