Annotate Gradle task inputs correctly. (#1752)

This commit is contained in:
Chris Rankin 2017-09-30 21:55:51 +01:00 committed by GitHub
parent f36ca78f88
commit 4d4027947b
2 changed files with 11 additions and 12 deletions

View File

@ -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);

View File

@ -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);
}
}