<commit_before>package org.sonar.plugins.stash;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public final class PluginUtils {

    // Hiding implicit public constructor with an explicit private one (squid:S1118)
    private PluginUtils() {
    }
    
    public static PluginInfo infoForPluginClass(Class klass) {
        try {
            Enumeration<URL> resources = klass.getClassLoader().getResources("META-INF/MANIFEST.MF");
            while (resources.hasMoreElements()) {
                URL resource = resources.nextElement();
                Manifest man;
                try (InputStream ms = resource.openStream()) {
                    man = new Manifest(ms);
                }
                Attributes attrs = man.getMainAttributes();
                if (attrs == null) {
                    continue;
                }
                String pluginClass = attrs.getValue("Plugin-Class");
                if (pluginClass == null) {
                    continue;
                }
                if (!pluginClass.equals(klass.getName())) {
                    continue;
                }

                String pluginVersion = attrs.getValue("Plugin-Version");
                String pluginName = attrs.getValue("Plugin-Name");
                return new PluginInfo(pluginName, pluginVersion);
            }
        } catch (IOException e) {
            return null;
        }

        return null;
    }
}
<commit_msg>CQ: fixing SQUID:S1166<commit_after>package org.sonar.plugins.stash;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class PluginUtils {

    // Hiding implicit public constructor with an explicit private one (squid:S1118)
    private PluginUtils() {
    }

    private static final Logger LOGGER = LoggerFactory.getLogger(PluginUtils.class);


    public static PluginInfo infoForPluginClass(Class klass) {
        try {
            Enumeration<URL> resources = klass.getClassLoader().getResources("META-INF/MANIFEST.MF");
            while (resources.hasMoreElements()) {
                URL resource = resources.nextElement();
                Manifest man;
                try (InputStream ms = resource.openStream()) {
                    man = new Manifest(ms);
                }
                Attributes attrs = man.getMainAttributes();
                if (attrs == null) {
                    continue;
                }
                String pluginClass = attrs.getValue("Plugin-Class");
                if (pluginClass == null) {
                    continue;
                }
                if (!pluginClass.equals(klass.getName())) {
                    continue;
                }

                String pluginVersion = attrs.getValue("Plugin-Version");
                String pluginName = attrs.getValue("Plugin-Name");
                return new PluginInfo(pluginName, pluginVersion);
            }
        } catch (IOException e) {
            LOGGER.warn("Exception detected: {}", e.getMessage());
            LOGGER.debug("Exception stack trace", e);
            return null;
        }

        return null;
    }
}

{'fraction_non_alphanumeric': 0.09770453207769277, 'fraction_numerical': 0.004120070629782225, 'mean_word_length': 1.7746938775510204, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2271315', 'n_tokens_mistral': 879, 'n_tokens_neox': 832, 'n_words': 193}