lucene/gradle/ant-compat/forbidden-api-rules-in-sync...

55 lines
2.2 KiB
Groovy
Raw Normal View History

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
// Just make sure the forbidden API rules are in sync between gradle and ant versions until
// we get rid of ant build.
def linesOf(FileTree ftree) {
return ftree.collectMany { path ->
path.readLines("UTF-8")
.collect { line -> line.trim() }
.findAll { line -> !line.startsWith("#") }
.unique()
.collect { line -> [path: path, line: line] }
}.groupBy { e -> e.line }
}
configure(rootProject) {
task verifyForbiddenApiRulesInSync() {
doFirst {
// Read all rules line by line from ant, gradle, remove comments, uniq.
// Rule sets should be identical.
def gradleRules = linesOf(fileTree("gradle/validation/forbidden-apis", { include "**/*.txt" }))
def antRules = linesOf(project(":lucene").fileTree("tools/forbiddenApis", { include "**/*.txt" }))
def antOnlyLines = antRules.keySet() - gradleRules.keySet()
def gradleOnlyLines = gradleRules.keySet() - antRules.keySet()
if (!gradleOnlyLines.isEmpty() || !antOnlyLines.isEmpty()) {
project.logger.log(LogLevel.ERROR, "The following rules don't have counterparts:\n" +
(gradleRules.findAll { gradleOnlyLines.contains(it.key) } + antRules.findAll { antOnlyLines.contains(it.key)})
.collectMany { it.value }
.join("\n"))
throw new GradleException("Forbidden APIs rules out of sync.")
}
}
}
check.dependsOn verifyForbiddenApiRulesInSync
}