breskeby commented on code in PR #14824: URL: https://github.com/apache/lucene/pull/14824#discussion_r2159937021
########## 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: forking the jvm is still expensive to some degree. I usually try to get away with isolated first if I need separate classpaths. you should be able to do configure the jvm options like this: ``` return getWorkerExecutor().processIsolation(spec -> { spec.forkOptions(javaForkOptions -> { javaForkOptions.jvmArgs("-Xmx2g", "-Xms2g"); }); }); ``` There is no build-in mechanism to restrict the parallization for a specific task implementation. gradle just has a global property of `org.gradle.workers.max` that defaults to #cpus which is used when forking jvms for workers, test tasks, etc etc. Is the point here to parallise the handling of sources in a single project and speed up format checks by this? If forking a process is needed I would actually rework the implementation of the worker api to not submit one file after another but operate on the list of sources within the worker. This would basically mean having one worker per task. It'll still really improve the paralleiism as you can run on different sourcesets per project. -- 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