<commit_before>/*
 * Copyright 2011 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 spock.lang.Issue

class MavenParentPomResolveIntegrationTest extends AbstractHttpDependencyResolutionTest {

    def "includes dependencies from parent pom"() {
        given:
        def parentDep = mavenHttpRepo.module("org", "parent_dep", "1.2").publish()
        def childDep = mavenHttpRepo.module("org", "child_dep", "1.7").publish()

        def parent = mavenHttpRepo.module("org", "parent", "1.0")
        parent.hasPackaging('pom')
        parent.dependsOn("org", "parent_dep", "1.2")
        parent.publish()

        def child = mavenHttpRepo.module("org", "child", "1.0")
        child.dependsOn("org", "child_dep", "1.7")
        child.parent("org", "parent", "1.0")
        child.publish()

        buildFile << """
repositories {
    maven { url '${mavenHttpRepo.uri}' }
}
configurations { compile }
dependencies { compile 'org:child:1.0' }
task retrieve(type: Sync) {
    into 'libs'
    from configurations.compile
}
"""

        when:
        child.pom.expectGet()
        parent.pom.expectGet()

        child.artifact.expectGet()

        parentDep.pom.expectGet()
        parentDep.artifact.expectGet()
        childDep.pom.expectGet()
        childDep.artifact.expectGet()

        and:
        run 'retrieve'

        then:
        file('libs').assertHasDescendants('child-1.0.jar', 'parent_dep-1.2.jar', 'child_dep-1.7.jar')

        when:
        server.resetExpectations()
        file('libs').deleteDir()

        and:
        run 'retrieve'

        then:
        file('libs').assertHasDescendants('child-1.0.jar', 'parent_dep-1.2.jar', 'child_dep-1.7.jar')
    }

    def "uses dependencyManagement from parent pom"() {
        given:
        mavenRepo.module("org", "child_dep", "1.7").publish()

        def parent = mavenRepo.module("org", "parent", "1.0")
        parent.hasPackaging('pom')
        parent.publish()

        parent.pomFile.text = parent.pomFile.text.replace("</project>", '''
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org</groupId>
            <artifactId>child_dep</artifactId>
            <version>1.7</version>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>
''')

        def child = mavenRepo.module("org", "child", "1.0")
        child.parent("org", "parent", "1.0")
        child.dependsOn("org", "child_dep", null)
        child.publish()

        buildFile << """
repositories {
    maven { url '${mavenRepo.uri}' }
}
configurations { compile }
dependencies { compile 'org:child:1.0' }
task libs << { assert configurations.compile.files*.name == ['child-1.0.jar', 'child_dep-1.7.jar'] }
"""<commit_msg>More integration tests for pom dependencyManagement<commit_after>/*
 * Copyright 2011 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 spock.lang.Issue

class MavenParentPomResolveIntegrationTest extends AbstractHttpDependencyResolutionTest {

    def "includes dependencies from parent pom"() {
        given:
        def parentDep = mavenHttpRepo.module("org", "parent_dep", "1.2").publish()
        def childDep = mavenHttpRepo.module("org", "child_dep", "1.7").publish()

        def parent = mavenHttpRepo.module("org", "parent", "1.0")
        parent.hasPackaging('pom')
        parent.dependsOn("org", "parent_dep", "1.2")
        parent.publish()

        def child = mavenHttpRepo.module("org", "child", "1.0")
        child.dependsOn("org", "child_dep", "1.7")
        child.parent("org", "parent", "1.0")
        child.publish()

        buildFile << """
repositories {
    maven { url '${mavenHttpRepo.uri}' }
}
configurations { compile }
dependencies { compile 'org:child:1.0' }
task retrieve(type: Sync) {
    into 'libs'
    from configurations.compile
}
"""

        when:
        child.pom.expectGet()
        parent.pom.expectGet()

        child.artifact.expectGet()

        parentDep.pom.expectGet()
        parentDep.artifact.expectGet()
        childDep.pom.expectGet()
        childDep.artifact.expectGet()

        and:
        run 'retrieve'

        then:
        file('libs').assertHasDescendants('child-1.0.jar', 'parent_dep-1.2.jar', 'child_dep-1.7.jar')

        when:
        server.resetExpectations()
        file('libs').deleteDir()

        and:
        run 'retrieve'

        then:
        file('libs').assertHasDescendants('child-1.0.jar', 'parent_dep-1.2.jar', 'child_dep-1.7.jar')
    }

    def "uses dependencyManagement from parent pom"() {
        given:
        mavenRepo.module("org", "child_dep", "1.7").publish()
        mavenRepo.module("org", "typed_dep", "1.8").artifact(type: 'bar').publish()
        mavenRepo.module("org", "classified_dep", "1.9").artifact(classifier: 'classy').publish()

        def parent = mavenRepo.module("org", "parent", "1.0")
        parent.hasPackaging('pom')
        parent.publish()

        parent.pomFile.text = parent.pomFile.text.replace("</project>", '''
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org</groupId>
            <artifactId>child_dep</artifactId>
            <version>1.7</version>
        </dependency>
        <dependency>
            <groupId>org</groupId>
            <artifactId>typed_dep</artifactId>
            <type>bar</type>
            <version>1.8</version>
        </dependency>
        <dependency>
            <groupId>org</groupId>
            <artifactId>classified_dep</artifactId>
            <classifier>classy</classifier>
            <version>1.9</version>
        </dependency>
    </dependencies>
</dependencyManagement>
</project>
''')

        def child = mavenRepo.module("org", "child", "1.0")
        child.parent("org", "parent", "1.0")
        child.dependsOn("org", "child_dep", null)
        child.dependsOn("org", "typed_dep", null, "bar", null, null)
        child.dependsOn("org", "classified_dep", null, null, null, "classy")
        child.publish()

        buildFile << """
repositories {
    maven { url '${mavenRepo.uri}' }
}
configurations { compile }
dependencies { compile 'org:child:1.0' }
task libs << { assert configurations.compile.files*.name == ['child-1.0.jar', 'child_dep-1.7.jar', 'typed_dep-1.8.bar', 'classified_dep-1.9-classy.jar'] }
"""
{'fraction_non_alphanumeric': 0.14460526315789474, 'fraction_numerical': 0.015263157894736841, 'mean_word_length': 2.856418061897514, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 51, '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': '7596218', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2267, 'n_words': 507}