<commit_before>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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.wso2.developerstudio.internal.tomcat.server;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import javax.servlet.ServletException;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;
import org.wso2.developerstudio.eclipse.logging.core.Logger;
import org.wso2.developerstudio.internal.tomcat.EmbeddedTomcatPlugin;
import org.wso2.developerstudio.internal.tomcat.api.ITomcatServer;

public class EmbeddedTomcatManager implements ITomcatServer {

	private static final String WEB_APP_EXT_POINT_ID = "org.wso2.developerstudio.embedded.webapp";
	private static final String WEB_XML_REL_PATH = "/WEB-INF/web.xml";
	protected Tomcat tomcat;
	protected Map<String, String> deployedApps;
	protected Integer port;
	
	private static IDeveloperStudioLog log = Logger.getLog(EmbeddedTomcatPlugin.PLUGIN_ID);


	public EmbeddedTomcatManager() throws IOException {
		deployedApps = new HashMap<>();
		configureServer();
	}

	private void initWebApps() throws Exception {
		IExtensionRegistry reg = Platform.getExtensionRegistry();
		IExtensionPoint ep = reg.getExtensionPoint(WEB_APP_EXT_POINT_ID);
		IExtension[] extensions = ep.getExtensions();
		for (IExtension ext : extensions) {
			Bundle bundle = ext.getDeclaringPluginDescriptor().getPlugin()
					.getBundle();
			IConfigurationElement element = ext.getConfigurationElements()[0];
			String appID = element.getAttribute("appID");
			String relativePath = element.getAttribute("relativePath");
			String isStatic = element.getAttribute("isStatic");
			if (appID != null && relativePath != null) {
				URL webAppsURL = FileLocator.find(bundle,
						new Path(relativePath), null);
				URL fileURL = FileLocator.toFileURL(webAppsURL);
				addWebApp(appID, appID,<commit_msg>Getting rid of deprecated API<commit_after>/*
 * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) 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.wso2.developerstudio.internal.tomcat.server;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.ServerSocket;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

import javax.servlet.ServletException;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtension;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.osgi.framework.Bundle;
import org.wso2.developerstudio.eclipse.logging.core.IDeveloperStudioLog;
import org.wso2.developerstudio.eclipse.logging.core.Logger;
import org.wso2.developerstudio.internal.tomcat.EmbeddedTomcatPlugin;
import org.wso2.developerstudio.internal.tomcat.api.ITomcatServer;

public class EmbeddedTomcatManager implements ITomcatServer {

	private static final String WEB_APP_EXT_POINT_ID = "org.wso2.developerstudio.embedded.webapp";
	private static final String WEB_XML_REL_PATH = "/WEB-INF/web.xml";
	protected Tomcat tomcat;
	protected Map<String, String> deployedApps;
	protected Integer port;
	
	private static IDeveloperStudioLog log = Logger.getLog(EmbeddedTomcatPlugin.PLUGIN_ID);


	public EmbeddedTomcatManager() throws IOException {
		deployedApps = new HashMap<>();
		configureServer();
	}

	private void initWebApps() throws Exception {
		IExtensionRegistry reg = Platform.getExtensionRegistry();
		IExtensionPoint ep = reg.getExtensionPoint(WEB_APP_EXT_POINT_ID);
		IExtension[] extensions = ep.getExtensions();
		for (IExtension ext : extensions) {
			String bundleName = ext.getContributor().getName();
			Bundle bundle = Platform.getBundle(bundleName);
			IConfigurationElement element = ext.getConfigurationElements()[0];
			String appID = element.getAttribute("appID");
			String relativePath = element.getAttribute("relativePath");
			String isStatic = element.getAttribute("isStatic");
			if (appID != null && relativePath != null) {
				URL webAppsURL = FileLocator.find(bundle,
						new Path(relativePath), null);
				URL fileURL = FileLocator.toFileURL(webAppsURL);
				addWebApp(appID, appID,
{'fraction_non_alphanumeric': 0.09761634506242906, 'fraction_numerical': 0.005513215501864764, 'mean_word_length': 5.33264887063655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1096082', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1779, 'n_words': 461}