Bug 29374 - Adding ant build script validation support
Summary: Adding ant build script validation support
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.1
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-06-03 19:00 UTC by Scott Coleman
Modified: 2008-11-24 03:58 UTC (History)
0 users



Attachments
Partial Ant 1.6.5 schema (347.12 KB, text/xml)
2005-10-28 05:58 UTC, Nicole Tedesco
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Scott Coleman 2004-06-03 19:00:39 UTC
Hi,

I was wondering whether there is currently any support for validing the ant 
build script, by this I mean some sort of XML Schema support so that when the 
ant build script is parsed all errors can be reported and fixed prior to any 
task being executed.

Regards,
Scott
Comment 1 Jay Drummond 2004-07-07 20:17:17 UTC
Try editing with jedit. www.jedit.org

Go to Plugins - Plugin Manager

Add at least these plugins.
XML
XML Indenter
XSLT
ErrorList

Set ErrorList up to automatically show errors on save. Utilities->Global 
Options->Plugins->ErrorList-> check automatically display on error. You can 
also have the ErrorList window dock (I dock left set by Utilities->Global 
Options->JEdit->Docking->ErrorList->Left) so it doesn't get in the way.

This catches many of the errors that have to do with XML syntax of the 
document, like missing closing tags, missing quotes on attributes, etc...

There are also some ANT specific plugins, but I find that the XML stuff finds a 
lot of errors. 

I use jedit 4.1 which is the stable version.


Comment 2 Nicole Tedesco 2005-10-28 05:58:42 UTC
Created attachment 16826 [details]
Partial Ant 1.6.5 schema

The attached XML schema is a partial Ant validation schema.  As it stands now,
and  especially when it becomes complete, can work quite well for Ant build
file validation, and retained desired flexibility either by:

* Writing extending schemas which include new tasks and macros defined through
taskdef and macrodef, or...

* "element" elements in macrodefs (for instance) support defining elements that
can be assigned to different namespaces.  You can see within this partial
schema that I have littered it with many "any" elements which validate against
##other namespaces.  This is the only way to encode flexibility in a schema
without becoming ambiguosly non-unique (try changing the ##others to ##any and
you'll see what I mean).  I would really, really like this feature.

Example of a macrodef with an element from another namespace (assume the mchx
namespace was defined on the project element to be some namespace,
http://www.foo.com/ant):

	
<target name="-init-macrodef-java" depends="-init">
	<macrodef name="java" uri="http://www.marchex.com/ant">
		<attribute name="classname" default="${main.class}"/>
		<element name="mchx:customize" optional="true"/>
		<sequential>
			<java fork="true" classname="@{classname}">
				<jvmarg line="${runmain.jvmargs}"/>
				<classpath>
					<path
path="${build.classes.dir.real}:${javac.classpath}:${j2ee.platform.classpath}"/>

				</classpath>
				<syspropertyset>
					<propertyref prefix="run-sys-prop."/>
					<mapper type="glob"
from="run-sys-prop.*" to="*"/>
				</syspropertyset>
				<mchx:customize/>
			</java>
		</sequential>
	</macrodef>
</target>
Comment 3 Nicole Tedesco 2005-10-28 06:00:36 UTC
BTW, while the schema is legal and the build fragment in the previous comment
passes validation, Ant 1.6.5 rejects it with a " Illegal name [mchx:customize]
for attribute" error and fails the build.
Comment 4 Steve Loughran 2005-10-28 11:38:01 UTC
First, I personally think XSD is evil, and that is speaking as someone who works
in standards bodies for whom XSD and WSDL are the core outputs.

putting that aside, ant also abuses xml namespaces to make namespace'd
macros/tasks/presets easier to use. When you have a task in a namespace, ant
will accept child elements that are either in the same namespace, or the default
namespace: we match on the name, not the qname. 
A generated schema would have to take this into account by offering a choice of
child elements in both namespaces.