1 © Luxoft Training 2012 ANT introduction. 2 © Luxoft Training 2012 Build tools When developing software, a developer must solve routine tasks such as:

Презентация:



Advertisements
Похожие презентации
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
Advertisements

© Luxoft Training 2013 Annotations. © Luxoft Training 2013 Java reflection / RTTI // given the name of a class, get a "Class" object that // has all info.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary © Wind River Systems, released under EPL 1.0. All logos are TM of their respective.
Operator Overloading Customised behaviour of operators Chapter: 08 Lecture: 26 & 27 Date:
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Applying Route-Maps as BGP Filters.
Unit II Constructor Cont… Destructor Default constructor.
PAT312, Section 21, December 2006 S21-1 Copyright 2007 MSC.Software Corporation SECTION 21 GROUPS.
© 2009 Avaya Inc. All rights reserved.1 Chapter Two, Voic Pro Components Module Two – Actions, Variables & Conditions.
1 © Luxoft Training 2012 Inner and anonymous classes.
1/27 Chapter 9: Template Functions And Template Classes.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
Date: File:GRAPH_02e.1 SIMATIC S7 Siemens AG All rights reserved. SITRAIN Training for Automation and Drives Project Planning and Configuration.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Customer-to-Provider Connectivity with BGP Connecting a Multihomed Customer to Multiple Service.
S4-1 PAT328, Section 4, September 2004 Copyright 2004 MSC.Software Corporation SECTION 4 FIELD IMPORT AND EXPORT.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Attributes Setting BGP Local Preferences.
Running Commands & Getting Help. Running Commands Commands have the following syntax: command options arguments Each item is separated by a space Options.
HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Managing Your Network Environment Managing Cisco Devices.
Using Dreamweaver MX Slide 1 Window menu Manage Sites… Window menu Manage Sites… 2 2 Open Dreamweaver 1 1 Set up a website folder (1). Click New…
Standard I/O and Pipes. Standard Input and Output Linux provides three I/O channels to Programs Standard input (STDIN) - keyboard by default Standard.
Транксрипт:

1 © Luxoft Training 2012 ANT introduction

2 © Luxoft Training 2012 Build tools When developing software, a developer must solve routine tasks such as: Compile initial modules Carry out unit testing Give folder structure to compiled modules Archive them Copy necessary resources to modules

3 © Luxoft Training 2012 ANT Build Build with open-source code Java based ANT is an open-source project

4 © Luxoft Training 2012 ANT Build ANT is a Java program Start main Java class ANT includes a set of command files facilitating ANT launch Key parameter of command file is build file name Starting ANT

5 © Luxoft Training 2012 ANT Build ANT uses build file written in XML If build file name is not specified, than it is given default name build.xml File describes required sequence of actions Build script

6 © Luxoft Training 2012 ANT Build Starting ANT C:\work>ant C:\work>ant –buildfile custom.xml

7 © Luxoft Training 2012 ANT Build Script should (optionally) describe XML prologue Build script is XML document … build.xml The version prologue attribute is required The encoding attribute defines encoding

8 © Luxoft Training 2012 ANT Build Build script structure … … … build.xml project

9 © Luxoft Training 2012 ANT Build Project consists of set of targets Target defines what must be done Project can have several targets, e.g.: Compile to a certain folder Archive it and delete source classes Locate archives in specified folders Build script structure, targets

10 © Luxoft Training 2012 ANT Build By default, targets are handled independently If necessary, targets interrelations can be indicated When launching ANT, you can specify a certain target or select default target in the build script Build script structure, targets

11 © Luxoft Training 2012 ANT Build Build script structure slide 2-11 … … … build.xml project target

12 © Luxoft Training 2012 ANT Build Target is a sequence of tasks Task defines the way it should be done Standard nested tasks: Copy/Move/Delete Compilation (javac) Archiving (jar) New tasks can be added as far as ANT is extensible Build script structure, tasks

13 © Luxoft Training 2012 ANT Build Build script structure … … … build.xml project target task target task target task

14 © Luxoft Training 2012 ANT Build Launching certain target C:\work>ant C:\work>ant archive Command line

15 © Luxoft Training 2012 ANT Build Working with file system Compiling Java classes Archiving to jar archive Starting Java and OS programs The most common tasks

16 © Luxoft Training 2012 ANT Build Conclusion on build script … … … build.xml

17 © Luxoft Training 2012 Installing ANT Download installation package from Installation package is a zip archive Unpack it Include bin folder to the variable of PATH environment, to start ANT from any file system location slide3-17 ANT is an open software

18 © Luxoft Training 2012 Installing ANT Checking ANT installation

19 © Luxoft Training 2012 Starting ANT Getting help in ANT

20 © Luxoft Training 2012 Starting ANT Key parameter is build file; if it is not indicated, then name is build.xml Build filename can be specified by parameters -buildfile -file -f Parameters

21 © Luxoft Training 2012 Starting ANT The following startup parameters affect ANT displaying: -diagnostics -quiet -verbose -debug -log filename ANT build displaying parameters

22 © Luxoft Training 2012 Build script Target dependencies, option 1 … … … build.xml If target B depends on target A, then when target B is invoked, target A is run automatically

23 © Luxoft Training 2012 Build script Target dependencies, option 2 … … … build.xml

24 © Luxoft Training 2012 Build script Target dependencies

25 © Luxoft Training 2012 Build script Frequently, build file contains the most popular target To avoid specifying its name every time when build is started, developer can define default target Default target

26 © Luxoft Training 2012 Build script Default target … … … build.xml

27 © Luxoft Training 2012 Build script Default target

28 © Luxoft Training 2012 Build script Sometimes we need to specify directory that differs from the default To specify directory use basedir attribute of the project Path directory … build.xml

29 © Luxoft Training 2012 Build script Comments … <target name='archive' depends='compile' description=' archiving them into one JAR '> … … build.xml

30 © Luxoft Training 2012 Build script Project help

31 © Luxoft Training 2012 Build File Properties Properties are named constants Having set the property value once only, developer can refer to it any time by its name Properties facilitate portability and supportability of build files Properties

32 © Luxoft Training 2012 Build File Properties Developer can set build file properties Special element is provided for that Setting script properties To refer to property use this syntax: ${ property_name }

33 © Luxoft Training 2012 Build File Properties Using properties ${ message } build.xml

34 © Luxoft Training 2012 Build File Properties Using properties

35 © Luxoft Training 2012 Build File Properties It is not always convenient to set properties directly in script, because it decreases scripts supportability and portability You can set properties: In build file In external file As JVM properties when launching ANT Setting properties

36 © Luxoft Training 2012 Build File Properties You can refer to external properties file from build file Properties file syntax: Setting properties in external file property1=value1 property2=value2 property3=value3 … *.properties

37 © Luxoft Training 2012 Build File Properties Setting properties in external file ${ message } build.xml

38 © Luxoft Training 2012 Build File Properties JVM properties are « key-value » pairs available in Java program and JVM They are set when Java program is launched by the –D option Setting properties in external file as JVM properties C:\work>java –D property_name = value MyClass Command line

39 © Luxoft Training 2012 Build File Properties Setting script properties as JVM properties ${ message } build.xml

40 © Luxoft Training 2012 Build File Properties Properties can be set: In build file In external file As JVM properties when launching ANT What is the priority of each option of properties setting? What is the difference between loading properties from file via the element and the –propertyfile key? Priorities in setting the properties

41 © Luxoft Training 2012 Build File Properties The highest priority As JVM properties when launching ANT Priority of place of property setting: In build file In external file Priorities in setting the properties Property value is set according to the first definition, regardless where it was done, in script or in external file

42 © Luxoft Training 2012 Build File Properties ANT has built-in properties: Built-in ANT properties ant.file The absolute path of the build file ant.home Home directory of ANT ant.java.version The JVM version ant.project.name The name of the project that is currently executing ant.version The ANT version basedir Projects base directory

43 © Luxoft Training 2012 Build Errors By default, ANT stops when it detects the first build file error This can be bypassed with the help of attributes below. When doing this, all correct tasks will be executed: -keep-going -k ANT Stop

44 © Luxoft Training 2012 Build Errors ANT Stop

45 © Luxoft Training 2012 Build Errors ANT does not provide for automatic file rollback when an error occurs Developers should implement special listeners for overall error handling ANT Stop

46 © Luxoft Training 2012 The most popular ANT tasks ANT task allows inputting data from console Data input from console <input message="input boolean variable:" validargs="y,n" addproperty="new_bool_property" /> build.xml Default value for input properties can be defined Input can be blocked by the –noinput key when ANT is launched

47 © Luxoft Training 2012 The most popular ANT tasks ANT task the allow automating the process of document creation ANT task the is wrapper for javadoc tool from JDK JavaDoc Documenting

48 © Luxoft Training 2012 The most popular ANT tasks Example of Java code with JavaDoc comments JavaDoc Documenting /** This application prints out "No worries." */ public class Project { public static void main(String args[]) { System.out.println("No worries."); } Project.java

49 © Luxoft Training 2012 The most popular ANT tasks Documenting in ANT scripts JavaDoc Documenting <javadoc sourcefiles="${src}/Project.java" destdir="${docs}" author="true" version="true" use="true" windowtitle="Project API" > Project API ]]> Copyright &#169; 2005 ]]> build.xml

50 © Luxoft Training 2012 The most popular ANT tasks Build number support

51 © Luxoft Training 2012 The most popular ANT tasks You can add prefixes for all parameters set Properties values can be freely edited Binding to the date and time ${TODAY} ${DSTAMP} ${TSTAMP} build.xml Variables TODAY, DSTAMP, TSTAMP are created

52 © Luxoft Training 2012 The most popular ANT tasks Binding to the date and time

53 © Luxoft Training 2012 The most popular ANT tasks ANT task the creates directories Creating directories build.xml Does nothing if the directory already exists

54 © Luxoft Training 2012 The most popular ANT tasks ANT task the deletes directories and files Deleting directories and files build.xml

55 © Luxoft Training 2012 The most popular ANT tasks and tasks allow to determine directory path and local file name from composite file name The result is saved to specified property Working with composite file name build.xml

56 © Luxoft Training 2012 The most popular ANT tasks The task allows copying files Copy files build.xml <copy file="" tofile="" | todir="" overwrite="bool" preservelastmodified="bool" /> task does not copy directories. For that you should use file masks

57 © Luxoft Training 2012 The most popular ANT tasks task moves files and directories Moving files and directories build.xml <move file="" tofile="" | todir="" overwrite="bool" preservelastmodified="bool" />

58 © Luxoft Training 2012 The most popular ANT tasks task is a wrapper for Java compiler Java code compilation <javac srcdir="${src};${src2}" destdir="${build}" classpath="common.jar" debug="on" /> build.xml It is possible to specify File Sets and their patterns flexibly. Well talk about that in Module 4 It is possible to fork compile process You can choose between compilers

59 © Luxoft Training 2012 The most popular ANT tasks Setting compiler options Java code compilation <javac srcdir="${src}" destdir="${build}" classpath="xyz.jar" debug="on" > build.xml

60 © Luxoft Training 2012 The most popular ANT tasks task allows archiving file sets to jar archive The jar utility exploits usual zip algorithm However, it adds at the same time so called manifest It is also possible to sign the archive with electronic signature Jar archiving

61 © Luxoft Training 2012 The most popular ANT tasks Jar archiving build.xml

62 © Luxoft Training 2012 The most popular ANT tasks allows running necessary Java class Running Java programs <java classname= classpath= fork=boolean output= timeout= /> build.xml It is possible to specify heap size, program and JVM arguments

63 © Luxoft Training 2012 The most popular ANT tasks Conclusions echo Input/output input javadoc Documenting buildnumber Build number tracking, versioning tstamp mkdir Working with file system delete copy move basename Working with file names dirname javac Compilation jar Archiving java Running

64 © Luxoft Training 2012 The most popular ANT tasks Task that were not covered

65 © Luxoft Training 2012 File and directory sets Their main task is to flexibly define file and directory sets Path patterns (masks, patterns) are used for that purpose Fileset and Dirset Data Types

66 © Luxoft Training 2012 File and directory sets Fileset type is formed by: Root directory Include sets Exclude sets Fileset Data Type build.xml

67 © Luxoft Training 2012 File and directory sets Masks used for definition of file set: ? any single symbol * any symbol set ** any symbol set in current directory and in sub directories (directory structure is maintained) Fileset, using masks

68 © Luxoft Training 2012 File and directory sets Fileset, Example 1 What will get to the test directory? build.xml The test directory will be created if there is anything to copy

69 © Luxoft Training 2012 File and directory sets Fileset, example 2 What will get to the test directory? build.xml

70 © Luxoft Training 2012 File and directory sets Fileset, example 3 What will get to the test directory? build.xml

71 © Luxoft Training 2012 File and directory sets Default excludes Fileset **/*~**/#*# **/.#***/%*% **/._***/CVS **/CVS/****/.cvsignore **/SCCS**/SCCS/** **/vssver.scc**/.svn **/.svn/****/.DS_Store

72 © Luxoft Training 2012 File and directory sets Useful attributes of fileset Fileset casesensitive File patterns are treated in a case sensitive way (true) defaultexcludes Whether default excludes shall be used or not (true) excludes s ub-element analogue excludesfile External file with a list of excluded patterns file A shortcut for specifying a single-file fileset (mutually exclusive property with dir ) followsymlinks Shall symbolic links be followed? (Unix) includes s ub-element analogue includesfile External file with a list of included patterns

73 © Luxoft Training 2012 File and directory sets Using Fileset, example 1 build.xml

74 © Luxoft Training 2012 File and directory sets Using Fileset, example 2 build.xml <javac destdir="${build.classes.dir}" srcdir="${src.dir}"> In task you cant directly refer to fileset to get source Java files

75 © Luxoft Training 2012 File and directory sets Using Fileset, example 3 build.xml

76 © Luxoft Training 2012 Conditional Target Execution For that, use if and unless attributes of target element The condition for identifying the specified property in build file will act as a condition It is possible to specify conditions of target execution:

77 © Luxoft Training 2012 Conditional Target Execution Condition of target execution, if attribute build.xml The to_arhive property can be set both as target-scoped for other targets and as JVM property at ANT launch if to_archive property is set then the target will get executed

78 © Luxoft Training 2012 Conditional Target Execution Condition of target execution, unless attribute build.xml unless is opposite to if Target is executed if property is not set

79 © Luxoft Training 2012 Specifying Conditions Condition is a logical function of the set of variables Condition result is whether the property shall be set or not Condition variables are other properties and external factors Conditions are particularly useful in conditional target execution Conditions

80 © Luxoft Training 2012 Predicates and Logical AND or Logical OR not Logical NOT available The file exists or is available contains Specified string contains specified substring equals Specified strings are equal filesmatch Specified files contain matching data isset Specified property is set uptodate Specified file is older than other elsewhere Specifying Conditions

81 © Luxoft Training 2012 Examples of conditions Specifying Conditions

82 © Luxoft Training 2012 Examples of conditions Specifying Conditions

83 © Luxoft Training 2012 Specifying Conditions Availability condition Apart from predicate there is similar ANT task Predicate and target syntax: <available property= classname= | file= | resource= classpath= filepath= type= />

84 © Luxoft Training 2012 Build Interruption When conditions and conditional target execution is used, it may be required to stop the build For that ANT task is used The stopping condition is the condition of whether particular property is set or not Build stop

85 © Luxoft Training 2012 Build Interruption task syntax Build stop <fail message="oops…" unless="prop_name" | if= "prop_name" />

86 © Luxoft Training 2012 Build Interruption Build stop example

87 © Luxoft Training 2012 Building EJB Applications Use ANT task At the task input we have: Specific deployment descriptors Basic descriptors Set of compiled EJB (*.class) Automating the Process of Building

88 © Luxoft Training 2012 Building EJB Applications Syntax of ANT task Automating the Process of Building <ejbjar srcdir="${build.classes.dir}" descriptordir="metadata" destdir="${dist.dir}" basejarname="${ejbjar.name}" genericjarsuffix=""> The task will locate files to relevant folders and will archive them

89 © Luxoft Training 2012 Building EAR Applications Use ANT task At the task input we have: Basic deployment descriptor Set of modules( *.war, *.jar, *.rar ) Automating the Process of Building

90 © Luxoft Training 2012 Building EAR Applications Syntax of ANT task Automating the Process of Building <ear destfile="${output}/app.ear" appxml="${src}/application.xml"> The task will locate files to relevant folders and will archive them