How prevent post-compile enhancement of non entity classes

#1

I have recently moved to post-compile enhancement (from automatic run-time enhancement) using an Ant build.xml for a NetBeans web app. My adapted build.xml works for both full project build and per-file compilation (with NetBeans "compile on save" off), but it is not yet perfect at only invoking the enhancer on entity files.

For full project build the following works, by grouping entities under clearly named packages:

<property name="objectdbjar" value="/usr/local/objectdb/objectdb/bin/objectdb.jar"/>

<target name="-post-compile">
 <echo message="begin ObjectDB enhancer"/> 
 <java classname="com.objectdb.Enhancer" fork="true" classpath="${objectdbjar}:${javac.classpath}:${j2ee.platform.classpath}">
   <arg line="-s ./build/web/WEB-INF/classes/com/example/entity/*.class ./build/web/WEB-INF/classes/com/exanple/subpackage/entity/*.class"/>
  </java>
  <echo message="end ObjectDB enhancer"/>
 </target>

But the following for per-file post-compile enhancement also invokes the enhancer on non-entity files:

<target name="-post-compile-single">
 <loadresource property="compiled">
   <propertyresource name="javac.includes"/>
   <filterchain>
     <tokenfilter>
     <filetokenizer/>
     <replacestring from=".java" to=".class"/>
    </tokenfilter>
   </filterchain>
 </loadresource>
 <echo message="post compile single: compiled: ${compiled}"/>
 <echo message="post compile single: begin ObjectDB enhancer"/>
 <java classname="com.objectdb.Enhancer" fork="true" classpath="${objectdbjar}:${javac.classpath}:${j2ee.platform.classpath}">
  <arg line="-s ./${build.classes.dir}/${compiled}"/>
 </java>
 <echo message="post compile single: end ObjectDB enhancer"/>
</target>

Ant has a selector system (https://ant.apache.org/manual/Types/selectors.html) for use with <fileset> and a <contains> operator (https://ant.apache.org/manual/Types/selectors.html#containsselect), so one could select on files containing @entity, but I can't find how to combined <fileset> with the <java> task (in this case I need to somehow select on files appearing in the -s arguments passed to the enhancer).

Glad for suggestions. 

 

#2

Usually an attempt to enhance non entity classes should not be a problem.

Anyway, this question seems to be a question about Ant, so maybe getting tips on this would be more effective on stackoverflow or a specific Ant forum.

ObjectDB Support

Reply