You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Antoine Toulme <an...@lunar-ocean.com> on 2009/09/15 15:41:47 UTC

Redirecting RJB output

Hi everyone,
I'm trying to find a nice way to redirect the RJB output. I have some output
made directly from Java that I would like to reformat and eventually
colorize.

>From what I read, the best solution would be to replace the PrintStreams
used in System.out and System.err by something that would pipe to $stdout
and $stderr respectively.

>From the RJB doc, I see RJB can bind a Ruby object to a Java interface. That
sounds like the right deal...

but PrintStream is a class.

The workaround is to have some Java code exposing an interface, with a
PrintStream implementation that delegates everything to said interface, and
have RJB instanciate the interface and pass output along to stdout and
stderr.

Was this attempted before ? Any advice on this ?

Thanks,

Antoine

Re: Redirecting RJB output

Posted by Antoine Toulme <an...@lunar-ocean.com>.
Hi,
you can see it here used in the redirect_java_err function:
http://github.com/intalio/buildr4osgi/blob/master/spec/compile/compiler_spec.rb

The javac specs could also use this function to check whether warnings are
issued or not.

Thanks,

Antoine

On Wed, Sep 16, 2009 at 09:19, peter schröder <ps...@blau.de> wrote:

> Could you post a simple working example to the wiki?
>
> Am 15.09.2009 um 23:42 schrieb Antoine Toulme:
>
>
>  So this works:
>>   byteArray = Rjb::import('java.io.ByteArrayOutputStream')
>>   printStream = Rjb::import('java.io.PrintStream')
>>   out = byteArray.new()
>>   Rjb::import('java.lang.System').out = printStream.new(out)
>>   err = byteArray.new()
>>   Rjb::import('java.lang.System').err = printStream.new(err)
>>   ... [do something]
>>   err.toString.should match(/WARNING/)
>>
>> Thanks Alex!
>>
>> Antoine
>>
>> On Tue, Sep 15, 2009 at 21:02, Alex Boisvert <alex.boisvert@gmail.com
>> >wrote:
>>
>>  Maybe worth considering just substituting System.out, System.err with a
>>> PrintStream hooked to a ByteArrayOutputStream, collecting the result and
>>> applying regexps to colorize and output to $stdout, $stderr respectively.
>>> That way, there's no messing with the classpath and no additional
>>> interface
>>> complexity.
>>>
>>> alex
>>>
>>>
>>>
>>> On Tue, Sep 15, 2009 at 10:38 AM, Antoine Toulme <
>>> antoine@lunar-ocean.com>wrote:
>>>
>>>  So, I would have a .class file for the Java code needed, that I would
>>>> add
>>>> to buildr.The .class would be added to the RJB classpath, and the
>>>> manipulation itself would be done on Java.load.
>>>> I can probably to do this in a pluggable way (read: as a separate
>>>> project).
>>>>
>>>> Thanks,
>>>>
>>>> Antoine
>>>>
>>>> On Tue, Sep 15, 2009 at 17:53, Alex Boisvert <alex.boisvert@gmail.com
>>>> >wrote:
>>>>
>>>>  It should work fine and I don't see a better approach.
>>>>>
>>>>> alex
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <
>>>>> antoine@lunar-ocean.com
>>>>>
>>>>>> wrote:
>>>>>>
>>>>>
>>>>>  Hi everyone,
>>>>>> I'm trying to find a nice way to redirect the RJB output. I have some
>>>>>> output
>>>>>> made directly from Java that I would like to reformat and eventually
>>>>>> colorize.
>>>>>>
>>>>>> From what I read, the best solution would be to replace the
>>>>>> PrintStreams
>>>>>> used in System.out and System.err by something that would pipe to
>>>>>> $stdout
>>>>>> and $stderr respectively.
>>>>>>
>>>>>> From the RJB doc, I see RJB can bind a Ruby object to a Java
>>>>>> interface.
>>>>>> That
>>>>>> sounds like the right deal...
>>>>>>
>>>>>> but PrintStream is a class.
>>>>>>
>>>>>> The workaround is to have some Java code exposing an interface, with a
>>>>>> PrintStream implementation that delegates everything to said
>>>>>> interface,
>>>>>> and
>>>>>> have RJB instanciate the interface and pass output along to stdout and
>>>>>> stderr.
>>>>>>
>>>>>> Was this attempted before ? Any advice on this ?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> Antoine
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>
>>>
> _________________________________
> Peter Schröder
> IT
>
> blau: +49 (0) 178 139 1035
> fax: +49 (0) 40 288 071 - 71
> mail: ps@blau.de
>
> blau Mobilfunk GmbH
> Schulterblatt 124
> D-20357 Hamburg
>
> Sitz: Hamburg
> HRB 80531 Amtsgericht Hamburg
> Geschäftsführer: Dirk Freise, Martin Ostermayer, Thorsten Rehling
>
>

Re: Redirecting RJB output

Posted by peter schröder <ps...@blau.de>.
Could you post a simple working example to the wiki?

Am 15.09.2009 um 23:42 schrieb Antoine Toulme:

> So this works:
>    byteArray = Rjb::import('java.io.ByteArrayOutputStream')
>    printStream = Rjb::import('java.io.PrintStream')
>    out = byteArray.new()
>    Rjb::import('java.lang.System').out = printStream.new(out)
>    err = byteArray.new()
>    Rjb::import('java.lang.System').err = printStream.new(err)
>    ... [do something]
>    err.toString.should match(/WARNING/)
>
> Thanks Alex!
>
> Antoine
>
> On Tue, Sep 15, 2009 at 21:02, Alex Boisvert  
> <al...@gmail.com>wrote:
>
>> Maybe worth considering just substituting System.out, System.err  
>> with a
>> PrintStream hooked to a ByteArrayOutputStream, collecting the  
>> result and
>> applying regexps to colorize and output to $stdout, $stderr  
>> respectively.
>> That way, there's no messing with the classpath and no additional  
>> interface
>> complexity.
>>
>> alex
>>
>>
>>
>> On Tue, Sep 15, 2009 at 10:38 AM, Antoine Toulme <antoine@lunar-ocean.com 
>> >wrote:
>>
>>> So, I would have a .class file for the Java code needed, that I  
>>> would add
>>> to buildr.The .class would be added to the RJB classpath, and the
>>> manipulation itself would be done on Java.load.
>>> I can probably to do this in a pluggable way (read: as a separate
>>> project).
>>>
>>> Thanks,
>>>
>>> Antoine
>>>
>>> On Tue, Sep 15, 2009 at 17:53, Alex Boisvert <alex.boisvert@gmail.com 
>>> >wrote:
>>>
>>>> It should work fine and I don't see a better approach.
>>>>
>>>> alex
>>>>
>>>>
>>>>
>>>> On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <antoine@lunar-ocean.com
>>>>> wrote:
>>>>
>>>>> Hi everyone,
>>>>> I'm trying to find a nice way to redirect the RJB output. I have  
>>>>> some
>>>>> output
>>>>> made directly from Java that I would like to reformat and  
>>>>> eventually
>>>>> colorize.
>>>>>
>>>>> From what I read, the best solution would be to replace the  
>>>>> PrintStreams
>>>>> used in System.out and System.err by something that would pipe to
>>>>> $stdout
>>>>> and $stderr respectively.
>>>>>
>>>>> From the RJB doc, I see RJB can bind a Ruby object to a Java  
>>>>> interface.
>>>>> That
>>>>> sounds like the right deal...
>>>>>
>>>>> but PrintStream is a class.
>>>>>
>>>>> The workaround is to have some Java code exposing an interface,  
>>>>> with a
>>>>> PrintStream implementation that delegates everything to said  
>>>>> interface,
>>>>> and
>>>>> have RJB instanciate the interface and pass output along to  
>>>>> stdout and
>>>>> stderr.
>>>>>
>>>>> Was this attempted before ? Any advice on this ?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Antoine
>>>>>
>>>>
>>>>
>>>
>>

_________________________________
Peter Schröder
IT

blau: +49 (0) 178 139 1035
fax: +49 (0) 40 288 071 - 71
mail: ps@blau.de

blau Mobilfunk GmbH
Schulterblatt 124
D-20357 Hamburg

Sitz: Hamburg
HRB 80531 Amtsgericht Hamburg
Geschäftsführer: Dirk Freise, Martin Ostermayer, Thorsten Rehling


Re: Redirecting RJB output

Posted by Antoine Toulme <an...@lunar-ocean.com>.
So this works:
    byteArray = Rjb::import('java.io.ByteArrayOutputStream')
    printStream = Rjb::import('java.io.PrintStream')
    out = byteArray.new()
    Rjb::import('java.lang.System').out = printStream.new(out)
    err = byteArray.new()
    Rjb::import('java.lang.System').err = printStream.new(err)
    ... [do something]
    err.toString.should match(/WARNING/)

Thanks Alex!

Antoine

On Tue, Sep 15, 2009 at 21:02, Alex Boisvert <al...@gmail.com>wrote:

> Maybe worth considering just substituting System.out, System.err with a
> PrintStream hooked to a ByteArrayOutputStream, collecting the result and
> applying regexps to colorize and output to $stdout, $stderr respectively.
> That way, there's no messing with the classpath and no additional interface
> complexity.
>
> alex
>
>
>
> On Tue, Sep 15, 2009 at 10:38 AM, Antoine Toulme <an...@lunar-ocean.com>wrote:
>
>> So, I would have a .class file for the Java code needed, that I would add
>> to buildr.The .class would be added to the RJB classpath, and the
>> manipulation itself would be done on Java.load.
>> I can probably to do this in a pluggable way (read: as a separate
>> project).
>>
>> Thanks,
>>
>> Antoine
>>
>> On Tue, Sep 15, 2009 at 17:53, Alex Boisvert <al...@gmail.com>wrote:
>>
>>> It should work fine and I don't see a better approach.
>>>
>>> alex
>>>
>>>
>>>
>>> On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <antoine@lunar-ocean.com
>>> > wrote:
>>>
>>>> Hi everyone,
>>>> I'm trying to find a nice way to redirect the RJB output. I have some
>>>> output
>>>> made directly from Java that I would like to reformat and eventually
>>>> colorize.
>>>>
>>>> From what I read, the best solution would be to replace the PrintStreams
>>>> used in System.out and System.err by something that would pipe to
>>>> $stdout
>>>> and $stderr respectively.
>>>>
>>>> From the RJB doc, I see RJB can bind a Ruby object to a Java interface.
>>>> That
>>>> sounds like the right deal...
>>>>
>>>> but PrintStream is a class.
>>>>
>>>> The workaround is to have some Java code exposing an interface, with a
>>>> PrintStream implementation that delegates everything to said interface,
>>>> and
>>>> have RJB instanciate the interface and pass output along to stdout and
>>>> stderr.
>>>>
>>>> Was this attempted before ? Any advice on this ?
>>>>
>>>> Thanks,
>>>>
>>>> Antoine
>>>>
>>>
>>>
>>
>

Re: Redirecting RJB output

Posted by Alex Boisvert <al...@gmail.com>.
Maybe worth considering just substituting System.out, System.err with a
PrintStream hooked to a ByteArrayOutputStream, collecting the result and
applying regexps to colorize and output to $stdout, $stderr respectively.
That way, there's no messing with the classpath and no additional interface
complexity.

alex


On Tue, Sep 15, 2009 at 10:38 AM, Antoine Toulme <an...@lunar-ocean.com>wrote:

> So, I would have a .class file for the Java code needed, that I would add
> to buildr.The .class would be added to the RJB classpath, and the
> manipulation itself would be done on Java.load.
> I can probably to do this in a pluggable way (read: as a separate project).
>
> Thanks,
>
> Antoine
>
> On Tue, Sep 15, 2009 at 17:53, Alex Boisvert <al...@gmail.com>wrote:
>
>> It should work fine and I don't see a better approach.
>>
>> alex
>>
>>
>>
>> On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <an...@lunar-ocean.com>wrote:
>>
>>> Hi everyone,
>>> I'm trying to find a nice way to redirect the RJB output. I have some
>>> output
>>> made directly from Java that I would like to reformat and eventually
>>> colorize.
>>>
>>> From what I read, the best solution would be to replace the PrintStreams
>>> used in System.out and System.err by something that would pipe to $stdout
>>> and $stderr respectively.
>>>
>>> From the RJB doc, I see RJB can bind a Ruby object to a Java interface.
>>> That
>>> sounds like the right deal...
>>>
>>> but PrintStream is a class.
>>>
>>> The workaround is to have some Java code exposing an interface, with a
>>> PrintStream implementation that delegates everything to said interface,
>>> and
>>> have RJB instanciate the interface and pass output along to stdout and
>>> stderr.
>>>
>>> Was this attempted before ? Any advice on this ?
>>>
>>> Thanks,
>>>
>>> Antoine
>>>
>>
>>
>

Re: Redirecting RJB output

Posted by Antoine Toulme <an...@lunar-ocean.com>.
So, I would have a .class file for the Java code needed, that I would add to
buildr.The .class would be added to the RJB classpath, and the manipulation
itself would be done on Java.load.
I can probably to do this in a pluggable way (read: as a separate project).

Thanks,

Antoine

On Tue, Sep 15, 2009 at 17:53, Alex Boisvert <al...@gmail.com>wrote:

> It should work fine and I don't see a better approach.
>
> alex
>
>
>
> On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <an...@lunar-ocean.com>wrote:
>
>> Hi everyone,
>> I'm trying to find a nice way to redirect the RJB output. I have some
>> output
>> made directly from Java that I would like to reformat and eventually
>> colorize.
>>
>> From what I read, the best solution would be to replace the PrintStreams
>> used in System.out and System.err by something that would pipe to $stdout
>> and $stderr respectively.
>>
>> From the RJB doc, I see RJB can bind a Ruby object to a Java interface.
>> That
>> sounds like the right deal...
>>
>> but PrintStream is a class.
>>
>> The workaround is to have some Java code exposing an interface, with a
>> PrintStream implementation that delegates everything to said interface,
>> and
>> have RJB instanciate the interface and pass output along to stdout and
>> stderr.
>>
>> Was this attempted before ? Any advice on this ?
>>
>> Thanks,
>>
>> Antoine
>>
>
>

Re: Redirecting RJB output

Posted by Alex Boisvert <al...@gmail.com>.
It should work fine and I don't see a better approach.

alex


On Tue, Sep 15, 2009 at 6:41 AM, Antoine Toulme <an...@lunar-ocean.com>wrote:

> Hi everyone,
> I'm trying to find a nice way to redirect the RJB output. I have some
> output
> made directly from Java that I would like to reformat and eventually
> colorize.
>
> From what I read, the best solution would be to replace the PrintStreams
> used in System.out and System.err by something that would pipe to $stdout
> and $stderr respectively.
>
> From the RJB doc, I see RJB can bind a Ruby object to a Java interface.
> That
> sounds like the right deal...
>
> but PrintStream is a class.
>
> The workaround is to have some Java code exposing an interface, with a
> PrintStream implementation that delegates everything to said interface, and
> have RJB instanciate the interface and pass output along to stdout and
> stderr.
>
> Was this attempted before ? Any advice on this ?
>
> Thanks,
>
> Antoine
>