<commit_before>package org.jcryptool.functionlistgen;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.nio.file.Paths;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.IStartup;
import org.jcryptool.core.ApplicationActionBarAdvisor;
import org.jcryptool.core.operations.CommandInfo;
import org.jcryptool.core.operations.OperationsPlugin;
import org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler;
import org.jcryptool.core.util.directories.DirectoryService;
import org.jcryptool.core.views.AlgorithmView;
import org.jcryptool.crypto.flexiprovider.algorithms.ui.views.providers.FlexiProviderAlgorithmsViewContentProvider;
import org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode;

public class AtStartup implements IStartup {

	private static final String MESSAGE_DIGESTS = "Message Digests";
	private static final String SIGNATURES = "Signatures";
	private static final String PSEUDO_RANDOM_NUMBER_GENERATORS = "Pseudo Random Number Generators";
	private static final String HYBRID_CIPHERS = "Hybrid Ciphers";
	private static final String MESSAGE_AUTHENTICATION_CODES = "Message Authentication Codes";
	private static final String BLOCK_CIPHERS = "Block Ciphers";
	private static final String PASSWORD_BASED_CIPHERS = "Password-Based Ciphers";
	private static final String ASYMMETRIC_BLOCK_CIPHERS = "Asymmetric Block Ciphers";

	/**
	 * translates the "Algorithm perspective" Algorithms from all languages to English.
	 * This is necessary to use them as secondary sorting IDs so that all entries are written to 
	 * the output in the same order across all languages 
	 */
	private static Map<String, String> flexiproviderTranslations = new HashMap<String, String>(){/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	{ 
		put(MESSAGE_DIGESTS                  , MESSAGE_DIGESTS);
		put(SIGNATURES                       , SIGNATURES);
		put(PSEUDO_RANDOM_NUMBER_GENERATORS  , PSEUDO_RANDOM_NUMBER_GENERATORS);
		put(HYBRID_CIPHERS                   , HYBRID_CIPHERS);
		put(MESSAGE_AUTHENTICATION_CODES     , MESSAGE_AUTHENTICATION_CODES);
		put(BLOCK_CIPHERS                    , BLOCK_CIPHERS);
		put(PASSWORD_BASED_CIPHERS           , PASSWORD_BASED_CIPHERS);
		put(ASYMMETRIC_BLOCK_CIPHERS         , ASYMMETRIC_BLOCK_CIPHERS);

		put("Hash-Funktionen"                , MESSAGE_DIGESTS);
		put("Signaturen"                     , SIGNATURES);
		put("Pseudo-Zufallszahlengeneratoren", PSEUDO_RANDOM_NUMBER_GENERATORS);
		put("Hybride Verschlüsselung"        , HYBRID_CIPHERS);
		put("Authentifizierungscodes"        , MESSAGE_AUTHENTICATION_CODES);
		put("Blockchiffren"                  , BLOCK_CIPHERS);
		put("Passwortbasierte Chiffren"      , PASSWORD_BASED_CIPHERS);
		put("Asymmetrische Blockchiffren"    , ASYMMETRIC_BLOCK_CIPHERS);
	}};

	/**
	 * This method is called at JCT startup. It checks the command line arguments for -GenerateFunctionList
	 * and parses them like this:
	 * - no further argument: create files in ~/Documents/.jcryptool
	 * - further arguments: split by ",," and write to all these files
	 * 
	 * further information about the purpose of this is available at https://github.com/simlei/org.cryptool.functionlist
	 */
	@Override
	public void earlyStartup() {
		List<File> outputs = new LinkedList<File>();
		String[] cmdlineargs = Platform.getCommandLineArgs();

		System.err.println("[JCT-debug] Function List Plugin is processing command line parameters of length " + cmdlineargs.length + "...");
		boolean pluginActivated = false;
		for (int i = 0; i < cmdlineargs.length; i++) {
			String currentArg = cmdlineargs[i];
			if(currentArg.equals("-GenerateFunctionList")) {
				pluginActivated=true;
				if (cmdlineargs.length -1 == i) {
					System.err.println("-GenerateFunctionList takes a target file argument. It was not provided, so the default location will be used.");
					outputs.add(new File(DirectoryService.getWorkspaceDir(), "functionlist_jct_" + Locale.getDefault().toString() + ".csv"));
				} else {
					String nextArg = cmdlineargs[i+1];
					String[] split = nextArg.split(",,");
					for (String sp : split) {
						if( ! Paths.get(sp).isAbsolute() ) {
							System.err.println("-GenerateFunctionList file argument is not an absolute path; it is interpreted as relative to " + DirectoryService.getWorkspaceDir().toString());
							File wsDir = new File(DirectoryService.getWorkspaceDir());
							outputs.add(Paths.get(wsDir.getAbsolutePath(), sp).toFile());
						} else {
							outputs.add(Paths.get(sp).toFile());
						}<commit_msg>remove debug output of o.j.functionlistgen<commit_after>package org.jcryptool.functionlistgen;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import java.nio.file.Paths;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.Platform;
import org.eclipse.ui.IStartup;
import org.jcryptool.core.ApplicationActionBarAdvisor;
import org.jcryptool.core.operations.CommandInfo;
import org.jcryptool.core.operations.OperationsPlugin;
import org.jcryptool.core.operations.algorithm.ShadowAlgorithmHandler;
import org.jcryptool.core.util.directories.DirectoryService;
import org.jcryptool.core.views.AlgorithmView;
import org.jcryptool.crypto.flexiprovider.algorithms.ui.views.providers.FlexiProviderAlgorithmsViewContentProvider;
import org.jcryptool.crypto.flexiprovider.ui.nodes.ITreeNode;

public class AtStartup implements IStartup {

	private static final String MESSAGE_DIGESTS = "Message Digests";
	private static final String SIGNATURES = "Signatures";
	private static final String PSEUDO_RANDOM_NUMBER_GENERATORS = "Pseudo Random Number Generators";
	private static final String HYBRID_CIPHERS = "Hybrid Ciphers";
	private static final String MESSAGE_AUTHENTICATION_CODES = "Message Authentication Codes";
	private static final String BLOCK_CIPHERS = "Block Ciphers";
	private static final String PASSWORD_BASED_CIPHERS = "Password-Based Ciphers";
	private static final String ASYMMETRIC_BLOCK_CIPHERS = "Asymmetric Block Ciphers";

	/**
	 * translates the "Algorithm perspective" Algorithms from all languages to English.
	 * This is necessary to use them as secondary sorting IDs so that all entries are written to 
	 * the output in the same order across all languages 
	 */
	private static Map<String, String> flexiproviderTranslations = new HashMap<String, String>(){/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	{ 
		put(MESSAGE_DIGESTS                  , MESSAGE_DIGESTS);
		put(SIGNATURES                       , SIGNATURES);
		put(PSEUDO_RANDOM_NUMBER_GENERATORS  , PSEUDO_RANDOM_NUMBER_GENERATORS);
		put(HYBRID_CIPHERS                   , HYBRID_CIPHERS);
		put(MESSAGE_AUTHENTICATION_CODES     , MESSAGE_AUTHENTICATION_CODES);
		put(BLOCK_CIPHERS                    , BLOCK_CIPHERS);
		put(PASSWORD_BASED_CIPHERS           , PASSWORD_BASED_CIPHERS);
		put(ASYMMETRIC_BLOCK_CIPHERS         , ASYMMETRIC_BLOCK_CIPHERS);

		put("Hash-Funktionen"                , MESSAGE_DIGESTS);
		put("Signaturen"                     , SIGNATURES);
		put("Pseudo-Zufallszahlengeneratoren", PSEUDO_RANDOM_NUMBER_GENERATORS);
		put("Hybride Verschlüsselung"        , HYBRID_CIPHERS);
		put("Authentifizierungscodes"        , MESSAGE_AUTHENTICATION_CODES);
		put("Blockchiffren"                  , BLOCK_CIPHERS);
		put("Passwortbasierte Chiffren"      , PASSWORD_BASED_CIPHERS);
		put("Asymmetrische Blockchiffren"    , ASYMMETRIC_BLOCK_CIPHERS);
	}};

	/**
	 * This method is called at JCT startup. It checks the command line arguments for -GenerateFunctionList
	 * and parses them like this:
	 * - no further argument: create files in ~/Documents/.jcryptool
	 * - further arguments: split by ",," and write to all these files
	 * 
	 * further information about the purpose of this is available at https://github.com/simlei/org.cryptool.functionlist
	 */
	@Override
	public void earlyStartup() {
		List<File> outputs = new LinkedList<File>();
		String[] cmdlineargs = Platform.getCommandLineArgs();

		//System.err.println("[JCT-debug] Function List Plugin is processing command line parameters of length " + cmdlineargs.length + "...");
		boolean pluginActivated = false;
		for (int i = 0; i < cmdlineargs.length; i++) {
			String currentArg = cmdlineargs[i];
			if(currentArg.equals("-GenerateFunctionList")) {
				pluginActivated=true;
				if (cmdlineargs.length -1 == i) {
					System.err.println("-GenerateFunctionList takes a target file argument. It was not provided, so the default location will be used.");
					outputs.add(new File(DirectoryService.getWorkspaceDir(), "functionlist_jct_" + Locale.getDefault().toString() + ".csv"));
				} else {
					String nextArg = cmdlineargs[i+1];
					String[] split = nextArg.split(",,");
					for (String sp : split) {
						if( ! Paths.get(sp).isAbsolute() ) {
							System.err.println("-GenerateFunctionList file argument is not an absolute path; it is interpreted as relative to " + DirectoryService.getWorkspaceDir().toString());
							File wsDir = new File(DirectoryService.getWorkspaceDir());
							outputs.add(Paths.get(wsDir.getAbsolutePath(), sp).toFile());
						} else {
							outputs.add(Paths.get(sp).toFile());
						}
{'fraction_non_alphanumeric': 0.09761409761409762, 'fraction_numerical': 0.000792000792000792, 'mean_word_length': 4.319641916798315, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '7062402', 'n_tokens_mistral': 3364, 'n_tokens_neox': 3090, 'n_words': 710}