Introduction to Ant a framework example - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to Ant a framework example

Description:

Integrated with all major IDEs. March 3rd, 2004. Object Oriented Design Course. 6. Hello world ... Which of them will probably be the default? project name ... – PowerPoint PPT presentation

Number of Views:63
Avg rating:3.0/5.0
Slides: 22
Provided by: davidrab
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Ant a framework example


1
Introduction to Ant-a framework example
  • Amit Shabtay

2
Frameworks
  • A set of cooperating abstract and concrete
    classes that makes up a reusable design for a
    specific class of software
  • An Object-Oriented Reuse Technique
  • Design Reuse Code Reuse

3
Designing an OO Framework
  • Domain Knowledge
  • What applications is the framework for?
  • What is common to all of them?
  • Architecture
  • Biggest, most critical technical decisions
  • What is required besides classes?
  • Object-oriented design
  • Design Reuse Patterns
  • Inversion of Control Find right hooks

4
Ant
  • Yet another build tool?
  • Why do we need one where there are make, gmake,
    namke, imake, etc. ?

5
Ant- Cross Platform Ability
  • A cross platform language needs a cross platform
    build tool
  • Use of XML as the scripting language
  • No more !ing tabs
  • Tasks like javac, javadoc, mkdir, delete, jar and
    many many more
  • Easy to add more tasks
  • junit
  • Integrated with all major IDEs

6
Hello world
  • lt?xml version1.0?gt
  • ltproject nameHello World defaulthellogt
  • lttarget namehello descriptionPrints hello
    Antgt
  • ltecho messageHello Ant/gt
  • lt/targetgt
  • lt/projectgt

lt2500gtdar_at_sands/agt ant Buildfile
build.xml hello echo Hello Ant BUILD
SUCCESSFUL Total time 0 seconds lt2510gtdar_at_sands
/agt
7
Concepts
  • project
  • default which is the default target
  • name the projects name
  • basedir the base directory from which all path
    calculations are done.
  • target
  • Name the targets name
  • Depends - a comma-separated list of names of
    targets on which this target depends.
  • Tasks
  • Where the work is really done!

8
Target Dependencies
  • Suppose we have the following
  • lttarget name"A"/gt
  • lttarget name"B" depends"A"/gt
  • lttarget name"C" depends"B"/gt
  • lttarget name"D" depends"C,B,A"/gt
  • We call ant D, which of the targets will be the
    first to be executed?
  • Which of them will probably be the default?
  • ltproject nameproj default???gt

9
Examples
  • What happens here?lttarget name"A" /gt lttarget
    name"B" /gt lttarget name"" /gt is called a
    wild card
  • And here?lttarget name"build-module-A"
    if"module-A-present" /gt

10
Core tasks
  • Over 80 core tasks!
  • We are going to focus on the basic

11
File System
  • Create new directory
  • ltmkdir dir"lib"/gt
  • Copy file
  • ltcopy file"myfile.txt" tofile"mycopy.txt"/gt
  • ltcopy file"myfile.txt" todir"../some/other/dir"/
    gt
  • Zip the contents of a directory
  • ltzip destfile"manual.zip" basedir"htdocs/manual"
    /gt

12
File Sets (I)
  • How to filter certain files?
  • ltzip destfile"dist/manual.zip"
    basedir"htdocs/manual" includes"api//.html"
    excludes"/todo.html" /gt
  • The use of ltfilesetgt is common
  • ltfileset dir"htdocs/manual"/gt ltfileset
    dir". includes"ChangeLog.txt"/gt

13
File Sets (II)
  • So we will have
  • ltzip destfilemanual.zip"gt
  • ltfileset dir"htdocs/manual"/gt
  • ltfileset dir". includes"ChangeLog.txt"/gt
  • lt/zipgt

14
Properties
  • How to define variables or system specific
    properties?
  • ltproperty namedist.dir" value"dist"/gt
  • ltproperty file"foo.properties"/gt
  • ltproperty environmentenv/gt
  • Use using sign
  • ltzip destfilezip.file basedirdocs/api/
    gt
  • ltecho messagePath is env.PATH/gt(PATH
    should be Path on windows)

15
Java (I)
  • javac
  • ltjavac srcdir"src" destdir"build"
    classpath"xyz.jar" /gt
  • ltjavac srcdir"srcsrc2" destdir"build"
    includes"mypackage/p1/,mypackage/p2/"
    excludes"mypackage/p1/testpackage/"
    classpath"xyz.jar" debug"on" /gt

16
Java (II)
  • jar
  • ltjar destfile"dist/lib/app.jar"
    basedir"build/classes"/gt
  • ltjar destfile"dist/lib/app.jar"
    basedir"build/classes" excludes"/Test.clas
    s" /gt

17
Java (III)
  • junit
  • ltjunitgt
  • lttest name"my.test.AllTests"/gt
  • lt/junitgt

18
Java (IV)
  • Execute Java files
  • ltexec executable"emacs"gt ltenv key"DISPLAY"
    value"1.0"/gt
  • lt/execgt
  • lttarget nametransform dependscompilegt
  • ltjava classname org.codehaus.aspectwerkz.compil
    er.AspectWerkzC forktruegt
  • ltjvmarg value-Daspectwerkz.definition.file
  • src.dir/aspectwerkz.xml/gt
  • ltarg valuebuild.dir/gt
  • lt/javagt
  • lt/targetgt

19
More tasks
  • tar, untar, gzip, gunzip
  • move, delete
  • CVS
  • tstamp
  • mail
  • And many many more

20
Defining new tasks
  • taskdef - Adds a task definition to the current
    project
  • lttaskdef name"myjavadoc" classname"com.mydomain.
    JavadocTask"/gt
  • The task must extend org.apache.tools.ant.Task
  • How does ant knows how to set the tasks
    attributes?

21
Conclusion
  • The de-facto build tool of the Java world
  • Cross-platform
  • Target dependencies
  • http//ant.apache.org/manual/
Write a Comment
User Comments (0)
About PowerShow.com