breskeby commented on code in PR #14824: URL: https://github.com/apache/lucene/pull/14824#discussion_r2159972822
########## build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/spotless/ParentGoogleJavaFormatTask.java: ########## @@ -0,0 +1,69 @@ +package org.apache.lucene.gradle.plugins.spotless; + +import com.google.googlejavaformat.java.Formatter; +import com.google.googlejavaformat.java.JavaFormatterOptions; +import org.gradle.api.DefaultTask; +import org.gradle.api.file.ConfigurableFileCollection; +import org.gradle.api.file.FileType; +import org.gradle.api.file.ProjectLayout; +import org.gradle.api.file.RegularFileProperty; +import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.Internal; +import org.gradle.api.tasks.OutputFile; +import org.gradle.api.tasks.PathSensitive; +import org.gradle.api.tasks.PathSensitivity; +import org.gradle.work.ChangeType; +import org.gradle.work.FileChange; +import org.gradle.work.Incremental; +import org.gradle.work.InputChanges; +import org.gradle.workers.WorkQueue; +import org.gradle.workers.WorkerExecutor; + +import javax.inject.Inject; +import java.io.File; +import java.util.List; +import java.util.stream.StreamSupport; + +abstract class ParentGoogleJavaFormatTask extends DefaultTask { + @Incremental + @InputFiles + @PathSensitive(PathSensitivity.RELATIVE) + public abstract ConfigurableFileCollection getSourceFiles(); + + @OutputFile + public abstract RegularFileProperty getOutputChangeListFile(); + + @Inject + protected abstract WorkerExecutor getWorkerExecutor(); + + public ParentGoogleJavaFormatTask(ProjectLayout layout, String gjfTask) { + getOutputChangeListFile().convention(layout.getBuildDirectory().file("gjf-" + gjfTask + ".txt")); + } + + protected static Formatter getFormatter() { + JavaFormatterOptions options = + JavaFormatterOptions.builder() + .style(JavaFormatterOptions.Style.GOOGLE) + .formatJavadoc(true) + .reorderModifiers(true) + .build(); + return new Formatter(options); + } + + protected List<File> getIncrementalBatch(InputChanges inputChanges) { + return StreamSupport.stream(inputChanges.getFileChanges(getSourceFiles()).spliterator(), false) + .filter(fileChange -> { + return fileChange.getFileType() == FileType.FILE && + (fileChange.getChangeType() == ChangeType.ADDED || + fileChange.getChangeType() == ChangeType.MODIFIED); + }) + .map(FileChange::getFile) + .toList(); + } + + @Internal + protected WorkQueue getWorkQueue() { + // TODO: maybe fork a separate jvm so that we can pass open-module settings there and fine-tune the jvm for the task? + return getWorkerExecutor().noIsolation(); + } Review Comment: Thinking about this more I wonder if you can restrict the parallization by using a BuildService. Again this is not exactly the simple api for restricting parallization but it should work. Here's an example on how to use it with WorkerAPI: https://docs.gradle.org/current/userguide/build_services.html#using_a_build_service_with_the_worker_api Then you would register the service on project level and set a maxParallel usage. Here's an example on how we throttle things this way in the elasticsearch build: https://github.com/elastic/elasticsearch/blob/7b6bdfa323fcc7460dc252b3dbc84c6b1314fb66/build-tools/src/main/java/org/elasticsearch/gradle/testclusters/TestClustersPlugin.java#L126-L133 -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org