blob: 12d4eaa0622ba94314d37c94c3fe4518b19f4112 [file] [log] [blame]
import groovy.text.markup.MarkupTemplateEngine
import groovy.text.markup.TemplateConfiguration
/*
* Copyright 2003-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
allprojects {
apply plugin: 'checkstyle'
apply plugin: 'codenarc'
// don't fail build on CodeNarc tasks
tasks.withType(CodeNarc) {
ignoreFailures = true
configFile = file("$rootProject.projectDir/config/codenarc/codenarc.groovy")
}
tasks.withType(Checkstyle) {
showViolations = false
ignoreFailures = true
configFile = file("$rootProject.projectDir/config/checkstyle/checkstyle.xml")
configProperties = ['rootProject.projectDir': rootProject.projectDir]
def reportFile = file("${buildDir}/reports/checkstyle/${name}.xml")
reports {
include ( '**/*.java')
xml {
destination reportFile
}
}
task("${name}Report") {
def configDir = file("$rootProject.projectDir/config/checkstyle")
def templateFile = 'checkstyle-report.groovy'
def htmlReportFile = file("${buildDir}/reports/checkstyle/${name}.html")
inputs.file file("$configDir/$templateFile")
inputs.file reportFile
outputs.file htmlReportFile
doLast {
if (reportFile.exists()) {
def templateConfiguration = new TemplateConfiguration()
templateConfiguration.with {
autoIndent = true
autoNewLine = true
}
def engine = new MarkupTemplateEngine(this.class.classLoader, configDir, templateConfiguration)
def xml = new XmlSlurper().parse(reportFile.newReader('utf-8'))
def files = []
xml.file.each { f ->
if (f.error.size()) {
files << [
name: f.@name.toString(),
errors: f.error.collect { e ->
def rule = e.@source.toString()
rule = rule.substring(rule.lastIndexOf('.')+1)
[line: e.@line.toString(),
column: e.@column.toString(),
message: e.@message.toString(),
source: rule,
severity: e.@severity.toString()]
}]
}
}
def model = [
project: project,
files: files
]
htmlReportFile.withWriter('utf-8') { wrt ->
engine.createTemplateByPath('checkstyle-report.groovy').make(model).writeTo(wrt)
}
}
}
}
finalizedBy "${name}Report"
}
}
apply from: 'gradle/jacoco/jacoco.gradle'
apply from: 'gradle/binarycompatibility.gradle'