Hi Adam,
Thank you for the responses. I have more questions below.
On Tue, Aug 24, 2010 at 2:48 AM, Adam Murdoch <[email protected]> wrote:
> On 21/08/10 6:46 AM, Eric Berry wrote:
>
> I'm making some progress on this. Initially, I think my plugin is going to
> have these tasks:
> build
> clean
> cleanAll
>
>
> What would be the difference between clean and cleanAll?
>
clean deletes the 'build' directory, cleanAll deletes the 'build' directory
(via clean) and the 'dist' directory. Is there a better way to do this
that's already implemented in the JavaBasePlugin?
>
> You might think about applying the JavaBasePlugin from your plugin. It will
> add these tasks like clean, build, and so on for you.
>
This is what I was trying to do initially, but didn't understand the magic
behind it. I think I've got it worked out a bit more now. Please correct me
if I'm wrong.
After looking through the Groovy, Scala and Antlr plugins, it looks like all
I need to do is apply the JavaBasePlugin?
[code]
public class JavascriptLibPlugin implements Plugin<Project> {
public void apply(Project project) {
project.plugins.apply(JavaBasePlugin.class)
// set the dependencies of build task
project.tasks.build.dependsOn = ['compileJavascript', 'docJavascript',
'minifyJavascript']
// add dist directory to clean task
project.tasks.clean << {
delete(project.convention.plugins.javascript.distDir) }
// define my own tasks below
project.task('compileJavascript', dependsOn: ['combineJavascript',
'filterJavascript']) {}
// using a class
project.task('combineJavascript', type: JavascriptCombine, depends:
'init')
...
}
}
[/code]
Does the JavaBasePlugin do any initialization of build directories, or do I
need to do this in my plugin? I didn't see anything initially? Does the
compile task create the build directory before doing anything there?
Currently, I have an 'init' task which creates the build and dist
directories.
>
> combineJavascript
> compileJavascript
> compileTestJavascript
> distJavascript
>
>
> What would this task do?
>
The distJavascript task depends on build, and then just copies over the
"distributable" files over to the dist directory. This might be something
like [project name]-[version].js, and [project name]-[version].min.js.
Perhaps I should make use of the package task of the JavaBasePlugin? How do
I go about doing that, as my understanding of Gradle lifecycle and task
definitions is that the '<<' syntax only configures the tasks and is a
shortcut for [task].doLast?
>
> docJavascript
> filterJavascript
> minifyJavascript
> testJavascript
>
>
> You might think about adding a dependency from 'check' to 'testJavascript'
>
The check task comes from the JavaBasePlugin correct?
>
>
>
> I have some questions though. First, my 'compileJavascript' task is
> probably just going to be a meta-task which just depends on, or calls the
> 'combineJavascript', and 'filterJavascript' tasks. I've created the latter 2
> to extend SourceTask, but I'm not sure how to hook them up with a
> JavascriptPluginConvention object. Can someone please explain to me how I
> can make use of a convention, and have it set the source, includes,
> excludes, etc.. in a SourceTask? Also, if I have the compile task simply
> depends on, or call the combine and filter tasks, can I have 1 configuration
> for those tasks which or should I have individual ones for each? Eg. it
> doesn't make sense to have a "filterSourceDir", and "combineSourceDir". I'd
> rather just have the user supply/set 1 sourceDir and just use that in both
> tasks. I'm thinking this should be part of the convention, but again, not
> sure how to hook the convention up with extended tasks.
>
>
> There's some information about this in the user guide:
> http://gradle.org/0.9-rc-1/docs/userguide/custom_plugins.html#N148A7
>
> Also, have a look at this mail thread for some more info:
> http://markmail.org/message/zdyafo5qpq4llkl2
>
>
>
> Would I do something kind of like:
> [code lang=groovy]
> class JavascriptPlugin implements Plugin<Project> {
> void apply(Project project) {
> ...
> project.task('combineJavascript', type: Source) << {
> super.source = project.convention.plugins.javascript.srcDir
> super.excludes = project.convention.plugins.javascript.srcExcludes
> super.execute()
> }
> ...
> }
> }
> [/code]
>
> Also, if I want the doc, minify, and test tasks to execute some external
> process what's the appropriate way to handle this?
>
>
> You might use the Exec or JavaExec tasks.
>
Ok. Thanks.
>
>
> Is it possible for plugins to define dependencies on external jars?
>
>
> Yes. For example, the Groovy plugin does this for Groovy.
>
>
> Eg. There is a Google "Closure Compiler" jar file which I could download
> then use via command line on the user's sources.
>
> Or is it better to do a check for the existence of the libraries on the
> filesystem and print an error to users if those libraries are not installed?
>
>
> Personally, I think it's better to download them.
>
>From my understanding this isn't really done "automatically" though right,
the user is required to add the groovy dependencies to their build script
for the plugin to work properly, correct?
--
Learn from the past. Live in the present. Plan for the future.
Blog: http://www.townsfolkdesigns.com/blogs/elberry
jEdit <http://www.jedit.org> - Programmer's Text Editor
Bazaar <http://bazaar.canonical.com> - Version Control for Humans