Skip to content

Commit 6f180df

Browse files
committed
cleanup
1 parent 4cf5748 commit 6f180df

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

plantuml-plugin/src/main/java/io/freefair/gradle/plugins/plantuml/PlantumlAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
import org.gradle.workers.WorkAction;
88

99
/**
10+
* Gradle {@link WorkAction} for PlantUML {@link SourceFileReader}.
11+
*
1012
* @author Lars Grefer
13+
* @see SourceFileReader
1114
*/
1215
public abstract class PlantumlAction implements WorkAction<PlantumlParameters> {
1316

@@ -21,6 +24,7 @@ public void execute() {
2124
.getOrElse(FileFormat.PNG);
2225

2326
FileFormatOption fileFormatOption = new FileFormatOption(fileFormat, getParameters().getWithMetadata().get());
27+
2428
SourceFileReader sourceFileReader = new SourceFileReader(
2529
getParameters().getInputFile().getAsFile().get(),
2630
getParameters().getOutputDirectory().getAsFile().get(),

plantuml-plugin/src/main/java/io/freefair/gradle/plugins/plantuml/PlantumlParameters.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import org.gradle.workers.WorkParameters;
77

88
/**
9+
* {@link WorkParameters} for {@link PlantumlAction}.
10+
*
911
* @author Lars Grefer
12+
* @see PlantumlPlugin
1013
*/
1114
public interface PlantumlParameters extends WorkParameters {
1215

plantuml-plugin/src/main/java/io/freefair/gradle/plugins/plantuml/PlantumlTask.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import lombok.Getter;
44
import org.gradle.api.file.ConfigurableFileCollection;
55
import org.gradle.api.file.DirectoryProperty;
6+
import org.gradle.api.file.FileSystemOperations;
67
import org.gradle.api.provider.Property;
78
import org.gradle.api.tasks.*;
9+
import org.gradle.workers.WorkQueue;
810
import org.gradle.workers.WorkerExecutor;
911

1012
import 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

Comments
 (0)