You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Paolo Castagna <pa...@hplb.hpl.hp.com> on 2009/06/16 15:41:20 UTC

process-sources: process the source code, for example to filter any values.

Hi,
the "Introduction to the Build Lifecycle" [1] documentation describes a
"process-sources" phase of the default lifecycle.

The description says: "process-sources - process the source code, for
example to filter any values."

This is exactly what I want to do (i.e. filter some values in my source
code before compiling it).

Could you, please, point me to an example which shows how to do that in
practice?

Thanks,
Paolo

  [1] http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference

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


Re: process-sources: process the source code, for example to filter any values.

Posted by Dominic Mitchell <do...@semantico.com>.
On 17 Jun 2009, at 08:29, Paolo Castagna wrote:

> Anders Hammar wrote:
> > Found this through Google:
> > http://www.gxdeveloperweb.com/Blogs/Bram-de-Kruijff/Maven-secrets-filtering-sources.htm
> >
> > Not sure if it's the best way to do it though. Never tried filtering
> > java source code.
>
> Thanks Anders for your reply.
>
> Yep, I've been searching with Google as well and I found the same  
> page,
> among others. However, I do not need to filter all the sources, just  
> one
> specific file, which contains version and build timestamp information.
>
> As an alternative, one could use Ant via maven-antrun-plugin:

I did this a while back and it's been quite successful.

http://happygiraffe.net/blog/2008/10/01/embedding-the-maven-version-number/

-Dom

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


Re: process-sources: process the source code, for example to filter any values.

Posted by Paolo Castagna <pa...@hplb.hpl.hp.com>.
Anders Hammar wrote:
 > Found this through Google:
 > http://www.gxdeveloperweb.com/Blogs/Bram-de-Kruijff/Maven-secrets-filtering-sources.htm
 >
 > Not sure if it's the best way to do it though. Never tried filtering
 > java source code.

Thanks Anders for your reply.

Yep, I've been searching with Google as well and I found the same page,
among others. However, I do not need to filter all the sources, just one
specific file, which contains version and build timestamp information.

As an alternative, one could use Ant via maven-antrun-plugin:

       <plugin>
         <artifactId>maven-antrun-plugin</artifactId>
         <executions>
           <execution>
             <phase>process-sources</phase>
             <configuration>
               <tasks>
                 <tstamp>
                   <format property="build-time" pattern="d-MMMM-yyyy HH:mm"/>
                 </tstamp>
                 <copy file="src/main/java/com/.../Version.java.template" toFile="src/main/java/com/.../Version.java" overwrite="true">
                   <filterset>
                     <filter token="version-major" value="${version-major}"/>
                     <filter token="version-minor" value="${version-minor}"/>
                     <filter token="version-revision" value="${version-revision}"/>
                     <filter token="version-status" value="${version-status}"/>
                     <filter token="version" value="${project.version}"/>
                     <filter token="Name" value="${project.name}"/>
                     <filter token="website" value="${project.url}"/>
                     <filter token="build-time" value="${build-time}"/>
                   </filterset>
                 </copy>
               </tasks>
             </configuration>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
         </executions>
       </plugin>

A similar thing could be done with a property file put in your project
resources.

Are there others and simpler ways to do this?

Paolo



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


Re: process-sources: process the source code, for example to filter any values.

Posted by Anders Hammar <an...@hammar.net>.
Found this through Google:
http://www.gxdeveloperweb.com/Blogs/Bram-de-Kruijff/Maven-secrets-filtering-sources.htm

Not sure if it's the best way to do it though. Never tried filtering
java source code.

/Anders

On Tue, Jun 16, 2009 at 15:41, Paolo
Castagna<pa...@hplb.hpl.hp.com> wrote:
> Hi,
> the "Introduction to the Build Lifecycle" [1] documentation describes a
> "process-sources" phase of the default lifecycle.
>
> The description says: "process-sources - process the source code, for
> example to filter any values."
>
> This is exactly what I want to do (i.e. filter some values in my source
> code before compiling it).
>
> Could you, please, point me to an example which shows how to do that in
> practice?
>
> Thanks,
> Paolo
>
>  [1]
> http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

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