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

com.github.mictaege.jitter.plugin.CriticalTermsViolations.groovy Maven / Gradle / Ivy

package com.github.mictaege.jitter.plugin

import com.google.common.collect.HashBasedTable
import com.google.common.collect.Table

import static com.google.common.html.HtmlEscapers.htmlEscaper

class CriticalTermsViolations {

    FlavourCfg flavour
    Table table

    CriticalTermsViolations(FlavourCfg flavour) {
        this.flavour = flavour
        table = HashBasedTable.create()
    }

    void add(FlavourCfg flavour, String pattern, File violated) {
        def rowIdx = table.rowKeySet().size()
        table.put(rowIdx, 0, flavour.name)
        table.put(rowIdx, 1, pattern)
        table.put(rowIdx, 2, violated.absolutePath)
    }

    boolean hasViolations() {
        return table.rowKeySet().size() > 0
    }

    void report(String path) {
        StringBuilder html = new StringBuilder()
        html.append("\n")
        html.append("\n")
        html.append("\n")
        html.append("\n")
        html.append("\n")
        html.append("Critical Terms Report\n")
        html.append("\n")
        html.append("\n")
        html.append("

Critical Terms Report

\n") if (hasViolations()) { html.append("

Critical terms violated!

\n") html.append("\n") html.append("\n") table.rowKeySet().each { i -> def row = table.row(i) def flavour = htmlEscaper().escape(row.get(0)) def pattern = htmlEscaper().escape(row.get(1)) def violated = htmlEscaper().escape(row.get(2)) html.append("\n") } html.append("
FlavourCritical TermViolated Resource
$flavour$pattern$violated
\n") } else { html.append("

No critical terms violated.

\n") } html.append("\n") html.append("") File reportFile = prepareFile(path) reportFile.text = html.toString() } private File prepareFile(String path) { def reportFolder = new File(path + "/reports/jitter") if (!reportFolder.exists()) { reportFolder.mkdirs() } def reportFile = new File(path + "/reports/jitter/CriticalTermsReport.html") if (!reportFile.exists()) { reportFile.createNewFile() } reportFile } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy