33import lombok .Getter ;
44import org .gradle .api .file .ConfigurableFileCollection ;
55import org .gradle .api .file .DirectoryProperty ;
6+ import org .gradle .api .file .FileSystemOperations ;
67import org .gradle .api .provider .Property ;
78import org .gradle .api .tasks .*;
9+ import org .gradle .workers .WorkQueue ;
810import org .gradle .workers .WorkerExecutor ;
911
1012import javax .inject .Inject ;
@@ -17,6 +19,8 @@ public class PlantumlTask extends SourceTask {
1719
1820 private final WorkerExecutor workerExecutor ;
1921
22+ private final FileSystemOperations fileSystemOperations ;
23+
2024 @ Getter
2125 @ Classpath
2226 private final ConfigurableFileCollection plantumlClasspath = getProject ().files ();
@@ -39,28 +43,29 @@ public class PlantumlTask extends SourceTask {
3943 private final Property <String > includePattern = getProject ().getObjects ().property (String .class ).convention ("**/*.puml" );
4044
4145 @ Inject
42- public PlantumlTask (WorkerExecutor workerExecutor ) {
43- this .setGroup ( "plantuml" ) ;
46+ public PlantumlTask (WorkerExecutor workerExecutor , FileSystemOperations fileSystemOperations ) {
47+ this .fileSystemOperations = fileSystemOperations ;
4448 this .workerExecutor = workerExecutor ;
49+ this .setGroup ("plantuml" );
4550 }
4651
4752 @ TaskAction
4853 public void execute () {
4954
50- getProject ().delete (outputDirectory );
55+ fileSystemOperations .delete (deleteSpec -> deleteSpec .delete (outputDirectory ));
56+
57+ WorkQueue workQueue = workerExecutor .processIsolation (process -> {
58+ process .getClasspath ().from (plantumlClasspath );
59+ process .getForkOptions ().systemProperty ("java.awt.headless" , true );
60+ });
5161
5262 for (File file : getSource ().matching (p -> p .include (includePattern .get ()))) {
53- workerExecutor
54- .processIsolation (iso -> {
55- iso .getClasspath ().from (plantumlClasspath );
56- iso .getForkOptions ().systemProperty ("java.awt.headless" , true );
57- })
58- .submit (PlantumlAction .class , params -> {
59- params .getInputFile ().set (file );
60- params .getOutputDirectory ().set (outputDirectory );
61- params .getFileFormat ().set (fileFormat );
62- params .getWithMetadata ().set (withMetadata );
63- });
63+ workQueue .submit (PlantumlAction .class , params -> {
64+ params .getInputFile ().set (file );
65+ params .getOutputDirectory ().set (outputDirectory );
66+ params .getFileFormat ().set (fileFormat );
67+ params .getWithMetadata ().set (withMetadata );
68+ });
6469 }
6570 }
6671}
0 commit comments