Skip to content

Commit fd612a2

Browse files
ewencpjunrao
authored andcommitted
kafka-2248; Use Apache Rat to enforce copyright headers; patched by Ewen Cheslack-Postava; reviewed by Gwen Shapira, Joel Joshy and Jun Rao
1 parent 3f8480c commit fd612a2

File tree

10 files changed

+409
-46
lines changed

10 files changed

+409
-46
lines changed

.rat-excludes

Lines changed: 0 additions & 26 deletions
This file was deleted.

build.gradle

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16+
import org.ajoberstar.grgit.Grgit
17+
1618
buildscript {
1719
repositories {
1820
mavenCentral()
1921
}
2022
apply from: file('gradle/buildscript.gradle'), to: buildscript
23+
24+
dependencies {
25+
// For Apache Rat plugin to ignore non-Git files, need ancient version for Java 6 compatibility
26+
classpath group: 'org.ajoberstar', name: 'grgit', version: '0.2.3'
27+
}
2128
}
2229

2330
def slf4jlog4j='org.slf4j:slf4j-log4j12:1.7.6'
@@ -41,8 +48,24 @@ ext {
4148
}
4249

4350
apply from: file('wrapper.gradle')
44-
apply from: file('gradle/license.gradle')
4551
apply from: file('scala.gradle')
52+
apply from: file('gradle/rat.gradle')
53+
54+
rat {
55+
// Exclude everything under the directory that git should be ignoring via .gitignore or that isn't checked in. These
56+
// restrict us only to files that are checked in or are staged.
57+
def repo = Grgit.open(project.file('.'))
58+
excludes = new ArrayList<String>(repo.clean(ignore: false, directories: true, dryRun: true))
59+
// And some of the files that we have checked in should also be excluded from this check
60+
excludes.addAll([
61+
'**/.git/**',
62+
'gradlew',
63+
'gradlew.bat',
64+
'**/README.md',
65+
'.reviewboardrc',
66+
'system_test/**',
67+
])
68+
}
4669

4770
subprojects {
4871
apply plugin: 'java'
@@ -52,8 +75,6 @@ subprojects {
5275

5376
sourceCompatibility = 1.6
5477

55-
licenseTest.onlyIf { isVerificationRequired(project) }
56-
5778
uploadArchives {
5879
repositories {
5980
signing {

core/src/test/scala/other/kafka/TestOffsetManager.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
118
package other.kafka
219

320
import org.I0Itec.zkclient.ZkClient

gradle/buildscript.gradle

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one or more
2+
// contributor license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright ownership.
4+
// The ASF licenses this file to You under the Apache License, Version 2.0
5+
// (the "License"); you may not use this file except in compliance with
6+
// the License. You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
116
repositories {
217
repositories {
318
// For license plugin.
@@ -6,7 +21,3 @@ repositories {
621
}
722
}
823
}
9-
10-
dependencies {
11-
classpath 'nl.javadude.gradle.plugins:license-gradle-plugin:0.10.0'
12-
}

gradle/license.gradle

Lines changed: 0 additions & 9 deletions
This file was deleted.

gradle/rat.gradle

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import org.gradle.api.Plugin
21+
import org.gradle.api.Project
22+
import org.gradle.api.Task
23+
import org.gradle.api.internal.project.IsolatedAntBuilder
24+
25+
apply plugin: RatPlugin
26+
27+
class RatTask extends DefaultTask {
28+
@Input
29+
List<String> excludes
30+
31+
def reportPath = 'build/rat'
32+
def stylesheet = 'gradle/resources/rat-output-to-html.xsl'
33+
def xmlReport = reportPath + '/rat-report.xml'
34+
def htmlReport = reportPath + '/rat-report.html'
35+
36+
def generateXmlReport(File reportDir) {
37+
def antBuilder = services.get(IsolatedAntBuilder)
38+
def ratClasspath = project.configurations.rat
39+
antBuilder.withClasspath(ratClasspath).execute {
40+
ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml')
41+
ant.report(format: 'xml', reportFile: xmlReport) {
42+
fileset(dir: ".") {
43+
patternset {
44+
excludes.each {
45+
exclude(name: it)
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
53+
def printUnknownFiles() {
54+
def ratXml = new XmlParser().parse(xmlReport)
55+
def unknownLicenses = 0
56+
ratXml.resource.each { resource ->
57+
if (resource.'license-approval'.@name[0] == "false") {
58+
println('Unknown license: ' + resource.@name)
59+
unknownLicenses++
60+
}
61+
}
62+
if (unknownLicenses > 0) {
63+
throw new GradleException("Found " + unknownLicenses + " files with " +
64+
"unknown licenses.")
65+
}
66+
}
67+
68+
def generateHtmlReport() {
69+
def antBuilder = services.get(IsolatedAntBuilder)
70+
def ratClasspath = project.configurations.rat
71+
antBuilder.withClasspath(ratClasspath).execute {
72+
ant.xslt(
73+
in: xmlReport,
74+
style: stylesheet,
75+
out: htmlReport,
76+
classpath: ratClasspath)
77+
}
78+
println('Rat report: ' + htmlReport)
79+
}
80+
81+
@TaskAction
82+
def rat() {
83+
File reportDir = new File(reportPath)
84+
if (!reportDir.exists()) {
85+
reportDir.mkdirs()
86+
}
87+
generateXmlReport(reportDir)
88+
printUnknownFiles()
89+
generateHtmlReport()
90+
}
91+
}
92+
93+
class RatPlugin implements Plugin<Project> {
94+
void apply(Project project) {
95+
configureDependencies(project)
96+
project.plugins.apply(JavaPlugin);
97+
Task ratTask = project.task("rat",
98+
type: RatTask,
99+
group: 'Build',
100+
description: 'Runs Apache Rat checks.')
101+
project.tasks[JavaPlugin.TEST_TASK_NAME].dependsOn ratTask
102+
}
103+
104+
void configureDependencies(final Project project) {
105+
project.configurations {
106+
rat
107+
}
108+
project.repositories {
109+
mavenCentral()
110+
}
111+
project.dependencies {
112+
rat 'org.apache.rat:apache-rat-tasks:0.11'
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)