[GRADLE-588] Add support for an init script Created: 10/Aug/09 Updated: 04/Jan/13 Resolved: 26/Sep/09 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | None |
Fix Version/s: | 0.8 |
Type: | New Feature | ||
Reporter: | John Murph | Assignee: | Adam Murdoch |
Resolution: | Fixed | Votes: | 0 |
Issue Links: |
|
Description |
It is desirable for Gradle to support the concept of initialization scripts. These scripts could set up the environment for each Gradle execution. Several use cases have been discussed:
The first of these needs the script to be explicitly stated via command line options. I envision a "--init-script" option that must be followed by a file path. For ALL such options on the command line, the specified script would be executed. The remaining use cases are per-user settings that would benefit from an automatically included "user init script" that does not have to be explicitly stated on the command line for every execution of Gradle. I envision looking in ~/.gradle/init.gradle for such a script. If one is found, it is also executed. These scripts need to be able to specify classpaths and load classes from those classpaths. This is similar to the buildscript idea currently supported in build.gradle scripts. Init scripts will have a similar mechanism. They also need to be able to register listeners with Gradle. To accomplish this, the init scripts will be executed with the Build object as their "delegate". This means that init scripts would configure builds, and build scripts would configure projects. That's a bit confusing, but can be worked out later. |
Comments |
Comment by John Murph [ 10/Aug/09 ] |
I have the first Phase 1 implementation up on GitHub at git://github.com/sappling/gradle.git in branch init_script. |
Comment by Adam Murdoch [ 11/Aug/09 ] |
This looks good to me. Some comments:
|
Comment by John Murph [ 11/Aug/09 ] |
I was thinking of this method as an implementation detail, so I uesd BuildInternal. Will this method ever be exposed to users? I don't know of any way for them to get the Gradle instance right now. However, I don't really mind making it Build either. Unless you override yourself, I'll change it to Build.
Why? Once again, this seems like an unnecessary method. Right now several uses do "gradle.getBuild().addBuildListener()" but I expect that to change. Again, not very important to me, so I'll add it back unless you override yourself.
I thought about doing that several times during this work. Ultimately I decided not yet just to keep the change smaller. I will do it now.
Oops. I had thought I did that. Must have missed it. Thanks for the reminder. |
Comment by John Murph [ 11/Aug/09 ] |
I just pushed updated code to the init_script branch on GitHub. This incorporates all suggestions (except for Gradle.getBuild(), I removed that method as it was no longer used after adding the Gradle.adBuildListener() method back). I also updated it to work with the "build buildSource before settings" change that got submitted. I think this completes phase 1. For phase 2, I intent to add basic init script support (--init-script command line and per-user file handling). This includes allowing the classpath to be specified and used in the script. The "delegate" object will be Build, but I will not add much to Build to support other needs. Seems fairly straight forward to me. Sound good? |
Comment by Adam Murdoch [ 26/Sep/09 ] |
This is all finished. Thank you for the patches. |