how do I convert a `Provider<File>` into a `Provid...
# community-support
c
how do I convert a
Provider<File>
into a `ProviderDirectory`; bonus points for doing it inside of a
ValueSource
v
Copy code
layout.dir(fileProvider)
p
And how do you get a layout instance? https://github.com/gradle/gradle/issues/28576
v
I didn't target the bonus points 😄
c
Yeah I had a vague memory of that ticket. I think I thumbed it up. I was hoping there was another way to convert a file into a directory. I really don't understand why there isn't something like Directory.of Gradle needs to stop with the service locator anti pattern
I was hoping that maybe since I already had an instance of a directory property that I could use that to convert a new file instance into a directory
Ps speech to texting right now so sorry that not everything is written in code form
v
If you have a directory property, you should be able to use its
dir
to do it, shouldn't you?
p
Also, what’s the exact use-case? A value source provides an input to a task. If your task requires a directory by using DirectoryProperty, you can just pass the output of the value source, the file provider directly. If you want to use a directory property as input of the value source, you could do the mapping when setting the property in your build script/plugin etc with a project layout as a workaround.
Or do you „just“ want to provide a convention value like I want to do in the issue?
c
I want to provide it to another directory property for another thing. A provider file being kind of awkward to set on a directory property
p
I do prefer the directory (property) apis too, but using a file provider is the best workaround at the moment.
c
I mean I'm returning a file provider that is needed to input into a directory property
So I'm going to have to map one to the other
v
Why do your need to convert for that?
directoryProperty.fileProvider(fileProvider)
c
That's probably the thing I've been looking for... I'd have to check later when I'm at that computer
👌 1
it doesn't seem like this would be equivalent
Copy code
spec.getParameters().getGitDirectory().fileProvider(gitDir);
to
Copy code
spec.getParameters().getGitDirectory().set(gitDir);
if
gitDir
was a
Provider<Directory>
instead of a
Provider<File>
Copy code
spec.getParameters().getGitDirectory().set(project.getLayout().dir(gitDir));
is probably correct
v
Why is it not equivalent? What is the difference?
c
I really wouldn't know... The documentation suggests all kinds of things, including that it might change the path, and it returns a value. It's not clear that it even sets anything.
v
I don't get what you mean. The doc is pretty clear to me. And that it returns something is exactly the same as with
.value(...)
the property itself for method call chaning.