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

ConventionMapping doesn't work correctly for DirectoryProperty and RegularFileProperty after upgrade #29177

Closed
asodja opened this issue May 16, 2024 · 0 comments · Fixed by #29180
Labels
a:bug in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty p:lazy-migration Issues covered by migration to an all-lazy API
Milestone

Comments

@asodja
Copy link
Member

asodja commented May 16, 2024

If we upgrade a property from a File to DirectoryProperty or RegularFileProperty, and there are some convention mapping defined in plugins, we incorrectly handle them. The logic that modifies that code is here:

private boolean mapConventionOn(SupportsConvention target, MappedPropertyImpl mapping) {
if (target instanceof Property) {
Property<Object> asProperty = Cast.uncheckedNonnullCast(target);
asProperty.convention(new DefaultProvider<>(() -> mapping.getValue(_convention, _source)));
} else if (target instanceof MapProperty) {
MapProperty<Object, Object> asMapProperty = Cast.uncheckedNonnullCast(target);
DefaultProvider<Map<Object, Object>> convention = new DefaultProvider<>(() -> Cast.uncheckedNonnullCast(mapping.getValue(_convention, _source)));
asMapProperty.convention(convention);
} else if (target instanceof HasMultipleValues) {
HasMultipleValues<Object> asCollectionProperty = Cast.uncheckedNonnullCast(target);
asCollectionProperty.convention(new DefaultProvider<>(() -> Cast.uncheckedNonnullCast(mapping.getValue(_convention, _source))));
} else if (target instanceof ConfigurableFileCollection) {
ConfigurableFileCollection asFileCollection = Cast.uncheckedNonnullCast(target);
asFileCollection.convention((Callable) () -> mapping.getValue(_convention, _source));
} else {
return false;
}
return true;
}

For example user can have code like:

createStartScripts.getConventionMapping()
	.map("outputDir", () -> project.getLayout().getBuildDirectory().dir("bootScripts").get().getAsFile());

(see spring-boot plugin).

Failure looks like:

FAILURE: Build failed with an exception.
  
  * What went wrong:
  Execution failed for task ':bootStartScripts'.
  > Failed to calculate the value of task ':bootStartScripts' property 'outputDir'.
     > Cannot get the value of task ':bootStartScripts' property 'outputDir' of type org.gradle.api.file.Directory as the provider associated with this property returned a value of type java.io.File.

The problem is, that convention mapping returns a File, while DirectoryProperty.convention() expects a Directory and RegularFileProperty.convention() expects a RegularFile.

@asodja asodja added a:bug in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty p:lazy-migration Issues covered by migration to an all-lazy API labels May 16, 2024
@bot-gradle bot-gradle added this to the 8.9 RC1 milestone May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:bug in:provider-api property lazy provider MapProperty ListProperty DirectoryProperty p:lazy-migration Issues covered by migration to an all-lazy API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants