Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear root metadata when adding or removing configurations #23991

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -18,7 +18,6 @@ package org.gradle.integtests.resolve.api

import org.gradle.integtests.fixtures.AbstractIntegrationSpec


class AddingConfigurationIntegrationTest extends AbstractIntegrationSpec {
def "can add configurations" () {
buildFile << """
Expand Down Expand Up @@ -79,4 +78,29 @@ class AddingConfigurationIntegrationTest extends AbstractIntegrationSpec {
expect:
succeeds "addConfigs"
}

def "can remove and add configurations between resolutions"() {
given:
mavenRepo.module("org", "foo", "1.0").publish()

buildFile << """
repositories {
maven { url '$mavenRepo.uri' }
}

task resolve {
def conf = configurations.create("conf")
conf.dependencies.add(project.dependencies.create("org:foo:1.0"))
conf.files
configurations.remove(conf)

def conf2 = configurations.create("conf2")
conf2.dependencies.add(project.dependencies.create("org:foo:1.0"))
conf2.files
}
"""

expect:
succeeds("resolve")
}
}
Expand Up @@ -81,6 +81,8 @@ public DefaultConfigurationContainer(
};
this.rootComponentMetadataBuilder = rootComponentMetadataBuilderFactory.create(this);
this.defaultConfigurationFactory = defaultConfigurationFactory;
this.getEventRegister().registerLazyAddAction(x -> rootComponentMetadataBuilder.discardAll());
this.whenObjectRemoved(x -> rootComponentMetadataBuilder.discardAll());
}

@Override
Expand Down
Expand Up @@ -131,6 +131,10 @@ public MutationValidator getValidator() {
return holder;
}

public void discardAll() {
holder.cachedValue = null;
}

private static class MetadataHolder implements MutationValidator {
private DefaultLocalComponentMetadata cachedValue;
private final ConfigurationsProvider configurationsProvider;
Expand Down
Expand Up @@ -15,6 +15,7 @@
*/
package org.gradle.api.internal.artifacts.configurations

import org.gradle.api.Action
import org.gradle.api.artifacts.UnknownConfigurationException
import org.gradle.api.internal.CollectionCallbackActionDecorator
import org.gradle.api.internal.DocumentationRegistry
Expand Down Expand Up @@ -72,8 +73,9 @@ class DefaultConfigurationContainerSpec extends Specification {
private UserCodeApplicationContext userCodeApplicationContext = Mock()
private CalculatedValueContainerFactory calculatedValueContainerFactory = Mock()

private CollectionCallbackActionDecorator domainObjectCollectionCallbackActionDecorator = Mock() {
private CollectionCallbackActionDecorator domainObjectCollectionCallbackActionDecorator = Mock(CollectionCallbackActionDecorator) {
decorateSpec(_) >> { Spec spec -> spec }
decorate(_ as Action) >> { it[0] }
}
def immutableAttributesFactory = AttributeTestUtil.attributesFactory()
private DefaultRootComponentMetadataBuilder.Factory rootComponentMetadataBuilderFactory = Mock(DefaultRootComponentMetadataBuilder.Factory) {
Expand Down
Expand Up @@ -17,6 +17,7 @@
package org.gradle.api.internal.artifacts.configurations

import groovy.test.NotYetImplemented
import org.gradle.api.Action
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.UnknownConfigurationException
import org.gradle.api.internal.CollectionCallbackActionDecorator
Expand Down Expand Up @@ -63,7 +64,9 @@ class DefaultConfigurationContainerTest extends Specification {
private DependencyLockingProvider lockingProvider = Mock(DependencyLockingProvider)
private ProjectStateRegistry projectStateRegistry = Mock(ProjectStateRegistry)
private DocumentationRegistry documentationRegistry = Mock(DocumentationRegistry)
private CollectionCallbackActionDecorator callbackActionDecorator = Mock()
private CollectionCallbackActionDecorator callbackActionDecorator = Mock(CollectionCallbackActionDecorator) {
decorate(_ as Action) >> { it[0] }
}
private UserCodeApplicationContext userCodeApplicationContext = Mock()
private CalculatedValueContainerFactory calculatedValueContainerFactory = Mock()
private Instantiator instantiator = TestUtil.instantiatorFactory().decorateLenient()
Expand Down