You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Sebastian Hennebrueder <us...@laliluna.de> on 2010/02/05 20:21:59 UTC

Bug in Java::Command

On Mac OS I cannot execute something like
Java::Commands.java('-jar', "yuicompressor-2.4.2.jar", "--line-break 
1000 --type css src/main/webapp/styles/styles-all.css",
                                                "> 
src/main/webapp/styles/styles-all-min.css",
                                                {:verbose=>true})

The reason is that the parameters are not joined with a ' '
In java/commands.rb
the method       def java(*args, &block) needed the line below. Most 
likely this may break thinks on Windows. The orgininal developer will 
probably know how to fix it correctly.

        unless Buildr.application.options.dryrun
          info "Running #{name}"
          block = lambda { |ok, res| fail "Failed to execute #{name}, 
see errors above" unless ok } unless block
          puts cmd_args.join(' ') if Buildr.application.options.trace
          cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
# neeeded the next line on MAC OS
          cmd_args = cmd_args.join(' ')
# end of mac changes
          sh(*cmd_args) do |ok, ps|
            block.call ok, ps
          end
        end

-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de




Re: Bug in Java::Command

Posted by Alex Boisvert <al...@gmail.com>.
Ok, I updated the rdoc to clarify and show an example.

This approach is a convention inherited from Ruby's Kernel.exec(), and
allows you to pass command-line arguments containing spaces.

If you don't like all the quotes and commas, you can use the following Ruby
syntax to convert the String into distinct array values,

Java::Commands.java %w[-jar yuicompressor-2.4.2.jar --line-break 1000 --type
css src/main/webapp/styles/styles-all.css -o
src/main/webapp/styles/styles-all-min.css], {:verbose=>true}

alex

On Sat, Feb 6, 2010 at 12:37 PM, Sebastian Hennebrueder
<us...@laliluna.de>wrote:

> Hi Alex,
>
> running the code with one parameter per string works but you cannot have
> space separated words in a single String. Thank you for the hint. Below you
> can find the working command. It is the yahoo UI compressor which can be
> used to compress CSS or JavaScript files.
>
>
> Java::Commands.java('-jar', "yuicompressor-2.4.2.jar",
> "--line-break","1000","--type","css","src/main/webapp/styles/styles-all.css",
>
>                    "-o", "src/main/webapp/styles/styles-all-min.css",
>
>                    {:verbose=>true})
> I am not sure, if this is the expected behaviour. With my change, I can
> concatenate any number of space separated commands in a single String. At
> least, I feel that this should be clearer in the documentation.
>
>
>
> --
> Best Regards / Viele Grüße
>
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
>
>
>
>
>
> Alex Boisvert schrieb:
>
>  Hi Sebastian,
>>
>> I just tested on OS X (Snow Leopard) and I can't reproduce your issue.
>>
>> Further, each argument should be its own array value, like "--line-break",
>> "1000".   And redirection won't work as you expect since this isn't a
>> shell,
>> it's just a Unix exec() call.
>>
>> I have a feeling you may want to reach directly for the system() call or
>> something along that line since Java::Commands doesn't really support
>> redirection.
>>
>> alex
>>
>>
>> On Fri, Feb 5, 2010 at 11:21 AM, Sebastian Hennebrueder
>> <us...@laliluna.de>wrote:
>>
>>  On Mac OS I cannot execute something like
>>> Java::Commands.java('-jar', "yuicompressor-2.4.2.jar", "--line-break 1000
>>> --type css src/main/webapp/styles/styles-all.css",
>>>                                              ">
>>> src/main/webapp/styles/styles-all-min.css",
>>>                                              {:verbose=>true})
>>>
>>> The reason is that the parameters are not joined with a ' '
>>> In java/commands.rb
>>> the method       def java(*args, &block) needed the line below. Most
>>> likely
>>> this may break thinks on Windows. The orgininal developer will probably
>>> know
>>> how to fix it correctly.
>>>
>>>      unless Buildr.application.options.dryrun
>>>        info "Running #{name}"
>>>        block = lambda { |ok, res| fail "Failed to execute #{name}, see
>>> errors above" unless ok } unless block
>>>        puts cmd_args.join(' ') if Buildr.application.options.trace
>>>        cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
>>> # neeeded the next line on MAC OS
>>>        cmd_args = cmd_args.join(' ')
>>> # end of mac changes
>>>        sh(*cmd_args) do |ok, ps|
>>>          block.call ok, ps
>>>        end
>>>      end
>>>
>>> --
>>> Best Regards / Viele Grüße
>>>
>>> Sebastian Hennebrueder
>>> -----
>>> Software Developer and Trainer for Hibernate / Java Persistence
>>> http://www.laliluna.de
>>>
>>>
>>>
>>>
>>>
>>
>
>

Re: Bug in Java::Command

Posted by Sebastian Hennebrueder <us...@laliluna.de>.
Hi Alex,

running the code with one parameter per string works but you cannot have 
space separated words in a single String. Thank you for the hint. Below 
you can find the working command. It is the yahoo UI compressor which 
can be used to compress CSS or JavaScript files.

Java::Commands.java('-jar', "yuicompressor-2.4.2.jar", 
"--line-break","1000","--type","css","src/main/webapp/styles/styles-all.css",
												"-o", "src/main/webapp/styles/styles-all-min.css",
												{:verbose=>true})
I am not sure, if this is the expected behaviour. With my change, I can 
concatenate any number of space separated commands in a single String. 
At least, I feel that this should be clearer in the documentation.


-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder
-----
Software Developer and Trainer for Hibernate / Java Persistence
http://www.laliluna.de





Alex Boisvert schrieb:
> Hi Sebastian,
> 
> I just tested on OS X (Snow Leopard) and I can't reproduce your issue.
> 
> Further, each argument should be its own array value, like "--line-break",
> "1000".   And redirection won't work as you expect since this isn't a shell,
> it's just a Unix exec() call.
> 
> I have a feeling you may want to reach directly for the system() call or
> something along that line since Java::Commands doesn't really support
> redirection.
> 
> alex
> 
> 
> On Fri, Feb 5, 2010 at 11:21 AM, Sebastian Hennebrueder
> <us...@laliluna.de>wrote:
> 
>> On Mac OS I cannot execute something like
>> Java::Commands.java('-jar', "yuicompressor-2.4.2.jar", "--line-break 1000
>> --type css src/main/webapp/styles/styles-all.css",
>>                                               ">
>> src/main/webapp/styles/styles-all-min.css",
>>                                               {:verbose=>true})
>>
>> The reason is that the parameters are not joined with a ' '
>> In java/commands.rb
>> the method       def java(*args, &block) needed the line below. Most likely
>> this may break thinks on Windows. The orgininal developer will probably know
>> how to fix it correctly.
>>
>>       unless Buildr.application.options.dryrun
>>         info "Running #{name}"
>>         block = lambda { |ok, res| fail "Failed to execute #{name}, see
>> errors above" unless ok } unless block
>>         puts cmd_args.join(' ') if Buildr.application.options.trace
>>         cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
>> # neeeded the next line on MAC OS
>>         cmd_args = cmd_args.join(' ')
>> # end of mac changes
>>         sh(*cmd_args) do |ok, ps|
>>           block.call ok, ps
>>         end
>>       end
>>
>> --
>> Best Regards / Viele Grüße
>>
>> Sebastian Hennebrueder
>> -----
>> Software Developer and Trainer for Hibernate / Java Persistence
>> http://www.laliluna.de
>>
>>
>>
>>
> 



Re: Bug in Java::Command

Posted by Alex Boisvert <al...@gmail.com>.
Hi Sebastian,

I just tested on OS X (Snow Leopard) and I can't reproduce your issue.

Further, each argument should be its own array value, like "--line-break",
"1000".   And redirection won't work as you expect since this isn't a shell,
it's just a Unix exec() call.

I have a feeling you may want to reach directly for the system() call or
something along that line since Java::Commands doesn't really support
redirection.

alex


On Fri, Feb 5, 2010 at 11:21 AM, Sebastian Hennebrueder
<us...@laliluna.de>wrote:

> On Mac OS I cannot execute something like
> Java::Commands.java('-jar', "yuicompressor-2.4.2.jar", "--line-break 1000
> --type css src/main/webapp/styles/styles-all.css",
>                                               ">
> src/main/webapp/styles/styles-all-min.css",
>                                               {:verbose=>true})
>
> The reason is that the parameters are not joined with a ' '
> In java/commands.rb
> the method       def java(*args, &block) needed the line below. Most likely
> this may break thinks on Windows. The orgininal developer will probably know
> how to fix it correctly.
>
>       unless Buildr.application.options.dryrun
>         info "Running #{name}"
>         block = lambda { |ok, res| fail "Failed to execute #{name}, see
> errors above" unless ok } unless block
>         puts cmd_args.join(' ') if Buildr.application.options.trace
>         cmd_args = cmd_args.map(&:inspect).join(' ') if Util.win_os?
> # neeeded the next line on MAC OS
>         cmd_args = cmd_args.join(' ')
> # end of mac changes
>         sh(*cmd_args) do |ok, ps|
>           block.call ok, ps
>         end
>       end
>
> --
> Best Regards / Viele Grüße
>
> Sebastian Hennebrueder
> -----
> Software Developer and Trainer for Hibernate / Java Persistence
> http://www.laliluna.de
>
>
>
>