1 Reply Latest reply on Jun 18, 2009 4:14 PM by Stan Silvert

    Making test-enabled WAR with Ant

    Darrel Riekhof Newbie

      I tried using the org.jboss.jsfunit.ant.JSFUnitWarTask to make a JSFUnit-enabled WAR file. It worked, but I ran into a couple problems with it that made me switch to doing it myself:

      1) Its very very slow. Takes 2+ minutes to make the war. Not sure what its doing, but whatever it is takes forever. Doing the same thing myself takes about 10 seconds. Why is it so slow?

      2) It leaves a copy of the war files in my /tmp dir. I only noticed this after I ran out of diskspace on my tmp disk.

      Here's my ant tasks that do the same thing (AFAIK )much faster without leaving garbage behind:

       <javac debug="on" srcdir="${test.src.dir}" destdir="${test.classes.dir}"
       <!-- Copy all the test stuff over to build classes. -->
       <copy todir="${build.classes.dir}">
       <fileset dir="${test.classes.dir}"/>
       <format property="jsfunit-war.start.ts" pattern="HH:mm:ss" />
       <echo message="Starting to make JSFUnit War at ${jsfunit-war.start.ts}"/>
       <!-- copy test libs to the lib dir in build dir -->
       <copy todir="${build.lib.dir}">
       <fileset dir="${test.lib.dir}/jsfunit">
       <include name="**/*.jar"/>
       <fileset dir="${test.lib.dir}/junit_4">
       <include name="**/*.jar"></include>
       <!-- Edit the web.xml in the build dir to include the defs for
       the JSFUnit test servlet -->
       <echo message="Filtering"/>
       <filter token="JSFUnit-servlet-tags-start" value="JSFUnit servlet tags start -->"/>
       <filter token="JSFUnit-servlet-tags-end" value="<!-- JSFUnit servlet tags end"/>
       <touch file="${build.webinf.dir}/web.xml"/>
       <copy file="${build.webinf.dir}/web.xml" tofile="${build.webinf.dir}/test-web.xml" filtering="true"/>
       <move file="${build.webinf.dir}/web.xml" tofile="${build.webinf.dir}/notest-web.xml"/>
       <move file="${build.webinf.dir}/test-web.xml" tofile="${build.webinf.dir}/web.xml"/>
       <echo message="Done Filtering"/>
       <!-- make the war from the build dir, which now contains all the files
       needed for testing. -->
       <jar compress="${jar.compress}" jarfile="${dist.dir}/jsfunit-${war.name}">
       <fileset dir="${build.web.dir}"/>
       <format property="jsfunit-war.end.ts" pattern="HH:mm:ss" />
       <echo message="Finished making JSFUnit War at ${jsfunit-war.end.ts}"/>
       <move file="${dist.dir}/${war.name}" tofile="${dist.dir}/notests-${war.name}"/>
       <move file="${dist.dir}/jsfunit-${war.name}" tofile="${dist.dir}/${war.name}"/>
       <!-- copying to this dir redeploys the app as long as glassfish is
       configured to autodeploy. -->
       <copy file="${dist.dir}/${war.name}"
       todir="${glassfish.autodeploy.dir}" />

        • 1. Re: Making test-enabled WAR with Ant
          Stan Silvert Master

          I think the reason is because JSFUnitWarTask is taking a very different approach. The idea is that you already have a WAR (exploded or unexploaded). Then the WAR needs to be modified for JSFUnit. To do that, the WAR has to be copied and changed to make a new WAR. So if your WAR is large this can take a long time. Leaving stuff in the temp dir should probably be considered a bug and fixed.

          It looks like you are building the JSFUnit WAR at the same time you build everything else. This is much quicker because you don't have to unjar and copy. So maybe the approach for JSFUnitWARTask needs to be changed. If you want to build a better ant task I'd be happy to include it with the JSFUnit project.

          IMHO, the best solution is to use the JSFUnit Deployer with JBoss AS5. Then everything JSFUnit needs is added at deploy time and you never have to change your WAR at all. The Servlet 3.0 spec may give us enough functionality that we can deploy this way in other containers as well.