If you're using JRuby, then you should be able to just wrap the innards of
the task up inside a thread:

task 'run-mailserver' do
  Thread.new do
    begin
      Java::Commands.java ...
      ...
    rescue
      ...
    end
  end
end

However, this will not work on MRI (either 1.8 or 1.9) due to the way that
threads work.  On that platform, I think you will need to use fork.  Just be
aware that fork doesn't *really* work on JRuby, so you almost need to
abstract some sort of quicky-and-dirty facade over both APIs in order to
avoid writing your task more than once.

Daniel

On Fri, Jul 10, 2009 at 5:17 AM, Martin Grotzke <
[email protected]> wrote:

> Hi,
>
> I have another one :)
>
> I want to start a mailserver with test.setup so that it's available for
> tests.
>
> I created a task that starts a simple java mail server which blocks
> until it's interrupted. Now I wonder how it's possible to run this in
> the background during the tests.
>
> This is the task:
>
>  desc "Start mailserver on unprivileged ports"
>  task "run-mailserver" do
>    begin
>      Java::Commands.java('com.ericdaugherty.mail.server.Mail',
> _('runtime/mailserver'),
>        :classpath => ['runtime/mailserver/lib',
> FileList['runtime/mailserver/lib/*.jar']]
>        )
>    rescue Exception
>      # this is excepted, as java probably was interrupted via CTRL-C
>    end
>  end
>
> Is it possible somehow to run this in the background during the tests? I
> had a look at the jetty stuff, but there the lifecycle is managed via
> URL communication...
>
> Thanx && cheers,
> Martin
>
>
>

Reply via email to