#!/usr/bin/env groovy /* * Remove nasty trailing spaces inserted by the naughty Hippo * at the end of some .xml files. */ @Grab('org.apache.commons:commons-lang3:3.3.1') import org.apache.commons.lang3.StringUtils import static groovy.io.FileType.FILES def removeTrailingSpaces(String text) { def newText = new StringBuffer() boolean modified = false text.eachLine { line -> def stripped = StringUtils.stripEnd(line, ' ') if (stripped != line) { modified = true } newText.append stripped newText.append "\n" } return [modified, newText.toString()] } boolean removeTrailingSpacesFromFile(File file) { def (isModified, newContent) = removeTrailingSpaces(file.text) if (isModified) { println "Removed trailing spaces from ${file.getPath()}" file.write newContent } return isModified } def modifiedCount = 0 def base = '../../../..' File dir = new File(base) println "Base source directory: ${dir.getCanonicalPath()}" dir.traverse(type: FILES, nameFilter: ~/hippo.*\.xml$/) { file -> println "Processing ${file.getPath()}" if (removeTrailingSpacesFromFile(file)) { modifiedCount++ } } println "Modified files: $modifiedCount - certified on ${new Date()}"