<commit_before>/*
 * Copyright 2017 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.resolve.maven

import org.gradle.integtests.fixtures.AbstractHttpDependencyResolutionTest
import org.gradle.integtests.fixtures.FeaturePreviewsFixture
import org.gradle.integtests.fixtures.resolve.ResolveTestFixture
import org.gradle.test.fixtures.maven.MavenModule
import spock.lang.Ignore

class MavenBomResolveIntegrationTest extends AbstractHttpDependencyResolutionTest {
    def resolve = new ResolveTestFixture(buildFile).expectDefaultConfiguration('runtime')
    MavenModule bom
    MavenModule moduleA

    def setup() {
        resolve.prepare()
        settingsFile << "rootProject.name = 'testproject'"
        FeaturePreviewsFixture.enableImprovedPomSupport(settingsFile)
        buildFile << """
            repositories { maven { url "${mavenHttpRepo.uri}" } }
            configurations { compile }
        """
        moduleA = mavenHttpRepo.module('group', 'moduleA', '2.0').allowAll().publish()
        bom = mavenHttpRepo.module('group', 'bom', '1.0')
            .hasType("pom")
            .allowAll()
    }

    MavenModule bomDependency(String artifact, List<Map<String, String>> exclusions = null) {
        bom.dependencyConstraint(mavenHttpRepo.module('group', artifact, '2.0'), exclusions: exclusions)
    }

    def "can use a bom to select a version"() {
        given:
        bomDependency('moduleA').publish()
        buildFile << """
            dependencies {
                compile "group:moduleA"
                compile platform("group:bom:1.0")
            }
        """

        when:
        succeeds 'checkDep'

        then:
        resolve.expectGraph {
            root(':', ':testproject:') {
                module("group:bom:1.0:platform-runtime") {
                    module("group:moduleA:2.0")
                    noArtifacts()
                }
                edge("group:moduleA", "group:moduleA:2.0")
            }
        }
    }

    @Ignore("This is no longer true, since a dependency on a BOM is by default a dependency on a library")
    def "can import a bom transitively"() {
        given:
        bomDependency('moduleA').publish()
        mavenHttpRepo.module('group', 'main', '5.0').allowAll().dependsOn(bom).publish()

        buildFile << """
            dependencies {
                compile "group:moduleA"
                compile "group:main:5.0"
            }
        """

        when:
        succeeds 'checkDep'

        then:
        resolve.expectGraph {
            root(':', ':testproject:') {
                module("group:main:5.0") {
                    module("group:bom:1.0") {
                        module("group:moduleA:2.0")
                        noArtifacts()
                    }
                }
                edge("group:moduleA", "group:moduleA:2.0")
            }
        }
    }

    def "a bom dependencyManagement entry can declare excludes which are applied unconditionally to module"() {
        given:
        moduleA.dependsOn(mavenHttpRepo.module("group", "moduleC", "1.0").allowAll().publish()).publish()
        bomDependency('moduleA', [[group: 'group', module: 'moduleC']])
        bomDependency('moduleB', [[group: 'group', module: 'moduleC']]).publish()

        buildFile << """
            dependencies {
                compile "group:moduleA"
                compile platform("group:bom:1.0")
            }
        """

        when:<commit_msg>Remove irrelevant test<commit_after>/*
 * Copyright 2017 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.resolve.maven

import org.gradle.integtests.fixtures.AbstractHttpDependencyResolutionTest
import org.gradle.integtests.fixtures.FeaturePreviewsFixture
import org.gradle.integtests.fixtures.resolve.ResolveTestFixture
import org.gradle.test.fixtures.maven.MavenModule
import spock.lang.Ignore

class MavenBomResolveIntegrationTest extends AbstractHttpDependencyResolutionTest {
    def resolve = new ResolveTestFixture(buildFile).expectDefaultConfiguration('runtime')
    MavenModule bom
    MavenModule moduleA

    def setup() {
        resolve.prepare()
        settingsFile << "rootProject.name = 'testproject'"
        FeaturePreviewsFixture.enableImprovedPomSupport(settingsFile)
        buildFile << """
            repositories { maven { url "${mavenHttpRepo.uri}" } }
            configurations { compile }
        """
        moduleA = mavenHttpRepo.module('group', 'moduleA', '2.0').allowAll().publish()
        bom = mavenHttpRepo.module('group', 'bom', '1.0')
            .hasType("pom")
            .allowAll()
    }

    MavenModule bomDependency(String artifact, List<Map<String, String>> exclusions = null) {
        bom.dependencyConstraint(mavenHttpRepo.module('group', artifact, '2.0'), exclusions: exclusions)
    }

    def "can use a bom to select a version"() {
        given:
        bomDependency('moduleA').publish()
        buildFile << """
            dependencies {
                compile "group:moduleA"
                compile platform("group:bom:1.0")
            }
        """

        when:
        succeeds 'checkDep'

        then:
        resolve.expectGraph {
            root(':', ':testproject:') {
                module("group:bom:1.0:platform-runtime") {
                    module("group:moduleA:2.0")
                    noArtifacts()
                }
                edge("group:moduleA", "group:moduleA:2.0")
            }
        }
    }
    
    def "a bom dependencyManagement entry can declare excludes which are applied unconditionally to module"() {
        given:
        moduleA.dependsOn(mavenHttpRepo.module("group", "moduleC", "1.0").allowAll().publish()).publish()
        bomDependency('moduleA', [[group: 'group', module: 'moduleC']])
        bomDependency('moduleB', [[group: 'group', module: 'moduleC']]).publish()

        buildFile << """
            dependencies {
                compile "group:moduleA"
                compile platform("group:bom:1.0")
            }
        """

        when:
{'fraction_non_alphanumeric': 0.11431757981318834, 'fraction_numerical': 0.008922347692736652, 'mean_word_length': 2.372825575928538, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 7, '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': '2283633', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1911, 'n_words': 470}