<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.integtests.tooling.r213

import groovy.transform.NotYetImplemented
import org.gradle.integtests.tooling.fixture.CompositeToolingApiSpecification
import org.gradle.tooling.BuildException
import org.gradle.tooling.model.eclipse.EclipseProject

/**
 * Basic tests for building and retrieving models from a composite.
 */
class SmokeCompositeBuildCrossVersionSpec extends CompositeToolingApiSpecification {

    def "throws IllegalStateException when no participants are added"() {
        when:
        createComposite()
        then:
        thrown(IllegalStateException)
    }

    @NotYetImplemented
    def "throws IllegalArgumentException when trying to add overlapping participants"() {
        given:
        def project = projectDir("project")
        def overlapping = project.file("overlapping").createDir()
        when:
        withCompositeConnection([ project, overlapping ]) { connection ->
            connection.getModels(EclipseProject)
        }
        then:
        thrown(IllegalArgumentException)
    }

    def "throws IllegalArgumentException when trying to retrieve a non-model type"() {
        when:
        withCompositeConnection(projectDir("project")) { connection ->
            connection.getModels(Object)
        }
        then:
        thrown(IllegalArgumentException)
    }

    def "throws IllegalStateException when using a closed connection"() {
        given:
        def project = populate("project") {
            settingsFile << "rootProject.name = 'project'"
        }
        when:
        withCompositeConnection(project) { connection ->
            def models = connection.getModels(EclipseProject)
            connection.close()
            def modelsAgain = connection.getModels(EclipseProject)
        }
        then:
        thrown(IllegalStateException)
    }

    def "propagates errors when trying to retrieve models"() {
        given:
        def project = populate("project") {
            settingsFile << "rootProject.name = '${rootProjectName}'"
            buildFile << "throw new RuntimeException()"
        }
        when:
        withCompositeConnection(project) { connection ->
            connection.getModels(EclipseProject).each {
                it.model
            }
        }
        then:
        def e = thrown(BuildException)
        assertFailure(e, "Could not fetch model of type 'EclipseProject'")
    }

    def "fails to retrieve model when participant is not a Gradle project"() {
        when:
        withCompositeConnection(projectDir("project-does-not-exist")) { connection ->
            connection.getModels(EclipseProject).each {
                it.model
            }
        }
        then:
        def e = thrown(BuildException)
        assertFailure(e,
            "Could not fetch model of type 'EclipseProject'",
            "project-does-not-exist' does not exist")
    }

    def "does not search upwards for projects"() {
        given:
        def rootDir = projectDir("root")
        rootDir.file("settings.gradle") << "include 'project', 'a', 'b', 'c'"
        def project = rootDir.createDir("project")
        project.createFile("build.gradle")

        when:
        def models = withCompositeConnection(project) { connection ->
            connection.getModels(EclipseProject)
        }
        then:
        // should only find 'project', not the other projects defined in root.
        models.size() == 1
        models[0].model.gradleProject.projectDirectory == project
    }
}
<commit_msg>Fix test so that can target versions of Gradle >= 1.0<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.integtests.tooling.r213

import groovy.transform.NotYetImplemented
import org.gradle.integtests.tooling.fixture.CompositeToolingApiSpecification
import org.gradle.tooling.BuildException
import org.gradle.tooling.model.eclipse.EclipseProject

/**
 * Basic tests for building and retrieving models from a composite.
 */
class SmokeCompositeBuildCrossVersionSpec extends CompositeToolingApiSpecification {

    def "throws IllegalStateException when no participants are added"() {
        when:
        createComposite()
        then:
        thrown(IllegalStateException)
    }

    @NotYetImplemented
    def "throws IllegalArgumentException when trying to add overlapping participants"() {
        given:
        def project = projectDir("project")
        def overlapping = project.file("overlapping").createDir()
        when:
        withCompositeConnection([ project, overlapping ]) { connection ->
            connection.getModels(EclipseProject)
        }
        then:
        thrown(IllegalArgumentException)
    }

    def "throws IllegalArgumentException when trying to retrieve a non-model type"() {
        when:
        withCompositeConnection(projectDir("project")) { connection ->
            connection.getModels(Object)
        }
        then:
        thrown(IllegalArgumentException)
    }

    def "throws IllegalStateException when using a closed connection"() {
        given:
        def project = populate("project") {
            settingsFile << "rootProject.name = 'project'"
        }
        when:
        withCompositeConnection(project) { connection ->
            def models = connection.getModels(EclipseProject)
            connection.close()
            def modelsAgain = connection.getModels(EclipseProject)
        }
        then:
        thrown(IllegalStateException)
    }

    def "propagates errors when trying to retrieve models"() {
        given:
        def project = populate("project") {
            settingsFile << "rootProject.name = '${rootProjectName}'"
            buildFile << "throw new RuntimeException()"
        }
        when:
        withCompositeConnection(project) { connection ->
            connection.getModels(EclipseProject).each {
                it.model
            }
        }
        then:
        def e = thrown(BuildException)
        assertFailure(e, "Could not fetch model of type 'EclipseProject'")
    }

    def "fails to retrieve model when participant is not a Gradle project"() {
        when:
        withCompositeConnection(projectDir("project-does-not-exist")) { connection ->
            connection.getModels(EclipseProject).each {
                it.model
            }
        }
        then:
        def e = thrown(BuildException)
        assertFailure(e,
            "Could not fetch model of type 'EclipseProject'",
            "project-does-not-exist' does not exist")
    }

    def "does not search upwards for projects"() {
        given:
        def rootDir = projectDir("root")
        rootDir.file("settings.gradle") << "include 'project', 'a', 'b', 'c'"
        def project = rootDir.createDir("project")
        project.createFile("build.gradle")

        when:
        def models = withCompositeConnection(project) { connection ->
            connection.getModels(EclipseProject)
        }
        then:
        // should only find 'project', not the other projects defined in root.
        models.size() == 1
        models[0].model.projectDirectory == project
    }
}

{'fraction_non_alphanumeric': 0.08826358826358827, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 2.507802614930409, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 16, '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': '5716918', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2046, 'n_words': 613}