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

org.gradle.performance.results.CrossVersionPerformanceTestHistory Maven / Gradle / Ivy

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2013 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.performance.results;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class CrossVersionPerformanceTestHistory implements PerformanceTestHistory {
    private final PerformanceExperiment experiment;
    private final List versions;
    private final List branches;
    private final List newestFirst;
    private List oldestFirst;
    private List knownVersions;

    public CrossVersionPerformanceTestHistory(PerformanceExperiment experiment, List versions, List branches, List newestFirst) {
        this.experiment = experiment;
        this.versions = versions;
        this.branches = branches;
        this.newestFirst = newestFirst;
    }

    @Override
    public PerformanceExperiment getExperiment() {
        return experiment;
    }

    public List getBaselineVersions() {
        return versions;
    }

    public List getBranches() {
        return branches;
    }

    public List getKnownVersions() {
        if (knownVersions == null) {
            ArrayList result = new ArrayList<>();
            result.addAll(versions);
            result.addAll(branches);
            knownVersions = result;
        }
        return knownVersions;
    }

    /**
     * Returns results from most recent to least recent.
     */
    public List getResults() {
        return newestFirst;
    }

    /**
     * Returns results from least recent to most recent.
     */
    public List getResultsOldestFirst() {
        if (oldestFirst == null) {
            oldestFirst = new ArrayList<>(newestFirst);
            Collections.reverse(oldestFirst);
        }
        return oldestFirst;
    }

    @Override
    public List getExecutions() {
        return getResults().stream().map(KnownVersionsPerformanceTestExecution::new).collect(Collectors.toList());
    }

    @Override
    public List getScenarios() {
        if (newestFirst.isEmpty()) {
            return Collections.emptyList();
        }
        CrossVersionPerformanceResults mostRecent = newestFirst.get(0);
        return getKnownVersions().stream()
            .map(input -> new ScenarioDefinition() {
                @Override
                public String getDisplayName() {
                    return input;
                }

                @Override
                public String getTestProject() {
                    return mostRecent.getTestProject();
                }

                @Override
                public List getTasks() {
                    return mostRecent.getTasks();
                }

                @Override
                public List getCleanTasks() {
                    return mostRecent.getCleanTasks();
                }

                @Override
                public List getArgs() {
                    return mostRecent.getArgs();
                }

                @Nullable
                @Override
                public List getGradleOpts() {
                    return mostRecent.getGradleOpts();
                }

                @Nullable
                @Override
                public Boolean getDaemon() {
                    return mostRecent.getDaemon();
                }
            })
            .collect(Collectors.toList());
    }

    @Override
    public int getScenarioCount() {
        return getKnownVersions().size();
    }

    @Override
    public List getScenarioLabels() {
        return getKnownVersions();
    }

    private class KnownVersionsPerformanceTestExecution implements PerformanceTestExecution {
        private final CrossVersionPerformanceResults result;

        public KnownVersionsPerformanceTestExecution(CrossVersionPerformanceResults result) {
            this.result = result;
        }

        @Override
        public String getExecutionId() {
            return String.valueOf(Math.abs(getVcsCommits() != null ? getVcsCommits().hashCode() : hashCode()));
        }

        @Override
        public String getTeamCityBuildId() {
            return result.getTeamCityBuildId();
        }

        @Override
        public String getVersionUnderTest() {
            return result.getVersionUnderTest();
        }

        @Override
        public String getVcsBranch() {
            return result.getVcsBranch();
        }

        @Override
        public long getStartTime() {
            return result.getStartTime();
        }

        @Override
        public long getEndTime() {
            return result.getEndTime();
        }

        @Override
        public List getVcsCommits() {
            return result.getVcsCommits();
        }

        @Override
        public List getScenarios() {
            return getKnownVersions().stream().map(version -> result.version(version).getResults()).collect(Collectors.toList());
        }

        @Override
        public String getOperatingSystem() {
            return result.getOperatingSystem();
        }

        @Override
        public String getHost() {
            return result.getHost();
        }

        @Override
        public String getJvm() {
            return result.getJvm();
        }

        @Nullable
        @Override
        public List getArgs() {
            return result.getArgs();
        }

        @Nullable
        @Override
        public String getTestProject() {
            return result.getTestProject();
        }

        @Nullable
        @Override
        public List getTasks() {
            return result.getTasks();
        }

        @Nullable
        @Override
        public List getCleanTasks() {
            return result.getCleanTasks();
        }

        @Nullable
        @Override
        public List getGradleOpts() {
            return result.getGradleOpts();
        }

        @Nullable
        @Override
        public Boolean getDaemon() {
            return result.getDaemon();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy