Welcome To My - PowerPoint PPT Presentation

1 / 42
About This Presentation
Title:

Welcome To My

Description:

When Tomcat became part of the Jakarta project, it became evident that it could ... Part of Apache's Jakarta project. Implemented in Java. Written for Java ... – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 43
Provided by: carlak5
Category:
Tags: jakarta | welcome

less

Transcript and Presenter's Notes

Title: Welcome To My


1
Joe Kueser
  • Welcome To My
  • Ant/Cruise Control

Thing
2
Joe Kueser
Welcome To My Ant/Cruise Control
Thing
3
Whats A Joe Kueser?
  • Have been programming for a whopping 23 years!!!
  • BASIC on a Timex Sinclair 1000
  • BASIC on an Atari 400/800/1040ST
  • Assembly and Pascal on an Apple
  • GW Basic on an IBM 8088
  • Visual Basic, VBA, Mumps, C/C, Java, HTML, WML,
    ASP, JSP, PHP, many flavors of databases.
  • 9 Years Professional Experience
  • Law, Medical, Telecommunications, Wireless, Web
    page development/design, Military Simulation, and
    Homeland Defense

4
Who Cares?
5
Whats He Talking About?
  • Ant
  • Basic Overview
  • Cool Tasks
  • Example Script
  • Typical Uses
  • Not-So-Typical Uses
  • Cruise Control
  • General Overview
  • Advantages/Disadvantages
  • The Future of Cruise Control
  • References
  • Web Pages, Etc.

6
An
Ant
7
A Little History Lesson
  • Ant was originally part of the Tomcat code base,
    and ONLY supported the Tomcat project.
  • When Tomcat became part of the Jakarta project,
    it became evident that it could solve some of the
    problems associated with Make.
  • Released publicly in April of 2000 with Tomcat.
    (Version 0.3.1)
  • First independent release was Ant 1.1 in July of
    2000.

8
What Is Ant?
  • A build tool like make
  • Open Source
  • Part of Apaches Jakarta project.
  • Implemented in Java
  • Written for Java
  • Used to build many open-source Java projects

Ant Development Cycle
9
Why Is It Called Ant?
  • According to the author (James Duncan Davidson)
  • Because ants do an extremely good job of building
    things.
  • Because ants are very small and can carry a dozen
    times their own weight
  • Stands for Another Neat Tool

10
How is Ant like Make?
  • Its a build tool
  • It has build targets make options
    target ant options target
  • That is pretty much where the similarities end

11
How Is Ant Different?
  • XML-based instead of script based.
  • Extended using Java classes.
  • Built-in multi-platform support
  • Automagically builds projects recursively (so
    there is no need for multiple build files.)

12
What Makes Ant So Cool?
  • Only requires a Java VM to use.
  • It is extended using Java classes, which makes it
    almost like fun for Java developers.
  • Easier to do Java-specific tasks, such as
    JavaDocs, WAR and JAR files, and Enterprise
    JavaBeans.
  • Instead of writing cryptic shell commands, the
    configuration files are easy to read XML.
  • Each task is defined in a separate XML block,
    making adding or removing additional tasks a
    breeze.

13
What Makes Ant So Cool? (cont)
  • Its FAST! (Uses the same VM for entire process)
  • Because it is Java based, it is easily
    expandable, and inherently cross-platform.
  • All of the cool Java IDEs have built-in support
    for Ant. (JBuilder seems to be the only
    exception.)
  • It can easily operate recursively, so only one
    Ant build script is required for most projects.
  • Ant has built-in CVS support.
  • Ant has built-in FTP support.
  • Ant has built-in JUnit support.

14
How Does Ant Work?
  • Ant commands (or tasks) are implemented by Java
    classes
  • many tasks are built-in
  • others come in optional JAR files
  • custom commands can be easily created
  • Each project using Ant will have a build file
  • typically called build.xml Ants default
  • Each build file is composed of any number of
    targets
  • these correspond to common activities like
    compiling and running code

15
How Does Ant Work? (cont)
  • Each target is composed of tasks
  • executed in sequence when the target is executed
  • like make, Ant targets can have dependencies
  • for example, the build file may have a task to
    build a JAR file, and can specify that before the
    JAR file can be created, package B needs to be
    compiled, and before package B is compiled,
    package A must be compiled.

16
How Does Ant Work? (cont)
  • Ant Targets
  • Can be specified on the command-line
  • A default can be defined, and will be used if no
    target is specified on the command-line.
  • Ant stops execution of the build when any errors
    are encountered.
  • Generally a good thing, but frustrating on large
    projects.
  • Each target is executed only once, no matter how
    many other targets define it as a dependency.

17
How Does Ant Work? (cont)
  • Ant Targets (cont)
  • Some tasks may be skipped, such as a compile task
    if no source has changed.

18
What Can Ant Do?
  • Compile
  • ltjavacgt
  • lttarget namecompilegt
  • ltjavac srcdirsrc destdirbuild/gt
  • lt/targetgt
  • Package
  • Jar, Tar, War, Zip
  • Test
  • JUnit, Cactus, ltjavagt
  • Document
  • JavaDoc, JUnit Reports, Build Log, Mail/MimeMail

19
What Can Ant Do? (cont)
  • Deploy
  • FTP, Telnet, Unwar, Untar, Unjar, Unzip
  • Source code management
  • CVS, SourceSafe, ClearCase, Perforce
  • and practically anything you want!

20
Ant Gotchas To Watch For
  • Like Unix, Ant doesnt take kindly to spaces in
    filenames. They should be avoided when possible.
  • Using carriage returns in the replace command
    doesnt work well, avoid using them when
    replacing.
  • Ant depends exclusively on date/time stamps to
    decide what needs to be rebuilt, so be careful!

21
Ant Gotchas To Watch For
  • Ant assumes you are using Sun-recommended Java
    package structures. (anything in the
    com.myco.demo package will be found in
    ./com/myco/demo/ directory) If you do not follow
    this convention, you are asking for trouble.
  • Tough to get very large, multi-language projects
    under control. Best to use multiple build files,
    or stick with Make.

22
Build File Example
  • ltproject name"MyProject" default"dist"
    basedir"."gt
  • ltdescriptiongt
  • simple example build file
  • lt/descriptiongt
  • lt!-- set global properties for this build --gt
  • ltproperty name"src" location"src"/gt
  • ltproperty name"build" location"build"/gt
  • ltproperty name"dist" location"dist"/gt
  • lttarget name"init"gt
  • lt!-- Create the time stamp --gt
  • lttstamp/gt
  • lt!-- Create the build directory used by
    compile --gt
  • ltmkdir dir"build"/gt
  • lt/targetgt

23
Build File Example
  • lttarget name"compile" depends"init"
  • description"compile the source " gt
  • lt!-- Compile code from src into build
    --gt
  • ltjavac srcdir"src" destdir"build"/gt
  • lt/targetgt
  • lttarget name"dist" depends"compile"
  • description"generate the distribution" gt
  • lt!-- Create the distribution directory --gt
  • ltmkdir dir"dist/lib"/gt
  • lt!-- Put everything in build into the
    MyProject-DSTAMP.jar file --gt
  • ltjar jarfile"dist/lib/MyProject-DSTAMP.
    jar" basedir"build"/gt
  • lt/targetgt

24
Build File Example
  • lttarget name"clean"
  • description"clean up" gt
  • lt!-- Delete build and dist dirs --gt
  • ltdelete dir"build"/gt
  • ltdelete dir"dist"/gt
  • lt/targetgt
  • lt/projectgt

25
Executing An Ant Script
  • In its basic form, an Ant script can be run by
    simply typing Ant
  • Command-line option summaryant options
    target target2 target3 ...
  • Options (trimmed to fit page)-help print
    this message -projecthelp print project help
    information -version print the version
    information and exit -quiet be extra quiet
    -verbose be extra verbose -logfile file use
    given file for log output -logger classname the
    class that performs logging-listener classname
    add class as a project listener -buildfile file
    use specified buildfile -Dpropertyvalue set
    property to value

26
Ants Commands
  • ant -projecthelp
  • lists targets in build.xml of the current
    directory
  • Searching for build.xml ...
  • Buildfile C\MyJava\Samples\build.xml
  • Main targets
  • clean deletes all generated files
  • compile compiles source files
  • deploy deploys the war file to Tomcat
  • dtd generates a DTD for Ant build files
  • javadoc generates javadoc from all .java files
  • prepare create output directories
  • test runs all JUnit tests
  • undeploy undeploys the war file from Tomcat
  • war builds the war file

27
Ant Commands
  • ltant/gt
  • calls a target in another build file
  • useful to build subprojects
  • ltantstructure/gt
  • generates a DTD describing all known tasks
  • ltcvs/gt
  • executes any CVS command
  • ltexec/gt
  • executes a system command
  • ltexecon/gt
  • like Exec but files and directories are passed as
    arguments to the system command
  • ltfilter/gt
  • used by tasks that copy files to replace all
    occurrences of an _at_ delimited string with another
    string

28
Ant Commands
  • ltfixcrlf/gt
  • changes line endings in a set of files to the
    convention of the current OS
  • ltget/gt
  • creates a copy of a remote file at a specified
    URL
  • can use http and ftp URLs
  • ltjavadoc/gt
  • generates javadoc HTML files from Java source
    files
  • ltmail/gt
  • sends email using SMTP
  • ltmkdir/gt
  • creates a directory and any missing parent
    directories
  • ltpatch/gt
  • applies a diff to file

29
Ant Commands
  • ltproperty/gt
  • sets properties that can be used in the current
    target and other targets
  • can load from a property file
  • ltreplace/gt
  • replaces all occurrences of a string with another
    string in a file
  • ltrmic/gt
  • runs the rmic compiler on .class files of Java
    classes that implement java.rmi.Remote
  • ltsignjar/gt
  • uses javasign to add a digital signature to a jar
    or zip file
  • ltsql/gt
  • executes a sequence of SQL statements specified
    in the build file or an external text file
  • output can be written to a file
  • ltstyle/gt (alias ltxslt/gt)
  • applies an XSLT stylesheet to a set of XML files
    to produce a set of output files

30
Ant Commands
  • lttaskdef/gt
  • defines a custom task that can be used in the
    project
  • lttouch/gt
  • creates a file if it doesnt exist
  • updates its modification time if it does
  • ltunjar/gt
  • expands a JAR file
  • ltuntar/gt
  • expands a TAR file
  • lttstamp/gt
  • sets the DSTAMP (ccyymmdd, i.e., 20020926),
    TSTAMP (hhmm) and TODAY (month day year)
    properties to the current date/time
  • useful for creating files and directories with
    names that reflect their creation date/time

31
Ant Commands (New to 1.5)
  • ltcvschangelog/gt
  • generates an XML report of changes that occur on
    CVS repository.
  • ltloadpropertiesgt
  • to load contents of file as Ant properties.
  • ltloadfilegt
  • to load a whole file into a property.
  • ltechopropertiesgt
  • to list your current properties to the screen or
    a file.
  • ltreplaceregexpgt, ltchecksumgt, lttranslategt,
    ltwaitforgt, ltmanifestgt,ltvsscreategt, ltsplashgt,
    ltconcatgt, ltsourceoffsitegt, ltjarlib-availablegt,
    ltjarlib-displaygt,.

32
Ant Optional Tasks
  • Cab
  • creates a Microsoft CAB archive from a set of
    files
  • FTP
  • lists, gets, puts and deletes files on an FTP
    server
  • JavaCC
  • CC stands for Compiler Compiler
  • reads a grammar specification and creates a Java
    application that can recognize matches to the
    grammar
  • Jlink
  • builds jar/zip files by merging entries from
    multiple jar/zip files
  • JUnit
  • runs JUnit tests
  • Script
  • executes a script written in a Bean Scripting
    Framework (BSF) language
  • includes JavaScript, PerlScript, VBScript,
    JPython and others

33
Creating Custom Tasks
  • Steps
  • create a Java class that
  • extends org.apache.tools.ant.Task
  • has a no-arg constructor
  • plan the attributes, text and child elements that
    your task element will use
  • for each attribute, add a set method
  • public void setAttrName(type attrName)
  • type can be String or any Java primitive type
  • for text, add an addText method
  • public void addText(String text)

34
Creating Custom Tasks
  • Steps (contd)
  • for each child element, add a create or add
    method
  • public ChildTask createChildTask()
  • for empty child task elements
  • public void addChildTask(ChildTask child)
  • for non-empty child task elements
  • add the method that implements the tasks
  • public void execute()
  • compile the class
  • insure that it can be found using the CLASSPATH
    environment variable

35
Creating Custom Tasks
  • import org.apache.tools.ant.BuildException
  • import org.apache.tools.ant.Task
  • public class MyVeryOwnTask extends Task
  • private String msg
  • // The method executing the task
  • public void execute() throws BuildException
  • System.out.println(msg)
  • // The setter for the "message" attribute
  • public void setMessage(String msg)
  • this.msg msg

36
Ant External Tasks/Tools
  • Anakia
  • XML transformation tool based on JDOM, Velocity
    and Ant.
  • Anteater
  • a set of Ant tasks for the functional testing of
    websites and web services.
  • Checkstyle
  • help programmers write Java code that adheres to
    a coding standard.
  • CleanImports
  • Removes unneeded imports and formats import
    sections.
  • Clover
  • an Ant-based Code Coverage tool. Provides method,
    statement, and branch coverage analysis
  • jMetra
  • tool for collecting code metrics. Compiles the
    results into JavaDoc-styled documentation to
    analyze project metrics over time.

37
Cruise Control
  • Open Source
  • a set of tasks to automate the checkout/
    build/test cycle
  • provides a servlet for viewing the status of the
    current build as well as the results of previous
    builds

38
Advantages of Using CC
  • Easy Setup
  • Install a Servlet under TomCat
  • Edit a well documented config file
  • Execute a shell/bat script
  • Watches CVS, and kicks off a build
    automatically when any new files are detected.
  • Emails anyone defined in the config file whenever
    a build fails

39
Advantages of Using CC
  • Will report that build was successful when it is
    fixed.
  • Can do a clean build at an interval you
    specify. (Means quicker incremental builds.)
  • Has built-in support for JUnit, for automated
    tests after every build.
  • Reports JUnit results, and build results on a web
    page generated by servlet.

40
A Few Downfalls
  • Does a build when ANY file is checked in,
    including data files, and then generates a Build
    Failed message because no build was needed.
  • Because it doesnt always do a clean build,
    removing or moving files can cause a long series
    of build failed messages.
  • Some flakiness when changing JDKs, such as
    missing build results.

41
The Future of CruiseControl
  • Last version was released over a year ago.
  • CORRECTION CC 2 was released on Friday, Sept 27,
    2002 (the day after the presentation)
  • A lot of Ant 1.5s new features make the hoops
    Cruise Control jumps through unnecessary, with
    many of Cruise Controls features now supported
    natively.
  • Development of CruiseControl 2.0 began about 2
    months ago, though there is no indication on the
    site of what we should expect.

42
References
  • Ant Web Pages
  • http//jakarta.apache.org/ant
  • http//jakarta.apache.org/ant/resources.html
  • http//www.jguru.com/faq/Ant
  • Ant Mailing Lists
  • ant-user_at_jakarta.apache.org
  • ant-dev_at_jakarta.apache.org
  • Cruise Control
  • http//cruisecontrol.sourceforge.net/
  • http//www.cruisecontrol.com/
Write a Comment
User Comments (0)
About PowerShow.com