ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peterrei...@apache.org>
Subject Re: Ant 1.6 API: Can't call War.addZipfileset() from JavaScript
Date Tue, 28 Jun 2005 12:37:23 GMT
I do not have time to look into this too much. However
the "unknownelement" is due to a difference in timing
of converting of xml classes to java tasks from ant 1.5 to ant 1.6.
Look at:
http://ant.apache.org/faq.html#unknownelement.taskcontainer

Your code does something similar:

        for (var i = 0; i < buildWarTasks.length; ++i) {
            var aTask = buildWarTasks[i];
            if (aTask.getTaskName() == "war") {
                warTask = aTask;
                break;
So you may need to configure the task?, I am not sure if
the approach will work anymore.

Peter


Lou_Miranda@bluecrossmn.com wrote:

>Any ideas on this? It's preventing us from upgrading to Ant 1.6, which we 
>need to do because of other dependencies. Am I doing something horribly 
>wrong? Any workarounds come to mind?
>
>Thanks.
>
>
>Lou_Miranda@bluecrossmn.com wrote on 06/24/2005 10:50:16 AM:
>
>  
>
>>More info:
>>
>>It's interesting to note that the output from Ant 1.5.4 shows:
>>   [script] 
>>reportSet.toString=org.apache.tools.ant.types.ZipFileSet@18f1d7e
>>   [script] warTask=org.apache.tools.ant.taskdefs.War@d9660d
>>
>>...whereas the output from Ant 1.6.2 shows:
>>   [script] reportSet.toString=fileRealm.properties
>>   [script] warTask=org.apache.tools.ant.UnknownElement@8ee016
>>
>>Ant 1.5.4 seems to know what type the references are, whereas Ant 1.6.2 
>>uses "UnknownElement". Is that the problem?
>>
>>
>>When I run the build.xml from my previous message, the output from Ant 
>>1.5.4 is:
>>
>>****** BEGIN ANT 1.5.4 OUTPUT *********
>>
>>Apache Ant version 1.5.4 compiled on August 12 2003
>>Buildfile: build.xml
>>Detected Java version: 1.4 in: C:\Program Files\Java\jdk142_06\jre
>>Detected OS: Windows 2000
>>parsing buildfile build.xml with URI = file:M:/.../___test/build.xml
>>Project base dir set to: M:\...\___test
>>Build sequence for target `buildWar' is [addWarDynamic, buildWar]
>>Complete build sequence is [addWarDynamic, buildWar]
>>
>>addWarDynamic:
>>
>>   [script] reportSet.getName()=**/*.sh
>>   [script] 
>>reportSet.toString=org.apache.tools.ant.types.ZipFileSet@18f1d7e
>>   [script] warTask=org.apache.tools.ant.taskdefs.War@d9660d
>>   [script] warTask.getTaskName()=war
>>   [script] about to addZipfileset()...
>>
>>buildWar:
>>   [delete] Deleting: M:\...\___test\deleteMe.war
>>      [war] Building war: M:\...\___test\deleteMe.war
>>      [war] adding directory META-INF/
>>      [war] adding entry META-INF/MANIFEST.MF
>>      [war] adding directory gfx/
>>      [war] adding directory gfx/included/
>>      [war] adding entry gfx/included/blank.gif
>>...
>>      [war] adding directory WEB-INF/
>>      [war] adding directory WEB-INF/classes/
>>      [war] adding directory WEB-INF/classes/com/
>>...
>>      [war] adding directory myStuff/
>>...
>>      [war] adding entry WEB-INF/web.xml
>>
>>BUILD SUCCESSFUL
>>Total time: 3 seconds
>>
>>****** END ANT 1.5.4 OUTPUT *********
>>
>>
>>... and the output from 1.6.2 is:
>>
>>
>>****** BEGIN ANT 1.6.2 OUTPUT *********
>>
>>Apache Ant version 1.6.2 compiled on July 16 2004
>>Buildfile: build.xml
>>Detected Java version: 1.4 in: C:\Program Files\Java\jdk142_06\jre
>>Detected OS: Windows 2000
>>parsing buildfile M:\...\___test\build.xml with URI = 
>>file:///M:/.../___test/build.xml
>>Project base dir set to: M:\...\___test
>>Build sequence for target `buildWar' is [addWarDynamic, buildWar]
>>Complete build sequence is [addWarDynamic, buildWar, ]
>>
>>addWarDynamic:
>>   [script]
>>   [script] reportSet.getName()=**/*.sh
>>   [script] reportSet.toString=fileRealm.properties
>>   [script] warTask=org.apache.tools.ant.UnknownElement@8ee016
>>   [script] warTask.getTaskName()=war
>>   [script] about to addZipfileset()...
>>
>>BUILD FAILED
>>M:\...\___test\build.xml:20: TypeError: undefined is not a function.
>>        at 
>>org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.jav
>>a:139)
>>        at 
>>org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:60)
>>
>>        at 
>>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
>>        at org.apache.tools.ant.Task.perform(Task.java:364)
>>        at org.apache.tools.ant.Target.execute(Target.java:341)
>>        at org.apache.tools.ant.Target.performTasks(Target.java:369)
>>        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
>>        at 
>>    
>>
>org.apache.tools.ant.Project.executeTargets(Project.java:1062)
>  
>
>>        at org.apache.tools.ant.Main.runBuild(Main.java:673)
>>        at org.apache.tools.ant.Main.startAnt(Main.java:188)
>>        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
>>        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
>>Caused by: TypeError: undefined is not a function.
>>        at org.mozilla.javascript.NativeGlobal.constructError(Unknown 
>>Source)
>>        at org.mozilla.javascript.NativeGlobal.constructError(Unknown 
>>Source)
>>        at org.mozilla.javascript.NativeGlobal.typeError1(Unknown 
>>    
>>
>Source)
>  
>
>>        at org.mozilla.javascript.ScriptRuntime.call(Unknown Source)
>>        at org.mozilla.javascript.gen.c1.call(Unknown Source)
>>        at org.mozilla.javascript.gen.c1.exec(Unknown Source)
>>        at org.mozilla.javascript.Context.evaluateReader(Unknown Source)
>>        at org.mozilla.javascript.Context.evaluateString(Unknown Source)
>>        at 
>>    
>>
>org.apache.bsf.engines.javascript.JavaScriptEngine.eval(Unknown 
>  
>
>>Sourc
>>e)
>>        at org.apache.bsf.util.BSFEngineImpl.exec(Unknown Source)
>>        at org.apache.bsf.BSFManager$6.run(Unknown Source)
>>        at java.security.AccessController.doPrivileged(Native Method)
>>        at org.apache.bsf.BSFManager.exec(Unknown Source)
>>        at 
>>org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.jav
>>a:128)
>>        ... 11 more
>>--- Nested Exception ---
>>TypeError: undefined is not a function.
>>        at org.mozilla.javascript.NativeGlobal.constructError(Unknown 
>>Source)
>>        at org.mozilla.javascript.NativeGlobal.constructError(Unknown 
>>Source)
>>        at org.mozilla.javascript.NativeGlobal.typeError1(Unknown 
>>    
>>
>Source)
>  
>
>>        at org.mozilla.javascript.ScriptRuntime.call(Unknown Source)
>>        at org.mozilla.javascript.gen.c1.call(Unknown Source)
>>        at org.mozilla.javascript.gen.c1.exec(Unknown Source)
>>        at org.mozilla.javascript.Context.evaluateReader(Unknown Source)
>>        at org.mozilla.javascript.Context.evaluateString(Unknown Source)
>>        at 
>>    
>>
>org.apache.bsf.engines.javascript.JavaScriptEngine.eval(Unknown 
>  
>
>>Sourc
>>e)
>>        at org.apache.bsf.util.BSFEngineImpl.exec(Unknown Source)
>>        at org.apache.bsf.BSFManager$6.run(Unknown Source)
>>        at java.security.AccessController.doPrivileged(Native Method)
>>        at org.apache.bsf.BSFManager.exec(Unknown Source)
>>        at 
>>org.apache.tools.ant.util.ScriptRunner.executeScript(ScriptRunner.jav
>>a:128)
>>        at 
>>org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:60)
>>
>>        at 
>>org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
>>        at org.apache.tools.ant.Task.perform(Task.java:364)
>>        at org.apache.tools.ant.Target.execute(Target.java:341)
>>        at org.apache.tools.ant.Target.performTasks(Target.java:369)
>>        at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
>>        at 
>>    
>>
>org.apache.tools.ant.Project.executeTargets(Project.java:1062)
>  
>
>>        at org.apache.tools.ant.Main.runBuild(Main.java:673)
>>        at org.apache.tools.ant.Main.startAnt(Main.java:188)
>>        at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
>>        at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)
>>
>>Total time: 3 seconds
>>
>>****** END ANT 1.6.2 OUTPUT *********
>>
>>Lou_Miranda@bluecrossmn.com wrote on 06/23/2005 01:56:55 PM:
>>
>>    
>>
>>>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@ant.apache.org
>>>For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>      
>>>
>>---------------------------- 
>>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@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
>>
>>    
>>
>
>
>---------------------------- 
>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@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message