rmuir commented on code in PR #15195: URL: https://github.com/apache/lucene/pull/15195#discussion_r2355027014
########## build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/licenses/CheckLicensesPlugin.java: ########## @@ -0,0 +1,126 @@ +/* + * 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. + */ +package org.apache.lucene.gradle.plugins.licenses; + +import org.apache.lucene.gradle.plugins.LuceneGradlePlugin; +import org.gradle.api.Project; + +/** This configures ASL and other license checks. */ +public class CheckLicensesPlugin extends LuceneGradlePlugin { + @Override + public void apply(Project project) { + applicableToRootProjectOnly(project); + + // Add check licenses task to the top-level project, configure it to scan all files, including + // those from subprojects. It's fast and simple. + var checkLicensesTask = + project + .getTasks() + .register("checkLicenses", CheckLicensesTask.class, this::configureCheckLicenses); + + // Link any 'check' task from any subproject to this top-level task. + project.subprojects( + subproject -> { + subproject + .getTasks() + .named("check") + .configure( + checkTask -> { + checkTask.dependsOn(checkLicensesTask); + }); + }); + } + + private void configureCheckLicenses(CheckLicensesTask task) { + Project project = task.getProject(); + + task.getReportFile().set(project.getLayout().getBuildDirectory().file("licenses-report.txt")); + task.getFiles() + .from( + project.fileTree( + ".", + tree -> { + // Exclude build outputs, ide files, .git. Review Comment: In the future could we instead please consider using `git ls-files` for this? I am afraid of when these long long lists of hardcoded excludes fall out of sync with .gitignore files, then checks become slow, or have false failures, or both. I am only referring to .git/build/etc exclusions which should not be necessary. In 2025 all checkers should respect .gitignore :) We should only have the "real" excludes here particular to the specific check (things in source control) -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
