<commit_before>/*******************************************************************************
 * 
 * Copyright (c) 2012 GigaSpaces Technologies Ltd. All rights reserved
 * 
 * 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 org.openspaces.launcher;

import com.gigaspaces.admin.cli.RuntimeInfo;
import com.gigaspaces.internal.io.FileUtils;
import com.gigaspaces.internal.utils.StringUtils;
import com.gigaspaces.logger.GSLogConfigLoader;
import com.j_spaces.kernel.ClassLoaderHelper;
import org.openspaces.pu.container.support.CommandLineParser;

import java.io.File;
import java.util.logging.Logger;

/**
 * @author <NAME>
 * @since 8.0.4
 */
public class Launcher {

    public static void main(String[] args) throws Exception {

        WebLauncherConfig config = new WebLauncherConfig();
        String name = System.getProperty("org.openspaces.launcher.name", "launcher");
        String loggerName = System.getProperty("org.openspaces.launcher.logger", "org.openspaces.launcher");
        String webLauncherClass = System.getProperty("org.openspaces.launcher.class", "org.openspaces.launcher.JettyLauncher");
        String hostAddress = null;

        CommandLineParser.Parameter[] params = CommandLineParser.parse(args);
        for (CommandLineParser.Parameter param : params) {
            String paramName = param.getName();
            if ("port".equals(paramName))
                config.setPort(Integer.parseInt(param.getArguments()[0]));
            else if ("path".equals(paramName))
                config.setWarFilePath(param.getArguments()[0]);
            else if ("work".equals(paramName))
                config.setTempDirPath(param.getArguments()[0]);
            else if ("name".equals(paramName))
                name = param.getArguments()[0];
            else if ("logger".equals(paramName))
            	loggerName = param.getArguments()[0];
            else if ("hostaddress".equals(paramName)) {
                hostAddress = param.getArguments()[0];
                config.setHostAddress(hostAddress);
            }
            else if("help".equals(paramName) || "h".equals(paramName)) {
            	printHelpMessage();
            	return;
            }
        }

        GSLogConfigLoader.getLoader(name);
        GSLogConfigLoader.getLoader();
        if (!validate(config)) {
            printHelpMessage();
        	return;
        }

        final Logger logger = Logger.getLogger(loggerName);
        logger.info(RuntimeInfo.getShortEnvironmentInfo());
        WebLauncher webLauncher = ClassLoaderHelper.newInstance(webLauncherClass);
        webLauncher.launch(config);
        String host = ( ( hostAddress == null ) ? "localhost" : " [" + hostAddress + "]" );
        logger.info(name + " server started on" + host + " port [" + config.getPort() + "]");
    }

    private static void printHelpMessage() {
        System.out.println("Launcher -path <path> [-work <work>] [-port <port>] [-name <name>] [-logger <logger>]");
    }

    private static boolean validate(WebLauncherConfig config) {
        // Verify path is not empty:
        if (!StringUtils.hasLength(config.getWarFilePath()))
            return false;

        // Verify path exists:<commit_msg>GS-12102 added option to change host address used by jetty web server , it can be dione by parameter "hostaddress" passed to gs-webui batch file<commit_after>/*******************************************************************************
 * 
 * Copyright (c) 2012 GigaSpaces Technologies Ltd. All rights reserved
 * 
 * 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 org.openspaces.launcher;

import com.gigaspaces.admin.cli.RuntimeInfo;
import com.gigaspaces.internal.io.FileUtils;
import com.gigaspaces.internal.utils.StringUtils;
import com.gigaspaces.logger.GSLogConfigLoader;
import com.j_spaces.kernel.ClassLoaderHelper;
import org.openspaces.pu.container.support.CommandLineParser;

import java.io.File;
import java.util.logging.Logger;

/**
 * @author <NAME>
 * @since 8.0.4
 */
public class Launcher {

    public static void main(String[] args) throws Exception {

        WebLauncherConfig config = new WebLauncherConfig();
        String name = System.getProperty("org.openspaces.launcher.name", "launcher");
        String loggerName = System.getProperty("org.openspaces.launcher.logger", "org.openspaces.launcher");
        String webLauncherClass = System.getProperty("org.openspaces.launcher.class", "org.openspaces.launcher.JettyLauncher");
        String hostAddress = null;

        CommandLineParser.Parameter[] params = CommandLineParser.parse(args);
        for (CommandLineParser.Parameter param : params) {
            String paramName = param.getName();
            if ("port".equals(paramName))
                config.setPort(Integer.parseInt(param.getArguments()[0]));
            else if ("path".equals(paramName))
                config.setWarFilePath(param.getArguments()[0]);
            else if ("work".equals(paramName))
                config.setTempDirPath(param.getArguments()[0]);
            else if ("name".equals(paramName))
                name = param.getArguments()[0];
            else if ("logger".equals(paramName))
            	loggerName = param.getArguments()[0];
            else if ("hostaddress".equals(paramName)) {
                hostAddress = param.getArguments()[0];
                config.setHostAddress(hostAddress);
            }
            else if("help".equals(paramName) || "h".equals(paramName)) {
            	printHelpMessage();
            	return;
            }
        }

        GSLogConfigLoader.getLoader(name);
        GSLogConfigLoader.getLoader();
        if (!validate(config)) {
            printHelpMessage();
        	return;
        }

        final Logger logger = Logger.getLogger(loggerName);
        logger.info(RuntimeInfo.getShortEnvironmentInfo());
        WebLauncher webLauncher = ClassLoaderHelper.newInstance(webLauncherClass);
        webLauncher.launch(config);
        String host = ( ( hostAddress == null ) ? "localhost" : "[" + hostAddress + "]" );
        logger.info(name + " server started on " + host + " port [" + config.getPort() + "]");
    }

    private static void printHelpMessage() {
        System.out.println("Launcher -path <path> [-work <work>] [-port <port>] [-name <name>] [-logger <logger>]");
    }

    private static boolean validate(WebLauncherConfig config) {
        // Verify path is not empty:
        if (!StringUtils.hasLength(config.getWarFilePath()))
            return false;

        // Verify path exists:
{'fraction_non_alphanumeric': 0.1513353115727003, 'fraction_numerical': 0.0050316088246677845, 'mean_word_length': 3.027012987012987, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '3429517', 'n_tokens_mistral': 2060, 'n_tokens_neox': 1968, 'n_words': 504}