Remove Gradle "fix"-scripts for Checkstyle rules

This commit is contained in:
Artem Bilan
2016-04-25 13:18:53 -04:00
parent 564eb165d1
commit b3087b4fc8
8 changed files with 0 additions and 413 deletions

View File

@@ -64,14 +64,6 @@ subprojects { subproject ->
apply plugin: 'jacoco'
apply plugin: 'checkstyle'
apply from: "${rootDir}/src/checkstyle/fixFinal.gradle"
apply from: "${rootDir}/src/checkstyle/fixHeaders.gradle"
apply from: "${rootDir}/src/checkstyle/fixModifiers.gradle"
apply from: "${rootDir}/src/checkstyle/fixThis.gradle"
apply from: "${rootDir}/src/checkstyle/fixRightCurly.gradle"
apply from: "${rootDir}/src/checkstyle/fixWhiteAround.gradle"
apply from: "${rootDir}/src/checkstyle/fixParenPad.gradle"
if (project.hasProperty('platformVersion')) {
apply plugin: 'spring-io'

View File

@@ -1,55 +0,0 @@
task fixFinal << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def finalErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.design.FinalClassCheck') {
finalErrors.add(error)
}
}
if (finalErrors) {
def errorInx = 0
def error = finalErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
boolean onNextLine
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (onNextLine || error && ln == (error.@line as int)) {
onNextLine = false
if (line.contains('@SuppressWarning')) {
onNextLine = true;
}
else {
line = line.replaceFirst('class', 'final class')
println "Fixed line $line"
error = finalErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}

View File

@@ -1,43 +0,0 @@
ext {
headerTemplate = new File('src/checkstyle/checkstyle-header.txt')
.text
.replaceAll(/\^\\Q|\\E\$|\^\$|\^\.\*\$/, '')
.replaceFirst(/\\E20\\d\\d\(\\-20\\d\\d\)\?\\Q/, '{year}')
.trim() + System.lineSeparator() + System.lineSeparator()
now = Calendar.instance.get(Calendar.YEAR) as String
}
task fixHeaders << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each {
if (it.error.@source == ['com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck']) {
def years = now
def file = new File(it.@name)
def line
file.withReader { reader ->
while (line = reader.readLine()) {
def matcher = line =~ /Copyright (20\d\d)(?:-20\d\d)?/
if (matcher.count) {
years = matcher[0][1]
if (years != now) {
years = years + "-$now"
}
break
}
}
}
def header = headerTemplate.replaceFirst(/\{year}/, years)
def sourceCode = file.text
sourceCode = sourceCode.replaceFirst(/(?s)(?:.*)(package org\.springframework\.integration.*)/,
"${header}\$1")
file.write(sourceCode)
println "Header fixed for $file"
}
}
}
}

View File

@@ -1,51 +0,0 @@
task fixModifiers << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def modifierErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.modifier.RedundantModifierCheck') {
modifierErrors.add(error)
}
}
if (modifierErrors) {
def errorInx = 0
def error = modifierErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
while (error && ln == (error.@line as int)) {
def message = error.@message
def modifier = message.substring(message.indexOf('\'') + 1, message.lastIndexOf('\''))
line = line.replaceFirst(modifier + ' ', '')
println "Fixed line $line"
error = modifierErrors[errorInx++]
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}

View File

@@ -1,63 +0,0 @@
task fixParenPad << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def thisErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.ParenPadCheck' ||
error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck') {
thisErrors.add(error)
}
}
if (thisErrors) {
def errorInx = 0
def error = thisErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (error && ln == (error.@line as int)) {
def message = error.@message
def index = (error.@column as int) - 1
def chars = line.toCharArray()
for (int i = 0; i < index; i++) {
if (chars[i] == '\t') { // tabs before code == 8
index -= 7;
}
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
break;
}
}
line = line.substring(0, index) + line.substring(index + 1)
println "Fixed line $line"
while (error && ln == (error.@line as int)) {
error = thisErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}

View File

@@ -1,63 +0,0 @@
task fixRightCurly << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def thisErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.blocks.RightCurlyCheck') {
thisErrors.add(error)
}
}
if (thisErrors) {
def errorInx = 0
def error = thisErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (error && ln == (error.@line as int)) {
def index = (error.@column as int) + 1
def chars = line.toCharArray()
def nextLine = System.lineSeparator()
for (int i = 0; i < index; i++) {
if (chars[i] == '\t') { // tabs before code == 8
index -= 7;
nextLine += '\t'
}
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
break;
}
}
line = line.substring(0, index-1) + nextLine + line.substring(index)
println "Fixed line $line"
while (error && ln == (error.@line as int)) {
error = thisErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}

View File

@@ -1,66 +0,0 @@
task fixThis << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def thisErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.coding.RequireThisCheck') {
thisErrors.add(error)
}
}
if (thisErrors) {
def errorInx = 0
def error = thisErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (error && ln == (error.@line as int)) {
def message = error.@message
def property = message.substring(message.indexOf('\'') + 1, message.lastIndexOf('\''))
def thisPrefix = message.substring(message.indexOf('"') + 1, message.lastIndexOf('"'))
def index = (error.@column as int) - 1
def chars = line.toCharArray()
for (int i = 0; i < index; i++) {
if (chars[i] == '\t') { // tabs before code == 8
index -= 7;
}
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
break;
}
}
line = line.substring(0, index) + thisPrefix + property + line.substring(index + property.length())
println "Fixed line $line"
while (error && ln == (error.@line as int)) {
error = thisErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}

View File

@@ -1,64 +0,0 @@
task fixWhiteAround << {
fileTree("${buildDir}/reports/checkstyle").include('*.xml').each { report ->
def xml = new XmlParser(false, false).parse(report)
xml.file.each { f ->
def errors = f.error
def thisErrors = []
errors.each { error ->
if (error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck' ||
error.@source == 'com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck') {
thisErrors.add(error)
}
}
if (thisErrors) {
def errorInx = 0
def error = thisErrors[errorInx++]
def file = new File(f.@name)
println "Fixing file $file ..."
boolean headerFixed
def outSource = ''
file.eachLine { line, ln ->
if (!headerFixed) {
def matcher = line =~ /Copyright (20\d\d)(?:-(20\d\d))?/
if (matcher.count) {
def year1 = matcher[0][1]
if (now != year1) {
if (now != matcher[0][2]) {
line = line.replaceFirst(/(20\d\d)(?:-20\d\d)?/, year1 + "-$now")
}
}
headerFixed = true
}
}
if (error && ln == (error.@line as int)) {
def message = error.@message
def index = (error.@column as int) - 1
def chars = line.toCharArray()
for (int i = 0; i < index; i++) {
if (chars[i] == '\t') { // tabs before code == 8
index -= 7;
}
else if (chars[i] != ' ') { // tabs after code start are only counted as 1
break;
}
}
line = line.substring(0, index) + ' ' + line.substring(index)
println "Fixed line $line"
while (error && ln == (error.@line as int)) {
error = thisErrors[errorInx++]
}
}
outSource += line + System.lineSeparator()
}
file.write(outSource)
println()
}
}
}
}