<commit_before>/*******************************************************************************
 * Copyright (c) 2018 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.commons.boot.app.cli;

import java.util.Set;

import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.util.StringUtil;

public class ContextPath {

	protected static Logger logger = LoggerFactory.getLogger(ContextPath.class);

	public static final String[] CONTEXTPATH = { "server.context-path", "server.contextPath", "SERVER_CONTEXT_PATH",
			"server.servlet.context-path", "server.servlet.contextPath", "SERVER_SERVLET_CONTEXT_PATH" };

	public static String getContextPath(String environment) {

		if (environment != null) {
			JSONObject env = new JSONObject(environment);
			for (String prop : CONTEXTPATH) {
				String contextPath = findContextPath(env, prop);
				if (StringUtil.hasText(contextPath)) {
					return contextPath;
				}
			}
		}

		return null;
	}

	private static String findContextPath(JSONObject env, String contextPathProp) {
		String contextPath = null;
		if (env != null) {<commit_msg>Added some comments on priority ordering when looking for context path<commit_after>/*******************************************************************************
 * Copyright (c) 2018 Pivotal, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Pivotal, Inc. - initial API and implementation
 *******************************************************************************/
package org.springframework.ide.vscode.commons.boot.app.cli;

import java.util.Set;

import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ide.vscode.commons.util.StringUtil;

public class ContextPath {

	protected static Logger logger = LoggerFactory.getLogger(ContextPath.class);

	public static final String[] CONTEXTPATH = { "server.context-path", "server.contextPath", "SERVER_CONTEXT_PATH",
			"server.servlet.context-path", "server.servlet.contextPath", "SERVER_SERVLET_CONTEXT_PATH" };

	public static String getContextPath(String environment) {

		if (environment != null) {
			JSONObject env = new JSONObject(environment);
			for (String prop : CONTEXTPATH) {
				String contextPath = findContextPath(env, prop);
				if (StringUtil.hasText(contextPath)) {
					return contextPath;
				}
			}
		}

		return null;
	}

	private static String findContextPath(JSONObject env, String contextPathProp) {
		String contextPath = null;
		if (env != null) {
			// Properties defined in command line args have higher priority over
			// those defined in application configuration files (properties/yaml files)
{'fraction_non_alphanumeric': 0.18125369603784744, 'fraction_numerical': 0.0059136605558840925, 'mean_word_length': 5.019572953736655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5458004', 'n_tokens_mistral': 973, 'n_tokens_neox': 878, 'n_words': 258}