Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
Ant 1.6 API: Can 't call War.addZipfileset() from JavaScript

Ant 1.6 API: Can 't call War.addZipfileset() from JavaScript

2005-06-23       - By Lou_Miranda@(protected)
Reply:     1     2     3     4     5  


I have an Ant 1.5.4 build script that doesn't work in Ant 1.6 (Ant 1.6.2
or 1.6.5). It has some embedded JavaScript that is calling the Ant API to
add a ZipFileSet to the War task.

What we're trying to do is dynamically add directories to the War task at
runtime. We decided to use JavaScript to calculate which directories need
to be added, and then modify the War task via JavaScript before the War
task is run. Using the Ant API worked straightforward for us in Ant 1.5.4.

Below is an example build.xml file that shows what we are doing. I took
out the logic that dynamically builds the directories to include, in order
to keep the example simple and straightforward. (Obviously, I wouldn't use
JavaScript to add a static, known path to the War task.)

If I add the appropriate BSF and Rhino libraries to Ant 1.5.4 and Ant
1.6.2 and run this exact same build file, it works fine in Ant 1.5.4 but
throws an exception in Ant 1.6.2. The exception starts out like this:

      build.xml:20: Type Error: undefined is not a function.

Pretty vague error message!

With some testing, I determined that I can't call a number of War task
methods from JavaScript in Ant 1.6.2. These include addZipfileset(),
addLib(), and addClasses(). Not sure if I'm doing something wrong, or if
something changed in Ant 1.6. Any ideas? Thanks!

The build.xml file below has 2 tasks: buildWar and addWarDynamic.
Basically we use JavaScript in addWarDynamic to modify the War task in
buildWar before it's run. As I said, this works fine in Ant 1.5.4, but
throws that vague exception in Ant 1.6.2.

Example build.xml file:


<project name="SelfServiceReporting" default="buildWar" basedir=".">

       <!--
================================================================= -->
       <!-- make WAR file     -->
       <!--
================================================================= -->
       <target name="buildWar" depends="addWarDynamic" >
       <delete file="deleteMe.war"/>
       <!-- build a .war file for the application -->
               <war destfile="deleteMe.war" webxml="junk-web.xml" update=
"false">
                       <zipfileset dir="images" prefix="gfx/included" >
                               <patternset>
                                       <include name="**/*" />
                               </patternset>
                       </zipfileset>
                       <classes dir="classes" />
               </war>
       </target>

       <target name="addWarDynamic">
               <script language="javascript">
                       <![CDATA[
       // get ahold of the "war" task in the "buildWar" target
       var buildWarTasks = buildWar.getTasks();
       var warTask = null;
       for (var i = 0; i < buildWarTasks.length; ++i) {
           var aTask = buildWarTasks[i];
           if (aTask.getTaskName() == "war") {
               warTask = aTask;
               break;
           }
       }

       // create a ZipFileSet to hold just the reports we've specified
       var reportSet = new
Packages.org.apache.tools.ant.types.ZipFileSet();
       var srcRoot = new java.io.File("includeTest");
       reportSet.setDir(srcRoot);
       reportSet.setPrefix("myStuff");
       reportSet.setIncludes("*");
       // exclude certain files
       var xxx = reportSet.createExclude();
       xxx.setName("**/*.sh");

       // due to a bug in Ant 1.6.x, we have to set the project
explicitly,
       // otherwise we get a null pointer exception in
ZipFileSet.toString()
       reportSet.setProject(project)
       java.lang.System.out.println("\nreportSet.getName()=" +
xxx.getName());
       java.lang.System.out.println("reportSet.toString=" +
reportSet.toString());
       java.lang.System.out.println("warTask=" + warTask.toString());  
       java.lang.System.out.println("warTask.getTaskName()=" +
warTask.getTaskName());
       java.lang.System.out.println("about to addZipfileset()...");
       warTask.addZipfileset(reportSet);
   ]]> </script>
       </target>

</project>



----------------------------
Important news about email communications:

If our business rules identify sensitive information, you will receive a
ZixMail Secure Message with a link to view your message. First-time recipients
will be asked to create a password before they are granted access. To learn
more about ZixMail, ZixCorp Secure Email Message Center, and other ZixCorp
offerings, please go to http://userawareness.zixcorp.com/secure4/index.php
----------------------------

The information contained in this communication may be confidential,
and is intended only for the use of the recipient(s) named above.
If the reader of this message is not the intended recipient, you
are hereby notified that any dissemination, distribution, or
copying of this communication, or any of its contents, is strictly
prohibited. If you have received this communication in error,
please return it to the sender immediately and delete the original
message and any copy of it from your computer system. If you have
any questions concerning this message, please contact the sender.

Unencrypted, unauthenticated Internet e-mail is inherently insecure.
Internet messages may be corrupted or incomplete, or may incorrectly
identify the sender.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.