<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.geronimo.st.v20.core;

import java.io.IOException;

import org.apache.geronimo.deployment.xbeans.EnvironmentDocument;
import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
import org.apache.geronimo.st.core.GeronimoUtils;
import org.apache.geronimo.xml.ns.deployment.ArtifactType;
import org.apache.geronimo.xml.ns.deployment.DeploymentPackage;
import org.apache.geronimo.xml.ns.deployment.EnvironmentType;
import org.apache.geronimo.xml.ns.j2ee.application.ApplicationPackage;
import org.apache.geronimo.xml.ns.j2ee.application.ApplicationType;
import org.apache.geronimo.xml.ns.j2ee.application.util.ApplicationResourceFactoryImpl;
import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorPackage;
import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorType;
import org.apache.geronimo.xml.ns.j2ee.connector.util.ConnectorResourceFactoryImpl;
import org.apache.geronimo.xml.ns.j2ee.web.DocumentRoot;
import org.apache.geronimo.xml.ns.j2ee.web.WebAppType;
import org.apache.geronimo.xml.ns.j2ee.web.WebPackage;
import org.apache.geronimo.xml.ns.j2ee.web.util.WebResourceFactoryImpl;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.server.core.IModule;
import org.openejb.xml.ns.openejb.jar.JarPackage;
import org.openejb.xml.ns.openejb.jar.OpenejbJarType;
import org.openejb.xml.ns.openejb.jar.util.JarResourceFactoryImpl;

/**
 * @version $Rev$ $Date$
 */
public class GeronimoV20Utils extends GeronimoUtils {
	
	public static EObject getDeploymentPlan(IFile file) {
		if (!file.exists())
			return null;

		if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME))
			return getApplicationDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME))
			return getOpenEjbDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME))
			return getWebDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME))
			return getConnectorDeploymentPlan(file);

		return null;
	}
	
	public static String getConfigId2(IModule module) {
		
		IFile planFile = null;
		IVirtualComponent comp = ComponentCore.createComponent(module.getProject());
		if (isWebModule(module)) {
			planFile = GeronimoUtils.getWebDeploymentPlanFile(comp);
		} else if (isEjbJarModule(module)) {
			planFile = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp);
		} else if (isEarModule(module)) {
			planFile = GeronimoUtils.getApplicationDeploymentPlanFile(comp);
		} else if (isRARModule(module)) {
			planFile = GeronimoUtils.getConnectorDeploymentPlanFile(comp);
		}
		
		if(planFile != null) {
			try {
				XmlObject xmlObject = XmlBeansUtil.parse(planFile.getLocation().toFile());
				XmlCursor cursor = xmlObject.newCursor();
				cursor.toFirstChild();
				xmlObject = cursor.getObject();
				XmlObject result[] = xmlObject.selectChildren(QNameSet.singleton(EnvironmentDocument.type.getDocumentElementName()));
				if(result != null && result.length > 0) {
					org.apache.geronimo.deployment.xbeans.EnvironmentType env = (org.apache.geronimo.deployment.xbeans.EnvironmentType) result[0].changeType(org.apache.geronimo.deployment.xbeans.EnvironmentType.type);
					org.apache.geronimo.deployment.xbeans.ArtifactType moduleId = env.getModuleId();
					return getQualifiedConfigID(moduleId);
				}
			} catch (IOException e) {
				e.printStackTrace();
			} catch (XmlException e) {
				e.printStackTrace();
			} catch (Throwable e) {
				e.printStackTrace();<commit_msg>backout debugging code<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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.apache.geronimo.st.v20.core;

import java.io.IOException;

import org.apache.geronimo.deployment.xbeans.EnvironmentDocument;
import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
import org.apache.geronimo.st.core.GeronimoUtils;
import org.apache.geronimo.xml.ns.deployment.ArtifactType;
import org.apache.geronimo.xml.ns.deployment.DeploymentPackage;
import org.apache.geronimo.xml.ns.deployment.EnvironmentType;
import org.apache.geronimo.xml.ns.j2ee.application.ApplicationPackage;
import org.apache.geronimo.xml.ns.j2ee.application.ApplicationType;
import org.apache.geronimo.xml.ns.j2ee.application.util.ApplicationResourceFactoryImpl;
import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorPackage;
import org.apache.geronimo.xml.ns.j2ee.connector.ConnectorType;
import org.apache.geronimo.xml.ns.j2ee.connector.util.ConnectorResourceFactoryImpl;
import org.apache.geronimo.xml.ns.j2ee.web.DocumentRoot;
import org.apache.geronimo.xml.ns.j2ee.web.WebAppType;
import org.apache.geronimo.xml.ns.j2ee.web.WebPackage;
import org.apache.geronimo.xml.ns.j2ee.web.util.WebResourceFactoryImpl;
import org.apache.xmlbeans.QNameSet;
import org.apache.xmlbeans.XmlCursor;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject;
import org.eclipse.core.resources.IFile;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.wst.common.componentcore.ComponentCore;
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
import org.eclipse.wst.server.core.IModule;
import org.openejb.xml.ns.openejb.jar.JarPackage;
import org.openejb.xml.ns.openejb.jar.OpenejbJarType;
import org.openejb.xml.ns.openejb.jar.util.JarResourceFactoryImpl;

/**
 * @version $Rev$ $Date$
 */
public class GeronimoV20Utils extends GeronimoUtils {
	
	public static EObject getDeploymentPlan(IFile file) {
		if (!file.exists())
			return null;

		if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME))
			return getApplicationDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME))
			return getOpenEjbDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME))
			return getWebDeploymentPlan(file);
		else if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME))
			return getConnectorDeploymentPlan(file);

		return null;
	}
	
	public static String getConfigId2(IModule module) {
		
		IFile planFile = null;
		IVirtualComponent comp = ComponentCore.createComponent(module.getProject());
		if (isWebModule(module)) {
			planFile = GeronimoUtils.getWebDeploymentPlanFile(comp);
		} else if (isEjbJarModule(module)) {
			planFile = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp);
		} else if (isEarModule(module)) {
			planFile = GeronimoUtils.getApplicationDeploymentPlanFile(comp);
		} else if (isRARModule(module)) {
			planFile = GeronimoUtils.getConnectorDeploymentPlanFile(comp);
		}
		
		if(planFile != null) {
			try {
				XmlObject xmlObject = XmlBeansUtil.parse(planFile.getLocation().toFile());
				XmlCursor cursor = xmlObject.newCursor();
				cursor.toFirstChild();
				xmlObject = cursor.getObject();
				XmlObject result[] = xmlObject.selectChildren(QNameSet.singleton(EnvironmentDocument.type.getDocumentElementName()));
				if(result != null && result.length > 0) {
					org.apache.geronimo.deployment.xbeans.EnvironmentType env = (org.apache.geronimo.deployment.xbeans.EnvironmentType) result[0].changeType(org.apache.geronimo.deployment.xbeans.EnvironmentType.type);
					org.apache.geronimo.deployment.xbeans.ArtifactType moduleId = env.getModuleId();
					return getQualifiedConfigID(moduleId);
				}
			} catch (IOException e) {
				e.printStackTrace();
			} catch (XmlException e) {
				e.printStackTrace();
{'fraction_non_alphanumeric': 0.10704878305763355, 'fraction_numerical': 0.0044252449689179225, 'mean_word_length': 5.273628552544613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 50}, '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': '3756417', 'n_tokens_mistral': 3178, 'n_tokens_neox': 2975, 'n_words': 571}