buildr-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lacton <lac...@users.sourceforge.net>
Subject Re: [buildr] How to use filter?
Date Sun, 06 Jul 2008 12:47:15 GMT
I found a way that works!

<code>
define 'jonas-web' do

  project.version = '1.0'

  package(:war).include _('target/WEB-INF/jonas-web.xml'), :path=>'WEB-INF'
  package(:war).exclude '**/*.tpl'

  file _('target/WEB-INF/jonas-web.xml') =>
[_('src/main/webapp/WEB-INF/jonas-web.xml.tpl')] do |task|
    filter(_('src/main/webapp/WEB-INF')).include('jonas-web.xml.tpl').into(_('target/WEB-INF')).using(/~(.*)~/,
'CLIENT'=>'some_client').run
    mv _('target/WEB-INF/jonas-web.xml.tpl'), _('target/WEB-INF/jonas-web.xml')
  end

  check package(:war) do
    it.should contain('WEB-INF/jonas-web.xml')
    it.should_not contain('WEB-INF/jonas-web.xml.tpl')
  end

  check package(:war).entry('WEB-INF/jonas-web.xml') do
    it.should contain(/some_client/)
    it.should_not contain(/~CLIENT~/)
  end
end
</code>

Here's what I think was wrong with my previous attempt.

1. Using 'package(:war).with :classes' was plain wrong, because
:classes means the file would go into WEB-INF/classes, not into
WEB-INF. Looking at the content of the generated war, I easily found
this mistake.

2. It looks like the filter command should be called only with a
directory, not a file path. To filter only one specific file, I had to
use both the source directory argument and the include method. I would
have liked the filter command to fail or at least to warn me that the
argument I was providing was invalid.

3. My custom mapping was defined with the key :CLIENT instead of
'CLIENT'. A warning or a failure would have been nice.

I'm still wondering if there's a way to achieve the same result
without using Rake's file statement.

Lacton

On Sat, Jul 5, 2008 at 10:46 PM, lacton <lacton@users.sourceforge.net> wrote:
> Hi,
>
> Starting point: a template file
> 'src/main/webapp/WEB-INF/jonas-web.xml.tpl', containing an XML
> configuration, with a token '~CLIENT~' to be replaced by a client code
> Ending point: a war file, containing a 'jonas-web.xml' file in its
> WEB-INF folder, with a client code instead of the '~CLIENT~' token
>
> I thought using 'filter' would be the way to go, but it seems I don't
> understand how it works. Here's what I tried.
>
> <code>
> define 'jonas-web' do
>
>  project.version = '1.0'
>
>  package(:war).with :classes=>_('target/WEB-INF/jonas-web.xml')
>
>  file _('target/WEB-INF/jonas-web.xml') =>
> [_('src/main/webapp/WEB-INF/jonas-web.xml.tpl')] do |task|
>    filter(_('src/main/webapp/WEB-INF/jonas-web.xml.tpl')).into(_('target/WEB-INF')).using(/~(.*)~/,
> :CLIENT=>'some_client').run
>    mv _('target/WEB-INF/jonas-web.xml.tpl'), _('target/WEB-INF/jonas-web.xml')
>  end
>
>  check package(:war) do
>    it.should contain('WEB-INF/jonas-web.xml')
>    it.should_not contain('WEB-INF/jonas-web.xml.tpl')
>  end
>
>  check package(:war).entry('WEB-INF/jonas-web.xml') do
>    it.should contain(/some_client/)
>    it.should_not contain(/~CLIENT~/)
>  end
> end
> </code>
>
> The 'mv' operation fails with "No such file or directory -
> /home/lacton/code/buildr/jonas-web/target/WEB-INF/jonas-web.xml.tpl or
> /home/lacton/code/buildr/jonas-web/target/WEB-INF/jonas-web.xml". When
> I check the contents of the target directory, it's weird, because I
> can see buildr created the 'target/WEB-INF' directory, but it's empty.
> There isn't a 'jonas-web.xml*' in it.
>
> What's wrong with the way I use filter? More broadly speaking, is
> there a better way to do what I'm trying to do?
>
> --
> Lacton

Mime
View raw message