Move inputs and outputs before action (#36539)

This commit is contained in:
Alpar Torok 2018-12-14 18:31:52 +02:00 committed by GitHub
parent 6ee6bb55e2
commit b5725ed482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 60 additions and 61 deletions

View File

@ -70,6 +70,59 @@ public class TestingConventionsTasks extends DefaultTask {
// Run only after everything is compiled
Boilerplate.getJavaSourceSets(getProject()).all(sourceSet -> dependsOn(sourceSet.getClassesTaskName()));
}
@Input
public Map<String, Set<File>> classFilesPerTask(FileTree testClassFiles) {
Map<String, Set<File>> collector = new HashMap<>();
// RandomizedTestingTask
collector.putAll(
Stream.concat(
getProject().getTasks().withType(getRandomizedTestingTask()).stream(),
// Look at sub-projects too. As sometimes tests are implemented in parent but ran in sub-projects against
// different configurations
getProject().getSubprojects().stream().flatMap(subproject ->
subproject.getTasks().withType(getRandomizedTestingTask()).stream()
)
)
.filter(Task::getEnabled)
.collect(Collectors.toMap(
Task::getPath,
task -> testClassFiles.matching(getRandomizedTestingPatternSet(task)).getFiles()
))
);
// Gradle Test
collector.putAll(
Stream.concat(
getProject().getTasks().withType(Test.class).stream(),
getProject().getSubprojects().stream().flatMap(subproject ->
subproject.getTasks().withType(Test.class).stream()
)
)
.filter(Task::getEnabled)
.collect(Collectors.toMap(
Task::getPath,
task -> task.getCandidateClassFiles().getFiles()
))
);
return Collections.unmodifiableMap(collector);
}
@Input
public Map<String, File> getTestClassNames() {
if (testClassNames == null) {
testClassNames = Boilerplate.getJavaSourceSets(getProject()).getByName("test").getOutput().getClassesDirs()
.getFiles().stream()
.filter(File::exists)
.flatMap(testRoot -> walkPathAndLoadClasses(testRoot).entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
return testClassNames;
}
@OutputFile
public File getSuccessMarker() {
return new File(getProject().getBuildDir(), "markers/" + getName());
}
@TaskAction
public void doCheck() throws IOException {
@ -112,7 +165,7 @@ public class TestingConventionsTasks extends DefaultTask {
.collect(Collectors.toSet())
)
);
problems = collectProblems(
checkNoneExists(
"Test classes implemented by inner classes will not run",
@ -130,13 +183,13 @@ public class TestingConventionsTasks extends DefaultTask {
),
collectProblems(
testClassesPerTask.entrySet().stream()
.map( entry ->
checkAtLeastOneExists(
"test class in " + entry.getKey(),
entry.getValue().stream()
.map( entry ->
checkAtLeastOneExists(
"test class in " + entry.getKey(),
entry.getValue().stream()
)
)
)
.collect(Collectors.joining())
.collect(Collectors.joining())
),
checkNoneExists(
"Test classes are not included in any enabled task (" +
@ -161,7 +214,6 @@ public class TestingConventionsTasks extends DefaultTask {
}
}
private String collectProblems(String... problems) {
return Stream.of(problems)
.map(String::trim)
@ -170,42 +222,6 @@ public class TestingConventionsTasks extends DefaultTask {
.collect(Collectors.joining());
}
@Input
public Map<String, Set<File>> classFilesPerTask(FileTree testClassFiles) {
Map<String, Set<File>> collector = new HashMap<>();
// RandomizedTestingTask
collector.putAll(
Stream.concat(
getProject().getTasks().withType(getRandomizedTestingTask()).stream(),
// Look at sub-projects too. As sometimes tests are implemented in parent but ran in sub-projects against
// different configurations
getProject().getSubprojects().stream().flatMap(subproject ->
subproject.getTasks().withType(getRandomizedTestingTask()).stream()
)
)
.filter(Task::getEnabled)
.collect(Collectors.toMap(
Task::getPath,
task -> testClassFiles.matching(getRandomizedTestingPatternSet(task)).getFiles()
))
);
// Gradle Test
collector.putAll(
Stream.concat(
getProject().getTasks().withType(Test.class).stream(),
getProject().getSubprojects().stream().flatMap(subproject ->
subproject.getTasks().withType(Test.class).stream()
)
)
.filter(Task::getEnabled)
.collect(Collectors.toMap(
Task::getPath,
task -> task.getCandidateClassFiles().getFiles()
))
);
return Collections.unmodifiableMap(collector);
}
@SuppressWarnings("unchecked")
private PatternFilterable getRandomizedTestingPatternSet(Task task) {
try {
@ -232,23 +248,6 @@ public class TestingConventionsTasks extends DefaultTask {
}
}
@Input
public Map<String, File> getTestClassNames() {
if (testClassNames == null) {
testClassNames = Boilerplate.getJavaSourceSets(getProject()).getByName("test").getOutput().getClassesDirs()
.getFiles().stream()
.filter(File::exists)
.flatMap(testRoot -> walkPathAndLoadClasses(testRoot).entrySet().stream())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
return testClassNames;
}
@OutputFile
public File getSuccessMarker() {
return new File(getProject().getBuildDir(), "markers/" + getName());
}
private String checkNoneExists(String message, Stream<? extends Class<?>> stream) {
String problem = stream
.map(each -> " * " + each.getName())