<commit_before>/*
 * Copyright 2007 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.testing;

import groovy.lang.Closure;
import groovy.lang.MissingPropertyException;
import org.gradle.api.*;
import org.gradle.api.artifacts.FileCollection;
import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.util.ExistingDirsFilter;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.api.testing.TestFramework;
import org.gradle.external.junit.JUnitTestFramework;
import org.gradle.external.testng.TestNGTestFramework;
import org.gradle.util.ConfigureUtil;
import org.gradle.util.GUtil;
import org.gradle.util.WrapUtil;
import org.gradle.util.GFileUtils;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * A task for executing Junit 3.8.x and Junit 4 tests.
 *
 * @author <NAME>
 */
public class Test extends ConventionTask implements PatternFilterable {
    public static final String FAILURES_OR_ERRORS_PROPERTY = "org.gradle.api.tasks.testing.failuresOrErrors";

    public static final String TEST_FRAMEWORK_DEFAULT_PROPERTY = "test.framework.default";

    private List<File> testSrcDirs = null;

    private File testClassesDir = null;

    private File testResultsDir = null;

    private File testReportDir = null;

    private PatternFilterable patternSet = new PatternSet();
    
    private boolean stopAtFailuresOrErrors = true;

    private FileCollection configuration;

    protected ExistingDirsFilter existingDirsFilter = new ExistingDirsFilter();

    private TestFramework testFramework = null;

    private boolean testReport = true;

    private boolean scanForTestClasses = true;

    public Test(Project project, String name) {
        super(project, name);
        doFirst(new TaskAction() {
            public void execute(Task task) {
                executeTests();
            }
        });
    }

    protected void executeTests() {
        final File testClassesDir = getTestClassesDir();

        if (testClassesDir == null)
            throw new InvalidUserDataException("The testClassesDir property is not set, testing can't be triggered!");
        if (getTestResultsDir() == null)
            throw new InvalidUserDataException("The testResultsDir property is not set, testing can't be triggered!");

        existingDirsFilter.checkExistenceAndThrowStopActionIfNot(testClassesDir);

        final TestFramework testFramework = getTestFramework();

        testFramework.prepare(getProject(), this);

        final Set<String> includes = getIncludes();
        final Set<String> excludes = getExcludes();

        final TestClassScanner testClassScanner = new TestClassScanner(
                testClassesDir,
                includes, excludes,
                testFramework,
                getProject().getAnt() ,
                scanForTestClasses
        );

        final Set<String> testClassNames = testClassScanner.getTestClassNames();

        Collection<String> toUseIncludes = null;
        Collection<String> toUseExcludes = null;
        if ( testClassNames.isEmpty() ) {
            toUseIncludes = includes;
            toUseExcludes = excludes;
        }
        else {
            toUseIncludes = testClassNames;
            toUseExcludes = new ArrayList<String>();
        }

        GFileUtils.createDirectoriesWhenNotExistent(getTestResultsDir());// needed for JUnit reporting

        if ( !(toUseIncludes.isEmpty() && toUseExcludes.isEmpty()))
            testFramework.execute(getProject(), this, toUseIncludes, toUseExcludes);
        // else when there are no includes/excludes -> don't execute test framework
        // TestNG execution fails when there are no tests
        // JUnit execution doesn't fail when there are no tests

        if (testReport) {
            testFramework.report(getProject(), this);
        }

        if (stopAtFailuresOrErrors && GUtil.isTrue(getProject().getAnt().getProject().getProperty(FAILURES_OR_ERRORS_PROPERTY))) {
            throw new GradleException("There were failing tests. See the report at " + getTestReportDir() + ".");
        }
    }<commit_msg>Fix for GRADLE-538, added debug logging statement when test execution is skipped<commit_after>/*
 * Copyright 2007 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.testing;

import groovy.lang.Closure;
import groovy.lang.MissingPropertyException;
import org.gradle.api.*;
import org.gradle.api.artifacts.FileCollection;
import org.gradle.api.internal.ConventionTask;
import org.gradle.api.tasks.util.ExistingDirsFilter;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;
import org.gradle.api.testing.TestFramework;
import org.gradle.external.junit.JUnitTestFramework;
import org.gradle.external.testng.TestNGTestFramework;
import org.gradle.util.ConfigureUtil;
import org.gradle.util.GUtil;
import org.gradle.util.WrapUtil;
import org.gradle.util.GFileUtils;
import org.apache.commons.io.FileUtils;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;

/**
 * A task for executing Junit 3.8.x and Junit 4 tests.
 *
 * @author <NAME>
 */
public class Test extends ConventionTask implements PatternFilterable {
    private static final Logger logger = LoggerFactory.getLogger(Test.class);

    public static final String FAILURES_OR_ERRORS_PROPERTY = "org.gradle.api.tasks.testing.failuresOrErrors";

    public static final String TEST_FRAMEWORK_DEFAULT_PROPERTY = "test.framework.default";

    private List<File> testSrcDirs = null;

    private File testClassesDir = null;

    private File testResultsDir = null;

    private File testReportDir = null;

    private PatternFilterable patternSet = new PatternSet();
    
    private boolean stopAtFailuresOrErrors = true;

    private FileCollection configuration;

    protected ExistingDirsFilter existingDirsFilter = new ExistingDirsFilter();

    private TestFramework testFramework = null;

    private boolean testReport = true;

    private boolean scanForTestClasses = true;

    public Test(Project project, String name) {
        super(project, name);
        doFirst(new TaskAction() {
            public void execute(Task task) {
                executeTests();
            }
        });
    }

    protected void executeTests() {
        final File testClassesDir = getTestClassesDir();

        if (testClassesDir == null)
            throw new InvalidUserDataException("The testClassesDir property is not set, testing can't be triggered!");
        if (getTestResultsDir() == null)
            throw new InvalidUserDataException("The testResultsDir property is not set, testing can't be triggered!");

        existingDirsFilter.checkExistenceAndThrowStopActionIfNot(testClassesDir);

        final TestFramework testFramework = getTestFramework();

        testFramework.prepare(getProject(), this);

        final Set<String> includes = getIncludes();
        final Set<String> excludes = getExcludes();

        final TestClassScanner testClassScanner = new TestClassScanner(
                testClassesDir,
                includes, excludes,
                testFramework,
                getProject().getAnt() ,
                scanForTestClasses
        );

        final Set<String> testClassNames = testClassScanner.getTestClassNames();

        Collection<String> toUseIncludes = null;
        Collection<String> toUseExcludes = null;
        if ( testClassNames.isEmpty() ) {
            toUseIncludes = includes;
            toUseExcludes = excludes;
        }
        else {
            toUseIncludes = testClassNames;
            toUseExcludes = new ArrayList<String>();
        }

        GFileUtils.createDirectoriesWhenNotExistent(getTestResultsDir());// needed for JUnit reporting

        if ( !(toUseIncludes.isEmpty() && toUseExcludes.isEmpty()))
            testFramework.execute(getProject(), this, toUseIncludes, toUseExcludes);
        else // when there are no includes/excludes -> don't execute test framework
            logger.debug("skipping test execution, because no tests were found");
        // TestNG execution fails when there are no tests
        // JUnit execution doesn't fail when there are no tests

        if (testReport) {
            testFramework.report(getProject(), this);
        }

        if (stopAtFailuresOrErrors && GUtil.isTrue(getProject().getAnt().getProject().getProperty(FAILURES_OR_ERRORS_PROPERTY))) {
            throw new GradleException("There were failing tests. See the report at " + getTestReportDir() + ".");
        }
    }
{'fraction_non_alphanumeric': 0.08584079702123378, 'fraction_numerical': 0.002717117842407165, 'mean_word_length': 3.2253401360544216, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, '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': '6536954', 'n_tokens_mistral': 2695, 'n_tokens_neox': 2541, 'n_words': 753}