<commit_before>/*
 *    Copyright 2017 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 */

package eu.fthevenet.binjr;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Bootstrap class for binjr that checks for JavaFX runtime presence and fails with an explicit error if not.
 *
 * @author <NAME>
 */
public final class Bootstrap {
    private static final Logger logger = LogManager.getLogger(Bootstrap.class);

    /**
     * The entry point fo the application.
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (checkForJavaFX()) {
            try {
                Binjr.main(args);
            } catch (Exception e) {
                logger.fatal("Failed to load binjr", e);
            }
        }
        else {
            logger.fatal("The JavaFX runtime must be present in order to run binjr. Please check with your Java vendor to see is JavaFX is available on your platform and how to install it.");
        }
    }

    private static boolean checkForJavaFX() {
        try {
            logger.info("Class " + Class.forName("javafx.application.Application") + " found: JavaFX runtime is available.");
            return true;
        } catch (ClassNotFoundException | NullPointerException e) {
            logger.info("JavaFX is not available on the current runtime environment:" +
                    "\njava.version=" +
                    System.getProperty("java.version") +
                    "\njava.vendor=" +
                    System.getProperty("java.vendor") +
                    "\njava.vm.name=" +
                    System.getProperty("java.vm.name") +
                    "\njava.vm.version=" +
                    System.getProperty("java.vm.version") +
                    "\njava.home=" +
                    System.getProperty("java.home"));
            logger.debug("JavaFX not available", e);
            return false;
        }
    }
}<commit_msg>Added sanity check on java version in bootstrap, and added an command line option to force startup even if checks fail. (ref issue #26)<commit_after>/*
 *    Copyright 2017 <NAME>
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 *
 */

package eu.fthevenet.binjr;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Bootstrap class for binjr that checks for JavaFX runtime presence and fails with an explicit error if not.
 *
 * @author <NAME>
 */
public final class Bootstrap {
    private static final Logger logger = LogManager.getLogger(Bootstrap.class);

    /**
     * The entry point fo the application.
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        boolean forceStart = false;
        for (String arg : args) {
            if (arg.equalsIgnoreCase("--forcestart") || arg.equalsIgnoreCase("-f")) {
                forceStart = true;
            }
        }
        if (!checkForJavaVersion()) {
            logger.log(forceStart ? Level.WARN : Level.FATAL, "This version on binjr only supports Java 8 and will likely fail on the version you're currently running. Please check 'https://github.com/fthevenet/binjr' for a version that runs on more recent versions of Java.");
            if (!forceStart) {
                System.exit(1);
            }
        }
        if (!checkForJavaFX()) {
            logger.log(forceStart ? Level.WARN : Level.FATAL, "The JavaFX runtime must be present in order to run binjr. Please check with your Java vendor to see is JavaFX is available on your platform and how to install it.");
            if (!forceStart) {
                System.exit(1);
            }
        }
        try {
            Binjr.main(args);
        } catch (Exception e) {
            logger.fatal("Failed to load binjr", e);
            System.exit(1);
        }
    }

    private static boolean checkForJavaVersion() {
        try {
            if (System.getProperty("java.runtime.version").startsWith("1.8")) {
                return true;
            }
        } catch (Exception e) {
            logger.error(e);
        }
        return false;
    }

    private static boolean checkForJavaFX() {
        try {
            logger.info("Class " + Class.forName("javafx.application.Application") + " found: JavaFX runtime is available.");
            return true;
        } catch (ClassNotFoundException | NullPointerException e) {
            logger.info("JavaFX is not available on the current runtime environment:" +
                    "\njava.version=" +
                    System.getProperty("java.version") +
                    "\njava.vendor=" +
                    System.getProperty("java.vendor") +
                    "\njava.vm.name=" +
                    System.getProperty("java.vm.name") +
                    "\njava.vm.version=" +
                    System.getProperty("java.vm.version") +
                    "\njava.home=" +
                    System.getProperty("java.home"));
            logger.debug("JavaFX not available", e);
            return false;
        }
    }
}
{'fraction_non_alphanumeric': 0.09816147082334133, 'fraction_numerical': 0.004636290967226219, 'mean_word_length': 1.9947343226424126, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3829322', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1591, 'n_words': 542}