<commit_before>/*
 * Copyright 2002-2007 <NAME>
 *
 * 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.intellij.plugins.xsltDebugger;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import org.intellij.lang.xpath.xslt.XsltSupport;
import org.intellij.lang.xpath.xslt.impl.XsltChecker;
import org.intellij.lang.xpath.xslt.run.XsltRunConfiguration;
import org.intellij.lang.xpath.xslt.run.XsltRunnerExtension;
import org.intellij.plugins.xsltDebugger.ui.OutputTabComponent;
import org.intellij.plugins.xsltDebugger.ui.StructureTabComponent;
import org.jetbrains.annotations.NonNls;
import javax.annotation.Nullable;
import com.intellij.diagnostic.logging.AdditionalTabComponent;
import com.intellij.diagnostic.logging.LogConsoleManagerBase;
import com.intellij.execution.CantRunException;
import com.intellij.execution.configurations.AdditionalTabComponentManager;
import com.intellij.execution.configurations.SimpleJavaParameters;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.execution.runners.RunTab;
import com.intellij.icons.AllIcons;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.PlatformIcons;
import com.intellij.util.net.NetUtils;
import consulo.vfs.util.ArchiveVfsUtil;

/**
 * Extension for XPathView that hooks into the execution of XSLT-scripts. Manages the creation of the XSLT-Debugger UI
 * and ensures the debugged process is started with the required JVM properties.
 */
public class XsltDebuggerExtension extends XsltRunnerExtension
{
	private static final Logger LOG = Logger.getInstance(XsltDebuggerExtension.class.getName());

	public static final Key<XsltChecker.LanguageLevel> VERSION = Key.create("VERSION");
	private static final Key<Integer> PORT = Key.create("PORT");
	private static final Key<Manifest> MANIFEST = Key.create("MANIFEST");

	@NonNls
	private static final String SAXON_6_JAR = "saxon.jar";

	@NonNls
	private static final String SAXON_9_JAR = "saxon9he.jar";

	@Override
	protected boolean supports(XsltRunConfiguration config, boolean debugger)
	{
		return (debugger || XsltDebuggerRunner.ACTIVE.get() == Boolean.TRUE) && config.getOutputType() == XsltRunConfiguration.OutputType.CONSOLE;
		// ?
	}

	@Override
	public ProcessListener createProcessListener(Project project, UserDataHolder extensionData)
	{
		final Integer port = extensionData.getUserData(PORT);
		assert port != null;
		return new DebugProcessListener(project, port);
	}

	@Override
	public boolean createTabs(Project project, AdditionalTabComponentManager manager, AdditionalTabComponent outputConsole, ProcessHandler process)
	{
		if(manager instanceof RunTab)
		{
			LogConsoleManagerBase logConsoleManager = ((RunTab) manager).getLogConsoleManager();
			logConsoleManager.addAdditionalTabComponent(new OutputTabComponent(outputConsole), "XSLT-Output", AllIcons.Debugger.Console);
			logConsoleManager.addAdditionalTabComponent(StructureTabComponent.create(process, outputConsole), "XSLT-Structure",
					PlatformIcons.FLATTEN_PACKAGES_ICON);
		}
		else
		{
			manager.addAdditionalTabComponent(new OutputTabComponent(outputConsole), "XSLT-Output");
			manager.addAdditionalTabComponent(StructureTabComponent.create(process, outputConsole), "XSLT-Structure");
		}
		return true;
	}

	@Override
	public void patchParameters(final SimpleJavaParameters parameters, XsltRunConfiguration configuration,
			UserDataHolder extensionData) throws CantRunException
	{
		final XsltRunConfiguration.OutputType outputType = configuration.getOutputType();

		final Sdk jdk = configuration.getEffectiveJDK();
		assert jdk != null;

		final String ver = jdk.getVersionString();
		if(ver == null || (ver.contains("1.0") || ver.contains("1.1") || ver.contains("1.2") || ver.contains("1.3") || ver.contains("1.4")))
		{
			throw new CantRunException("The XSLT Debugger can only be used with JDK 1.5+");
		}

		// TODO: fix and remove
		if(outputType != XsltRunConfiguration.OutputType.CONSOLE)<commit_msg>compilation<commit_after>/*
 * Copyright 2002-2007 <NAME>
 *
 * 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.intellij.plugins.xsltDebugger;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

import javax.annotation.Nullable;

import org.intellij.lang.xpath.xslt.XsltSupport;
import org.intellij.lang.xpath.xslt.impl.XsltChecker;
import org.intellij.lang.xpath.xslt.run.XsltRunConfiguration;
import org.intellij.lang.xpath.xslt.run.XsltRunnerExtension;
import org.intellij.plugins.xsltDebugger.ui.OutputTabComponent;
import org.intellij.plugins.xsltDebugger.ui.StructureTabComponent;
import org.jetbrains.annotations.NonNls;
import com.intellij.diagnostic.logging.AdditionalTabComponent;
import com.intellij.diagnostic.logging.LogConsoleManagerBase;
import com.intellij.execution.CantRunException;
import com.intellij.execution.configurations.AdditionalTabComponentManager;
import com.intellij.execution.configurations.SimpleJavaParameters;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.execution.runners.RunTab;
import com.intellij.icons.AllIcons;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.UserDataHolder;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiManager;
import com.intellij.util.net.NetUtils;
import consulo.vfs.util.ArchiveVfsUtil;

/**
 * Extension for XPathView that hooks into the execution of XSLT-scripts. Manages the creation of the XSLT-Debugger UI
 * and ensures the debugged process is started with the required JVM properties.
 */
public class XsltDebuggerExtension extends XsltRunnerExtension
{
	private static final Logger LOG = Logger.getInstance(XsltDebuggerExtension.class.getName());

	public static final Key<XsltChecker.LanguageLevel> VERSION = Key.create("VERSION");
	private static final Key<Integer> PORT = Key.create("PORT");
	private static final Key<Manifest> MANIFEST = Key.create("MANIFEST");

	@NonNls
	private static final String SAXON_6_JAR = "saxon.jar";

	@NonNls
	private static final String SAXON_9_JAR = "saxon9he.jar";

	@Override
	protected boolean supports(XsltRunConfiguration config, boolean debugger)
	{
		return (debugger || XsltDebuggerRunner.ACTIVE.get() == Boolean.TRUE) && config.getOutputType() == XsltRunConfiguration.OutputType.CONSOLE;
		// ?
	}

	@Override
	public ProcessListener createProcessListener(Project project, UserDataHolder extensionData)
	{
		final Integer port = extensionData.getUserData(PORT);
		assert port != null;
		return new DebugProcessListener(project, port);
	}

	@Override
	public boolean createTabs(Project project, AdditionalTabComponentManager manager, AdditionalTabComponent outputConsole, ProcessHandler process)
	{
		if(manager instanceof RunTab)
		{
			LogConsoleManagerBase logConsoleManager = ((RunTab) manager).getLogConsoleManager();
			logConsoleManager.addAdditionalTabComponent(new OutputTabComponent(outputConsole), "XSLT-Output", AllIcons.Debugger.Console);
			logConsoleManager.addAdditionalTabComponent(StructureTabComponent.create(process, outputConsole), "XSLT-Structure", AllIcons.ObjectBrowser.FlattenPackages);
		}
		else
		{
			manager.addAdditionalTabComponent(new OutputTabComponent(outputConsole), "XSLT-Output");
			manager.addAdditionalTabComponent(StructureTabComponent.create(process, outputConsole), "XSLT-Structure");
		}
		return true;
	}

	@Override
	public void patchParameters(final SimpleJavaParameters parameters, XsltRunConfiguration configuration, UserDataHolder extensionData) throws CantRunException
	{
		final XsltRunConfiguration.OutputType outputType = configuration.getOutputType();

		final Sdk jdk = configuration.getEffectiveJDK();
		assert jdk != null;

		final String ver = jdk.getVersionString();
		if(ver == null || (ver.contains("1.0") || ver.contains("1.1") || ver.contains("1.2") || ver.contains("1.3") || ver.contains("1.4")))
		{
			throw new CantRunException("The XSLT Debugger can only be used with JDK 1.5+");
		}

		// TODO: fix and remove
		if(outputType != XsltRunConfiguration.OutputType.CONSOLE)
{'fraction_non_alphanumeric': 0.09759671746776084, 'fraction_numerical': 0.005275498241500586, 'mean_word_length': 5.916891891891892, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3108922', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3047, 'n_words': 693}