-
Notifications
You must be signed in to change notification settings - Fork 30
/
PlantumlTask.java
71 lines (56 loc) · 2.27 KB
/
PlantumlTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package io.freefair.gradle.plugins.plantuml;
import lombok.Getter;
import org.gradle.api.file.ConfigurableFileCollection;
import org.gradle.api.file.DirectoryProperty;
import org.gradle.api.file.FileSystemOperations;
import org.gradle.api.provider.Property;
import org.gradle.api.tasks.*;
import org.gradle.workers.WorkQueue;
import org.gradle.workers.WorkerExecutor;
import javax.inject.Inject;
import java.io.File;
/**
* @author Lars Grefer
*/
public class PlantumlTask extends SourceTask {
private final WorkerExecutor workerExecutor;
private final FileSystemOperations fileSystemOperations;
@Getter
@Classpath
private final ConfigurableFileCollection plantumlClasspath = getProject().files();
@Getter
@OutputDirectory
private final DirectoryProperty outputDirectory = getProject().getObjects().directoryProperty();
@Getter
@Input
@Optional
private final Property<String> fileFormat = getProject().getObjects().property(String.class);
@Getter
@Input
private final Property<Boolean> withMetadata = getProject().getObjects().property(Boolean.class).convention(true);
@Getter
@Input
private final Property<String> includePattern = getProject().getObjects().property(String.class).convention("**/*.puml");
@Inject
public PlantumlTask(WorkerExecutor workerExecutor, FileSystemOperations fileSystemOperations) {
this.fileSystemOperations = fileSystemOperations;
this.workerExecutor = workerExecutor;
this.setGroup("plantuml");
}
@TaskAction
public void execute() {
fileSystemOperations.delete(deleteSpec -> deleteSpec.delete(outputDirectory));
WorkQueue workQueue = workerExecutor.processIsolation(process -> {
process.getClasspath().from(plantumlClasspath);
process.getForkOptions().systemProperty("java.awt.headless", true);
});
for (File file : getSource().matching(p -> p.include(includePattern.get()))) {
workQueue.submit(PlantumlAction.class, params -> {
params.getInputFile().set(file);
params.getOutputDirectory().set(outputDirectory);
params.getFileFormat().set(fileFormat);
params.getWithMetadata().set(withMetadata);
});
}
}
}