You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Dave Feltenberger <da...@gmail.com> on 2007/08/23 22:35:29 UTC

Question about filtering

Hi -

I'm working on a project that has the need to do the following, and I can't
think of an elegant way of achieving it using Maven without having to call
out to Ant:

We have several clients, each of which get a customized Java Web Start /
.jnlp file.  There are only 5 clients now, but the number could explode very
quickly, so automation is key.  The jnlp files are almost identical, with
only a few things changed.  In the current Ant build system -- which I'm
replacing with Maven2 -- one template.jnlp file is copied n times, one for
each client.  Each client has its own properties file that is used to filter
the jnlp.  So basically we start with:

template.jnlp
client1.properties
client2.properties
client3.properties

And end up with:
client1.jnlp (with the filtered properties in it)
client2.jnlp (ditto)
client3.jnlp (ditto)
etc.

It's not practical to create a new POM/artifact for each new client, since
there may be so many so soon.  The only thing I know how to do is to add
multiple properties files and multiple files to filter, but that's done at
more of a global level - the filter attributes in the jnlp files will be the
same since they'll come from the same template, so I need to do them one
.properties and .jnlp at a time.

This is what I have so far that works for only one client at a time (copy
the template to a new file in generate-resources phase, then do the
filtering during the regular life cycle).  I'm considering changing this to
do more work in the Ant taks - looping through a list, creating each .jnlp,
filtering, etc. -- but I feel like I'm breaking some kind of best practice
or re-creating a wheel someone on the list may have already created by going
down that path.

...
    <build>
        <filters>
            <filter>src/main/filters/${client.filter}.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>${temp.resources.dir}</directory>
                <includes>
                    <include>${client.filter}.jnlp</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
     </build>
...
        <plugins>
            <plugin>
                <inherited>true</inherited>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>generate-resources</phase>
                        <configuration>
                            <tasks>
                                <mkdir dir="${temp.resources.dir}" />
                                <copy file="${jnlp.template.file}"
tofile="${temp.resources.dir}/${client.filter}.jnlp" />
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
       </plugins>

Any help would be greatly appreciated!

Thanks.

Dave

Re: Question about filtering

Posted by Wayne Fay <wa...@gmail.com>.
If you have something that works in Ant, and you're happy with it,
then I wouldn't worry too much about doing it in the Maven way.

If you really want to make it work "the Maven way", I think it might
be easiest if you just write a plugin.

Wayne

On 8/23/07, Dave Feltenberger <da...@gmail.com> wrote:
> Hi -
>
> I'm working on a project that has the need to do the following, and I can't
> think of an elegant way of achieving it using Maven without having to call
> out to Ant:
>
> We have several clients, each of which get a customized Java Web Start /
> .jnlp file.  There are only 5 clients now, but the number could explode very
> quickly, so automation is key.  The jnlp files are almost identical, with
> only a few things changed.  In the current Ant build system -- which I'm
> replacing with Maven2 -- one template.jnlp file is copied n times, one for
> each client.  Each client has its own properties file that is used to filter
> the jnlp.  So basically we start with:
>
> template.jnlp
> client1.properties
> client2.properties
> client3.properties
>
> And end up with:
> client1.jnlp (with the filtered properties in it)
> client2.jnlp (ditto)
> client3.jnlp (ditto)
> etc.
>
> It's not practical to create a new POM/artifact for each new client, since
> there may be so many so soon.  The only thing I know how to do is to add
> multiple properties files and multiple files to filter, but that's done at
> more of a global level - the filter attributes in the jnlp files will be the
> same since they'll come from the same template, so I need to do them one
> .properties and .jnlp at a time.
>
> This is what I have so far that works for only one client at a time (copy
> the template to a new file in generate-resources phase, then do the
> filtering during the regular life cycle).  I'm considering changing this to
> do more work in the Ant taks - looping through a list, creating each .jnlp,
> filtering, etc. -- but I feel like I'm breaking some kind of best practice
> or re-creating a wheel someone on the list may have already created by going
> down that path.
>
> ...
>     <build>
>         <filters>
>             <filter>src/main/filters/${client.filter}.properties</filter>
>         </filters>
>         <resources>
>             <resource>
>                 <directory>${temp.resources.dir}</directory>
>                 <includes>
>                     <include>${client.filter}.jnlp</include>
>                 </includes>
>                 <filtering>true</filtering>
>             </resource>
>         </resources>
>      </build>
> ...
>         <plugins>
>             <plugin>
>                 <inherited>true</inherited>
>                 <artifactId>maven-antrun-plugin</artifactId>
>                 <executions>
>                     <execution>
>                         <phase>generate-resources</phase>
>                         <configuration>
>                             <tasks>
>                                 <mkdir dir="${temp.resources.dir}" />
>                                 <copy file="${jnlp.template.file}"
> tofile="${temp.resources.dir}/${client.filter}.jnlp" />
>                             </tasks>
>                         </configuration>
>                         <goals>
>                             <goal>run</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>        </plugins>
>
> Any help would be greatly appreciated!
>
> Thanks.
>
> Dave
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org