All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.gradle.api.tasks.diagnostics.AbstractProjectBasedReportTask Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.gradle.api.tasks.diagnostics;

import org.gradle.api.Incubating;
import org.gradle.api.Project;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.diagnostics.internal.ProjectDetails;
import org.gradle.internal.serialization.Cached;
import org.gradle.work.DisableCachingByDefault;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * The base class for all Project based project report tasks.
 *
 * @param  The report model type
 * @since 7.6
 */
@Incubating
@DisableCachingByDefault(because = "Abstract super-class, not to be instantiated directly")
public abstract class AbstractProjectBasedReportTask extends ConventionReportTask {

    private final Cached> reportModels = Cached.of(this::calculateReportModel);

    private ProjectBasedReportModel calculateReportModel() {
        Map map = new LinkedHashMap<>();
        for (Project project : getProjects()) {
            map.put(
                ProjectDetails.of(project),
                calculateReportModelFor(project)
            );
        }
        return new ProjectBasedReportModel<>(map);
    }

    protected abstract T calculateReportModelFor(Project project);

    /**
     * Provides a means of printing a customizable header section above the per-project details body
     * of the report.
     * 

* By default, there is no header information printed. * * @param modelsByProjectDetails information about the projects under report * @since 8.9 */ @Incubating protected void generateReportHeaderFor(Map modelsByProjectDetails) { /* default is no header */ }; protected abstract void generateReportFor(ProjectDetails project, T model); /** * Provides a means of printing a customizable footer section below the per-project details body * of the report. *

* By default, there is no footer information printed. * * @param modelsByProjectDetails information about the projects under report * @since 8.9 */ @Incubating protected void generateReportFooterFor(Map modelsByProjectDetails) { /* default is no footer */ }; @TaskAction void action() { Map modelsByProjectDetails = reportModels.get().modelsByProjectDetails; reportGenerator().generateReport( modelsByProjectDetails.entrySet(), Map.Entry::getKey, () -> generateReportHeaderFor(modelsByProjectDetails), entry -> { generateReportFor(entry.getKey(), entry.getValue()); logClickableOutputFileUrl(); }, () -> generateReportFooterFor(modelsByProjectDetails) ); } private static class ProjectBasedReportModel { private final Map modelsByProjectDetails; private ProjectBasedReportModel(Map modelsByProjectDetails) { this.modelsByProjectDetails = modelsByProjectDetails; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy