Optimize checkTestConfigs task for UP_TO_DATE

We really don't need to parse `inputs.files` for wrong XSD configuration.
This is already a responsibility of the task.
There is just enough to track changes in the XML configs and if they
happened only after that treat the task as out of date and parse configs
for wrong XSD configuration
This commit is contained in:
Artem Bilan
2019-02-14 10:39:50 -05:00
parent 1fad620b8f
commit fe5d0affde

View File

@@ -192,22 +192,22 @@ subprojects { subproject ->
[compileJava, compileTestJava]*.options*.compilerArgs = [xLintArg]
task checkTestConfigs {
def configFiles = []
sourceSets.test.java.srcDirs.each {
fileTree(it).include('**/*.xml').exclude('**/log4j2-test.xml').each { configFile ->
def configXml = new XmlParser(false, false).parse(configFile)
if (configXml.@'xsi:schemaLocation' ==~ /.*spring-[a-z-]*\d\.\d\.xsd.*/) {
configFiles << configFile
}
}
}
inputs.files(configFiles)
inputs.files(
sourceSets.test.java.srcDirs.collect {
fileTree(it)
.include('**/*.xml')
.exclude('**/log4j2-test.xml')
})
outputs.dir('build')
doLast {
if (!inputs.files.empty) {
def wrongConfigs = inputs.files.filter {
new XmlParser(false, false)
.parse(it)
.@'xsi:schemaLocation' ==~ /.*spring-[a-z-]*\d\.\d\.xsd.*/
}
if (!wrongConfigs.empty) {
throw new InvalidUserDataException('Hardcoded XSD version in the config files:\n' +
inputs.files.collect {relativePath(it) }.join('\n') +
wrongConfigs.collect { relativePath(it) }.join('\n') +
'\nPlease, use versionless schemaLocations for Spring XSDs to avoid issues with builds ' +
'on different versions of dependencies.')
}