Sophie

Sophie

distrib > Mageia > 5 > i586 > by-pkgid > d6ed6c5147aa2cde3d48cc9fb4d84ac5 > files > 7

ant-antlr3-20110110-11.mga5.noarch.rpm

<project name="composite-java" default="dist" basedir=".">
    <description>
        Build file for Anltr composite example.
    </description>
    
    <property name="project.name" value="composite-java" />
    
    <!-- program version -->
    <property name="version" value="1.1" />
    
    <!-- set global properties for this build -->
    <property name="build" location="."/>
 
    <!-- directory layout for this build:
         
         .
         +- src
         +- grammar
         +- classes
         +- dist
              +- javadoc
         
         the following properties reflect this hierarchy
    -->
         
    <!-- the src directory in this example -->
    <property name="src" location="src"/>
    
    <!-- name of the package -->
    <property name="package" value=""/>
    
    <!-- where to write/find token files -->
    <property name="token.lib" location="${src}/${package}" />
    
    <!-- where to find the grammar files
         in this example the grammar file is placed in the source
         directory. Some people might prefer to locate it in a
         separate directory, e.g. grammar directory.
         To do so, just change
         
         location="${src}" into
         location="grammar"
         
         if you like and make sure that the grammar
         files are copied into the grammar directory.
    -->
    <property name="grammar" location="${src}"/>
    
    <!-- where to write compiled source -->
    <property name="classes" location="classes"/>
    
    <!-- distribution directory -->
    <property name="dist" location="dist" />
    
    <!-- where to write java doc files -->
    <property name="doc" location="${dist}/javadoc"/>   

    <!-- Inquire environment variables -->
    <property environment="envList"/>

    <!-- Get environment variable ANTLR_HOME -->
    <property name="antlrHome" value="${envList.ANTLR_HOME}"/>
             
    <!-- antlr options -->
    <property name="report" value="true" />
    <property name="multithreaded" value="true" />
    <property name="debug" value="false" />
 
    <!-- A convenience macro which invokes antlr
         Be aware that JVM arguments can be specified via the jvmarg directive
    -->
    <macrodef name="antlr3">
        <attribute name="grammar.name"/>
        <attribute name="package" default="${package}"/>
        <attribute name="make" default="True"/>
        <attribute name="verbose" default="True"/>
        <sequential>
            <echo message="antlr ${grammar}/@{grammar.name}" />
            <antlr:ant-antlr3 xmlns:antlr="antlib:org/apache/tools/ant/antlr"
                  target="${grammar}/@{grammar.name}"
                  outputdirectory="${src}/@{package}"
                  libdirectory="${src}/@{package}"
                  multithreaded="${multithreaded}"
                  make="@{make}"
                  verbose="@{verbose}"
                  report="${report}"
                  debug="${debug}">
                <classpath>
                    <path refid="antlr.path"/>
                </classpath>
                <jvmarg value="-Xmx512M"/>
            </antlr:ant-antlr3>
        </sequential>
    </macrodef>

    <target name="init">
        <!-- Create the time stamp -->
        <tstamp />
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${grammar}" />
        <mkdir dir="${src}/${package}" />
        <mkdir dir="${classes}/${package}" />
        <mkdir dir="${classes}/META-INF" />
        <mkdir dir="${dist}/javadoc" />

        <!-- Copy all files into the source directory -->
        <copy todir="${src}" includeEmptyDirs="false">
            <fileset dir=".">
                <patternset id="sourcefiles">
                   <include name="*.java"/>
                   <include name="*.g"/>
                </patternset>
            </fileset>
        </copy>

        <!-- Check if environment variable ANTLR_HOME is set -->
        <fail message="Environment variable ANTLR_HOME is not set!">
           <condition>
              <not>
                 <isset property="envList.ANTLR_HOME"/>
              </not>
           </condition>
        </fail>
    </target>

    <!-- Use wildcards in pattern definition -->
    <!-- to be independent of antlr versions -->
    <patternset id="antlr.libs">
        <include name="antlr-*.jar" />
        <include name="stringtemplate-*.jar" />
        <include name="runtime-*.jar" />
    </patternset>
    
    <!-- Looking for archives in ANTLR_HOME directory -->
    <path id="antlr.path">
        <fileset dir="${antlrHome}" casesensitive="yes">
            <patternset refid="antlr.libs" />
        </fileset>
    </path>   
    
    <!-- Antlr is called here -->
    <!-- The antlr3 macro is doing the work -->
    <!-- The dependency among grammars has to be described -->
    <!-- The hierarchy in this example is:
    
         Java.g
            importing JavaDecl.g
            importing JavaAnnotations.g
            importing JavaExpr.g
            importing JavaStat.g
            importing JavaLexerRules.g
      
         Imported grammars are resolved by Antlr.
             
         Call "ant" without parameters twice and you will
         notice that no compilation by Antlr is done in 
         the second call.
         To force a recompile use "ant clean dist" or
         "ant all".
     -->
        
    <target name="Composite">
        <antlr3 grammar.name="Java.g"/>
    </target>

    <target name="compile" depends="init, Composite" description="compile">
        <!-- Compile the java code from ${src} into ${classes} -->
        <javac debug="true" srcdir="${src}" destdir="${classes}"             
               listfiles="Yes" deprecation="Yes">
            <compilerarg value="-Xlint:unchecked"/>
            <classpath>
               <path refid="antlr.path"/>
            </classpath>
        </javac>
    </target>

    <target name="manifest">
        <manifest file="${classes}/META-INF/MANIFEST.MF">
            <attribute name="Main-Class" value="Main" />
        </manifest>
    </target>

    <target name="dist" depends="compile, manifest" 
       description="generate for distribution">
       <jar jarfile="${dist}/${project.name}.jar" basedir="${classes}" 
            manifest="${classes}/META-INF/MANIFEST.MF"/>
    </target>

    <target name="doc" depends="init, compile" description="generate documentation">
       <javadoc destdir="${doc}"
                author="true"
                version="true"
                use="true"
                windowtitle="${project.name}"
                source="${src}"
                Protected="All"
                Private="All"
                Public="All"
                linksource="yes"
                breakiterator="Yes">
         <fileset dir="${src}" casesensitive="yes">
             <include name="**/*.java" />
         </fileset>
         <classpath>
             <path refid="antlr.path"/>
         </classpath>
       </javadoc>
    </target>

    <target name="run" depends="dist">
       <echo message="Compile 'input' and write informations to 'output'"/>
       <java classname="Main"
             input="input"
             output="output"
             fork="true"
             failonerror="true"
             maxmemory="128m">
         <classpath>
             <pathelement location="${dist}/${project.name}.jar"/>
             <path refid="antlr.path"/>
         </classpath>
       </java>
    </target>
    
    <target name="clean" description="clean up">
       <delete>
          <fileset dir="${src}" includes="**/*.class,**/*.tokens" />
          <fileset dir="${classes}" />
          <fileset dir="${dist}" includes="**/*.jar" />
          <fileset dir="${doc}" />
       </delete>
    </target>
    
    <target name="all" depends="init, clean, compile, dist, doc, run" description="do all"/>
            
</project>