Discussion:
How to properly use filtering on resources.
Damien Raude-Morvan
2005-02-14 17:39:49 UTC
Permalink
Hello,

I'm trying to get working resources filtering in thesame way as
explained on Maven Wiki [1].
I've put in project.xml :
<resource>
...bla..
<filtering>true</filtering>
</resource>
And in maven.xml
<preGoal name="java:jar-resources">
<ant:filter filtersfile="config/environnement/${platform}.conf" />
</preGoal>
I'm figuring couple of problems :
1) It doesn't filter anything. Files are not touched, just copied.
2) Maven always try to load a file named "some.properties" ?!

I'm now using :
<preGoal name="java:jar-resources">
<ant:filter filtersfile="config/environnement/${platform}.conf" />
<copy todir="target/classes" filtering="false" overwrite="true">
<fileset dir="config/template" />
</copy>
</preGoal>
Which works quite well but doesn't satisfy me has I must hardcode
resources in maven.xml.

Any clues ?


Cheers,

[1] http://wiki.codehaus.org/maven/FilteringResources
--
Damien Raude-Morvan
Movalys / www.movalys.com
Adeuza / www.adeuza.fr
Brett Porter
2005-02-14 20:13:41 UTC
Permalink
Post by Damien Raude-Morvan
1) It doesn't filter anything. Files are not touched, just copied.
Double check your resource set matches the one copied, and that it
doesn't overlap with another one defined to contain the same files
without filtering.
Post by Damien Raude-Morvan
2) Maven always try to load a file named "some.properties" ?!
That's not from Maven - search your project.xml, maven.xml and
project.properties files, including any you inherit from using
<extend/>.
Post by Damien Raude-Morvan
<preGoal name="java:jar-resources">
<ant:filter filtersfile="config/environnement/${platform}.conf" />
<copy todir="target/classes" filtering="false" overwrite="true">
<fileset dir="config/template" />
</copy>
</preGoal>
This is equivalent to using the resources, however will not allow
other parts of Maven (eg the IDE plugins) to see where you reosources
are.

- Brett
Damien Raude-Morvan
2005-02-15 22:42:49 UTC
Permalink
Hello,
Post by Brett Porter
Post by Damien Raude-Morvan
1) It doesn't filter anything. Files are not touched, just copied.
Double check your resource set matches the one copied, and that it
doesn't overlap with another one defined to contain the same files
without filtering.
Many thanks, you made me look at the right place : my <filtering/> was not
at the right place : child node of <include/> instead of <resource/>...
Post by Brett Porter
Post by Damien Raude-Morvan
2) Maven always try to load a file named "some.properties" ?!
That's not from Maven - search your project.xml, maven.xml and
project.properties files, including any you inherit from using
<extend/>.
You're right. I didn't know that
<extend>../otherproject/project.xml</extend> also "extend" maven.xml of
otherproject !
Post by Brett Porter
Post by Damien Raude-Morvan
<preGoal name="java:jar-resources">
<ant:filter filtersfile="config/environnement/${platform}.conf"
/> <copy todir="target/classes" filtering="false" overwrite="true">
<fileset dir="config/template" />
</copy>
</preGoal>
This is equivalent to using the resources, however will not allow
other parts of Maven (eg the IDE plugins) to see where you reosources
are.
That's why I was asking another way to do this :)

Have a good day,

- --
Damien Raude-Morvan / DrazziB
GPG : 0x85C79389 (new!)
WWW : www.drazzib.com
ICQ : 68119943
TEL : (+33) 06 08 80 36 98
Rick Mangi
2005-02-21 16:35:48 UTC
Permalink
So what is the proper way to do the following:

1) Filter a config file to put the properties in place
2) Copy the file to the target directory and rename it

For example: I have a property file called hibernate.conf.tmpl.xml and
I want it to be filtered and then copied as hibernate.conf.xml

Any ideas? I'd rather not have to know the name of the file ahead of
time...

Thanks,

Rick
Post by Brett Porter
Post by Damien Raude-Morvan
1) It doesn't filter anything. Files are not touched, just copied.
Double check your resource set matches the one copied, and that it
doesn't overlap with another one defined to contain the same files
without filtering.
Post by Damien Raude-Morvan
2) Maven always try to load a file named "some.properties" ?!
That's not from Maven - search your project.xml, maven.xml and
project.properties files, including any you inherit from using
<extend/>.
Post by Damien Raude-Morvan
<preGoal name="java:jar-resources">
<ant:filter
filtersfile="config/environnement/${platform}.conf" />
<copy todir="target/classes" filtering="false"
overwrite="true">
<fileset dir="config/template" />
</copy>
</preGoal>
This is equivalent to using the resources, however will not allow
other parts of Maven (eg the IDE plugins) to see where you reosources
are.
- Brett
---------------------------------------------------------------------
Damien Raude-Morvan
2005-02-21 16:55:31 UTC
Permalink
Post by Rick Mangi
1) Filter a config file to put the properties in place
2) Copy the file to the target directory and rename it
For example: I have a property file called hibernate.conf.tmpl.xml and
I want it to be filtered and then copied as hibernate.conf.xml
Any ideas? I'd rather not have to know the name of the file ahead of
time...
In your project.xml, you should activate filtering on a particular
resource (done via <filtering/> tag). This resource should include
*.tmpl.xml files :
<resource>
<directory>${basedir}/src/resources/</directory>
<includes>
<include>*.tmpl.xml</include>
</includes>
<filtering>true</filtering>
</resource>


In your maven.xml, you define a new pre-dependency on goal
"test:test-resources" or "jar:jar-resources" (depends on what you want) :

<j:set var="platform" value="dev"/>

<preGoal name="jar:jar-resources">
<util:available file="${basedir}/config/${platform}.properties">
<echo>Filtering files fot use with -${platform}- parameters.</echo>
<ant:filter filtersfile="${basedir}/config/${platform}.conf" />
</util:available>
</preGoal>

In this case, it's read properties from a file in config/dev.properties.
With some tweaks (jelly tags), you should achieve to rename the file
after copy. But IMHO, it's simplier to have "templates/" and "filtered/"
directory than templates and filtered files in same dir.
--
Damien Raude-Morvan
Movalys / www.movalys.com
Adeuza / www.adeuza.fr
Rick Mangi
2005-02-21 17:00:53 UTC
Permalink
Post by Damien Raude-Morvan
In this case, it's read properties from a file in
config/dev.properties. With some tweaks (jelly tags), you should
achieve to rename the file after copy. But IMHO, it's simplier to have
"templates/" and "filtered/" directory than templates and filtered
files in same dir.
Damien,

Thanks. It's this last part that I'm unclear about. I can see how to do
this with a hack, but I'd rather do it the "right" way. Ideally I'd
like to have the templates not included in the final war, just the
filtered and renamed files. So I guess what I'm looking for is a hook
into the filtering mechanism, perhaps as a preGoal before it does the
copy.

It seems to me like either there is a good deal of documentation
missing on this or it would be better for filtering to be extracted out
into a plugin instead of having it as a "core" feature of maven.

I guess what I might be missing is this: what is the input to the
<preGoal name=jar:jar-resources">? Is there an object that we can grab
and work with? I'd assume there's a list of files being passed around
somewhere.

Rick
Rick Mangi
2005-02-21 18:25:53 UTC
Permalink
Ok, I've been reading lots of jelly this morning... now I have a clear
understanding of what exactly my question is :-)


So, I have the following preGoal:

<preGoal name="java:jar-resources">
<ant:filter filtersfile="${basedir}/conf/configuration.properties" />
</preGoal>

I have 1 file being filtered:

<resources>
<resource>
<directory>conf</directory>
<includes>
<include>*.tmpl.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>

Ok, now what happens here is that the resource hibernate.conf.tmpl.xml
gets filtered and copied into target/clasess just fine, but I want it
to be renamed.

The confusing part is this: I looked at the java:jar-resources jelly
and it looks like all it does is peek at the pom.build.resources,
applies the filename filtering, and copies the files.

<goal name="java:jar-resources"
description="Copy any resources that must be present in the
deployed JAR
file">

<j:if test="${!pom.build.resources.isEmpty()}">
<maven:copy-resources
resources="${pom.build.resources}"
todir="${maven.build.dest}"/>
</j:if>
</goal>

So here's my question: (I know you've all been waiting...) Where do the
filtered resources go before they are copied? There is no copy kept in
my conf directory... after the preGoal is executed and the ant:filter
happens, where do the files go? Are they kept in the build object as
StringBuffers or File objects?

I'm tempted to edit these in their temporary living quarters, seems
like if I stepped in after the filtering, before the jar:resources
copy-resources tag is executed I could simply rename the output file
and everything would be great...

Thanks, in the very least I'm learning a lot about the internals of
maven :-)

Rick
Post by Rick Mangi
Post by Damien Raude-Morvan
In this case, it's read properties from a file in
config/dev.properties. With some tweaks (jelly tags), you should
achieve to rename the file after copy. But IMHO, it's simplier to
have "templates/" and "filtered/" directory than templates and
filtered files in same dir.
Damien,
Thanks. It's this last part that I'm unclear about. I can see how to
do this with a hack, but I'd rather do it the "right" way. Ideally I'd
like to have the templates not included in the final war, just the
filtered and renamed files. So I guess what I'm looking for is a hook
into the filtering mechanism, perhaps as a preGoal before it does the
copy.
It seems to me like either there is a good deal of documentation
missing on this or it would be better for filtering to be extracted
out into a plugin instead of having it as a "core" feature of maven.
I guess what I might be missing is this: what is the input to the
<preGoal name=jar:jar-resources">? Is there an object that we can grab
and work with? I'd assume there's a list of files being passed around
somewhere.
Rick
---------------------------------------------------------------------
Loading...