<commit_before>/*
 * Copyright 2014 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

import org.gradle.integtests.fixtures.AbstractDependencyResolutionTest
import org.gradle.test.fixtures.HttpRepository

abstract class ComponentMetadataRulesChangingModulesIntegrationTest extends AbstractDependencyResolutionTest {
    abstract HttpRepository getRepo()
    abstract String getRepoDeclaration()

    def moduleA = getRepo().module('org.test', 'moduleA', '1.0')

    def setup() {
        server.start()
        moduleA.publish()
        moduleA.allowAll()
    }

    def "changing dependency doesn't affect changing flag"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules
}
dependencies {
    modules("org.test:moduleA:1.0") { changing = true }
    components {
        eachComponent { details ->
            assert !details.changing
        }
    }
}
task resolve << {
    configurations.modules.resolve()
}
"""

        expect:
        succeeds("resolve")
    }

    def "static and dynamic dependencies have changing flag initialized to false"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules
}
dependencies {
    modules "org.test:moduleA:$version"
    components {
        eachComponent { details ->
            assert !details.changing
        }
    }
}
task resolve << {
    configurations.modules.resolve()
}
"""

        expect:
        succeeds("resolve")

        where:
        version << ["1.0", "[1.0,2.0]"]
    }


    def "rule can make a component changing"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules {
        resolutionStrategy.cacheChangingModulesFor 0, "seconds"
    }
}
dependencies {
    modules("org.test:moduleA:1.0")
    components {
        eachComponent { it.changing = true }
    }
}
task resolve << {
    copy {
        from configurations.modules
        into "modules"
    }
}
"""

        when:
        run("resolve")
        def artifact = file("modules/moduleA-1.0.jar")
        def snapshot = artifact.snapshot()

        and:
        moduleA.publishWithChangedContent()
        run("resolve")

        then:
        artifact.assertContentsHaveChangedSince(snapshot)
    }

    def "rule cannot make a dependency non-changing"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules {
        resolutionStrategy.cacheChangingModulesFor 0, "seconds"
    }
}
dependencies {
    modules("org.test:moduleA:1.0") { changing = true }
    components {
        eachComponent { it.changing = false }
    }
}
task resolve << {
    copy {
        from configurations.modules
        into "modules"
    }
}
"""<commit_msg>Added a little test coverage for dealing with meta-data rules that tweak the changing flag.<commit_after>/*
 * Copyright 2014 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

import org.gradle.integtests.fixtures.AbstractDependencyResolutionTest
import org.gradle.test.fixtures.HttpRepository

abstract class ComponentMetadataRulesChangingModulesIntegrationTest extends AbstractDependencyResolutionTest {
    abstract HttpRepository getRepo()
    abstract String getRepoDeclaration()

    def moduleA = getRepo().module('org.test', 'moduleA', '1.0')

    def setup() {
        server.start()
        moduleA.publish()
        moduleA.allowAll()
    }

    def "changing dependency doesn't affect changing flag"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules
}
dependencies {
    modules("org.test:moduleA:1.0") { changing = true }
    components {
        eachComponent { details ->
            assert !details.changing
        }
    }
}
task resolve << {
    configurations.modules.resolve()
}
"""

        expect:
        succeeds("resolve")
    }

    def "static and dynamic dependencies have changing flag initialized to false"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules
}
dependencies {
    modules "org.test:moduleA:$version"
    components {
        eachComponent { details ->
            assert !details.changing
        }
    }
}
task resolve << {
    configurations.modules.resolve()
}
"""

        expect:
        succeeds("resolve")

        where:
        version << ["1.0", "[1.0,2.0]"]
    }


    def "rule can make a component changing"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules {
        resolutionStrategy.cacheChangingModulesFor 0, "seconds"
    }
}
dependencies {
    modules("org.test:moduleA:1.0")
    components {
        eachComponent { it.changing = true }
    }
}
task resolve << {
    copy {
        from configurations.modules
        into "modules"
    }
}
"""

        when:
        run("resolve")
        def artifact = file("modules/moduleA-1.0.jar")
        def snapshot = artifact.snapshot()

        and:
        moduleA.publishWithChangedContent()
        run("resolve")

        then:
        artifact.assertContentsHaveChangedSince(snapshot)

        when:
        buildFile << """
dependencies.components.eachComponent { it.changing = false }
"""
        snapshot = artifact.snapshot()
        server.resetExpectations()

        and:
        run("resolve")

        then:
        artifact.assertContentsHaveNotChangedSince(snapshot)
    }

    def "rule cannot make a dependency non-changing"() {
        buildFile <<
"""
$repoDeclaration
configurations {
    modules {
        resolutionStrategy.cacheChangingModulesFor 0, "seconds"
    }
}
dependencies {
    modules("org.test:moduleA:1.0") { changing = true }
    components {
        eachComponent { it.changing = false }
    }
}
task resolve << {
    copy {
        from configurations.modules
        into "modules"
    }
}
"""
{'fraction_non_alphanumeric': 0.10223782360684511, 'fraction_numerical': 0.007605675003656574, 'mean_word_length': 2.662560257096947, 'pattern_counts': {'":': 0, '<': 41, '<?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': '3027464', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1816, 'n_words': 506}