Chapter 3 Understanding Ant datatypes and properties.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 4 Writing Java Applications, Java Development Tools.
Advertisements

ANT: Another Nice Tool Ali Beyad October 1, 2003.
ANT – Another Neat Tool Representation and Management of Data on the Internet.
ANT: Another Nice Tool Ali Beyad October 1, 2003.
Lists Introduction to Computing Science and Programming I.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Ant – Another Neat Tool Representation and Management of Data on the Internet.
© S Ramakrishnan1 Systems V & V, Quality and Standards Dr Sita Ramakrishnan School CSSE Monash University.
CSC 395 – Software Engineering Lecture 24: Apache Ant –or– Programming the results of programming Based upon a talk by Anthony Wat.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
File Management System The way a user or application may access files Programmer does not need to develop file management software You take files for granted.
Chapter 11 ASP.NET JavaScript, Third Edition. 2 Objectives Learn about client/server architecture Study server-side scripting Create ASP.NET applications.
Introduction to Ant- a framework example Amit Shabtay.
Using Ant to build J2EE Applications Kumar
Introduction to ant Guy Rixon AstroGrid Consortium Meeting
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 Python Control of Flow and Defining Classes LING 5200 Computational Corpus Linguistics Martha Palmer.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Mohammed Mohsen Links Links are what make the World Wide Web web-like one document on the Web can link to several other documents, and those.
JavaScript, Fourth Edition
Apache Ant Java-Based Build Tool. Making your builds boring… Building projects should be easy and standardized. You should not be spending a substantial.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Chapter 6: Modularity Using Functions. In this chapter, you will learn about: – Function and parameter declarations – Returning a single value – Returning.
C++ for Engineers and Scientists Second Edition Chapter 6 Modularity Using Functions.
Ant Build Tools.  Creating a product from source may take several steps: Compile Link Copy files to various directories Remove intermediate files Generate.
Chapter Two Exploring the UNIX File System and File Security.
July 2011CMSC 341 CVS/Ant 1 CMSC 341 Java Packages Ant CVS Project Submission.
Variables and Functions. Open your Encoder program Let’s begin by opening the “Labyrinth Auto Straight” code. Save this file as Labyrinth with variables.
Ant Presentation by: Bart Taylor. What is Ant? The simple definition: A Java-based build tool The Official Definition: “Apache Ant is a Java-based build.
Test Automation For Web-Based Applications Portnov Computer School Presenter: Ellie Skobel.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
Live and Learn – ant. Resources  Ant User Manual  Skip the book, most of the material is right here  Apache.
Overview of the Automated Build & Deployment Process Johnita Beasley Tuesday, April 29, 2008.
Software Development COMP220/COMP285 Seb Coope Introducing Ant These slides are mainly based on “Java Development with Ant” - E. Hatcher & S.Loughran.
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 1 Introducing Ant. What is ant? Ant is a build tool  Automate the tasks of compiling code, running test, and packaging the results for redistribution.
CS-1030 Dr. Mark L. Hornick 1 Basic C++ State the difference between a function/class declaration and a function/class definition. Explain the purpose.
Henrik Bærbak Christensen1 Build Management Clean environment that works...
Building Packages BCIS 3680 Enterprise Programming.
File Paths *referenced from
CSC 110 – Intro to Computing - Programming
15 – PHP(5) Informatics Department Parahyangan Catholic University.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
XML Schema – XSLT Week 8 Web site:
Using Ant in Eclipse Dwight Deugo Nesa Matic
Software Development Tools COMP220 Seb Coope Ant: Datatypes and Properties These slides are mainly based on “Java Development with Ant” - E. Hatcher &
Software Development COMP220 Seb Coope Ant: Structured Build These slides are mainly based on “Java Development with Ant” - E. Hatcher & S.Loughran. Manning.
Software Development Tools COMP220 Seb Coope Ant: Datatypes and Properties These slides are mainly based on “Java Development with Ant” - E. Hatcher &
An Introduction to Ant. What is Ant? How do you use it? Why would you want to?
Software Development Tools
Querying and Transforming XML Data
Play Framework: Introduction
The Command Prompt Commands are the way to “do things” in Unix
Arrays and files BIS1523 – Lecture 15.
C++ for Engineers and Scientists Second Edition
PL/SQL Scripting in Oracle:
Exploring the UNIX File System and File Security
Ant.
Chapter 3 Introduction to Classes, Objects Methods and Strings
The Linux Command Line Chapter 4
Nilanjan Banerjee Java Packages Ant CVS Project Submission
Object Oriented Programming in java
SPL – PS1 Introduction to C++.
The Linux Command Line Chapter 4
Presentation transcript:

Chapter 3 Understanding Ant datatypes and properties

Ant datatype An Ant datatype is equivalent to a Java class Behind the scenes they are actually implemented as such Behind the scenes they are actually implemented as such Datatypes store complex pieces of information used in the build Datatypes store complex pieces of information used in the build For example For example Datatypes can store a list of files to compile Datatypes can store a list of files to compile Datatypes can store a set of directories to delete Datatypes can store a set of directories to delete

Ant datatype The datatypes act as a parameter to tasks You can declare them inside a task or define them outside, give them a name, and then pass that name to a task A typical Ant build has to handle files and paths, especially the notorious classpath The fileset and path datatypes crop up throughout Ant build files

Example use of fileset datatype <fileset id="source.fileset“ dir="src" includes=“**/*.java" This specifies all java files under all sub- directories of dir src This specifies all java files under all sub- directories of dir src By providing an id attribute, we’re defining a reference, this reference name can be used later wherever a fileset is expected By providing an id attribute, we’re defining a reference, this reference name can be used later wherever a fileset is expected For example, copying our source code to another directory: For example, copying our source code to another directory:

Datatype path A path is an ordered list of elements, where each element can be a file or a directory It describes paths such as the Java CLASSPATH, or the PATH environment variable of Unix and Windows. It may have a task-specific name, such as above, or it may just have the simple name It may have a task-specific name, such as above, or it may just have the simple name

Datatype path Example<path> </path> This definition contains one element, whose location attribute can specify a single file or directory

Datatype path If you need to specify multiple files or directories, you may use path instead of location For example <path> </path> This path attribute separates its parameters into individual elements, using either a semicolor (;) or colon (:) to split them This path attribute separates its parameters into individual elements, using either a semicolor (;) or colon (:) to split them

Datatype path Directories used in datatype path can be separated by either a forward slash (/) or a back-slash (\), regardless of operating systems A build file should not have to care about what system it runs on A build file should not have to care about what system it runs on

Datatype path One exception related to the property file However, if you are using Windows for your homework/lab, in your property file build.properties for ANT, you need to make sure using "/" in your path. However, if you are using Windows for your homework/lab, in your property file build.properties for ANT, you need to make sure using "/" in your path. Do not use "\" in your path in your property file for Windows (Inside Ant build file build.xml, it does not matter if you use "\" or "/" in your path). Do not use "\" in your path in your property file for Windows (Inside Ant build file build.xml, it does not matter if you use "\" or "/" in your path).

Datatype path For example, following build.properties file has the correct path build.properties tomcat.home=c:/apache-tomcat application=lab If you use tomcat.home=c:\apache-tomcat , it will cause trouble to you when deploy it. In this case, what happened is that Ant will ignore "\" and deploy everything to a directory tree under your current directory where build.xml is located.

Datatype path If a path structure consists of only a single path or location, it can be specified using a shortcut form as in or with multiple files separated by either the : or ; path separator or with multiple files separated by either the : or ; path separator

Datatype path Paths can include a set of files

Datatype path How to use a path? A standalone path declaration can be given a name via its id attribute A standalone path declaration can be given a name via its id attribute The name can be referenced whenever a path is needed The other way to use a path is inline The other way to use a path is inline For example, javac task has the element For example, javac task has the element

Datatype fileset A fileset is a set of files rooted from a single directory This includes all the files in the directory tree, including files in all subdirectories recursively This includes all the files in the directory tree, including files in all subdirectories recursively For example For example </copy> All files from the web dir (including sub-directories) are copied to the newweb directory

Datatype fileset A fileset can contain multiple patternsets which restricts the files in the fileset to those that match or don’t match a specified pattern For example, to include all jsp files in a dir </copy> Had we only specified just *.jsp, only the jsp files in the web dir would have been copied, but the files in any subdir would not have been copied Had we only specified just *.jsp, only the jsp files in the web dir would have been copied, but the files in any subdir would not have been copied

Datatype fileset Files can also be excluded using attribute exclude For example

Ant property An Ant property represents any string- specified item Ant properties are essential not just to share information around the build, but to control build files from the outside Example After defining this property, if you want to use the property later, you can use ${host} After defining this property, if you want to use the property later, you can use ${host} For example For example host=${host} host=${host}

Ant property Although Ant property’s functionality looks like a programming language’s variable, ant property is immutable: you cannot change them The first task, project, or person to set a property fixes it for that build

Use datatype and properties </path> <javac <javacdestdir="${build.classes.dir}"debug="true"srcdir="src"> </target></project> We set a property to the directory where we want to compile our source We declare a datatype path for JARs to use in the compile ${…} denotes the use of the property element declares the classpath for the compiler

Setting a property to a filename or directory name In our previous example, we use You can actually use You can actually use It essential does the same thing in this example It essential does the same thing in this example Using attribute location sets the property to the absolute filename of the given file. If the value of this attribute is an absolute path, it is left unchanged (with / and \ characters converted to the current platforms conventions). Otherwise it is taken as a path relative to the project's basedir and expanded. Using attribute value sets the property to be whatever value that is given. No automatic absolute path conversion involved.

Flexibility of Ant Properties ant -Dapplication=fly Buildfile: C:\j2ee_class\lab4-3\build.xml init: [mkdir] Created dir: C:\j2ee_class\lab4-3\classes [mkdir] Created dir: C:\j2ee_class\lab4-3\classes [mkdir] Created dir: c:\tomcat \webapps\fly [mkdir] Created dir: c:\tomcat \webapps\fly [mkdir] Created dir: c:\tomcat \webapps\fly\WEB-INF [mkdir] Created dir: c:\tomcat \webapps\fly\WEB-INF [mkdir] Created dir: c:\tomcat \webapps\fly\WEB- INF\classes [mkdir] Created dir: c:\tomcat \webapps\fly\WEB- INF\classescompile: [javac] C:\j2ee_class\lab4-3\build.xml:27: warning: 'includeantrunt [javac] C:\j2ee_class\lab4-3\build.xml:27: warning: 'includeantruntdsdeploy: [copy] Copying 2 files to c:\tomcat \webapps\fly [copy] Copying 2 files to c:\tomcat \webapps\fly [copy] Copying 1 file to c:\tomcat \webapps\fly\WEB- INF [copy] Copying 1 file to c:\tomcat \webapps\fly\WEB- INF BUILD SUCCESSFUL Total time: 0 secondspplication=fly Although I have a build.properties file having the following contents: tomcat.home=c:/tomcat application=lab4-3 I can runI can run ant -Dapplication=fly ant -Dapplication=fly to make it deploy files to a different place without changing the build.properties file. to make it deploy files to a different place without changing the build.properties file.

Flexibility of Ant Properties The reason that Ant makes properties to be immutable (you cannot change them) is that It let you control build files from the outside It let you control build files from the outside Command line IDEs IDEs Automated build systems Whoever sets a property first fixes its value. This is the direct opposite of variables in a program, where the last assignment becomes its value Ant’s property override rule turns every property into a place in which someone can deliberately override the build file to meet their needs