All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.hm.hafner.analysis.parser.SphinxBuildLinkCheckParser Maven / Gradle / Ivy

package edu.hm.hafner.analysis.parser;

import java.util.Optional;
import java.util.regex.Matcher;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.LookaheadParser;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.util.LookaheadStream;

import static edu.hm.hafner.analysis.Categories.*;

/**
 * A parser for the Sphinx warnings generated by the linkcheck builder.
 *
 * @author Davide Mancusi
 */
public class SphinxBuildLinkCheckParser extends LookaheadParser {
    private static final long serialVersionUID = 1L;

    private static final String SPHINX_BUILD_LINK_CHECK_WARNING_PATTERN = "^(.*):(\\d+|None|): \\[(.*?)\\] (.*)";

    /**
     * Creates a new instance of {@link SphinxBuildLinkCheckParser}.
     */
    public SphinxBuildLinkCheckParser() {
        super(SPHINX_BUILD_LINK_CHECK_WARNING_PATTERN);
    }

    @Override
    protected Optional createIssue(final Matcher matcher, final LookaheadStream lookahead,
            final IssueBuilder builder) {
        String message = matcher.group(4);
        String category = guessCategoryIfEmpty(matcher.group(3), message);

        return builder.setFileName(matcher.group(1))
                .setLineStart(matcher.group(2))
                .setCategory(category)
                .setMessage(message)
                .setSeverity(mapPriority(category))
                .buildOptional();
    }

    private Severity mapPriority(final String priority) {
        if (equalsIgnoreCase(priority, "broken")) {
            return Severity.WARNING_HIGH;
        }
        else {
            return Severity.WARNING_NORMAL;
        }
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy