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

Backports to 6x #22359

Merged
merged 4 commits into from Oct 13, 2022
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 @@ -506,6 +506,65 @@ class DependenciesAttributesIntegrationTest extends AbstractModuleDependencyReso
'c1' | 'c2' | 'runtime' | ['org.gradle.status': defaultStatus(), 'org.gradle.usage': 'java-runtime', 'org.gradle.libraryelements': 'jar', 'org.gradle.category': 'library', custom: 'c2']
}

@Issue("https://github.com/gradle/gradle/issues/20182")
@RequiredFeature(feature = GradleMetadataResolveRunner.GRADLE_METADATA, value = "true")
@Unroll("Selects variant #expectedVariant using custom attribute value #dependencyValue overriding configuration attribute #configurationValue using dependency constraint without version")
def "dependency attribute value overrides configuration attribute using dependency constraint without version"() {
given:
repository {
'org:test:1.0' {
variant('api') {
attribute('custom', 'c1')
}
variant('runtime') {
attribute('custom', 'c2')
}
}
}

buildFile << """
configurations.conf.attributes.attribute(CUSTOM_ATTRIBUTE, '$configurationValue')

dependencies {
constraints {
conf('org:test') {
attributes {
attribute(CUSTOM_ATTRIBUTE, '$dependencyValue')
}
}
}
conf 'org:test:1.0'
}
"""

when:
repositoryInteractions {
'org:test:1.0' {
expectResolve()
}
}
succeeds 'checkDeps'

then:
resolve.expectGraph {
root(":", ":test:") {
module('org:test:1.0') {
configuration = expectedVariant
variant(expectedVariant, expectedAttributes)
}
constraint('org:test', 'org:test:1.0') {
configuration = expectedVariant
variant(expectedVariant, expectedAttributes)
}
}
}

where:
configurationValue | dependencyValue | expectedVariant | expectedAttributes
'c2' | 'c1' | 'api' | ['org.gradle.status': defaultStatus(), 'org.gradle.usage': 'java-api', 'org.gradle.libraryelements': 'jar', 'org.gradle.category': 'library', custom: 'c1']
'c1' | 'c2' | 'runtime' | ['org.gradle.status': defaultStatus(), 'org.gradle.usage': 'java-runtime', 'org.gradle.libraryelements': 'jar', 'org.gradle.category': 'library', custom: 'c2']
}

@RequiredFeature(feature = GradleMetadataResolveRunner.GRADLE_METADATA, value = "true")
@ToBeFixedForConfigurationCache
def "Fails resolution because consumer configuration attributes and constraint attributes conflict"() {
Expand Down
Expand Up @@ -189,26 +189,26 @@ private DependencyConstraint doAdd(Configuration configuration, Object dependenc
return dependency;
}

private DependencyConstraint doAddProvider(Configuration configuration, Provider<?> dependencyNotation, Action<? super DependencyConstraint> configureAction) {
private DependencyConstraint doAddProvider(Configuration configuration, Provider<?> dependencyNotation, @Nullable Action<? super DependencyConstraint> configureAction) {
Provider<DependencyConstraint> lazyConstraint = dependencyNotation.map(mapDependencyConstraintProvider(configureAction));
configuration.getDependencyConstraints().addLater(lazyConstraint);
// Return a fake dependency constraint object to satisfy Kotlin DSL backwards compatibility
return DUMMY_CONSTRAINT;
}

private DependencyConstraint doAddListProvider(Configuration configuration, Provider<?> dependencyNotation, Action<? super DependencyConstraint> configureAction) {
private DependencyConstraint doAddListProvider(Configuration configuration, Provider<?> dependencyNotation, @Nullable Action<? super DependencyConstraint> configureAction) {
// workaround for the fact that mapping to a list will not create a `CollectionProviderInternal`
ListProperty<DependencyConstraint> constraints = objects.listProperty(DependencyConstraint.class);
constraints.set(dependencyNotation.map(notation -> {
List<MinimalExternalModuleDependency> deps = Cast.uncheckedCast(notation);
return deps.stream().map(d -> create(d, configureAction)).collect(Collectors.toList());
return deps.stream().map(d -> doCreate(d, configureAction)).collect(Collectors.toList());
}));
configuration.getDependencyConstraints().addAllLater(constraints);
return DUMMY_CONSTRAINT;
}

private <T> Transformer<DependencyConstraint, T> mapDependencyConstraintProvider(Action<? super DependencyConstraint> configurationAction) {
return lazyNotation -> create(lazyNotation, configurationAction);
private <T> Transformer<DependencyConstraint, T> mapDependencyConstraintProvider(@Nullable Action<? super DependencyConstraint> configurationAction) {
return lazyNotation -> doCreate(lazyNotation, configurationAction);
}

@Override
Expand Down
Expand Up @@ -439,7 +439,7 @@ private List<ModuleDependencyConstraint> consumeDependencyConstraints(JsonReader
String group = null;
String module = null;
String reason = null;
VersionConstraint version = null;
VersionConstraint version = DefaultImmutableVersionConstraint.of();
ImmutableAttributes attributes = ImmutableAttributes.EMPTY;

reader.beginObject();
Expand Down
Expand Up @@ -98,12 +98,12 @@ private final static class UnsupportedCapabilitiesHandler implements ModuleDepen

@Override
public void requireCapability(Object capabilityNotation) {
throw new InvalidUserDataException("Capabilies are not supported by dependency constraints");
throw new InvalidUserDataException("Capabilities are not supported by dependency constraints");
}

@Override
public void requireCapabilities(Object... capabilityNotations) {
throw new InvalidUserDataException("Capabilies are not supported by dependency constraints");
throw new InvalidUserDataException("Capabilities are not supported by dependency constraints");
}
}
}
Expand Up @@ -381,7 +381,8 @@ class GradleModuleMetadataParserTest extends Specification {
"group": "g3",
"module": "m3",
"version": { "requires": "v3" }
}
},
{ "group": "g4", "module": "m4" }
],
"attributes": { "usage": "compile" }
},
Expand All @@ -404,6 +405,7 @@ class GradleModuleMetadataParserTest extends Specification {
1 * variant1.addDependencyConstraint("g1", "m1", requires("v1"), null, ImmutableAttributes.EMPTY)
1 * variant1.addDependencyConstraint("g2", "m2", prefers("v2"), null, ImmutableAttributes.EMPTY)
1 * variant1.addDependencyConstraint("g3", "m3", requires("v3"), null, ImmutableAttributes.EMPTY)
1 * variant1.addDependencyConstraint("g4", "m4", emptyConstraint(), null, ImmutableAttributes.EMPTY)
1 * variant1.setAvailableExternally(false)
1 * metadata.addVariant("runtime", attributes(usage: "runtime", packaging: "zip")) >> variant2
1 * variant2.addDependencyConstraint("g3", "m3", prefers("v3"), null, ImmutableAttributes.EMPTY)
Expand Down
Expand Up @@ -168,21 +168,30 @@ public void skipChunked() throws EOFException, IOException {
public <T> T decodeChunked(DecodeAction<Decoder, T> decodeAction) throws EOFException, Exception {
if (nested == null) {
nested = new KryoBackedDecoder(new InputStream() {
private int leftover = 0;

@Override
public int read() throws IOException {
throw new UnsupportedOperationException();
}

@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
if (leftover > 0) {
int count = Math.min(leftover, length);
leftover -= count;
readBytes(buffer, offset, count);
return count;
}

int count = readSmallInt();
if (count == 0) {
// End of stream has been reached
return -1;
}
if (count > length) {
// For now, assume same size buffers used to read and write
throw new UnsupportedOperationException();
leftover = count - length;
count = length;
}
readBytes(buffer, offset, count);
return count;
Expand Down