29
What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Embed Size (px)

Citation preview

Page 1: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

What’s new in Ant 1.6

Tim DawsonChief ArchitectInternational Decision Systems

Page 2: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Sources of Information

My own experiences updating the build system for a 9000-file J2EE project.

Ant 1.6 online docs Erik Hatcher’s TCSS presentation

Page 3: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Overview

“Finally, a real build tool.” – posting at TSSHuh? People have been using Ant for

years.Make, without make’s wrinkles (but with

some new ones!)Before 1.6, Ant could be very painful for

large projects (consisting of lots of subprojects).

Page 4: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Common Complaints

Lack of support for build-file standardization (Maven, anyone?)

Difficult to package custom tasks/types (e.g. WebLogic’s inclusion of Ant)

No modularization (build file reuse) Tight-coupling between parent/child

projects requires extra maintenance.

Ant 1.6 fixes all this

Page 5: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

How?

Ability to import other build files and reuse targets and tasks (import)

Ability to create tasks in Ant (macrodef)

Better packaging for libraries of tasks, types in Java (antlib)

Ability to easily build multiple subprojects (subant)

Page 6: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Build File Reuse

<project name=“import”> <import file=“common.xml”/>

<target name=“foo” depends=“bar”> <echo>foo</echo> </target></project>

<project name=“common”>

<target name=“bar”> <echo>bar</echo> </target>

</project>

common.xmlbuild.xml

Page 7: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Build File Reuse

> ant fooBuildfile: build.xml

bar: [echo] bar

foo: [echo] foo

BUILD SUCCESSFULTotal time: 0 seconds

> ant barBuildfile: build.xml

bar: [echo] bar

BUILD SUCCESSFULTotal time: 0 seconds

build.xml common.xml

Page 8: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Build File Reuse

Usages IncludeStandard targets: clean, compile, build,

installHighlighting differences (e.g. this

subproject creates a lucene index of all html pages)

Limitations:Can only “call super” with depends or

(ugh) antcall. (but there is a workaround)

Page 9: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Build File Reuse

myProject/ lines common/build.xml 244 ejbsub1/build.xml 372 ejbsub2/build.xml 350 ejb-utils/build.xml 208 utils/build.xml 249 webapp1/build.xml 245 webapp2/build.xml 260 web-utils/build.xml 203 build.xml 341

myProject/ lines ant/build-java.xml 293 ant/build-ejb.xml 323 ant/build-web.xml 63 common/build.xml 15 ejbsub1/build.xml 12 ejbsub2/build.xml 12 ejb-utils/build.xml 7 utils/build.xml 5 webapp1/build.xml 12 webapp2/build.xml 12 web-utils/build.xml 7 build.xml 130

before after

Page 10: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: macrodef

No more <antcall>! Defines a new task using a

<sequential> nested task as a template Nested elements <attribute> and

<element> specify attributes and elements of the new task

Attributes/elements substituted into the <sequential> task at runtime

Page 11: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: macrodef

<project name=“macrodef” default=“foo”> <macrodef name="bar"> <attribute name="msg"/> <sequential> <echo>bar: @{msg}</echo> </sequential> </macrodef>

<target name="foo"> <bar msg="sent from foo"/> </target></project>

> antBuildfile: build.xml

foo: [echo] bar:sent from foo

BUILD SUCCESSFULTotal time: 0 seconds

build.xml output

Page 12: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: macrodef

Usages include:Executing <java> tasks when you don’t want

to take the time to write a task in Java e.g. calling a vendor’s jspc class

Specifying post-dependencies for overrides e.g. define task “compile” and target “compile”<target name=“compile” description=“override”> <mkdir…/><compile/><delete…/></target>

Page 13: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: presetdef

Defines a new task using any other task as a template

Arguments provided to the template task are simply used as defaults

Property resolution takes place when the preset definition is used, not when it’s defined.

Page 14: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: presetdef

<project name=“presetdef” default=“foo”> <presetdef name="my.echo"> <echo message="default message"/> </presetdef> <target name="foo"> <my.echo/> <my.echo message=" override message"/> </target></project>

> antBuildfile: build.xml

foo: [my.echo] default message [my.echo] override

BUILD SUCCESSFULTotal time: 0 seconds

build.xml output

Page 15: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Defining Tasks in Ant: presetdef

Usages Include:??? (I’m open to suggestions)

With build-file inclusion, this doesn’t seem that useful.

Rather than “my.javac”, just define <target name=“compile”> and use properties to define src and output dirs.

Page 16: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Task/Type Libraries: old way

Didn’t support XML namespaces Usage was somewhat difficult

Lots of <taskdef> or <typedef> calls - or -Modify default.properties in

org.apache.tools.ant.taskdefs

<taskdef resource="checkstyletask.properties" classpath="extensions/checkstyle/checkstyle-all-3.3.jar"/><taskdef name="queryConstantGen" classname="com.thoughtworks.tools.sqlgen.QueryXMLConstantGen" classpath="${twtasks}; ${jdbc};${jdom}"/><taskdef name="proxygen" classname="com.thoughtworks.tools.proxygen.ProxyGenTask" classpath="${twtasks}"/><taskdef name="schemac" classname="com.thoughtworks.util.schemac.SchemacTask" classpath="${twtasks};${schemac}"/><taskdef name="sqlgen" classname="com.thoughtworks.tools.sqlgen.SQLGen" classpath="${twtasks}"/><taskdef name="sqlcheck" classname="com.thoughtworks.tools.sqlgen.SQLChecker" classpath="${twtasks}; ${jdbc}"/><taskdef name="queryXMLcheck" classname="com.thoughtworks.tools.sqlgen.QueryXMLChecker" c classpath="${twtasks}; ${jdbc};${jdom}"/><taskdef name="getDBConstraints" classname="com.thoughtworks.tools.sqlgen.FieldLengthReader" classpath="${twtasks}; ${jdbc}"/><taskdef name="javancss" classname="com.thoughtworks.tools.javancss.JavaNcss" classpath="${twtasks}"/>

Page 17: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Task/Type Libraries: antlib

Now, simply include a deployment descriptor in your jar file with your custom tasks/types

Reference the package with an xml namespace (e.g. xmlns:ids="antlib:com.idsgrp.ant“)

Put the jar file in your classpath (more on this later)

Page 18: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Task/Type Libraries: antlib

<?xml version="1.0"?><antlib> <typedef name="writable" classname="example.WritableFileSelector"/></antlib>

(located in the example package)

<project name="antlib" default="build" xmlns:example= "antlib:example"> <target name=“build”> <copy todir="build"> <fileset dir="src"> <example:writable/> </fileset> </copy> </target></project>

Definition - antlib.xml Usage - build.xml

Page 19: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Managing Subprojects: subant

Remember how Make used to traverse subdirectories looking for a build files to execute?

Previously, you had to use <ant> for each and every subproject.

Now, <subant> will automatically do that work for you.

Page 20: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Managing Subprojects: subant

<project name=“myproject”> <target name="build"> <subant> <filelist dir="." files="import/build.xml macrodef/build.xml presetdef/build.xml antlib/build.xml"/> </subant> </target></project>

<project name=“myproject”> <target name="build-old"> <ant dir="import"/> <ant dir="macrodef"/> <ant dir="presetdef"/> <ant dir="antlib"/> </target></project>

New way Old way

How is this better?

Page 21: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Managing Subprojects: subant

<project name=“myproject”> <filelist id=“subs” dir="." files="import/build.xml macrodef/build.xml presetdef/build.xml antlib/build.xml"/> <target name=“clean"> <subant target=“clean”> <filelist refid=“subs”/> </subant> </target>…

<target name="build">

<subant target=“build”>

<filelist refid=“subs”/>

</subant>

</target>

</project>

Multiple Targets

Page 22: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

To Recap…

Ability to import other build files and reuse targets and tasks (import)

Ability to create tasks in Ant (macrodef) Better packaging for libraries of tasks,

types in Java (antlib) Ability to easily build multiple subprojects

(subant)

Page 23: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

But Wait, There’s More

New Command-line Options Java 1.2 required New Classloader XML Namespaces All tasks can now live outside targets New Tasks

Page 24: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

New Command Line Options

Aliases-h = -help-p = -projecthelp-d = -debug-s = -find

New -lib -k / -keep-going -noinput

Page 25: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

New Classloader

Search OrderDirectories/jars specified on command

line with “-lib” argument$CLASSPATH

(actually added to –lib by wrapper script)

.jar files from ${user.home}/.ant/lib$ANT_HOME/lib

Page 26: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Tasks Outside Targets

Previously, only some tasks could live outside targets. In particular, property, typedef, and taskdef Required “init” targets with dependencies

everywhere Now, any task can live outside a target

Executed at parse time Eliminates unnecessary “init” targets

Page 27: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Other New Tasks

DefaultExcludescan now modify default excludes

Syncadds/removes files from destination to

match source Scriptdef

similar to taskdef & macrodef, but with scripts

Page 28: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved

         

         

Creative Commons

In case you noticed the “cc” at the bottom instead of the usual copyright… here’s a brief overview of what that’s all about:

Creative Commons was started by Lawrence Lessig after the Supreme Court rejected his request to declare the Sonny Bono Copyright Extension Act unconstitutional. His latest book (available in print and free download) highlights the

dangers of our oppressive legal landscape surrounding copyrights. All content is copyrighted automatically and requires lawyers to

navigate the fair-use landscape. Even if you think you’re ok, anyone can sue you and the risks of huge fines and certainty of nonrecoverable legal fees stifles a lot of creative freedom.

The goal of Creative Commons is to allow content creators who want to share to do so easily/effectively.

This presentation is licensed with the creative commons “attribute-sharealike 1.0” license available athttp://creativecommons.org/licenses/by-sa/1.0/

Page 29: What’s new in Ant 1.6 Tim Dawson Chief Architect International Decision Systems

Tim Dawson, Some Rights Reserved