dweiss commented on a change in pull request #1157: Add RAT check using Gradle
URL: https://github.com/apache/lucene-solr/pull/1157#discussion_r365565330
 
 

 ##########
 File path: gradle/validation/rat-sources.gradle
 ##########
 @@ -0,0 +1,174 @@
+/*
+ * 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 groovy.xml.NamespaceBuilder
+
+allprojects {
+    configurations {
+        rat
+    }
+
+    dependencies {
+        rat 'org.apache.rat:apache-rat-tasks:0.13'
+    }
+}
+
+subprojects {
+    plugins.withId("java", {
+        task("rat", type: RatTask) {
+            group = 'Verification'
+            description = 'Runs Apache Rat checks.'
+        }
+    })
+}
+
+// Somewhat inspired by existing task from Apache Kafka
+class RatTask extends DefaultTask {
+    @Input
+    List<String> includes = []
+
+    @Input
+    List<String> excludes = []
+
+    @Input
+    List<String> additionalExcludes = []
+
+    def reportDir = new File(project.buildDir, 'rat')
+    def xmlReport = new File(reportDir, 'rat-report.xml')
+
+    def generateXmlReport(File reportDir) {
+        def uri = 'antlib:org.apache.rat.anttasks'
+        def ratClasspath = project.configurations.rat.asPath
+        ant.taskdef(resource: 'org/apache/rat/anttasks/antlib.xml', uri: uri, 
classpath: ratClasspath)
+
+        def projectPath = project.projectDir.absolutePath
+
+        def rat = NamespaceBuilder.newInstance(ant, uri)
+        rat.report(format: 'xml', reportFile: xmlReport, 
addDefaultLicenseMatchers: true) {
+            ant.fileset(dir: projectPath) {
+                ant.include(name: '*.xml')
+                includes.each {
+                    ant.include(name: it)
+                }
+                additionalExcludes.each {
+                    ant.exclude(name: it)
+                }
+            }
+
+            // There may be a more efficient way to write these next two 
blocks since they use the same logic
+            project.sourceSets.main.java.srcDirs.each {
+                ant.fileset(dir: it, erroronmissingdir: false) {
+                    excludes.each { x -> ant.exclude(name: x) }
+                }
+            }
+            project.sourceSets.test.java.srcDirs.each {
+                ant.fileset(dir: it, erroronmissingdir: false) {
+                    excludes.each { x -> ant.exclude(name: x) }
+                }
+            }
+
+            project.sourceSets.main.resources.srcDirs.each {
+                ant.fileset(dir: it, erroronmissingdir: false) {
+                    ant.include(name: 'META-INF/**')
+                }
+            }
+
+            // The license rules below were manually copied from 
lucene/common-build.xml, there is currently no mechanism to sync them
+
+            // BSD 4-clause stuff (is disallowed below)
+            substringMatcher(licenseFamilyCategory: "BSD4 ", 
licenseFamilyName: "Original BSD License (with advertising clause)") {
+                pattern(substring: "All advertising materials")
+            }
+
+            // BSD-like stuff
+            substringMatcher(licenseFamilyCategory: "BSD  ", 
licenseFamilyName: "Modified BSD License") {
+                // brics automaton
+                pattern(substring: "Copyright (c) 2001-2009 Anders Moeller")
+                // snowball
+                pattern(substring: "Copyright (c) 2001, Dr Martin Porter")
+                // UMASS kstem
+                pattern(substring: "THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF 
MASSACHUSETTS AND OTHER CONTRIBUTORS")
+                // Egothor
+                pattern(substring: "Egothor Software License version 1.00")
+                // JaSpell
+                pattern(substring: "Copyright (c) 2005 Bruno Martins")
+                // d3.js
+                pattern(substring: "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
HOLDERS AND CONTRIBUTORS")
+                // highlight.js
+                pattern(substring: "THIS SOFTWARE IS PROVIDED BY THE REGENTS 
AND CONTRIBUTORS")
+            }
+
+            // MIT-like
+            substringMatcher(licenseFamilyCategory: "MIT  ", 
licenseFamilyName:"Modified BSD License") {
+                // ICU license
+                pattern(substring: "Permission is hereby granted, free of 
charge, to any person obtaining a copy")
+            }
+
+            // Apache
+            substringMatcher(licenseFamilyCategory: "AL   ", 
licenseFamilyName: "Apache") {
+                pattern(substring: "Licensed to the Apache Software Foundation 
(ASF) under")
+                // this is the old - school one under some files
+                pattern(substring: "Licensed under the Apache License, Version 
2.0 (the &quot;License&quot;)")
+            }
+
+            substringMatcher(licenseFamilyCategory: "GEN  ", 
licenseFamilyName: "Generated") {
+                // svg files generated by gnuplot
+                pattern(substring: "Produced by GNUPLOT")
+                // snowball stemmers generated by snowball compiler
+                pattern(substring: "This file was generated automatically by 
the Snowball to Java compiler")
+                // parsers generated by antlr
+                pattern(substring: "ANTLR GENERATED CODE")
+            }
+
+            approvedLicense(familyName: "Apache")
+            approvedLicense(familyName: "The MIT License")
+            approvedLicense(familyName: "Modified BSD License")
+            approvedLicense(familyName: "Generated")
+        }
+    }
+
+    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)
 
 Review comment:
   collect offending resources to an array and throw the exception with all 
offenders -- see other validation tasks (license checksum validation for 
example)?
   
   this matters when tasks run concurrently - easier to spot the problem 
(reported by gradle at the end of the build).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to