https://github.com/abego/jpp
jpp - A Simple Java Preprocessor for Ant
https://github.com/abego/jpp
ant java java-preprocessor jpp preprocessor
Last synced: about 1 month ago
JSON representation
jpp - A Simple Java Preprocessor for Ant
- Host: GitHub
- URL: https://github.com/abego/jpp
- Owner: abego
- License: other
- Created: 2012-05-07T12:08:02.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2018-06-01T22:51:30.000Z (almost 8 years ago)
- Last Synced: 2023-03-14T00:35:14.797Z (about 3 years ago)
- Topics: ant, java, java-preprocessor, jpp, preprocessor
- Language: Java
- Homepage:
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.html
- Changelog: CHANGES.txt
- License: LICENSE.txt
Awesome Lists containing this project
README
jpp - A Simple Java Preprocessor for Ant
code{white-space: pre;}
html {color: #333333; line-height: 1.5; font-family: Helvetica, arial, sans-serif;} pre {background-color: #f8f8f8;border: 1px solid #ddd;}
jpp - A Simple Java Preprocessor for Ant
About jpp
jpp is an Ant task for preprocessing text files, especially Java source files.
Its main purpose is to allow “conditional compilation”. Other features commonly provided by text preprocessors, like inclusion of files or macro expansion, are not supported.
Ant provides the jpp task with properties that control the preprocessing of the files. Using conditional directives parts of the text file can be excluded in the resulting file.
Syntax
#if [!]propertyName [# ... optional inline comment ...]
...text 1...
[#else
...text 2...]
#endif
(’[ … ]’ encloses optional parts).
Preprocessing
jpp analyses a file’s text line-by-line and writes the result to the destination file.
Here the details of the preprocessing:
- When the
#ifcondition is true the lines following the#if(i.e. “...text 1...”) are copied to the destination file, otherwise the lines following the#else(i.e. “...text 2...”) are copied. - All lines containing a jpp directive (
#if,#else,#endif) are removed. - All lines outside an
#if...#endifblock are copied to the destination file. -
#if…#endifblocks can be nested, i.e. they can appear in the “if” and “else” areas of an outer#if…#endifblock.
An #if condition is true if either
- a single name is specified (e.g. “
#if FOO”) and the property with that name holds the valuetrue, or - a negate operator
!and a name is given (e.g. “#if !FOO”) and no property with that name is defined or the property does not hold the valuetrue.
Using jpp directives in Java source files
When using jpp directives in Java source files the directives must be included in Java comments to avoid compile errors.
You may either use single line comments, e.g. as in:
//#if FOO
... regular Java text
//#endif
or block comments like:
/*#if FOO
... text in comment ...
#endif*/
When using the block comment approach the text inside the directive block will not be compiled in the original file. However when the condition is satisfied the resulting file will contain the text without the wrapping comment, i.e. it will be compiled.
Examples
/*#if FOO
... text in comment ...
#else*/
... text outside comment ...
//#endif
//#if !FOO
... text to be excluded when FOO is true ...
//#endif
Ant integration
<project name="YourProjectName" ... >
<!-- Register the jpp ant task -->
<taskdef resource="jpp.xml" classpath="lib/jpp/1.0.3/jpp-1.0.3.jar" />
...
<!-- defined properties to control the preprocessing -->
<property name="NO_FOO" value="true" />
<property name="WITH_BLA" value="true" />
...
<!-- call the jpp tool inside a target -->
<target name="preprocess">
<jpp destdir="src-gen" readonly="true" verbose="false">
<fileset dir="src/" includes="**/*.java" excludesfile="config/excludes.txt" />
<fileset dir="src/" includesfile="config/includes.txt" />
</jpp>
</target>
...
</project>
License
jpp is distributed under a BSD license of abego Software.
Links
Sources: https://github.com/abego/jpp