Templating Maven Plugin usage

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Templating Maven Plugin usage

Kevin Mayer
I need to filter a java source file(in src/main/java-templates) with
this line of code:

"${outputLine}"

with a property in a properties file. Ex:
outputLine=res.sendRedirect(res.encodeURL(redirectURL));

I can run the example fine given here:
http://www.hascode.com/2013/09/filtering-source-files-using-the-templating-maven-plugin/

but it is using maven pom properties.  

Do I need to specify the delimiters as provide here?:
http://mojo.codehaus.org/templating-maven-plugin/filter-sources-mojo.html

If so, can someone show me the pom?

Here is what I am using thus far:

        <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>templating-maven-plugin</artifactId>
                  <version>1.0-alpha-3</version>
                  <executions>
                      <execution>
                      <phase>generate-sources</phase>
                      <id>filter-src</id>
                      <goals>
                          <goal>filter-sources</goal>
                      </goals>
                      </execution>
                  </executions>
                </plugin>      

thank you


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Templating Maven Plugin usage

Baptiste MATHUS-4
Hi,

What templating-maven-plugin actually does is filtering sources with the properties the current maven properties context.
It will not load any property anywhere if you don't configure it somewhere.

The simplest way would be by defining a new property outputLine in your pom.xml under xpath://project/properties tag with the value you want.

If you want is to somehow create a dynamic property (see <properties> tag in maven pom.xml file to understand the parallel), there are many possibilities. You might want for example to have a look at http://mojo.codehaus.org/properties-maven-plugin/read-project-properties-mojo.html to load properties from a property file.

HTH
Cheers



2013/9/24 Kevin Mayer <[hidden email]>
I need to filter a java source file(in src/main/java-templates) with
this line of code:

"${outputLine}"

with a property in a properties file. Ex:
outputLine=res.sendRedirect(res.encodeURL(redirectURL));

I can run the example fine given here:
http://www.hascode.com/2013/09/filtering-source-files-using-the-templating-maven-plugin/

but it is using maven pom properties.

Do I need to specify the delimiters as provide here?:
http://mojo.codehaus.org/templating-maven-plugin/filter-sources-mojo.html

If so, can someone show me the pom?

Here is what I am using thus far:

                <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>templating-maven-plugin</artifactId>
                  <version>1.0-alpha-3</version>
                  <executions>
                      <execution>
                      <phase>generate-sources</phase>
                      <id>filter-src</id>
                      <goals>
                          <goal>filter-sources</goal>
                      </goals>
                      </execution>
                  </executions>
                </plugin>

thank you


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email

--
Baptiste <Batmat> MATHUS - http://batmat.net
Sauvez un arbre,
Mangez un castor ! nbsp;!
Reply | Threaded
Open this post in threaded view
|

Re: Templating Maven Plugin usage

Kevin Mayer
That did help!  Thanks!!

Using Baptiste's suggestion, here is how you would do this:

    <profiles>
     <profile>
             <id>development</id>
             <activation>
                <activeByDefault>true</activeByDefault>
             </activation>
             <properties>
                <env>${env.ENVIRONMENT}</env>
                <outputLine>out.println(redirectURL);</outputLine>
             </properties>
     </profile>
.
.
.

        <plugin>
                  <groupId>org.codehaus.mojo</groupId>
                  <artifactId>templating-maven-plugin</artifactId>
                  <version>1.0-alpha-3</version> <!-- Be sure to use the last version.
Check on the website's plugin -->
                  <executions>
                      <execution>
                      <phase>generate-sources</phase>
                      <id>filter-src</id>
                      <goals>
                          <goal>filter-sources</goal>
                      </goals>
                      </execution>
                  </executions>
                </plugin>      

Using this will insert the value you have in the <outputLine> into the
source code in src/main/java-templates where you have a corresponding
filter: in my example it is @outputLine@.  @outputLine in the source
will be replaced with out.println(redirectURL);

you can verify in target/generated-sources/java-templates


On Wed, 2013-09-25 at 06:11 -0600, Baptiste Mathus wrote:

> Hi,
>
>
> What templating-maven-plugin actually does is filtering sources with
> the properties the current maven properties context.
> It will not load any property anywhere if you don't configure it
> somewhere.
>
>
> The simplest way would be by defining a new property outputLine in
> your pom.xml under xpath://project/properties tag with the value you
> want.
>
>
> If you want is to somehow create a dynamic property (see <properties>
> tag in maven pom.xml file to understand the parallel), there are many
> possibilities. You might want for example to have a look
> at http://mojo.codehaus.org/properties-maven-plugin/read-project-properties-mojo.html to load properties from a property file.
>
>
> HTH
> Cheers
>
>
>
>
> 2013/9/24 Kevin Mayer <[hidden email]>
>         I need to filter a java source file(in
>         src/main/java-templates) with
>         this line of code:
>        
>         "${outputLine}"
>        
>         with a property in a properties file. Ex:
>         outputLine=res.sendRedirect(res.encodeURL(redirectURL));
>        
>         I can run the example fine given here:
>         http://www.hascode.com/2013/09/filtering-source-files-using-the-templating-maven-plugin/
>        
>         but it is using maven pom properties.
>        
>         Do I need to specify the delimiters as provide here?:
>         http://mojo.codehaus.org/templating-maven-plugin/filter-sources-mojo.html
>        
>         If so, can someone show me the pom?
>        
>         Here is what I am using thus far:
>        
>                         <plugin>
>                           <groupId>org.codehaus.mojo</groupId>
>        
>         <artifactId>templating-maven-plugin</artifactId>
>                           <version>1.0-alpha-3</version>
>                           <executions>
>                               <execution>
>                               <phase>generate-sources</phase>
>                               <id>filter-src</id>
>                               <goals>
>                                   <goal>filter-sources</goal>
>                               </goals>
>                               </execution>
>                           </executions>
>                         </plugin>
>        
>         thank you
>        
>        
>         ---------------------------------------------------------------------
>         To unsubscribe from this list, please visit:
>        
>             http://xircles.codehaus.org/manage_email
>        
>        
>         --
>         Baptiste <Batmat> MATHUS - http://batmat.net
>         Sauvez un arbre,
>         Mangez un castor ! nbsp;!



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email