Download presentation
Presentation is loading. Please wait.
1
CSC 395 – Software Engineering Lecture 24: Apache Ant –or– Programming the results of programming Based upon a talk by Anthony Wat
2
In This Lecture Provide overview of using Apache Ant What does Ant do? How do we use it? Why should I care?
3
Ant in a Nutshell Java-based build tool Uses scripts to automate large processes Enables multiplatform actions Useful aspect of Java-based implementation Scripts must be written to take advantage Many built-in tasks available Javac, Copy, Delete, etc. Can write & import additional tasks
4
Sample Build Script
5
Properties Name-value pair used like variables in scripts Many ways of defining/importing Some properties automatically available basedir ant.file ant.version ant.project.name ant.java.version
6
Define In External File File written in plain text (usually XYZ.properties) Specify in file using name=value Example: bin.dir=${basedir}/bin HelloWorldStr=Hello world. Load file using task: Example:
7
Define Properties Other Ways Use name & value attributes of Example: Specify in command that calls Ant Example: ant -Ddate=050206
8
Using Properties Syntax similar to UNIX environment variables Examples: First line could do 1 of 2 things If HelloWorldStr defined, then ${HelloWorldStr} replaced by its value Otherwise, prints literal value “${HelloWorldStr}”
9
Caution! Characters must escaped in properties files Must escape ‘\’ in Windows-based directories: C:\tmp is bad (\t replaced to become “C:mp”) C:\\tmp is good Do NOT escape ‘\’ inside build script, but instead escape XML characters (e.g. ‘<’ becomes <) Properties like final variable in Java Once defined, cannot easily modify values
10
Filesets A fundamental structures in Ant Define rules including and/or excluding files: Include only.java files in build directory Delete backup files generated by a program Copy only files specified in a list
11
Using Filesets in Ant Use to delete.bak files: or Can often nest multiple
12
Implicit Filesets Some tasks define implicit filesets Include,, Treat task like genuine To compile Ant’s Java files:
13
Chaining Scripts Usually not necessary task calls another script Example: Runs Ant script named other.xml Called script inherits all defined properties New script can also define new properties Enables combining individual projects into single larger project
14
Helper Target Helper targets used like a method Can be called using different parameters task used to call targets Specify parameters using can also override global properties Initially set a default message globally Use to override message when needed
15
Helper Target (cont.) …
16
Building With Ant Run single script to build end-to-end Can also make daily builds Schedule daily builds to run automatically Send e-mails when build available Send e-mails whenever submission breaks build
17
One-Step Build Process Ant provides a lot of useful tasks: check out and update repository & rearrange files & compile and run Java programs executes program from command-line But this will be specific to the system and OS & helps package software Also provides ability to write your own tasks!
18
One-Step Build Process (cont.) Should be enough for end-to-end build Can fit everything into build.xml script Default name for Ant script Otherwise must use -buildfile parameter to run script Start build by running Ant Uses ant or ant.bat in ant\bin directory
19
Build Notification Send as part of build script sends e-mail Today’s build is done
20
Build Notification – Mail Logger Another way is to use the mail logger org.apache.tools.ant.listener.MailLogger Call Ant using the -logger option to specify the logger Example: ant -logger org.apache.tools.ant.listener.MailLogger –DMailLogger.properties.file=mail.properties All of the required properties for the mail logger (SMTP, addresses, etc.) are defined in mail.properties
21
Build Notification – Mail Logger (cont.) Instead of piping output to console, it will be cached and sent as e-mail when the build finishes successfully or fails The logs can be sent to developers Schedule Ant builds with cron (UNIX) or Task Scheduler (Windows)
22
Summary We’ve looked at: Properties and filesets Multiple build scripts and helper targets, which provide better maintainability of build scripts How to achieve one-step automated build process using Ant Ant is used everywhere – from open source projects to commercial software projects A good skill to have
23
For Next Lecture Read about SCM Change is inevitable SCM looks to control the results of changes that occur
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.