name.remal.gradle_plugins.finalize_by_jacoco.FinalizeByJacocoPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of finalize-by-jacoco Show documentation
Show all versions of finalize-by-jacoco Show documentation
Remal Gradle plugins: finalize-by-jacoco
The newest version!
package name.remal.gradle_plugins.finalize_by_jacoco;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import static name.remal.gradle_plugins.toolkit.ExtensionContainerUtils.getOptionalExtension;
import static name.remal.gradle_plugins.toolkit.PredicateUtils.not;
import static name.remal.gradle_plugins.toolkit.TaskUtils.onlyIfWithReason;
import java.io.File;
import java.util.List;
import javax.annotation.Nullable;
import lombok.val;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.testing.jacoco.plugins.JacocoTaskExtension;
import org.gradle.testing.jacoco.tasks.JacocoBase;
import org.gradle.testing.jacoco.tasks.JacocoReportBase;
public abstract class FinalizeByJacocoPlugin implements Plugin {
@Override
public void apply(Project project) {
project.getPluginManager().apply("jacoco");
configureOnlyIf(project);
configureFinalizedBy(project);
configureDependsOn(project);
}
private static void configureOnlyIf(Project project) {
project.getTasks()
.withType(JacocoReportBase.class)
.configureEach(it ->
onlyIfWithReason(it, "Any of the execution data files exists", reportTask ->
reportTask.getExecutionData().getFiles().stream()
.anyMatch(File::exists)
)
);
}
private static void configureFinalizedBy(Project project) {
project.getTasks()
.matching(task -> !(task instanceof JacocoBase))
.configureEach(task ->
task.finalizedBy(project.provider(() -> getFinalizedBy(task)))
);
}
private static List