<commit_before>package com.crowdin.cli.utils;

import com.crowdin.cli.properties.PropertiesBean;
import com.crowdin.cli.utils.console.ConsoleUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.InputStream;
import java.nio.file.FileSystems;
import java.util.Optional;
import java.util.Properties;
import java.util.ResourceBundle;


public class Utils {

    private static final String APPLICATION_BASE_URL = "application.base_url";

    private static final String APPLICATION_NAME = "application.name";

    private static final String APPLICATION_VERSION = "application.version";

    private static final String PROPERTIES_FILE = "/crowdin.properties";

    private static final String USER_AGENT = "application.user_agent";

    /**
     * Path separator for use when concatenating or using non-regex findLanguage/replace methods.
     */
    public static final String PATH_SEPARATOR = FileSystems.getDefault().getSeparator();

    /**
     * Path separator for use in regex patterns, or in regex replacements, which use the same escaping.
     */
    public static final String PATH_SEPARATOR_REGEX = "\\".equals(PATH_SEPARATOR) ? "\\\\" : PATH_SEPARATOR;

    private static final ResourceBundle RESOURCE_BUNDLE = MessageSource.RESOURCE_BUNDLE;

    public static String getAppName() {
        Properties properties = new Properties();
        String applicationName = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("exception_app_name"));
        }
        if (properties != null && properties.get(APPLICATION_NAME) != null) {
            applicationName = properties.get(APPLICATION_NAME).toString();
        }
        return applicationName;
    }

    public static String getAppVersion() {
        Properties properties = new Properties();
        String applicationVersion = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("exception_app_version"));
        }
        if (properties.get(APPLICATION_VERSION) != null) {
            applicationVersion = properties.get(APPLICATION_VERSION).toString();
        }
        return applicationVersion;
    }

    public static String getBaseUrl() {
        Properties properties = new Properties();
        String applicationBaseUrl = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("error_get_base_url"));
        }
        if (properties.get(APPLICATION_BASE_URL) != null) {
            applicationBaseUrl = properties.get(APPLICATION_BASE_URL).toString();
        }
        return applicationBaseUrl;
    }

    public static String replaceBasePath(String path, String basePath) {
        if (path == null || path.isEmpty()) {
            System.out.println(RESOURCE_BUNDLE.getString("error_empty_path"));
            ConsoleUtils.exitError();
        }
        String result;
        if (StringUtils.isNoneEmpty(basePath)) {
            path = path.replaceAll(PATH_SEPARATOR_REGEX + "+", PATH_SEPARATOR_REGEX);
            result = path.replace(basePath, PATH_SEPARATOR);
        } else {
            result = PATH_SEPARATOR;
        }
        result = result.replaceAll(PATH_SEPARATOR_REGEX + "+", PATH_SEPARATOR_REGEX);
        return result;
    }

    public static Boolean isWindows() {
        return SystemUtils.IS_OS_WINDOWS;
    }

    public static String getUserAgent() {
        Properties prop = new Properties();
        try {<commit_msg>fix no-config<commit_after>package com.crowdin.cli.utils;

import com.crowdin.cli.properties.PropertiesBean;
import com.crowdin.cli.utils.console.ConsoleUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.io.InputStream;
import java.nio.file.FileSystems;
import java.util.Optional;
import java.util.Properties;
import java.util.ResourceBundle;


public class Utils {

    private static final String APPLICATION_BASE_URL = "application.base_url";

    private static final String APPLICATION_NAME = "application.name";

    private static final String APPLICATION_VERSION = "application.version";

    private static final String PROPERTIES_FILE = "/crowdin.properties";

    private static final String USER_AGENT = "application.user_agent";

    /**
     * Path separator for use when concatenating or using non-regex findLanguage/replace methods.
     */
    public static final String PATH_SEPARATOR = FileSystems.getDefault().getSeparator();

    /**
     * Path separator for use in regex patterns, or in regex replacements, which use the same escaping.
     */
    public static final String PATH_SEPARATOR_REGEX = "\\".equals(PATH_SEPARATOR) ? "\\\\" : PATH_SEPARATOR;

    private static final ResourceBundle RESOURCE_BUNDLE = MessageSource.RESOURCE_BUNDLE;

    public static String getAppName() {
        Properties properties = new Properties();
        String applicationName = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("exception_app_name"));
        }
        if (properties != null && properties.get(APPLICATION_NAME) != null) {
            applicationName = properties.get(APPLICATION_NAME).toString();
        }
        return applicationName;
    }

    public static String getAppVersion() {
        Properties properties = new Properties();
        String applicationVersion = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("exception_app_version"));
        }
        if (properties.get(APPLICATION_VERSION) != null) {
            applicationVersion = properties.get(APPLICATION_VERSION).toString();
        }
        return applicationVersion;
    }

    public static String getBaseUrl() {
        Properties properties = new Properties();
        String applicationBaseUrl = null;
        try {
            InputStream in = Utils.class.getResourceAsStream(PROPERTIES_FILE);
            properties.load(in);
            in.close();
        } catch (Exception e) {
            System.out.println(RESOURCE_BUNDLE.getString("error_get_base_url"));
        }
        if (properties.get(APPLICATION_BASE_URL) != null) {
            applicationBaseUrl = properties.get(APPLICATION_BASE_URL).toString();
        }
        return applicationBaseUrl;
    }

    public static String replaceBasePath(String path, String basePath) {
        if (path == null || path.isEmpty()) {
            System.out.println(RESOURCE_BUNDLE.getString("error_empty_path"));
            ConsoleUtils.exitError();
        }
        String result;
        if (StringUtils.isNoneEmpty(basePath)) {
            path = path.replaceAll(PATH_SEPARATOR_REGEX + "+", PATH_SEPARATOR_REGEX);
            result = path.replace(basePath, PATH_SEPARATOR);
        } else {
            String[] nodes = path.split(PATH_SEPARATOR_REGEX);
            result = nodes[nodes.length-1];
        }
        result = result.replaceAll(PATH_SEPARATOR_REGEX + "+", PATH_SEPARATOR_REGEX);
        return result;
    }

    public static Boolean isWindows() {
        return SystemUtils.IS_OS_WINDOWS;
    }

    public static String getUserAgent() {
        Properties prop = new Properties();
        try {
{'fraction_non_alphanumeric': 0.096, 'fraction_numerical': 0.000625, 'mean_word_length': 2.7740566037735848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6605567', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2110, 'n_words': 466}