From 4d4027947b80c715eb70b50078868ce5b50b6907 Mon Sep 17 00:00:00 2001 From: Chris Rankin Date: Sat, 30 Sep 2017 21:55:51 +0100 Subject: [PATCH] Annotate Gradle task inputs correctly. (#1752) --- .../java/net/corda/plugins/GenerateApi.java | 2 +- .../main/java/net/corda/plugins/ScanApi.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/GenerateApi.java b/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/GenerateApi.java index 59dbeca87b..9c87224075 100644 --- a/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/GenerateApi.java +++ b/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/GenerateApi.java @@ -48,7 +48,7 @@ public class GenerateApi extends DefaultTask { @TaskAction public void generate() { FileCollection apiFiles = getSources(); - if (!apiFiles.isEmpty() && (outputDir.isDirectory() || outputDir.mkdirs())) { + if (!apiFiles.isEmpty()) { try (OutputStream output = new BufferedOutputStream(new FileOutputStream(getTarget()))) { for (File apiFile : apiFiles) { Files.copy(apiFile.toPath(), output); diff --git a/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/ScanApi.java b/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/ScanApi.java index 667feb860c..53f7ee9fc0 100644 --- a/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/ScanApi.java +++ b/gradle-plugins/api-scanner/src/main/java/net/corda/plugins/ScanApi.java @@ -8,7 +8,9 @@ import io.github.lukehutch.fastclasspathscanner.scanner.ScanResult; import org.gradle.api.DefaultTask; import org.gradle.api.file.ConfigurableFileCollection; import org.gradle.api.file.FileCollection; +import org.gradle.api.tasks.CompileClasspath; import org.gradle.api.tasks.Input; +import org.gradle.api.tasks.InputFiles; import org.gradle.api.tasks.OutputFiles; import org.gradle.api.tasks.TaskAction; @@ -55,7 +57,7 @@ public class ScanApi extends DefaultTask { outputDir = new File(getProject().getBuildDir(), "api"); } - @Input + @InputFiles public FileCollection getSources() { return sources; } @@ -64,7 +66,8 @@ public class ScanApi extends DefaultTask { this.sources.setFrom(sources); } - @Input + @CompileClasspath + @InputFiles public FileCollection getClasspath() { return classpath; } @@ -106,16 +109,12 @@ public class ScanApi extends DefaultTask { @TaskAction public void scan() { - if (outputDir.isDirectory() || outputDir.mkdirs()) { - try (Scanner scanner = new Scanner(classpath)) { - for (File source : sources) { - scanner.scan(source); - } - } catch (IOException e) { - getLogger().error("Failed to write API file", e); + try (Scanner scanner = new Scanner(classpath)) { + for (File source : sources) { + scanner.scan(source); } - } else { - getLogger().error("Cannot create directory '{}'", outputDir.getAbsolutePath()); + } catch (IOException e) { + getLogger().error("Failed to write API file", e); } }