|
13 | 13 | import org.gradle.api.file.DirectoryProperty; |
14 | 14 | import org.gradle.api.file.RegularFileProperty; |
15 | 15 | import org.gradle.api.tasks.InputDirectory; |
| 16 | +import org.gradle.api.tasks.Optional; |
16 | 17 | import org.gradle.api.tasks.OutputFile; |
| 18 | +import org.gradle.api.tasks.PathSensitive; |
| 19 | +import org.gradle.api.tasks.PathSensitivity; |
17 | 20 | import org.gradle.api.tasks.TaskAction; |
18 | 21 |
|
19 | 22 | import java.io.IOException; |
| 23 | +import java.nio.charset.StandardCharsets; |
20 | 24 | import java.nio.file.Files; |
21 | 25 | import java.nio.file.Path; |
22 | 26 |
|
23 | 27 | public abstract class GenerateTransportVersionManifestTask extends DefaultTask { |
24 | 28 | @InputDirectory |
| 29 | + @Optional |
| 30 | + @PathSensitive(PathSensitivity.RELATIVE) |
25 | 31 | public abstract DirectoryProperty getDefinitionsDirectory(); |
26 | 32 |
|
27 | 33 | @OutputFile |
28 | 34 | public abstract RegularFileProperty getManifestFile(); |
29 | 35 |
|
30 | 36 | @TaskAction |
31 | 37 | public void generateTransportVersionManifest() throws IOException { |
32 | | - Path constantsDir = getDefinitionsDirectory().get().getAsFile().toPath(); |
33 | 38 | Path manifestFile = getManifestFile().get().getAsFile().toPath(); |
| 39 | + if (getDefinitionsDirectory().isPresent() == false) { |
| 40 | + // no definitions to capture, remove this leniency once all branches have at least one version |
| 41 | + Files.writeString(manifestFile, "", StandardCharsets.UTF_8); |
| 42 | + return; |
| 43 | + } |
| 44 | + Path constantsDir = getDefinitionsDirectory().get().getAsFile().toPath(); |
| 45 | + |
| 46 | + |
34 | 47 | try (var writer = Files.newBufferedWriter(manifestFile)) { |
35 | 48 | try (var stream = Files.list(constantsDir)) { |
36 | 49 | for (String filename : stream.map(p -> p.getFileName().toString()).toList()) { |
|
0 commit comments