mirror of https://github.com/apache/kafka.git
MINOR: Switch to using the Gradle RAT plugin (#10491)
The Gradle RAT plugin properly declares inputs and outputs and is also cachable. This also relieves the Kafka developers from maintaining the build integration with RAT. The generated RAT report is identical to the one generated previously. The only difference is the RAT report name: the RAT plugin sets the HTML report name to `index.html` (still under `build/rat`). Verified that the rat task fails if unlicensed files are present (and not excluded). Also `./gradlew rat` succeeds when there is no .git folder.
This commit is contained in:
parent
88eb24db40
commit
1e8a7c45ef
12
build.gradle
12
build.gradle
|
@ -35,6 +35,7 @@ plugins {
|
|||
id 'idea'
|
||||
id 'java-library'
|
||||
id 'org.owasp.dependencycheck' version '6.1.1'
|
||||
id 'org.nosphere.apache.rat' version "0.7.0"
|
||||
|
||||
id "com.github.spotbugs" version '4.6.0' apply false
|
||||
id 'org.gradle.test-retry' version '1.2.0' apply false
|
||||
|
@ -135,8 +136,11 @@ ext {
|
|||
apply from: file('wrapper.gradle')
|
||||
|
||||
if (file('.git').exists()) {
|
||||
apply from: file('gradle/rat.gradle')
|
||||
rat {
|
||||
verbose = true
|
||||
reportDir.set(project.file('build/rat'))
|
||||
stylesheet.set(file('gradle/resources/rat-output-to-html.xsl'))
|
||||
|
||||
// Exclude everything under the directory that git should be ignoring via .gitignore or that isn't checked in. These
|
||||
// restrict us only to files that are checked in or are staged.
|
||||
def repo = Grgit.open(currentDir: project.getRootDir())
|
||||
|
@ -159,11 +163,13 @@ if (file('.git').exists()) {
|
|||
'streams/quickstart/java/src/test/resources/projects/basic/goal.txt',
|
||||
'streams/streams-scala/logs/*',
|
||||
'licenses/*',
|
||||
'**/generated/**'
|
||||
'**/generated/**',
|
||||
'clients/src/test/resources/serializedData/*'
|
||||
])
|
||||
}
|
||||
} else {
|
||||
rat.enabled = false
|
||||
}
|
||||
|
||||
println("Starting build with version $version using Gradle $gradleVersion, Java ${JavaVersion.current()} and Scala ${versions.scala}")
|
||||
|
||||
subprojects {
|
||||
|
|
|
@ -1,120 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import org.gradle.api.internal.project.IsolatedAntBuilder
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
apply plugin: RatPlugin
|
||||
|
||||
class RatTask extends DefaultTask {
|
||||
@Input
|
||||
List<String> excludes
|
||||
|
||||
def reportDir = project.file('build/rat')
|
||||
def stylesheet = project.file('gradle/resources/rat-output-to-html.xsl').getAbsolutePath()
|
||||
def xmlReport = new File(reportDir, 'rat-report.xml')
|
||||
def htmlReport = new File(reportDir, 'rat-report.html')
|
||||
|
||||
def generateXmlReport(File reportDir) {
|
||||
def antBuilder = services.get(IsolatedAntBuilder)
|
||||
def ratClasspath = project.configurations.rat
|
||||
def projectPath = project.getRootDir().getAbsolutePath()
|
||||
antBuilder.withClasspath(ratClasspath).execute {
|
||||
ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml')
|
||||
ant.report(format: 'xml', reportFile: xmlReport) {
|
||||
fileset(dir: projectPath) {
|
||||
patternset {
|
||||
excludes.each {
|
||||
exclude(name: it)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def printUnknownFiles() {
|
||||
def ratXml = new XmlParser().parse(xmlReport)
|
||||
def unknownLicenses = 0
|
||||
ratXml.resource.each { resource ->
|
||||
if (resource.'license-approval'.@name[0] == "false") {
|
||||
println('Unknown license: ' + resource.@name)
|
||||
unknownLicenses++
|
||||
}
|
||||
}
|
||||
if (unknownLicenses > 0) {
|
||||
throw new GradleException("Found " + unknownLicenses + " files with " +
|
||||
"unknown licenses.")
|
||||
}
|
||||
}
|
||||
|
||||
def generateHtmlReport() {
|
||||
def antBuilder = services.get(IsolatedAntBuilder)
|
||||
def ratClasspath = project.configurations.rat
|
||||
antBuilder.withClasspath(ratClasspath).execute {
|
||||
ant.xslt(
|
||||
in: xmlReport,
|
||||
style: stylesheet,
|
||||
out: htmlReport,
|
||||
classpath: ratClasspath)
|
||||
}
|
||||
println('Rat report: ' + htmlReport)
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
def rat() {
|
||||
if (!reportDir.exists()) {
|
||||
reportDir.mkdirs()
|
||||
}
|
||||
def origEncoding = System.getProperty("file.encoding")
|
||||
try {
|
||||
System.setProperty("file.encoding", StandardCharsets.UTF_8.name()) //affects the output of the ant rat task
|
||||
generateXmlReport(reportDir)
|
||||
printUnknownFiles()
|
||||
generateHtmlReport()
|
||||
} finally {
|
||||
System.setProperty("file.encoding", origEncoding)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RatPlugin implements Plugin<Project> {
|
||||
void apply(Project project) {
|
||||
configureDependencies(project)
|
||||
project.plugins.apply(JavaPlugin);
|
||||
Task ratTask = project.task("rat",
|
||||
type: RatTask,
|
||||
group: 'Build',
|
||||
description: 'Runs Apache Rat checks.')
|
||||
project.tasks[JavaPlugin.TEST_TASK_NAME].dependsOn ratTask
|
||||
}
|
||||
|
||||
void configureDependencies(final Project project) {
|
||||
project.configurations {
|
||||
rat
|
||||
}
|
||||
project.repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
project.dependencies {
|
||||
rat 'org.apache.rat:apache-rat-tasks:0.13'
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue