001package org.maltparser.core.helper;
002
003import java.io.IOException;
004import java.net.URL;
005import java.util.Properties;
006
007import org.maltparser.core.options.OptionManager;
008
009/**
010 * 
011 * 
012 * @author Johan Hall
013 */
014public class SystemInfo {
015        private static SystemInfo uniqueInstance = new SystemInfo();
016        private static String version;
017        private static String buildDate;
018
019        private SystemInfo() {
020                URL url = getClass().getResource("/appdata/release.properties");
021                if (url != null) {
022                        Properties properties = new Properties();
023                        try {
024                           properties.load(url.openStream());
025                        } catch (IOException e) {
026                                
027                        }
028                        version = properties.getProperty("version", "undef");
029                        buildDate = properties.getProperty("builddate", "undef");
030                } else {
031                        version = "undef";
032                        buildDate = "undef";
033                }
034        }
035
036        /**
037         * Returns a reference to the single instance.
038         */
039        public static SystemInfo instance() {
040                return uniqueInstance;
041        }
042
043        /**
044         * Returns the application header
045         * 
046         * @return the application header
047         */
048        public static String header() {
049                StringBuilder sb = new StringBuilder();
050                sb
051                                .append("-----------------------------------------------------------------------------\n"
052                                                + "                          MaltParser "+ version + "                             \n"
053                                                + "-----------------------------------------------------------------------------\n"
054                                                + "         MALT (Models and Algorithms for Language Technology) Group          \n"
055                                                + "             Vaxjo University and Uppsala University                         \n"
056                                                + "                             Sweden                                          \n"
057                                                + "-----------------------------------------------------------------------------\n");
058                return sb.toString();
059        }
060
061        /**
062         * Returns a short version of the help
063         * 
064         * @return a short version of the help
065         */
066        public static String shortHelp() {
067                StringBuilder sb = new StringBuilder();
068                sb.append("\n"
069                                + "Usage: \n"
070                                + "   java -jar maltparser-"+version+".jar -f <path to option file> <options>\n"
071                                + "   java -jar maltparser-"+version+".jar -h for more help and options\n\n"
072                                + OptionManager.instance().getOptionDescriptions()
073                                                .toStringOptionGroup("system")
074                                + "Documentation: docs/index.html\n");
075                return sb.toString();
076        }
077
078
079        /**
080         * Returns the version number as string
081         * 
082         * @return the version number as string
083         */
084        public static String getVersion() {
085                return version;
086        }
087
088        /**
089         * Returns the build date
090         * 
091         * @return the build date
092         */
093        public static String getBuildDate() {
094                return buildDate;
095        }
096}