<commit_before>/*
 * Copyright 2016 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.fixture;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import org.gradle.performance.results.PerformanceTestExecution;
import org.gradle.performance.results.PerformanceTestHistory;
import org.gradle.performance.results.ResultsStore;
import org.gradle.performance.results.ResultsStoreHelper;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * Determines whether a specific scenario within a performance test should run and whether it should run locally
 * or be added to the list of scenarios to run in distributed mode.
 */
public class TestScenarioSelector {

    public boolean shouldRun(String testId, Set<String> templates, ResultsStore resultsStore) {
        if (testId.contains(";")) {
            throw new IllegalArgumentException("Test ID cannot contain ';', but was '" + testId + "'");
        }
        String scenarioProperty = System.getProperty("org.gradle.performance.scenarios", "");
        List<String> scenarios = Splitter.on(";").omitEmptyStrings().splitToList(scenarioProperty);
        boolean shouldRun = scenarios.isEmpty() || scenarios.contains(testId);
        String scenarioList = System.getProperty("org.gradle.performance.scenario.list");
        if (shouldRun && scenarioList != null) {
            addToScenarioList(testId, templates, new File(scenarioList), resultsStore);
            return false;
        } else {
            return shouldRun;
        }
    }

    private void addToScenarioList(String testId, Set<String> templates, File scenarioList, ResultsStore resultsStore) {
        try {
            long estimatedRuntime = getEstimatedRuntime(testId, resultsStore);
            List<String> args = Lists.newArrayList();
            args.add(testId);
            args.add(String.valueOf(estimatedRuntime));
            args.addAll(templates);<commit_msg>Trim performance test scenario names<commit_after>/*
 * Copyright 2016 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.fixture;

import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import org.gradle.performance.results.PerformanceTestExecution;
import org.gradle.performance.results.PerformanceTestHistory;
import org.gradle.performance.results.ResultsStore;
import org.gradle.performance.results.ResultsStoreHelper;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * Determines whether a specific scenario within a performance test should run and whether it should run locally
 * or be added to the list of scenarios to run in distributed mode.
 */
public class TestScenarioSelector {

    public boolean shouldRun(String testId, Set<String> templates, ResultsStore resultsStore) {
        if (testId.contains(";")) {
            throw new IllegalArgumentException("Test ID cannot contain ';', but was '" + testId + "'");
        }
        String scenarioProperty = System.getProperty("org.gradle.performance.scenarios", "");
        List<String> scenarios = Splitter.on(";").omitEmptyStrings().trimResults().splitToList(scenarioProperty);
        boolean shouldRun = scenarios.isEmpty() || scenarios.contains(testId);
        String scenarioList = System.getProperty("org.gradle.performance.scenario.list");
        if (shouldRun && scenarioList != null) {
            addToScenarioList(testId, templates, new File(scenarioList), resultsStore);
            return false;
        } else {
            return shouldRun;
        }
    }

    private void addToScenarioList(String testId, Set<String> templates, File scenarioList, ResultsStore resultsStore) {
        try {
            long estimatedRuntime = getEstimatedRuntime(testId, resultsStore);
            List<String> args = Lists.newArrayList();
            args.add(testId);
            args.add(String.valueOf(estimatedRuntime));
            args.addAll(templates);
{'fraction_non_alphanumeric': 0.09564898109050854, 'fraction_numerical': 0.0029373967321461355, 'mean_word_length': 3.704663212435233, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3639812', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1375, 'n_words': 437}