<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    
    http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.   
-->
<project name="enhance" basedir=".">
    <!--
        This build file executes the PCEnhancer on the test entities. It's in a
        separate file instead of nested in pom.xml to make some conditional 
        processing easier.
        
        Test classes will not be compiled if maven is invoked with 
        -Dmaven.test.skip=true. 
    -->

    <condition property="maven.test.skip.istrue">
        <istrue value="${maven.test.skip}" />
    </condition>

    <condition property="skip.enhance">
        <or>
        <equals arg1="${test}" arg2="false" />
        <equals arg1="${build.enhance}" arg2="false" />
        <istrue value="${maven.test.skip}" />
        <istrue value="${skipTests}" />
        </or>
    </condition>

    <!-- ================================= 
          target: enhance              
         ================================= -->
    <target name="enhance"
            description="--> run the enhancer unless test=false"
            unless="skip.enhance">
        <antcall target="enhance.all.entities"
                 inheritall="true"
                 inheritrefs="true" />
    </target>

    <!-- ================================= 
          target: enhance.all.entities              
         ================================= -->
    <target name="enhance.all.entities"
            description="--> enhance the test entities"
            unless="skip.enhance">
        <echo> running enhancer</echo>
        <!-- 
            Inherited references won't be present until the task is called. 
            Therefore the path definition needs to stay inside the task.
          -->
        <path id="cp">
            <path refid="maven.test.classpath" />
        </path>

        <taskdef name="openjpac"
                 classname="org.apache.openjpa.ant.PCEnhancerTask">
            <classpath refid="cp" />
        </taskdef>

        <fileset id="enhance.path.ref"
                 dir="${project.build.testOutputDirectory}">
            <include name="**/*.class" />
            <exclude name="**/inheritance/serializable/*.class" />
            <exclude name="**/detach/serializable/*.class" />
            <exclude name="**/proxy/entities/*.class" />
            <exclude name="**/xml/*.class" />
            <exclude name="**/Unenhanced*.class" />
            <exclude name="org/apache/openjpa/enhance/EnhancedSuperClass.class"/>
            <exclude name="org/apache/openjpa/enhance/EnhancedSubClass.class"/>
            <exclude name="**/AbstractUnenhanced*.class" />
            <exclude name="**/unenhanced/*.class" />
            <exclude name="**/persistence/property/AccessModsEntity.class"/>
            <exclude name="org/apache/openjpa/enhance/ids/*.class"/>
        </fileset>
        <openjpac>
            <classpath refid="cp" />
            <fileset refid="enhance.path.ref" />
            <config log="${openjpa.Log}" />
        </openjpac>
        <!--  Set detach state for serialization tests -->
        <openjpac>
            <config detachState="fgs(DetachedStateField=true)" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
                <include name="**/inheritance/serializable/*.class" />
                <include name="**/detach/serializable/*.class" />
                <!--  include files from orm.xml -->
                <include name="**/xml/*.class" />
                <exclude name="**/persistence/delimited/identifiers/xml/*.class"/>
                <exclude name="**/Test*.class" />
            </fileset>
            <config log="${openjpa.Log}" />
        </openjpac>
        <!-- Enhance with private persistent properties compatibility option -->
        <openjpac>
            <config propertiesFile="${project.build.testOutputDirectory}/META-INF/nopriv_persistence.xml" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
            <include name="**/persistence/property/AccessModsEntity.class"/>
            </fileset>
            <config log="${openjpa.Log}" />
        </openjpac>
        <!-- Enhance with DetachState fetch-groups option -->
        <openjpac>
            <config propertiesFile="${project.build.testOutputDirectory}/org/apache/openjpa/persistence/proxy/persistence1.xml" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
                <include name="**/proxy/entities/*.class"/>
            </fileset>
            <config log="${openjpa.Log}" />
        </openjpac>
        <!-- Enhance with DetachedStateField=true option -->
        <openjpac>
            <config propertiesFile="${project.build.testOutputDirectory}/org/apache/openjpa/enhance/persistence1.xml" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
                <include name="org/apache/openjpa/enhance/EnhancedSuperClass.class"/>
                <include name="org/apache/openjpa/enhance/EnhancedSubClass.class"/>
            </fileset>
            <config log="${openjpa.Log}" />
        </openjpac>
        <!-- Enhance delimited identifiers XML-based entities separately -->
        <openjpac>
            <config propertiesFile="${project.build.testOutputDirectory}/META-INF/delim_persistence.xml" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
                <include name="**/persistence/delimited/identifiers/xml/*.class"/>
                <exclude name="**/persistence/delimited/identifiers/xml/Test*.class"/>
            </fileset>
            <config log="${openjpa.Log}"/>
        </openjpac>
        <!-- Enhance with optimized id copy option -->
        <openjpac>
            <config propertiesFile="${project.build.testOutputDirectory}/META-INF/optidcpy_persistence.xml" />
            <classpath refid="cp" />
            <fileset dir="${project.build.testOutputDirectory}">
                <include name="org/apache/openjpa/enhance/ids/*.class"/>
            </fileset>
            <config log="${openjpa.Log}" />
        </openjpac>
    </target>
</project>
