• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3
4    Licensed to the Apache Software Foundation (ASF) under one
5    or more contributor license agreements.  See the NOTICE file
6    distributed with this work for additional information
7    regarding copyright ownership.  The ASF licenses this file
8    to you under the Apache License, Version 2.0 (the
9    "License"); you may not use this file except in compliance
10    with the License.  You may obtain a copy of the License at
11
12      http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing,
15    software distributed under the License is distributed on an
16    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17    KIND, either express or implied.  See the License for the
18    specific language governing permissions and limitations
19    under the License.
20
21-->
22<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23    <modelVersion>4.0.0</modelVersion>
24    <parent>
25        <groupId>org.apache.velocity</groupId>
26        <artifactId>velocity-engine-parent</artifactId>
27        <version>2.4-SNAPSHOT</version>
28    </parent>
29
30    <artifactId>velocity-custom-parser-example</artifactId>
31    <name>Apache Velocity Custom Parser Example</name>
32    <description>Custom Parser Example for Apache Velocity</description>
33
34    <packaging>pom</packaging>
35
36    <!--
37      This module demonstrates how to build a custom Velocity parser.
38      The proposed custom parser replaces '#' with '@' and '@' with '%'
39      so that it's suitable to use with Markdown template files, for instance.
40
41      The generated parser class is ${parser.package}.${parser.basename}Parser,
42      and must be specified at runtime using the Velocity property parser.class:
43        parser.class = foo.bar.MyCustomParser
44
45      Please note that all configurable chars (*, @, $, #) must be specified, even when similar to default ones.
46    -->
47
48    <properties>
49        <!-- whether to display debug logs while parsing -->
50        <parser.debug>false</parser.debug>
51        <!-- parser basename -->
52        <parser.basename>Custom</parser.basename>
53        <!-- parser package -->
54        <parser.package>org.apache.velocity.runtime.parser.custom</parser.package>
55        <!-- character to substitute to '*' -->
56        <parser.char.asterisk>*</parser.char.asterisk>
57        <!-- character to substitute to '@' -->
58        <parser.char.at>%</parser.char.at>
59        <!-- character to substitute to '$' -->
60        <parser.char.dollar>$</parser.char.dollar>
61        <!-- character to substitute to '#' -->
62        <parser.char.hash>@</parser.char.hash>
63    </properties>
64
65    <dependencies>
66        <dependency>
67            <groupId>org.apache.velocity</groupId>
68            <artifactId>velocity-engine-core</artifactId>
69            <version>${project.version}</version>
70        </dependency>
71        <dependency>
72            <groupId>junit</groupId>
73            <artifactId>junit</artifactId>
74            <version>${junit.version}</version>
75            <scope>test</scope>
76        </dependency>
77        <dependency>
78            <groupId>org.slf4j</groupId>
79            <artifactId>slf4j-simple</artifactId>
80            <version>${slf4j.version}</version>
81            <scope>test</scope>
82        </dependency>
83        <dependency>
84            <groupId>commons-io</groupId>
85            <artifactId>commons-io</artifactId>
86            <version>2.8.0</version>
87        </dependency>
88    </dependencies>
89
90    <build>
91        <plugins>
92            <!-- generate manifest file -->
93            <plugin>
94                <groupId>org.apache.felix</groupId>
95                <artifactId>maven-bundle-plugin</artifactId>
96            </plugin>
97
98            <!-- extract raw parser grammar from velocity jar -->
99            <plugin>
100                <groupId>org.apache.maven.plugins</groupId>
101                <artifactId>maven-dependency-plugin</artifactId>
102                <executions>
103                    <execution>
104                        <id>fetch-grammar-file</id>
105                        <phase>initialize</phase>
106                        <goals>
107                            <goal>unpack</goal>
108                        </goals>
109                        <configuration>
110                            <artifact>org.apache.velocity:velocity-engine-core:${project.version}</artifact>
111                            <includes>org/apache/velocity/runtime/parser/Parser.jjt</includes>
112                            <outputDirectory>${project.build.directory}/grammar</outputDirectory>
113                        </configuration>
114                    </execution>
115                </executions>
116            </plugin>
117
118            <!-- generate custom grammar file -->
119            <plugin>
120                <groupId>org.apache.maven.plugins</groupId>
121                <artifactId>maven-resources-plugin</artifactId>
122                <executions>
123                    <execution>
124                        <id>generate-parser-grammar</id>
125                        <phase>generate-sources</phase>
126                        <goals>
127                            <goal>copy-resources</goal>
128                        </goals>
129                        <configuration>
130                            <useDefaultDelimiters>false</useDefaultDelimiters>
131                            <delimiters>
132                                <delimiter>${*}</delimiter>
133                            </delimiters>
134                            <resources>
135                                <resource>
136                                    <directory>${project.build.directory}/grammar</directory>
137                                    <filtering>true</filtering>
138                                </resource>
139                            </resources>
140                            <outputDirectory>${project.build.directory}/parser</outputDirectory>
141                        </configuration>
142                    </execution>
143                </executions>
144            </plugin>
145
146            <!-- run javacc -->
147            <plugin>
148                <groupId>org.codehaus.mojo</groupId>
149                <artifactId>javacc-maven-plugin</artifactId>
150                <version>2.6</version>
151                <configuration>
152                    <isStatic>false</isStatic>
153                    <buildParser>true</buildParser>
154                    <buildNodeFiles>false</buildNodeFiles>
155                    <multi>true</multi>
156                    <debugParser>${parser.debug}</debugParser>
157                    <debugLookAhead>${parser.debug}</debugLookAhead>
158                    <debugTokenManager>${parser.debug}</debugTokenManager>
159                    <jdkVersion>${maven.compiler.target}</jdkVersion>
160                    <nodeUsesParser>true</nodeUsesParser>
161                    <nodePackage>${parser.package}.node</nodePackage>
162                    <sourceDirectory>${project.build.directory}/parser/org/apache/velocity/runtime/parser</sourceDirectory>
163                    <tokenManagerUsesParser>true</tokenManagerUsesParser>
164                </configuration>
165                <executions>
166                    <execution>
167                        <id>jjtree-javacc</id>
168                        <phase>generate-sources</phase>
169                        <goals>
170                            <goal>jjtree-javacc</goal>
171                        </goals>
172                        <configuration>
173                            <includes>
174                                <include>Parser.jjt</include>
175                            </includes>
176                        </configuration>
177                    </execution>
178                </executions>
179            </plugin>
180
181            <!-- Remove extra generated files we don't want -->
182            <plugin>
183                <groupId>org.apache.maven.plugins</groupId>
184                <artifactId>maven-clean-plugin</artifactId>
185                <executions>
186                    <execution>
187                        <id>clean-extra-javacc</id>
188                        <phase>process-sources</phase>
189                        <goals>
190                            <goal>clean</goal>
191                        </goals>
192                        <configuration>
193                            <excludeDefaultDirectories>true</excludeDefaultDirectories>
194                            <filesets>
195                                <fileset>
196                                    <directory>${project.build.directory}/generated-sources/javacc/</directory>
197                                    <includes>
198                                        <include>**/*.java</include>
199                                    </includes>
200                                    <excludes>
201                                        <exclude>**/*${parser.basename}*.java</exclude>
202                                    </excludes>
203                                </fileset>
204                                <fileset>
205                                    <directory>${project.build.directory}/generated-sources/jjtree/</directory>
206                                    <includes>
207                                        <include>**/node/*.java</include>
208                                    </includes>
209                                    <excludes>
210                                        <exclude>**/node/*${parser.basename}*.java</exclude>
211                                    </excludes>
212                                </fileset>
213                            </filesets>
214                        </configuration>
215                    </execution>
216                </executions>
217            </plugin>
218
219            <!-- add missing imports to some parser generated files -->
220            <plugin>
221                <groupId>com.google.code.maven-replacer-plugin</groupId>
222                <artifactId>replacer</artifactId>
223                <executions>
224                    <execution>
225                        <id>patch-parser-files</id>
226                        <phase>process-sources</phase>
227                        <goals>
228                            <goal>replace</goal>
229                        </goals>
230                        <configuration>
231                            <includes>
232                                <include>${project.build.directory}/generated-sources/jjtree/**/JJT${parser.basename}ParserState.java</include>
233                                <include>${project.build.directory}/generated-sources/jjtree/**/${parser.basename}ParserVisitor.java</include>
234                            </includes>
235                            <replacements>
236                                <replacement>
237                                    <token>import ${parser.package}.*;</token>
238                                    <value>import ${parser.package}.*;
239import org.apache.velocity.runtime.parser.node.*;</value>
240                                </replacement>
241                            </replacements>
242                        </configuration>
243                    </execution>
244                </executions>
245            </plugin>
246
247            <!-- tests -->
248            <plugin>
249                <groupId>org.apache.maven.plugins</groupId>
250                <artifactId>maven-surefire-plugin</artifactId>
251                <version>${surefire.plugin.version}</version>
252                <configuration>
253                    <skip>${maven.test.skip}</skip>
254                    <systemProperties>
255                        <property>
256                            <name>test</name>
257                            <value>${test}</value>
258                        </property>
259                        <property>
260                            <name>test.templates.dir</name>
261                            <value>${project.build.testOutputDirectory}/templates</value>
262                        </property>
263                        <property>
264                            <name>test.results.dir</name>
265                            <value>${project.build.directory}/results</value>
266                        </property>
267                        <property>
268                            <name>test.reference.dir</name>
269                            <value>${project.build.testOutputDirectory}/reference</value>
270                        </property>
271                        <property>
272                            <name>org.slf4j.simpleLogger.defaultLogLevel</name>
273                            <value>warn</value>
274                        </property>
275                        <property>
276                            <name>org.slf4j.simpleLogger.logFile</name>
277                            <value>${project.build.directory}/velocity.log</value>
278                        </property>
279                    </systemProperties>
280                </configuration>
281            </plugin>
282        </plugins>
283    </build>
284</project>
285