Austin Java Users Group 2005-Feb-22 Presented by Matt Albrecht.
-
Upload
sydney-robinson -
Category
Documents
-
view
213 -
download
0
Transcript of Austin Java Users Group 2005-Feb-22 Presented by Matt Albrecht.
Austin Java Users Group2005-Feb-22
Presented by Matt Albrecht
Quick Overview Helps organize libraries and inter-
project dependencies in Ant build scripts.
Requires Ant 1.6+, JDK 1.2+ Hosted on Sourceforge:
http://antlion.sf.net Apache 2.0 License
Problem: Dependencies Build relies on external libraries,
which need definitions in Ant: Properties Filesets Paths
Solutions Add and manage each type by
hand. Wait for Ant 1.7, which has limited
library support Use one of several Ant toolkits
which gives Maven-like support
Solution in Antlion Antlion gives you:
User-defined library repository structure
Local and remote repositories Configurable generation of Ant
references and properties Shorthand notation to keep builds
simple and easy to read
Quick Look Define a policy for repository
setup, library entry meta-data, and what to do with Ant.
Declare library groups and their entries.
Policies - Repositories<library-policy id=“policy”>
<repository basedir=“${thirdparty.dir}”>
<format text=“[prj]/[version]/[name].[type]”/>
<format text=
“[prj]/[version]/[name]-[version].[type]” />
<format text=
“[prj]/[version]/[prj]-[version].[type]” />
<format text=
“[prj]/[version]/[prj].[type]” />
</repository>
Policies – Remote repositories
<urlrepository cachedir=“${cache}”
remote=“ftp://internal/repository”
format=“[prj]/[name]-[version].[type]” />
<mavenrepository cachedir=“${maven.cache}” />
Policies – Working with Libs
<attribute attributes=“prj, version” />
<version-check versionAttribute=“version”
matchAttributes=“prj, name, type” />
<must-find />
Policies – Populating Ant
<property format=“lib.[prj].[name]” />
<fileset />
<filelist />
<path />
<manifest-classpath />
Defining Libraries<libraryDef policyRef=“policy”>
<library id=“lib.xerces” prj=“xerces”
version=“2.6.2”>
<lib-entry name=“xercesImpl” />
<lib-entry name=“xmlParserAPIs” />
</library>
Defining Libraries <library id=“compile”>
<library refid=“lib.xerces” />
<lib-entry prj=“junit” version=“3.8.1” />
</library>
</libraryDef>
Using the Libraries<echo>${lib.xerces.xercesImpl}</echo>
<javac …>
<classpath refid=“path.compile” />
</javac>
<copy todir=“${out}/WEB-INF/lib” flatten=“true”>
<fileset refid=“fileset.lib.xerces” />
</copy>
Problem: Inter-build depends The build is divided into several
“modules,” each with their own set of output files, called “artifacts.”
Some modules depend upon other modules to be built.
Dependencies upon dependencies. Build depends only when needed.
Solutions Hand code dependency building.
Using ant-contrib with macrodefs can give you build-if-not-up-to-date functionality, but it can be tricky.
Add paths within paths, but doesn’t scale to filesets.
Solution in Antlion <artifact> defines an output of a build,
the build file target, and can include all of its dependencies.
<artifact> file references are relative to the file containing the <artifact> tag, not basedir. This makes it easy to import artifacts.
<artifact> can be added to a <library>. <subprojects> allows for constructing
targets with the correct should-build logic.
Quick Look: artifacts.xml<project name=“mybuild-artifact”>
<artifact id=“mybuild.jar”
target=“jar” artifact=“export/mybuild.jar”>
<src><include name=“src/**/*.java” /></src>
<depends type=“build”>
<library refid=“lib.xerces” />
</depends>
</artifact>
</project>
Referencing Other Builds<import file=“../mybuild/artifacts.xml” />
<subprojects UseArtifactTarget=“false”
prefix=“SUB”>
<project name=“module” targets=“main”
antfile=“module/build.xml” />
<artifact refid=“mybuild.jar” />
</subprojects>
<target name=“all”
depends=“SUB::module::main, SUB::mybuild.jar”/>
Using Artifacts in Libraries<libraryDef policyRef=“policy”>
<library id=“other-build”>
<artifact refid=“mybuild.jar” />
<dependencies type=“build”
artifactRefId=“mybuild.jar” />
</library>
</libraryDef>
Summary Antlion helps you:
Get your libraries organized, and let the tool do the dirty work for you.
Simplify management of inter-project dependencies.