<commit_before>package hudson.plugins.trac;

import hudson.MarkupText;
import hudson.MarkupText.SubText;
import hudson.model.AbstractBuild;
import hudson.scm.ChangeLogAnnotator;
import hudson.scm.ChangeLogSet.Entry;

import java.util.regex.Pattern;

/**
 * Annotates <a href="http://trac.edgewall.org/wiki/TracLinks">TracLink</a>
 * and <a href="http://trac.edgewall.org/wiki/InterTrac">InterTrac</a>
 * notation in changelog messages.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class TracLinkAnnotator extends ChangeLogAnnotator {
    @Override
    public void annotate(AbstractBuild<?,?> build, Entry change, MarkupText text) {
        TracProjectProperty tpp = build.getProject().getProperty(TracProjectProperty.class);
        if(tpp==null || tpp.tracWebsite==null)
            return; // not configured

        annotate(tpp.tracWebsite, text);
    }

    void annotate(String url, MarkupText text) {
        for (LinkMarkup markup : MARKUPS) {
            markup.process(text, url);
        }
    }

    private static final class LinkMarkup {
        private final Pattern pattern;
        private final String href;

        LinkMarkup(String pattern, String href) {
            pattern = NUM_PATTERN.matcher(pattern).replaceAll("(\\\\d+)"); // \\\\d becomes \\d when in the expanded text.
            pattern = ANYWORD_PATTERN.matcher(pattern).replaceAll("((?:\\\\w|[.-])+)");
            this.pattern = Pattern.compile(pattern);
            this.href = href;
        }

        void process(MarkupText text, String url) {
            for(SubText st : text.findTokens(pattern)) {
                st.surroundWith(
                    "<a href='"+url+href+"'>",<commit_msg>Improve regular expression per Mike Dillon.<commit_after>package hudson.plugins.trac;

import hudson.MarkupText;
import hudson.MarkupText.SubText;
import hudson.model.AbstractBuild;
import hudson.scm.ChangeLogAnnotator;
import hudson.scm.ChangeLogSet.Entry;

import java.util.regex.Pattern;

/**
 * Annotates <a href="http://trac.edgewall.org/wiki/TracLinks">TracLink</a>
 * and <a href="http://trac.edgewall.org/wiki/InterTrac">InterTrac</a>
 * notation in changelog messages.
 *
 * @author <NAME>
 * @author <NAME>
 */
public class TracLinkAnnotator extends ChangeLogAnnotator {
    @Override
    public void annotate(AbstractBuild<?,?> build, Entry change, MarkupText text) {
        TracProjectProperty tpp = build.getProject().getProperty(TracProjectProperty.class);
        if(tpp==null || tpp.tracWebsite==null)
            return; // not configured

        annotate(tpp.tracWebsite, text);
    }

    void annotate(String url, MarkupText text) {
        for (LinkMarkup markup : MARKUPS) {
            markup.process(text, url);
        }
    }

    private static final class LinkMarkup {
        private final Pattern pattern;
        private final String href;

        LinkMarkup(String pattern, String href) {
            pattern = NUM_PATTERN.matcher(pattern).replaceAll("(\\\\d+)"); // \\\\d becomes \\d when in the expanded text.
            pattern = ANYWORD_PATTERN.matcher(pattern).replaceAll("([\\\\w.-]+)");
            this.pattern = Pattern.compile(pattern);
            this.href = href;
        }

        void process(MarkupText text, String url) {
            for(SubText st : text.findTokens(pattern)) {
                st.surroundWith(
                    "<a href='"+url+href+"'>",
{'fraction_non_alphanumeric': 0.12944983818770225, 'fraction_numerical': 0.0, 'mean_word_length': 2.807390817469205, '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': '7586638', 'n_tokens_mistral': 1069, 'n_tokens_neox': 1021, 'n_words': 218}