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

name.remal.gradle_plugins.toolkit.issues.TextIssuesRenderer Maven / Gradle / Ivy

There is a newer version: 0.69.7
Show newest version
package name.remal.gradle_plugins.toolkit.issues;

import static java.util.stream.Collectors.joining;
import static name.remal.gradle_plugins.toolkit.StringUtils.indentString;
import static name.remal.gradle_plugins.toolkit.StringUtils.normalizeString;
import static name.remal.gradle_plugins.toolkit.issues.Utils.appendDelimiter;
import static name.remal.gradle_plugins.toolkit.issues.Utils.ifPresent;
import static name.remal.gradle_plugins.toolkit.issues.Utils.streamIssues;

import java.util.stream.Stream;
import javax.annotation.Nullable;
import lombok.val;
import name.remal.gradle_plugins.toolkit.ObjectUtils;
import org.intellij.lang.annotations.Language;

public class TextIssuesRenderer implements IssuesRenderer {

    @Language("TEXT")
    @Override
    public String renderIssues(Iterable issues) {
        return streamIssues(issues)
            .map(issue -> {
                val sb = new StringBuilder();

                ifPresent(issue.getSeverity(), it -> sb.append(it).append(':'));

                val ruleText = Stream.of(issue.getCategory(), issue.getRule())
                    .filter(ObjectUtils::isNotEmpty)
                    .collect(joining(" | "));
                if (!ruleText.isEmpty()) {
                    appendDelimiter(sb).append('[').append(ruleText).append(']');
                }

                appendDelimiter(sb).append(issue.getSourceFile().getAbsolutePath());

                ifPresent(issue.getStartLine(), it -> sb.append(':').append(it));
                ifPresent(issue.getStartColumn(), it -> sb.append(':').append(it));

                val messageText = messageToText(issue.getMessage());
                if (!messageText.isEmpty()) {
                    if (messageText.contains("\n")) {
                        sb.append('\n').append(indentString(messageText));
                    } else {
                        sb.append(": ").append(messageText);
                    }
                }

                val descriptionText = messageToText(issue.getDescription());
                if (!descriptionText.isEmpty()) {
                    if (!messageText.isEmpty()) {
                        sb.append('\n');
                    }
                    sb.append('\n').append(indentString(descriptionText));
                }

                return sb.toString();
            })
            .collect(joining("\n\n"));
    }

    @Language("TEXT")
    private static String messageToText(@Nullable Message message) {
        return message != null ? normalizeString(message.renderAsText()) : "";
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy