You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Nicholas Andrews <no...@jhu.edu> on 2010/01/29 04:15:30 UTC

Run tasks

Hi,

I want to have several buildr run tasks.  My current run task looks like this:

task :run => :compile do
    Java.java "cc.HelloWorld", "arg1",
    :classpath => [ compile.dependencies, compile.target ],
    :java_args => ["-server", "-Xmx2048m"]
end

I thought I could just do:

task :run_with_blah to run with, say, "cc.ByeByeWorld" instead, but I
get a "don't know what to do with run_with_blah" error when I try to
run `buildr run_with_blah`.

The other thing I want is to be able to pass parameters to whatever it
is I'm running, instead of having to hard-code it in the build script.
 Can you access command line options from the buildfile script, or
does buildr eat them when it interprets it?  E.g.,

$ buildr run file1 file2

and use file1 and file2 as arguments to the class called in run.  This
could work for different main classes as well, where I'd just pass the
class name as an argument like

$ buildr run HelloWorld arg1 arg2

There may be a nicer way to accomplish what I'm doing here, for
instance with a testing framework.  I'd welcome any suggestions along
these lines too.

Cheers,
Nick

Re: Run tasks

Posted by Assaf Arkin <as...@labnotes.org>.
On Thu, Jan 28, 2010 at 7:15 PM, Nicholas Andrews <no...@jhu.edu> wrote:

> Hi,
>
> I want to have several buildr run tasks.  My current run task looks like
> this:
>
> task :run => :compile do
>    Java.java "cc.HelloWorld", "arg1",
>    :classpath => [ compile.dependencies, compile.target ],
>    :java_args => ["-server", "-Xmx2048m"]
> end
>
> I thought I could just do:
>
> task :run_with_blah to run with, say, "cc.ByeByeWorld" instead, but I
> get a "don't know what to do with run_with_blah" error when I try to
> run `buildr run_with_blah`.
>
> The other thing I want is to be able to pass parameters to whatever it
> is I'm running, instead of having to hard-code it in the build script.
>  Can you access command line options from the buildfile script, or
> does buildr eat them when it interprets it?  E.g.,
>
> $ buildr run file1 file2
>

Here's the documentation for defining tasks that take arguments:
http://github.com/jimweirich/rake/blob/cb9fc5d19663108986c92f4608da489a0dfb9875/doc/release_notes/rake-0.8.3.rdoc

Since Buildr uses Rake's tasks and command line parser, it will work the
same way when you run the buildr command.

Assaf



>
> and use file1 and file2 as arguments to the class called in run.  This
> could work for different main classes as well, where I'd just pass the
> class name as an argument like
>
> $ buildr run HelloWorld arg1 arg2
>
> There may be a nicer way to accomplish what I'm doing here, for
> instance with a testing framework.  I'd welcome any suggestions along
> these lines too.
>
> Cheers,
> Nick
>

Re: Run tasks

Posted by Alex Boisvert <al...@gmail.com>.
Two things,

1) Unless task :run appears at the top of your buildfile, it's implicitly
scoped inside a project.  For example, if you declare task :run inside
project 'foo', then you can run it by doing 'buildr foo:run'.
Alternatively, you can declare the task as 'project local' so if you're
already inside the foo project it will run 'foo:run' by declaring,

Project.local_task :run

2) To pass command-line parameter, you need to follow the
parameter=valueconvention.   All other arguments are assumed to be
task names, not
parameters.   You can access these parameters as environment variables
inside the buildfile by doing,

ENV['parameter']  # returns 'value'

For instance, if you want to parametrize your :run task with a main class,
you'd write,

task :run
  Java.java ENV['main'], ....
end

and invoke it from the command-line as,

buildr run main=com.example.Main

Hope this helps,
alex


On Thu, Jan 28, 2010 at 7:40 PM, Antoine Toulme <an...@lunar-ocean.com>wrote:

> Nick,
>
> you should look at the rule method in Rake. It does what you want.
>
> On Thu, Jan 28, 2010 at 19:15, Nicholas Andrews <no...@jhu.edu> wrote:
>
> > Hi,
> >
> > I want to have several buildr run tasks.  My current run task looks like
> > this:
> >
> > task :run => :compile do
> >    Java.java "cc.HelloWorld", "arg1",
> >    :classpath => [ compile.dependencies, compile.target ],
> >    :java_args => ["-server", "-Xmx2048m"]
> > end
> >
> > I thought I could just do:
> >
> > task :run_with_blah to run with, say, "cc.ByeByeWorld" instead, but I
> > get a "don't know what to do with run_with_blah" error when I try to
> > run `buildr run_with_blah`.
> >
> > The other thing I want is to be able to pass parameters to whatever it
> > is I'm running, instead of having to hard-code it in the build script.
> >  Can you access command line options from the buildfile script, or
> > does buildr eat them when it interprets it?  E.g.,
> >
> > $ buildr run file1 file2
> >
> > and use file1 and file2 as arguments to the class called in run.  This
> > could work for different main classes as well, where I'd just pass the
> > class name as an argument like
> >
> > $ buildr run HelloWorld arg1 arg2
> >
> > There may be a nicer way to accomplish what I'm doing here, for
> > instance with a testing framework.  I'd welcome any suggestions along
> > these lines too.
> >
> > Cheers,
> > Nick
> >
>

Re: Run tasks

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Nick,

you should look at the rule method in Rake. It does what you want.

On Thu, Jan 28, 2010 at 19:15, Nicholas Andrews <no...@jhu.edu> wrote:

> Hi,
>
> I want to have several buildr run tasks.  My current run task looks like
> this:
>
> task :run => :compile do
>    Java.java "cc.HelloWorld", "arg1",
>    :classpath => [ compile.dependencies, compile.target ],
>    :java_args => ["-server", "-Xmx2048m"]
> end
>
> I thought I could just do:
>
> task :run_with_blah to run with, say, "cc.ByeByeWorld" instead, but I
> get a "don't know what to do with run_with_blah" error when I try to
> run `buildr run_with_blah`.
>
> The other thing I want is to be able to pass parameters to whatever it
> is I'm running, instead of having to hard-code it in the build script.
>  Can you access command line options from the buildfile script, or
> does buildr eat them when it interprets it?  E.g.,
>
> $ buildr run file1 file2
>
> and use file1 and file2 as arguments to the class called in run.  This
> could work for different main classes as well, where I'd just pass the
> class name as an argument like
>
> $ buildr run HelloWorld arg1 arg2
>
> There may be a nicer way to accomplish what I'm doing here, for
> instance with a testing framework.  I'd welcome any suggestions along
> these lines too.
>
> Cheers,
> Nick
>