On 14/04/2011, at 12:34 PM, James Carr wrote:

> Hi All,
> 
> I've been thinking it would be useful to be able to run a build script
> from a uri, for example I could have a hosted gradle script with tasks
> that generate skeleton project structures like:
> 
> gradle -b http://repo/gradle-scripts/create.gradle java-jar
> 
> Thoughts?

This would make sense for init scripts: gradle -I http://some/url.gradle 
java-jar.

Not so sure about for -b, at least, not without some changes to how it works. 
At the moment, when you use -b, Gradle effectively defines a project whose 
projectDir is the directory containing the specified build script. What you're 
suggesting above is that Gradle should define a project whose projectDir is the 
current directory, when a URL is specified for -b. That is:

gradle -b /some/dir/build.gradle -> projectDir == /some/dir
gradle -b http:/some/resource.gradle -> projectDir = $PWD

I don't really like this inconsistency.

One option is to support urls for init scripts only. I think this would solve 
the use cases, probably with some tweaks to the init script dsl.

Another option is to merge -b into -p, so that -p define which projectDir to 
use, and then change -b so that it adds a build script which runs before the 
project's build script. That is, -b effectively defines an init build script. 
We should also ditch the -e option, if we do this.

That is:

gradle -p /some/dir -> projectDir = /some/dir, build script -> 
/some/dir/build.gradle
gradle -p /some/dir/build.gradle -> projectDir = /some/dir, build script -> 
/some/dir/build.gradle
gradle -b /some/dir/other.gradle -> projectDir = $PWD, build scripts -> 
/some/dir/other.gradle, $PWD/build.gradle

Not sure I like this. I think the init script approach would work.

> I've been poking around and discovered this doesn't work at
> the moment due to the way AbstractFileResolver resolves files and
> throws exceptions on URLs. Is there any reason against changing it to
> actually fetch content from URLs (aside from some added complexity)?

I don't think I'd change the contract of FileResolver.resolve(). It's used 
pretty extensively, and its callers assume that 1) if they pass in the path for 
a directory, they get back a File which contains the directory tree, and 2) 
that it's relatively cheap to call. Neither of those would be true if we change 
it to fetch content from non-file urls (at least, not without a bit of work).

Instead, I'd think about doing what we use for apply from: 'some-url', which is 
to use FileResolver.resolveUri() and change StartParameter to model the init 
scripts as URIs rather than Files.


--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com

Reply via email to