Example usage for java.lang Throwable getMessage

List of usage examples for java.lang Throwable getMessage

Introduction

In this page you can find the example usage for java.lang Throwable getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.cic.datacrawl.ui.Main.java

/**
 * Main entry point. Creates a debugger attached to a Rhino
 * {@link com.cic.datacrawl.ui.shell.Shell} shell session.
 *///from w  w  w. ja v  a  2 s . c  o  m
public static void main(final String[] args) {
    if (System.getProperties().get("os.name").toString().toLowerCase().indexOf("linux") >= 0)
        System.setProperty("sun.awt.xembedserver", "true");
    try {
        String path = null;
        boolean reflash = true;
        if (args != null && args.length > 0) {
            if (args[0].equalsIgnoreCase("-h")) {
                System.out.println("Command Format: \n" + "\t%JAVA_HOME%\\BIN\\JAVA -jar homepageCatcher.jar "
                        + "[-d config path]\n" + "\t%JAVA_HOME%\\BIN\\JAVA -jar homepageCatcher.jar "
                        + "[-d config path_1;path_2;....;path_n]\n");
            }

            int pathIndex = ArrayUtils.indexOf(args, "-d");
            if (pathIndex >= 0) {
                try {
                    path = args[pathIndex + 1];
                    File f = new File(path);
                    if (!f.exists()) {
                        LOG.warn("Invalid path of configuration. " + "Using default configuration.");
                    }
                } catch (Throwable e) {
                    LOG.warn("Invalid path of configuration. " + "Using default configuration.");
                }
            }
            // int reflashIndex = ArrayUtils.indexOf(args, "-r");
            //
            // reflash = new Boolean(args[reflashIndex + 1]).booleanValue();
        }
        if (path == null || path.trim().length() == 0)
            path = Config.INSTALL_PATH + File.separator + "config" + File.separator + "beans";

        LOG.debug("Config Path: \"" + path + "\"");
        // ?IOC
        // ????
        // ?
        ApplicationContext.initialiaze(path, reflash);
        System.setProperty(ApplicationContext.CONFIG_PATH, path);
        // js???
        InitializerRegister.getInstance().execute();
        // ???
        //VerifyCodeInputDialog.init();
        // ??
        //initTestData();
        // ?GUI
        Thread thread = new Thread(new Runnable() {

            @Override
            public void run() {
                startupGUI(args);
            }
        });
        thread.setName("UI_Thread");
        thread.start();

    } catch (Throwable e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:net.rptools.maptool.client.MapTool.java

public static void main(String[] args) {
    if (MAC_OS_X) {
        // On OSX the menu bar at the top of the screen can be enabled at any time, but the
        // title (ie. name of the application) has to be set before the GUI is initialized (by
        // creating a frame, loading a splash screen, etc).  So we do it here.
        System.setProperty("apple.laf.useScreenMenuBar", "true");
        System.setProperty("com.apple.mrj.application.apple.menu.about.name", "About MapTool...");
        System.setProperty("apple.awt.brushMetalLook", "true");
    }//from  w  ww  . ja  v  a  2  s  .c o m
    // Before anything else, create a place to store all the data
    try {
        AppUtil.getAppHome();
    } catch (Throwable t) {
        t.printStackTrace();

        // Create an empty frame so there's something to click on if the dialog goes in the background
        JFrame frame = new JFrame();
        SwingUtil.centerOnScreen(frame);
        frame.setVisible(true);

        String errorCreatingDir = "Error creating data directory";
        log.error(errorCreatingDir, t);
        JOptionPane.showMessageDialog(frame, t.getMessage(), errorCreatingDir, JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }
    verifyJavaVersion();

    configureLogging();

    // System properties
    System.setProperty("swing.aatext", "true");
    // System.setProperty("sun.java2d.opengl", "true");

    final SplashScreen splash = new SplashScreen(SPLASH_IMAGE, getVersion());
    splash.showSplashScreen();

    // Protocol handlers
    // cp:// is registered by the RPTURLStreamHandlerFactory constructor (why?)
    RPTURLStreamHandlerFactory factory = new RPTURLStreamHandlerFactory();
    factory.registerProtocol("asset", new AssetURLStreamHandler());
    URL.setURLStreamHandlerFactory(factory);

    final Toolkit tk = Toolkit.getDefaultToolkit();
    tk.getSystemEventQueue().push(new MapToolEventQueue());

    // LAF
    try {
        // If we are running under Mac OS X then save native menu bar look & feel components
        // Note the order of creation for the AppMenuBar, this specific chronology
        // allows the system to set up system defaults before we go and modify things.
        // That is, please don't move these lines around unless you test the result on windows and mac
        String lafname;
        if (MAC_OS_X) {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            menuBar = new AppMenuBar();
            lafname = "net.rptools.maptool.client.TinyLookAndFeelMac";
            UIManager.setLookAndFeel(lafname);
            macOSXicon();
        }
        // If running on Windows based OS, CJK font is broken when using TinyLAF.
        //         else if (WINDOWS) {
        //            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        //            menuBar = new AppMenuBar();
        //         }
        else {
            lafname = "de.muntjak.tinylookandfeel.TinyLookAndFeel";
            UIManager.setLookAndFeel(lafname);
            menuBar = new AppMenuBar();
        }
        // After the TinyLAF library is initialized, look to see if there is a Default.theme
        // in our AppHome directory and load it if there is.  Unfortunately, changing the
        // search path for the default theme requires subclassing TinyLAF and because
        // we have both the original and a Mac version that gets cumbersome.  (Really
        // the Mac version should use the default and then install the keystroke differences
        // but what we have works and I'm loathe to go playing with it at 1.3b87 -- yes, 87!)
        File f = AppUtil.getAppHome("config");
        if (f.exists()) {
            File f2 = new File(f, "Default.theme");
            if (f2.exists()) {
                if (Theme.loadTheme(f2)) {
                    // re-install the Tiny Look and Feel
                    UIManager.setLookAndFeel(lafname);

                    // Update the ComponentUIs for all Components. This
                    // needs to be invoked for all windows.
                    //SwingUtilities.updateComponentTreeUI(rootComponent);
                }
            }
        }

        com.jidesoft.utils.Lm.verifyLicense("Trevor Croft", "rptools", "5MfIVe:WXJBDrToeLWPhMv3kI2s3VFo");
        LookAndFeelFactory.addUIDefaultsCustomizer(new LookAndFeelFactory.UIDefaultsCustomizer() {
            public void customize(UIDefaults defaults) {
                // Remove red border around menus
                defaults.put("PopupMenu.foreground", Color.lightGray);
            }
        });
        LookAndFeelFactory.installJideExtension(LookAndFeelFactory.XERTO_STYLE);

        /****************************************************************************
         * For TinyLAF 1.3.04 this is how the color was changed for a
         * button.
         */
        // Theme.buttonPressedColor[Theme.style] = new ColorReference(Color.gray);

        /****************************************************************************
         * And this is how it's done in TinyLAF 1.4.0 (no idea about the
         * intervening versions).
         */
        Theme.buttonPressedColor = new SBReference(Color.GRAY, 0, -6, SBReference.SUB3_COLOR);

        configureJide();
    } catch (Exception e) {
        MapTool.showError("msg.error.lafSetup", e);
        System.exit(1);
    }

    /**
     * This is a tweak that makes the Chinese version work better.
     * <p>
     * Consider reviewing <a
     * href="http://en.wikipedia.org/wiki/CJK_characters"
     * >http://en.wikipedia.org/wiki/CJK_characters</a> before making
     * changes. And http://www.scarfboy.com/coding/unicode-tool is also a
     * really cool site.
     */
    if (Locale.CHINA.equals(Locale.getDefault())) {
        // The following font name appears to be "Sim Sun".  It can be downloaded
        // from here:  http://fr.cooltext.com/Fonts-Unicode-Chinese
        Font f = new Font("\u65B0\u5B8B\u4F53", Font.PLAIN, 12);
        FontUIResource fontRes = new FontUIResource(f);
        for (Enumeration<Object> keys = UIManager.getDefaults().keys(); keys.hasMoreElements();) {
            Object key = keys.nextElement();
            Object value = UIManager.get(key);
            if (value instanceof FontUIResource)
                UIManager.put(key, fontRes);
        }
    }

    // Draw frame contents on resize
    tk.setDynamicLayout(true);

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            initialize();
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    clientFrame.setVisible(true);
                    splash.hideSplashScreen();
                    EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            postInitialize();
                        }
                    });
                }
            });
        }
    });
    // new Thread(new HeapSpy()).start();
}

From source file:com.zimbra.cs.zclient.ZMailboxUtil.java

public static void main(String args[]) throws IOException, ServiceException {
    CliUtil.toolSetup();//  w w  w.  j av a  2s. c  o  m
    SoapTransport.setDefaultUserAgent("zmmailbox", BuildInfo.VERSION);

    ZMailboxUtil pu = new ZMailboxUtil();
    CommandLineParser parser = new GnuParser();
    Options options = new Options();
    options.addOption("a", "admin", true, "admin account name to auth as");
    options.addOption("z", "zadmin", false,
            "use zimbra admin name/password from localconfig for admin/password");
    options.addOption("h", "help", false, "display usage");
    options.addOption("f", "file", true, "use file as input stream");
    options.addOption("u", "url", true, "http[s]://host[:port] of server to connect to");
    options.addOption("r", "protocol", true, "protocol to use for request/response [soap11, soap12, json]");
    options.addOption("m", "mailbox", true, "mailbox to open");
    options.addOption(null, "auth", true, "account name to auth as; defaults to -m unless -A is used");
    options.addOption("A", "admin-priv", false, "execute requests with admin privileges");
    options.addOption("p", "password", true, "auth password");
    options.addOption("P", "passfile", true, "filename with password in it");
    options.addOption("t", "timeout", true, "timeout (in seconds)");
    options.addOption("v", "verbose", false, "verbose mode");
    options.addOption("d", "debug", false, "debug mode");
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);

    CommandLine cl = null;
    boolean err = false;

    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        stderr.println("error: " + pe.getMessage());
        err = true;
    }

    if (err || cl.hasOption('h')) {
        pu.usage();
    }

    try {
        boolean isAdmin = false;
        pu.setVerbose(cl.hasOption('v'));
        if (cl.hasOption('a')) {
            pu.setAdminAccountName(cl.getOptionValue('a'));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }
        if (cl.hasOption('z')) {
            pu.setAdminAccountName(LC.zimbra_ldap_user.value());
            pu.setPassword(LC.zimbra_ldap_password.value());
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }

        if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE))
            pu.usage();
        if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
            pu.setAdminAuthToken(ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN)));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }
        if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
            String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
            pu.setAdminAuthToken(ZAuthToken.fromJSONString(authToken));
            pu.setUrl(DEFAULT_ADMIN_URL, true);
            isAdmin = true;
        }

        String authAccount, targetAccount;
        if (cl.hasOption('m')) {
            if (!cl.hasOption('p') && !cl.hasOption('P') && !cl.hasOption('y') && !cl.hasOption('Y')
                    && !cl.hasOption('z')) {
                throw ZClientException.CLIENT_ERROR("-m requires one of the -p/-P/-y/-Y/-z options", null);
            }
            targetAccount = cl.getOptionValue('m');
        } else {
            targetAccount = null;
        }
        if ((cl.hasOption("A") || cl.hasOption("auth")) && !cl.hasOption('m')) {
            throw ZClientException.CLIENT_ERROR("-A/--auth requires -m", null);
        }
        if (cl.hasOption("A")) {
            if (!isAdmin) {
                throw ZClientException.CLIENT_ERROR("-A requires admin auth", null);
            }
            if (cl.hasOption("auth")) {
                throw ZClientException.CLIENT_ERROR("-A cannot be combined with --auth", null);
            }
            authAccount = null;
        } else if (cl.hasOption("auth")) {
            authAccount = cl.getOptionValue("auth");
        } else {
            // default case
            authAccount = targetAccount;
        }
        if (!StringUtil.isNullOrEmpty(authAccount))
            pu.setAuthAccountName(authAccount);
        if (!StringUtil.isNullOrEmpty(targetAccount))
            pu.setTargetAccountName(targetAccount);

        if (cl.hasOption('u'))
            pu.setUrl(cl.getOptionValue('u'), isAdmin);
        if (cl.hasOption('p'))
            pu.setPassword(cl.getOptionValue('p'));
        if (cl.hasOption('P')) {
            pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
        }
        if (cl.hasOption('d'))
            pu.setDebug(true);

        if (cl.hasOption('t'))
            pu.setTimeout(cl.getOptionValue('t'));

        args = cl.getArgs();

        pu.setInteractive(args.length < 1);

        pu.initMailbox();
        if (args.length < 1) {
            InputStream is = null;
            if (cl.hasOption('f')) {
                is = new FileInputStream(cl.getOptionValue('f'));
            } else {
                if (LC.command_line_editing_enabled.booleanValue()) {
                    try {
                        CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmmailbox_history");
                    } catch (IOException e) {
                        System.err.println("Command line editing will be disabled: " + e);
                        if (pu.mGlobalVerbose) {
                            e.printStackTrace(System.err);
                        }
                    }
                }
                is = System.in; // This has to happen last because JLine modifies System.in.
            }
            pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
        } else {
            pu.execute(args);
        }
    } catch (ServiceException e) {
        Throwable cause = e.getCause();
        stderr.println("ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? ""
                : " (cause: " + cause.getClass().getName() + " " + cause.getMessage() + ")"));
        if (pu.mGlobalVerbose)
            e.printStackTrace(stderr);
        System.exit(2);
    }
}

From source file:com.zimbra.cs.account.ProvUtil.java

public static void main(String args[]) throws IOException, ServiceException {
    CliUtil.setCliSoapHttpTransportTimeout();
    ZimbraLog.toolSetupLog4jConsole("INFO", true, false); // send all logs to stderr
    SocketFactories.registerProtocols();

    SoapTransport.setDefaultUserAgent("zmprov", BuildInfo.VERSION);

    ProvUtil pu = new ProvUtil();
    CommandLineParser parser = new PosixParser();
    Options options = new Options();

    options.addOption("h", "help", false, "display usage");
    options.addOption("f", "file", true, "use file as input stream");
    options.addOption("s", "server", true, "host[:port] of server to connect to");
    options.addOption("l", "ldap", false, "provision via LDAP");
    options.addOption("L", "logpropertyfile", true, "log4j property file");
    options.addOption("a", "account", true, "account name (not used with --ldap)");
    options.addOption("p", "password", true, "password for account");
    options.addOption("P", "passfile", true, "filename with password in it");
    options.addOption("z", "zadmin", false,
            "use zimbra admin name/password from localconfig for account/password");
    options.addOption("v", "verbose", false, "verbose mode");
    options.addOption("d", "debug", false, "debug mode (SOAP request and response payload)");
    options.addOption("D", "debughigh", false, "debug mode (SOAP req/resp payload and http headers)");
    options.addOption("m", "master", false, "use LDAP master (has to be used with --ldap)");
    options.addOption("t", "temp", false,
            "write binary values to files in temporary directory specified in localconfig key zmprov_tmp_directory");
    options.addOption("r", "replace", false, "allow replacement of multi-valued attr value");
    options.addOption("fd", "forcedisplay", false, "force display attr value");
    options.addOption(SoapCLI.OPT_AUTHTOKEN);
    options.addOption(SoapCLI.OPT_AUTHTOKENFILE);

    CommandLine cl = null;//from w w  w  . j  a v a2 s .  co  m
    boolean err = false;

    try {
        cl = parser.parse(options, args, true);
    } catch (ParseException pe) {
        printError("error: " + pe.getMessage());
        err = true;
    }

    if (err || cl.hasOption('h')) {
        pu.usage();
    }

    if (cl.hasOption('l') && cl.hasOption('s')) {
        printError("error: cannot specify both -l and -s at the same time");
        System.exit(2);
    }

    pu.setVerbose(cl.hasOption('v'));
    if (cl.hasOption('l')) {
        pu.setUseLdap(true, cl.hasOption('m'));
    }

    if (cl.hasOption('L')) {
        if (cl.hasOption('l')) {
            ZimbraLog.toolSetupLog4j("INFO", cl.getOptionValue('L'));
        } else {
            printError("error: cannot specify -L when -l is not specified");
            System.exit(2);
        }
    }

    if (cl.hasOption('z')) {
        pu.setAccount(LC.zimbra_ldap_user.value());
        pu.setPassword(LC.zimbra_ldap_password.value());
    }

    if (cl.hasOption(SoapCLI.O_AUTHTOKEN) && cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
        printError("error: cannot specify " + SoapCLI.O_AUTHTOKEN + " when " + SoapCLI.O_AUTHTOKENFILE
                + " is specified");
        System.exit(2);
    }
    if (cl.hasOption(SoapCLI.O_AUTHTOKEN)) {
        ZAuthToken zat = ZAuthToken.fromJSONString(cl.getOptionValue(SoapCLI.O_AUTHTOKEN));
        pu.setAuthToken(zat);
    }
    if (cl.hasOption(SoapCLI.O_AUTHTOKENFILE)) {
        String authToken = StringUtil.readSingleLineFromFile(cl.getOptionValue(SoapCLI.O_AUTHTOKENFILE));
        ZAuthToken zat = ZAuthToken.fromJSONString(authToken);
        pu.setAuthToken(zat);
    }

    if (cl.hasOption('s')) {
        pu.setServer(cl.getOptionValue('s'));
    }
    if (cl.hasOption('a')) {
        pu.setAccount(cl.getOptionValue('a'));
    }
    if (cl.hasOption('p')) {
        pu.setPassword(cl.getOptionValue('p'));
    }
    if (cl.hasOption('P')) {
        pu.setPassword(StringUtil.readSingleLineFromFile(cl.getOptionValue('P')));
    }

    if (cl.hasOption('d') && cl.hasOption('D')) {
        printError("error: cannot specify both -d and -D at the same time");
        System.exit(2);
    }
    if (cl.hasOption('D')) {
        pu.setDebug(SoapDebugLevel.high);
    } else if (cl.hasOption('d')) {
        pu.setDebug(SoapDebugLevel.normal);
    }

    if (!pu.useLdap() && cl.hasOption('m')) {
        printError("error: cannot specify -m when -l is not specified");
        System.exit(2);
    }

    if (cl.hasOption('t')) {
        pu.setOutputBinaryToFile(true);
    }

    if (cl.hasOption('r')) {
        pu.setAllowMultiValuedAttrReplacement(true);
    }

    if (cl.hasOption("fd")) {
        pu.setForceDisplayAttrValue(true);
    }

    args = recombineDecapitatedAttrs(cl.getArgs(), options, args);

    try {
        if (args.length < 1) {
            pu.initProvisioning();
            InputStream is = null;
            if (cl.hasOption('f')) {
                pu.setBatchMode(true);
                is = new FileInputStream(cl.getOptionValue('f'));
            } else {
                if (LC.command_line_editing_enabled.booleanValue()) {
                    try {
                        CliUtil.enableCommandLineEditing(LC.zimbra_home.value() + "/.zmprov_history");
                    } catch (IOException e) {
                        errConsole.println("Command line editing will be disabled: " + e);
                        if (pu.verboseMode) {
                            e.printStackTrace(errConsole);
                        }
                    }
                }

                // This has to happen last because JLine modifies System.in.
                is = System.in;
            }
            pu.interactive(new BufferedReader(new InputStreamReader(is, "UTF-8")));
        } else {
            Command cmd = pu.lookupCommand(args[0]);
            if (cmd == null) {
                pu.usage();
            }
            if (cmd.isDeprecated()) {
                pu.deprecated();
            }
            if (pu.forceLdapButDontRequireUseLdapOption(cmd)) {
                pu.setUseLdap(true, false);
            }

            if (pu.needProvisioningInstance(cmd)) {
                pu.initProvisioning();
            }

            try {
                if (!pu.execute(args)) {
                    pu.usage();
                }
            } catch (ArgException e) {
                pu.usage();
            }
        }
    } catch (ServiceException e) {
        Throwable cause = e.getCause();
        String errText = "ERROR: " + e.getCode() + " (" + e.getMessage() + ")" + (cause == null ? ""
                : " (cause: " + cause.getClass().getName() + " " + cause.getMessage() + ")");

        printError(errText);

        if (pu.verboseMode) {
            e.printStackTrace(errConsole);
        }
        System.exit(2);
    }
}

From source file:be.ibridge.kettle.spoon.Spoon.java

/**
 * This is the main procedure for Spoon.
 * //  ww  w  . ja va2 s . c om
 * @param a Arguments are available in the "Get System Info" step.
 */
public static void main(String[] a) throws KettleException {
    EnvUtil.environmentInit();
    ArrayList args = new ArrayList();
    for (int i = 0; i < a.length; i++)
        args.add(a[i]);

    Display display = new Display();

    Splash splash = new Splash(display);

    StringBuffer optionRepname, optionUsername, optionPassword, optionJobname, optionTransname, optionFilename,
            optionDirname, optionLogfile, optionLoglevel;

    CommandLineOption options[] = new CommandLineOption[] {
            new CommandLineOption("rep", "Repository name", optionRepname = new StringBuffer()),
            new CommandLineOption("user", "Repository username", optionUsername = new StringBuffer()),
            new CommandLineOption("pass", "Repository password", optionPassword = new StringBuffer()),
            new CommandLineOption("job", "The name of the job to launch", optionJobname = new StringBuffer()),
            new CommandLineOption("trans", "The name of the transformation to launch",
                    optionTransname = new StringBuffer()),
            new CommandLineOption("dir", "The directory (don't forget the leading /)",
                    optionDirname = new StringBuffer()),
            new CommandLineOption("file", "The filename (Transformation in XML) to launch",
                    optionFilename = new StringBuffer()),
            new CommandLineOption("level",
                    "The logging level (Basic, Detailed, Debug, Rowlevel, Error, Nothing)",
                    optionLoglevel = new StringBuffer()),
            new CommandLineOption("logfile", "The logging file to write to",
                    optionLogfile = new StringBuffer()),
            new CommandLineOption("log", "The logging file to write to (deprecated)",
                    optionLogfile = new StringBuffer(), false, true), };

    // Parse the options...
    CommandLineOption.parseArguments(args, options);

    String kettleRepname = Const.getEnvironmentVariable("KETTLE_REPOSITORY", null);
    String kettleUsername = Const.getEnvironmentVariable("KETTLE_USER", null);
    String kettlePassword = Const.getEnvironmentVariable("KETTLE_PASSWORD", null);

    if (!Const.isEmpty(kettleRepname))
        optionRepname = new StringBuffer(kettleRepname);
    if (!Const.isEmpty(kettleUsername))
        optionUsername = new StringBuffer(kettleUsername);
    if (!Const.isEmpty(kettlePassword))
        optionPassword = new StringBuffer(kettlePassword);

    // Before anything else, check the runtime version!!!
    String version = Const.JAVA_VERSION;
    if ("1.4".compareToIgnoreCase(version) > 0) {
        System.out.println("The System is running on Java version " + version);
        System.out.println("Unfortunately, it needs version 1.4 or higher to run.");
        return;
    }

    // Set default Locale:
    Locale.setDefault(Const.DEFAULT_LOCALE);

    LogWriter log;
    LogWriter.setConsoleAppenderDebug();
    if (Const.isEmpty(optionLogfile)) {
        log = LogWriter.getInstance(Const.SPOON_LOG_FILE, false, LogWriter.LOG_LEVEL_BASIC);
    } else {
        log = LogWriter.getInstance(optionLogfile.toString(), true, LogWriter.LOG_LEVEL_BASIC);
    }

    if (log.getRealFilename() != null)
        log.logBasic(APP_NAME, Messages.getString("Spoon.Log.LoggingToFile") + log.getRealFilename());//"Logging goes to "

    if (!Const.isEmpty(optionLoglevel)) {
        log.setLogLevel(optionLoglevel.toString());
        log.logBasic(APP_NAME, Messages.getString("Spoon.Log.LoggingAtLevel") + log.getLogLevelDesc());//"Logging is at level : "
    }

    /* Load the plugins etc.*/
    StepLoader stloader = StepLoader.getInstance();
    if (!stloader.read()) {
        log.logError(APP_NAME, Messages.getString("Spoon.Log.ErrorLoadingAndHaltSystem"));//Error loading steps & plugins... halting Spoon!
        return;
    }

    /* Load the plugins etc. we need to load jobentry*/
    JobEntryLoader jeloader = JobEntryLoader.getInstance();
    if (!jeloader.read()) {
        log.logError("Spoon", "Error loading job entries & plugins... halting Kitchen!");
        return;
    }

    final Spoon spoon = new Spoon(log, display, null);
    staticSpoon = spoon;
    spoon.setDestroy(true);
    spoon.setArguments((String[]) args.toArray(new String[args.size()]));

    log.logBasic(APP_NAME, Messages.getString("Spoon.Log.MainWindowCreated"));//Main window is created.

    RepositoryMeta repositoryMeta = null;
    UserInfo userinfo = null;

    if (Const.isEmpty(optionRepname) && Const.isEmpty(optionFilename)
            && spoon.props.showRepositoriesDialogAtStartup()) {
        log.logBasic(APP_NAME, Messages.getString("Spoon.Log.AskingForRepository"));//"Asking for repository"

        int perms[] = new int[] { PermissionMeta.TYPE_PERMISSION_TRANSFORMATION,
                PermissionMeta.TYPE_PERMISSION_JOB };
        splash.hide();
        RepositoriesDialog rd = new RepositoriesDialog(spoon.disp, perms,
                Messages.getString("Spoon.Application.Name"));//"Spoon"
        if (rd.open()) {
            repositoryMeta = rd.getRepository();
            userinfo = rd.getUser();
            if (!userinfo.useTransformations()) {
                MessageBox mb = new MessageBox(spoon.shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(Messages.getString("Spoon.Dialog.RepositoryUserCannotWork.Message"));//"Sorry, this repository user can't work with transformations from the repository."
                mb.setText(Messages.getString("Spoon.Dialog.RepositoryUserCannotWork.Title"));//"Error!"
                mb.open();

                userinfo = null;
                repositoryMeta = null;
            }
        } else {
            // Exit point: user pressed CANCEL!
            if (rd.isCancelled()) {
                splash.dispose();
                spoon.quitFile();
                return;
            }
        }
    }

    try {
        // Read kettle transformation specified on command-line?
        if (!Const.isEmpty(optionRepname) || !Const.isEmpty(optionFilename)) {
            if (!Const.isEmpty(optionRepname)) {
                RepositoriesMeta repsinfo = new RepositoriesMeta(log);
                if (repsinfo.readData()) {
                    repositoryMeta = repsinfo.findRepository(optionRepname.toString());
                    if (repositoryMeta != null) {
                        // Define and connect to the repository...
                        spoon.rep = new Repository(log, repositoryMeta, userinfo);
                        if (spoon.rep.connect(Messages.getString("Spoon.Application.Name")))//"Spoon"
                        {
                            if (Const.isEmpty(optionDirname))
                                optionDirname = new StringBuffer(RepositoryDirectory.DIRECTORY_SEPARATOR);

                            // Check username, password
                            spoon.rep.userinfo = new UserInfo(spoon.rep, optionUsername.toString(),
                                    optionPassword.toString());

                            if (spoon.rep.userinfo.getID() > 0) {
                                // Options /file, /job and /trans are mutually exclusive
                                int t = (Const.isEmpty(optionFilename) ? 0 : 1)
                                        + (Const.isEmpty(optionJobname) ? 0 : 1)
                                        + (Const.isEmpty(optionTransname) ? 0 : 1);
                                if (t > 1) {
                                    log.logError(APP_NAME, Messages.getString("Spoon.Log.MutuallyExcusive")); // "More then one mutually exclusive options /file, /job and /trans are specified."                                    
                                } else if (t == 1) {
                                    if (!Const.isEmpty(optionFilename)) {
                                        spoon.openFile(optionFilename.toString(), false);
                                    } else {
                                        // OK, if we have a specified job or transformation, try to load it...
                                        // If not, keep the repository logged in.
                                        RepositoryDirectory repdir = spoon.rep.getDirectoryTree()
                                                .findDirectory(optionDirname.toString());
                                        if (repdir == null) {
                                            log.logError(APP_NAME, Messages.getString(
                                                    "Spoon.Log.UnableFindDirectory", optionDirname.toString())); //"Can't find directory ["+dirname+"] in the repository."
                                        } else {
                                            if (!Const.isEmpty(optionTransname)) {
                                                TransMeta transMeta = new TransMeta(spoon.rep,
                                                        optionTransname.toString(), repdir);
                                                transMeta.setFilename(optionRepname.toString());
                                                transMeta.clearChanged();
                                                spoon.addSpoonGraph(transMeta);
                                            } else {
                                                // Try to load a specified job if any
                                                JobMeta jobMeta = new JobMeta(log, spoon.rep,
                                                        optionJobname.toString(), repdir);
                                                jobMeta.setFilename(optionRepname.toString());
                                                jobMeta.clearChanged();
                                                spoon.addChefGraph(jobMeta);
                                            }
                                        }
                                    }
                                }
                            } else {
                                log.logError(APP_NAME, Messages.getString("Spoon.Log.UnableVerifyUser"));//"Can't verify username and password."
                                spoon.rep.disconnect();
                                spoon.rep = null;
                            }
                        } else {
                            log.logError(APP_NAME, Messages.getString("Spoon.Log.UnableConnectToRepository"));//"Can't connect to the repository."
                        }
                    } else {
                        log.logError(APP_NAME, Messages.getString("Spoon.Log.NoRepositoryRrovided"));//"No repository provided, can't load transformation."
                    }
                } else {
                    log.logError(APP_NAME, Messages.getString("Spoon.Log.NoRepositoriesDefined"));//"No repositories defined on this system."
                }
            } else if (!Const.isEmpty(optionFilename)) {
                spoon.openFile(optionFilename.toString(), false);
            }
        } else // Normal operations, nothing on the commandline...
        {
            // Can we connect to the repository?
            if (repositoryMeta != null && userinfo != null) {
                spoon.rep = new Repository(log, repositoryMeta, userinfo);
                if (!spoon.rep.connect(Messages.getString("Spoon.Application.Name"))) //"Spoon"
                {
                    spoon.rep = null;
                }
            }

            if (spoon.props.openLastFile()) {
                log.logDetailed(APP_NAME, Messages.getString("Spoon.Log.TryingOpenLastUsedFile"));//"Trying to open the last file used."

                List lastUsedFiles = spoon.props.getLastUsedFiles();

                if (lastUsedFiles.size() > 0) {
                    LastUsedFile lastUsedFile = (LastUsedFile) lastUsedFiles.get(0);

                    spoon.loadLastUsedFile(lastUsedFile, repositoryMeta);
                }
            }
        }
    } catch (KettleException ke) {
        log.logError(APP_NAME, Messages.getString("Spoon.Log.ErrorOccurred") + Const.CR + ke.getMessage());//"An error occurred: "
        spoon.rep = null;
        // ke.printStackTrace();
    }

    spoon.open();

    splash.dispose();

    try {
        while (!spoon.isDisposed()) {
            if (!spoon.readAndDispatch())
                spoon.sleep();
        }
    } catch (Throwable e) {
        log.logError(APP_NAME,
                Messages.getString("Spoon.Log.UnexpectedErrorOccurred") + Const.CR + e.getMessage());//"An unexpected error occurred in Spoon: probable cause: please close all windows before stopping Spoon! "
        e.printStackTrace();
    }
    spoon.dispose();

    log.logBasic(APP_NAME, APP_NAME + " " + Messages.getString("Spoon.Log.AppHasEnded"));//" has ended."

    // Close the logfile
    log.close();

    // Kill all remaining things in this VM!
    System.exit(0);
}

From source file:Main.java

/**
 * Method that will wrap 't' as an {@link IllegalArgumentException} if it
 * is a checked exception; otherwise (runtime exception or error) throw as is
 *//* w  ww  .  jav a 2s  .com*/
public static void throwAsIAE(Throwable t) {
    throwAsIAE(t, t.getMessage());
}

From source file:Main.java

/** Handles the exception is a consistent way. */
public static void handle(String tag, Throwable e, String msg) {
    Log.e(tag, msg + ":" + e.getMessage());
}

From source file:Main.java

public static int wtf(String tag, Throwable tr) {
    return Log.wtf(tag, tr.getMessage(), tr);
}

From source file:Main.java

public static long getAvailableSpace(File dir) {
    try {/*from   ww  w .  ja v a2 s  .c o m*/
        final StatFs stats = new StatFs(dir.getPath());
        return (long) stats.getBlockSize() * (long) stats.getAvailableBlocks();
    } catch (Throwable e) {
        Log.e("getAvailableSpace", e.getMessage(), e);
        return -1;
    }
}

From source file:io.lightlink.utils.LogUtils.java

public static void warn(Class origin, Throwable t) {
    warn(origin, t.getMessage(), t);
}