rmuir commented on code in PR #15195: URL: https://github.com/apache/lucene/pull/15195#discussion_r2355122322
########## 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: I think the thing i am highly suspicious of: is this `project.fileTree`. Potential forbidden-apis candidate. Some old build processes got slower over months/years in exactly this way. This can go unnoticed, for example if they only **descend** into a python venv, because there are often thousands and thousands of directories files in there. They don't have to actually match any of the files to slow everything down, that's a big part of the trap. Maybe there is a gradle or java plugin we could use that behaves like https://docs.rs/ignore/latest/ignore/ or we can just use `git ls-files`. Sorry for the rant, I see this as the number one cause of slow checkers these days, and it is easy to avoid. -- 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]
