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

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

There is a newer version: 8.11.1
Show newest version
/*
 * Copyright 2014 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 com.google.common.base.Function;
import com.google.common.collect.Lists;

import javax.annotation.Nullable;
import java.util.List;

public class CrossBuildPerformanceTestHistory implements PerformanceTestHistory {
    private final String name;
    private final List builds;

    private final List newestFirst;

    public CrossBuildPerformanceTestHistory(String name, List builds, List newestFirst) {
        this.name = name;
        this.builds = builds;
        this.newestFirst = newestFirst;
    }

    public List getBuilds() {
        return builds;
    }

    public List getResults() {
        return newestFirst;
    }

    @Override
    public String getId() {
        return name.replaceAll("\\s+", "-");
    }

    public String getDisplayName() {
        return name;
    }

    @Override
    public List getExecutions() {
        return Lists.transform(newestFirst, new Function() {
            public PerformanceTestExecution apply(@Nullable final CrossBuildPerformanceResults results) {
                return new KnownBuildSpecificationsPerformanceTestExecution(results);
            }
        });
    }

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

    @Override
    public List getScenarioLabels() {
        return Lists.transform(builds, new Function() {
            public String apply(@Nullable BuildDisplayInfo specification) {
                return specification.getDisplayName();
            }
        });
    }

    @Override
    public List getScenarios() {
        return Lists.transform(builds, new Function() {
            @Override
            public ScenarioDefinition apply(final BuildDisplayInfo input) {
                return new ScenarioDefinition() {
                    @Override
                    public String getDisplayName() {
                        return input.getDisplayName();
                    }

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

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

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

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

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

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

    private class KnownBuildSpecificationsPerformanceTestExecution implements PerformanceTestExecution {
        private final CrossBuildPerformanceResults results;

        public KnownBuildSpecificationsPerformanceTestExecution(CrossBuildPerformanceResults results) {
            this.results = results;
        }

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

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

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

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

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

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

        @Override
        public List getScenarios() {
            return Lists.transform(builds, new Function() {
                @Override
                public MeasuredOperationList apply(@Nullable BuildDisplayInfo specification) {
                    return results.buildResult(specification.getDisplayName());
                }
            });
        }

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

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

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

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

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

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

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

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy