Skip to content

Commit

Permalink
Merge pull request #23991 Clear root metadata when adding or removing…
Browse files Browse the repository at this point in the history
… configurations

This ensures when a configuration is removed and added between resolutions, we can clear and subsequently re-calculate updated metadata

Fixes #23985

Co-authored-by: Justin Van Dort <jvandort@gradle.com>
  • Loading branch information
bot-gradle and jvandort committed Feb 23, 2023
2 parents 1966b65 + 9754d4e commit 87bcc57
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
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

0 comments on commit 87bcc57

Please sign in to comment.