<commit_before>package hudson.plugins.warnings;

import javax.annotation.CheckForNull;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilationFailedException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import groovy.lang.GroovyShell;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.plugins.warnings.parser.*;
import hudson.util.FormValidation;
import hudson.util.FormValidation.Kind;

/**
 * Defines the properties of a warnings parser that uses a Groovy script to
 * parse the warnings log.
 *
 * @author <NAME>
 */
public class GroovyParser extends AbstractDescribableImpl<GroovyParser> {
    private final String name;
    private final String regexp;
    private final String script;
    /** Example. @since 3.18 */
    private final String example;
    /** ProjectAction name. @since 4.0 */
    private String linkName;
    /** Trend report name. @since 4.0 */
    private String trendName;
    @CheckForNull
    private transient AbstractWarningsParser parser;

    /**
     * Creates a new instance of {@link GroovyParser}.
     *
     * @param name
     *            the name of the parser
     * @param regexp
     *            the regular expression
     * @param script
     *            the script to map the expression to a warning
     * @param example
     *            the example to verify the parser
     * @param linkName
     *            the name of the ProjectAction (link name)
     * @param trendName
     *            the name of the trend report
     */
    @DataBoundConstructor
    public GroovyParser(final String name, final String regexp, final String script, final String example,
            final String linkName, final String trendName) {
        super();

        this.name = name;
        this.regexp = regexp;
        this.script = script;
        this.example = example;
        this.linkName = linkName;
        this.trendName = trendName;
        parser = createParser();
    }

    /**
     * Creates a new instance of {@link GroovyParser}.
     *
     * @param name
     *            the name of the parser
     * @param regexp
     *            the regular expression
     * @param script
     *            the script to map the expression to a warning
     */
    public GroovyParser(final String name, final String regexp, final String script) {
        this(name, regexp, script, StringUtils.EMPTY, name, name);
    }

    /**
     * Adds link and trend names for 3.x serializations.
     *
     * @return the created object
     */
    private Object readResolve() {
        if (linkName == null) {
            linkName = Messages._Warnings_ProjectAction_Name().toString(Locale.ENGLISH);
        }
        if (trendName == null) {
            trendName = Messages._Warnings_Trend_Name().toString(Locale.ENGLISH);
        }
        parser = createParser();
        return this;
    }

    /**
     * Validates this instance.
     *
     * @return <code>true</code> if this instance is valid, <code>false</code>
     *         otherwise
     */
    public boolean isValid() {
        return parser != null;
    }

    private boolean canCreateParser() {
        DescriptorImpl d = new DescriptorImpl();
        return d.doCheckScript(script).kind == FormValidation.Kind.OK
                && d.doCheckRegexp(regexp).kind == FormValidation.Kind.OK
                && d.validate(name, Messages.Warnings_GroovyParser_Error_Name_isEmpty()).kind == FormValidation.Kind.OK;
    }

    /**
     * Returns the name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Returns the trend name.
     *
     * @return the trend name
     */
    public String getTrendName() {
        return trendName;
    }

    /**
     * Returns the link name.
     *
     * @return the link name
     */
    public String getLinkName() {
        return linkName;
    }

    /**
     * Returns the regular expression.
     *
     * @return the regular expression
     */
    public String getRegexp() {
        return regexp;
    }

    /**
     * Returns the Groovy script.
     *
     * @return the Groovy script
     */
    public String getScript() {
        return script;
    }

    /**
     * Returns the example to verify the parser.
     *
     * @return the example
     * @since 3.18
     */
    public String getExample() {
        return StringUtils.defaultString(example);
    }

    /**
     * Returns whether the parser can scan messages spanning multiple lines.
     *
     * @return <code>true</code> if the parser can scan messages spanning
     *         multiple lines
     */
    public final boolean hasMultiLineSupport() {<commit_msg>Deleted GroovyParser.example field, leaving it in the form only.<commit_after>package hudson.plugins.warnings;

import javax.annotation.CheckForNull;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilationFailedException;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import groovy.lang.GroovyShell;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;
import hudson.plugins.warnings.parser.*;
import hudson.util.FormValidation;
import hudson.util.FormValidation.Kind;

/**
 * Defines the properties of a warnings parser that uses a Groovy script to
 * parse the warnings log.
 *
 * @author <NAME>
 */
public class GroovyParser extends AbstractDescribableImpl<GroovyParser> {
    private final String name;
    private final String regexp;
    private final String script;
    /** ProjectAction name. @since 4.0 */
    private String linkName;
    /** Trend report name. @since 4.0 */
    private String trendName;
    @CheckForNull
    private transient AbstractWarningsParser parser;

    /**
     * Creates a new instance of {@link GroovyParser}.
     *
     * @param name
     *            the name of the parser
     * @param regexp
     *            the regular expression
     * @param script
     *            the script to map the expression to a warning
     * @param example
     *            the example to verify the parser
     * @param linkName
     *            the name of the ProjectAction (link name)
     * @param trendName
     *            the name of the trend report
     */
    @DataBoundConstructor
    public GroovyParser(final String name, final String regexp, final String script,
            final String linkName, final String trendName) {
        super();

        this.name = name;
        this.regexp = regexp;
        this.script = script;
        this.linkName = linkName;
        this.trendName = trendName;
        parser = createParser();
    }

    @Deprecated
    public GroovyParser(final String name, final String regexp, final String script, final String example,
            final String linkName, final String trendName) {
        this(name, regexp, script, linkName, trendName);
    }

    /**
     * Creates a new instance of {@link GroovyParser}.
     *
     * @param name
     *            the name of the parser
     * @param regexp
     *            the regular expression
     * @param script
     *            the script to map the expression to a warning
     */
    public GroovyParser(final String name, final String regexp, final String script) {
        this(name, regexp, script, name, name);
    }

    /**
     * Adds link and trend names for 3.x serializations.
     *
     * @return the created object
     */
    private Object readResolve() {
        if (linkName == null) {
            linkName = Messages._Warnings_ProjectAction_Name().toString(Locale.ENGLISH);
        }
        if (trendName == null) {
            trendName = Messages._Warnings_Trend_Name().toString(Locale.ENGLISH);
        }
        parser = createParser();
        return this;
    }

    /**
     * Validates this instance.
     *
     * @return <code>true</code> if this instance is valid, <code>false</code>
     *         otherwise
     */
    public boolean isValid() {
        return parser != null;
    }

    private boolean canCreateParser() {
        DescriptorImpl d = new DescriptorImpl();
        return d.doCheckScript(script).kind == FormValidation.Kind.OK
                && d.doCheckRegexp(regexp).kind == FormValidation.Kind.OK
                && d.validate(name, Messages.Warnings_GroovyParser_Error_Name_isEmpty()).kind == FormValidation.Kind.OK;
    }

    /**
     * Returns the name.
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Returns the trend name.
     *
     * @return the trend name
     */
    public String getTrendName() {
        return trendName;
    }

    /**
     * Returns the link name.
     *
     * @return the link name
     */
    public String getLinkName() {
        return linkName;
    }

    /**
     * Returns the regular expression.
     *
     * @return the regular expression
     */
    public String getRegexp() {
        return regexp;
    }

    /**
     * Returns the Groovy script.
     *
     * @return the Groovy script
     */
    public String getScript() {
        return script;
    }

    /**
     * Returns whether the parser can scan messages spanning multiple lines.
     *
     * @return <code>true</code> if the parser can scan messages spanning
     *         multiple lines
     */
    public final boolean hasMultiLineSupport() {
{'fraction_non_alphanumeric': 0.09012131715771231, 'fraction_numerical': 0.0016311550616780507, 'mean_word_length': 2.2006525285481238, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '7388093', 'n_tokens_mistral': 2740, 'n_tokens_neox': 2652, 'n_words': 803}