<commit_before>/*
 * 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.api.plugins.scala

import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.util.HelperUtil
import org.junit.Test

class ScalaRuntimeExtensionTest {
    private final Project project = HelperUtil.createRootProject()

    @Test void allowsToInferScalaCompilerClasspath() {
        project.plugins.apply(ScalaBasePlugin)

        project.repositories {
            mavenCentral()
        }

        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("scala-library-2.10.0.jar")])

        assert classpath instanceof Configuration
        assert classpath.state == Configuration.State.UNRESOLVED
        assert classpath.dependencies.size() == 1
        classpath.dependencies.iterator().next().with {
            assert group == "org.scala-lang"
            assert name == "scala-compiler"
            assert version == "2.10.0"
        }
    }

    @Test void inferenceFallsBackToScalaToolsIfNoRepositoryDeclared() {
        project.plugins.apply(ScalaBasePlugin)

        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("scala-library-2.10.0.jar")])

        assert classpath == project.configurations.scalaTools
    }

    @Test void inferenceFallsBackToScalaToolsIfScalaLibraryNotFoundOnClassPath() {
        project.plugins.apply(ScalaBasePlugin)

        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("other2.jar")])

        assert classpath == project.configurations.scalaTools
    }

    @Test void allowsToFindScalaJarInClassPath() {
        project.plugins.apply(ScalaBasePlugin)

        def file = project.scalaRuntime.findScalaJar([new File("other.jar"), new File("scala-jdbc-1.5.jar"), new File("scala-compiler-1.7.jar")], "jdbc")

        assert file.name == "scala-jdbc-1.5.jar"
    }

    @Test void returnsNullIfScalaJarNotFound() {
        project.plugins.apply(ScalaBasePlugin)

        def file = project.scalaRuntime.findScalaJar([new File("other.jar"), new File("scala-jdbc-1.5.jar"), new File("scala-compiler-1.7.jar")], "library")

        assert file == null
    }

    @Test void allowsToDetermineVersionOfScalaJar() {
        project.plugins.apply(ScalaBasePlugin)

        assert project.scalaRuntime.getScalaVersion(new File("scala-compiler-2.9.2.jar")) == "2.9.2"
        assert project.scalaRuntime.getScalaVersion(new File("scala-jdbc-2.9.2.jar")) == "2.9.2"
        assert project.scalaRuntime.getScalaVersion(new File("scala-library-2.10.0-SNAPSHOT.jar")) == "2.10.0-SNAPSHOT"
        assert project.scalaRuntime.getScalaVersion(new File("scala-library-2.10.0-rc-3.jar")) == "2.10.0-rc-3"
    }

    @Test void returnsNullIfScalaVersionCannotBeDetermined() {
        project.plugins.apply(ScalaBasePlugin)

        assert project.scalaRuntime.getScalaVersion(new File("scala-compiler.jar")) == null
        assert project.scalaRuntime.getScalaVersion(new File("groovy-compiler-2.1.0.jar")) == null
    }
}<commit_msg>ported test to spock<commit_after>/*
 * 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.api.plugins.scala

import org.gradle.api.artifacts.Configuration
import org.gradle.util.HelperUtil

import spock.lang.Specification

class ScalaRuntimeExtensionTest extends Specification {
    def project = HelperUtil.createRootProject()

    def "allows to infer Scala compiler class path"() {
        project.plugins.apply(ScalaBasePlugin)

        project.repositories {
            mavenCentral()
        }

        when:
        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("scala-library-2.10.0.jar")])

        then:
        classpath instanceof Configuration
        classpath.state == Configuration.State.UNRESOLVED
        classpath.dependencies.size() == 1
        with(classpath.dependencies.iterator().next()) {
            group == "org.scala-lang"
            name == "scala-compiler"
            version == "2.10.0"
        }
    }

    def "inference falls back to scalaTools if no repository declared"() {
        project.plugins.apply(ScalaBasePlugin)

        when:
        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("scala-library-2.10.0.jar")])

        then:
        classpath == project.configurations.scalaTools
    }

    def "inference falls back to scalaTools if Scala library not found on class path"() {
        project.plugins.apply(ScalaBasePlugin)

        when:
        def classpath = project.scalaRuntime.inferScalaCompilerClasspath([new File("other.jar"), new File("other2.jar")])

        then:
        classpath == project.configurations.scalaTools
    }

    def "allows to find Scala Jar on class path"() {
        project.plugins.apply(ScalaBasePlugin)

        when:
        def file = project.scalaRuntime.findScalaJar([new File("other.jar"), new File("scala-jdbc-1.5.jar"), new File("scala-compiler-1.7.jar")], "jdbc")

        then:
        file.name == "scala-jdbc-1.5.jar"
    }

    def "returns null if Scala Jar not found"() {
        project.plugins.apply(ScalaBasePlugin)

        when:
        def file = project.scalaRuntime.findScalaJar([new File("other.jar"), new File("scala-jdbc-1.5.jar"), new File("scala-compiler-1.7.jar")], "library")

        then:
        file == null
    }

    def "allows to determine version of Scala Jar"() {
        project.plugins.apply(ScalaBasePlugin)

        expect:
        with(project.scalaRuntime) {
            getScalaVersion(new File("scala-compiler-2.9.2.jar")) == "2.9.2"
            getScalaVersion(new File("scala-jdbc-2.9.2.jar")) == "2.9.2"
            getScalaVersion(new File("scala-library-2.10.0-SNAPSHOT.jar")) == "2.10.0-SNAPSHOT"
            getScalaVersion(new File("scala-library-2.10.0-rc-3.jar")) == "2.10.0-rc-3"
        }
    }

    def "returns null if Scala version cannot be determined"() {
        project.plugins.apply(ScalaBasePlugin)

        expect:
        with(project.scalaRuntime) {
            getScalaVersion(new File("scala-compiler.jar")) == null
            getScalaVersion(new File("groovy-compiler-2.1.0.jar")) == null
        }
    }
}
{'fraction_non_alphanumeric': 0.11737026082280183, 'fraction_numerical': 0.01747781661737026, 'mean_word_length': 3.047334058759521, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7064584', 'n_tokens_mistral': 2292, 'n_tokens_neox': 2135, 'n_words': 495}