<commit_before>package com.flowpowered.plugins.basic;

import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.flowpowered.cerealization.config.Configuration;
import com.flowpowered.cerealization.config.ConfigurationNode;
import com.flowpowered.cerealization.config.ConfigurationNodeSource;
import com.flowpowered.cerealization.config.yaml.YamlConfiguration;
import com.flowpowered.plugins.PluginHandle;
import com.flowpowered.plugins.PluginLoader;
import com.flowpowered.plugins.PluginManager;

public class SimpleJavaPluginLoader implements PluginLoader {
    private static final String DESCRIPTOR_NAME = "plugin.yml";
    private static final String NAME_KEY = "name";
    private static final String MAIN_KEY = "main";
    private final ClassLoader cl;

    public SimpleJavaPluginLoader(ClassLoader cl) {
        this.cl = cl;
    }

    @Override
    public Set<String> scan() {
        return findMains().keySet();
    }

    @Override
    public PluginHandle load(PluginManager manager, String pluginName) {
        return load(manager, pluginName, findMains());
    }

    protected PluginHandle load(PluginManager manager, String pluginName, Map<String, String> mains) {
        String main = mains.get(pluginName);
        if (main != null) {
            try {
                Class<?> clazz = Class.forName(main, false, cl);
                Class<? extends JavaPlugin> pluginClass = clazz.asSubclass(JavaPlugin.class);
                JavaPlugin plugin = pluginClass.newInstance();
                PluginHandle handle = new SimpleJavaPluginHandle(manager, plugin, pluginName);
                plugin.init(manager, handle);
                return handle;
            } catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException | ExceptionInInitializerError e) {
                // TODO: log
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    public Map<String, PluginHandle> loadAll(PluginManager manager) {
        Map<String, PluginHandle> loaded = new HashMap<>();
        Map<String, String> mains = findMains();
        for (String name : mains.keySet()) {
            PluginHandle plugin = load(manager, name, mains);
            if (plugin != null) {
                loaded.put(name, plugin);
            }
        }
        return loaded;
    }

    protected Map<String, String> findMains() {
        Map<String, String> mains = new HashMap<>();
        Enumeration<URL> urls;
        try {
            urls = cl.getResources(DESCRIPTOR_NAME);
        } catch (IOException e) {
            // TODO log
            e.printStackTrace();
            return mains;
        }
        for (URL url : Collections.list(urls)) {
            try {
                Configuration conf = new YamlConfiguration(url.openStream());
                ConfigurationNode name = conf.getChild(NAME_KEY);
                if (name == null || name.getString("").isEmpty()) {
                    // TODO: log
                    continue;
                }
                ConfigurationNode main = conf.getChild(MAIN_KEY);
                if (name == null || name.getString("").isEmpty()) {
                    // TODO: log
                    continue;
                }
                mains.put(name.getString(), main.getString());
            } catch (IOException e) {
                // TODO: log
                e.printStackTrace();
            }

        }
        return mains;
    }

    protected ConfigurationNodeSource parseDescriptor(Reader reader) {
        Configuration conf = new YamlConfiguration(reader);
        return conf;
    }
}<commit_msg>Remove unused method SimpleJavaPluginLoader.parseDescriptor()<commit_after>package com.flowpowered.plugins.basic;

import java.io.IOException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.flowpowered.cerealization.config.Configuration;
import com.flowpowered.cerealization.config.ConfigurationNode;
import com.flowpowered.cerealization.config.yaml.YamlConfiguration;
import com.flowpowered.plugins.PluginHandle;
import com.flowpowered.plugins.PluginLoader;
import com.flowpowered.plugins.PluginManager;

public class SimpleJavaPluginLoader implements PluginLoader {
    private static final String DESCRIPTOR_NAME = "plugin.yml";
    private static final String NAME_KEY = "name";
    private static final String MAIN_KEY = "main";
    private final ClassLoader cl;

    public SimpleJavaPluginLoader(ClassLoader cl) {
        this.cl = cl;
    }

    @Override
    public Set<String> scan() {
        return findMains().keySet();
    }

    @Override
    public PluginHandle load(PluginManager manager, String pluginName) {
        return load(manager, pluginName, findMains());
    }

    protected PluginHandle load(PluginManager manager, String pluginName, Map<String, String> mains) {
        String main = mains.get(pluginName);
        if (main != null) {
            try {
                Class<?> clazz = Class.forName(main, false, cl);
                Class<? extends JavaPlugin> pluginClass = clazz.asSubclass(JavaPlugin.class);
                JavaPlugin plugin = pluginClass.newInstance();
                PluginHandle handle = new SimpleJavaPluginHandle(manager, plugin, pluginName);
                plugin.init(manager, handle);
                return handle;
            } catch (ClassNotFoundException | ClassCastException | InstantiationException | IllegalAccessException | ExceptionInInitializerError e) {
                // TODO: log
                e.printStackTrace();
            }
        }
        return null;
    }

    @Override
    public Map<String, PluginHandle> loadAll(PluginManager manager) {
        Map<String, PluginHandle> loaded = new HashMap<>();
        Map<String, String> mains = findMains();
        for (String name : mains.keySet()) {
            PluginHandle plugin = load(manager, name, mains);
            if (plugin != null) {
                loaded.put(name, plugin);
            }
        }
        return loaded;
    }

    protected Map<String, String> findMains() {
        Map<String, String> mains = new HashMap<>();
        Enumeration<URL> urls;
        try {
            urls = cl.getResources(DESCRIPTOR_NAME);
        } catch (IOException e) {
            // TODO log
            e.printStackTrace();
            return mains;
        }
        for (URL url : Collections.list(urls)) {
            try {
                Configuration conf = new YamlConfiguration(url.openStream());
                ConfigurationNode name = conf.getChild(NAME_KEY);
                if (name == null || name.getString("").isEmpty()) {
                    // TODO: log
                    continue;
                }
                ConfigurationNode main = conf.getChild(MAIN_KEY);
                if (name == null || name.getString("").isEmpty()) {
                    // TODO: log
                    continue;
                }
                mains.put(name.getString(), main.getString());
            } catch (IOException e) {
                // TODO: log
                e.printStackTrace();
            }

        }
        return mains;
    }
}
{'fraction_non_alphanumeric': 0.09853277695517566, 'fraction_numerical': 0.0, 'mean_word_length': 2.1523122613491728, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '2145073', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1821, 'n_words': 457}