You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gobblin.apache.org by ab...@apache.org on 2018/01/03 20:02:12 UTC
[03/10] incubator-gobblin git commit: [GOBBLIN-355] Add gradle script
for Rat plugin
[GOBBLIN-355] Add gradle script for Rat plugin
Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/cc60a1ca
Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/cc60a1ca
Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/cc60a1ca
Branch: refs/heads/master
Commit: cc60a1caa63f0fe3551ac49b0a3b5c8f402e8bdc
Parents: 977e985
Author: Abhishek Tiwari <ab...@gmail.com>
Authored: Wed Jan 3 16:43:02 2018 +0530
Committer: Abhishek Tiwari <ab...@gmail.com>
Committed: Wed Jan 3 16:43:02 2018 +0530
----------------------------------------------------------------------
gradle/scripts/rat.gradle | 109 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 109 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/cc60a1ca/gradle/scripts/rat.gradle
----------------------------------------------------------------------
diff --git a/gradle/scripts/rat.gradle b/gradle/scripts/rat.gradle
new file mode 100644
index 0000000..8c8ac5e
--- /dev/null
+++ b/gradle/scripts/rat.gradle
@@ -0,0 +1,109 @@
+/*
+ * 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.Plugin
+import org.gradle.api.Project
+import org.gradle.api.Task
+import org.gradle.api.internal.project.IsolatedAntBuilder
+
+apply plugin: RatPlugin
+
+class RatTask extends DefaultTask {
+ @Input
+ List<String> excludes
+
+ def reportPath = 'build/rat'
+ def stylesheet = 'gradle/resources/rat-output-to-html.xsl'
+ def xmlReport = reportPath + '/rat-report.xml'
+ def htmlReport = reportPath + '/rat-report.html'
+
+ def generateXmlReport(File reportDir) {
+ def antBuilder = services.get(IsolatedAntBuilder)
+ def ratClasspath = project.configurations.rat
+ antBuilder.withClasspath(ratClasspath).execute {
+ ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml')
+ ant.report(format: 'xml', reportFile: xmlReport) {
+ fileset(dir: ".") {
+ patternset {
+ excludes.each {
+ exclude(name: it)
+ }
+ }
+ }
+ }
+ }
+ }
+
+ def printUnknownFiles() {
+ def ratXml = new XmlParser().parse(xmlReport)
+ ratXml.resource.each { resource ->
+ if (resource.'license-approval'.@name[0] == "false") {
+ println('Unknown license: ' + resource.@name)
+ }
+ }
+ }
+
+ 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() {
+ File reportDir = new File(reportPath)
+ if (!reportDir.exists()) {
+ reportDir.mkdirs()
+ }
+ generateXmlReport(reportDir)
+ printUnknownFiles()
+ generateHtmlReport()
+ }
+}
+
+class RatPlugin implements Plugin<Project> {
+ void apply(Project project) {
+ configureDependencies(project)
+ project.plugins.apply(JavaBasePlugin);
+ Task ratTask = project.task("rat",
+ type: RatTask,
+ group: 'Build',
+ description: 'Runs Apache Rat checks.')
+ project.tasks[JavaBasePlugin.CHECK_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.8'
+ }
+ }
+}