ANT
Upcoming SlideShare
Loading in...5
×
 

ANT

on

  • 714 views

 

Statistics

Views

Total Views
714
Views on SlideShare
714
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    ANT ANT Presentation Transcript

    • Ant, MSBuild, Shell Scripts
      8 March 2010
    • What Is Ant?
      A build tool like make
      Open source
      from the Apache Jakarta project
      http://jakarta.apache.org/ant
      Implemented in Java
      Used to build many open source products
    • Why Use Ant?
      Develop big programs by automating all tasks of compiling code, running tests, packaging and etc.
      Ant is more portable
      Ant only requires a Java VM
      Ant targets are described in XML
      Does not have cryptic syntax.
    • How Does Ant Work?
      Ant commands (or tasks) are implemented by Java classes
      many are built-in
      others come in optional JAR files
      custom tasks can be created
      Each project using Ant will have a build file
      typically called build.xml since Ant looks for this by default
      Each build file is composed of targets
      these correspond to common activities like compiling and running code
      Each target is composed of tasks
      executed in sequence when the target is executed
      Ant targets can have dependencies
      for example, modified source files must be compiled
      before the application can be run
    • How Does Ant Work? (Cont’d)
      Targets to be executed
      can be specified on the command line when invoking Ant
      if none are specified then the default target is executed
      execution stops if an error is encountered so all requested targets may not be executed
      Each target is only executed once
      for example
      the “test” and “deploy” targets both depend on “compile”
      the “all” target depends on “test” and “deploy”
      but “compile” is only executed once when “all” is executed
      Some tasks are only executed when they need to be
      for example, files that have not changed since the last time they were compiled are not recompiled
    • <?xml version="1.0" ?>
      <project name="testAnt" default="run" >
      <property name="src" location="src/test" />
      <property name="output" location="build/classes" />
      <property name="msg" value="First Ant Making Directories..." />
      <target name="init">
      <echo> ${msg} </echo>
      <mkdir dir="${output}" />
      </target>
      <target name="compile" depends="init">
      <echo> Compiling... </echo>
      <javac srcdir="${src}" destdir="${output}"/>
      </target>
      Sample Build File (build.xml)
      Default target name
      Property values
      A target named by “init”
      Tasks which is executed in the sequence order
      Using property value “output”
    • Sample Build File (Cont’d)
      <target name="run" depends="init,compile" >
      <java fork="true" classname="test.Main">
      <classpath>
      <pathelement location="${output}"/>
      </classpath>
      </java>
      </target>
      <target name="clean">
      <delete dir="${output}" />
      </target>
      </project>
      Means that the init,compile targets must be executed before this target
    • MSBuild
      Microsoft Build Engine 
    • What Is MSbuild?
      A Build tool like Ant
      Ships with Microsoft.NET Framework
      General purpose build automation system
      Uses XML-based language
      Syntax similar to Ant
    • The Basic Elements
      Root container for Msbuild file (.csproj)
      <Project DefaultTargets="SampleTarget" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      </Project>
      Properties
      A property defines a value associated with a name
      <PropertyGroup>
      <OutputDirectory>Output</OutputDirectory>
      <AppName>test</AppName>
      </PropertyGroup>
      Using properties
      <Target Name="CreateDirectories“>
      <MakeDir Directories="$(MSBuildProjectDirectory)$(OutputDirectory)"/>
      </Target>
      All other elements
      Using
      property value
    • The Basic Elements (cont’d)
      Items
      An item is a named reference to a file or to many files.
      Contain associated metadata, such as the full path or filename.
      <ItemGroup>
      <Compile Include="Program.cs" />
      <Compile Include=“Form.cs" />
      </ItemGroup>
      Using Items
      Reference the item collection in the example above with @(Compile)
      Accessing well known meta data of items
      syntax %(ItemMetadataName)
      Item collection named as Compile
    • The Basic Elements (cont’d)
      Targets
      Is a container for related tasks that will be executed sequentially
      Equivalent to Methods
      Must have a name
      <Target Name="SampleTarget" DependsOnTargets="DepTarget">
      <Message Text="SampleTarget executed" />
      </Target>
      <Target Name=“DepTarget">
      <Message Text="DependentTarget executed " />
      </Target>
      Means that the DepTarget must be executed before this target
    • The Basic Elements (cont’d)
      Tasks
      Equivalent to a Statement
      Smallest unit of execution
      Must be declared within a Target
      Many standard ones included in MSBuild
      MakeDir,Copy, Message, Csc, Exec, etc.
      Custom tasks can be created
      <Project xmlns=“http://schemas.microsoft.com/developer/msbuild/2003”>
      <Target Name="CreateDirectories">
      <MakeDir Directories=“output"/>
      </Target>
      </Project>
      Simple task which create directory called “output”
    • Shell Scripts
      Windows scripting 
    • About Shell Scripts
      Also called batch programs or scripts
      Contains one or more commands and has a .bat or .cmd file name extension
      for, goto, call and if, enable you to do conditional processing of the commands
      Commands are not case sensitive
      Executed by the command interpreter
    • Batch Parameters
      Similar to Command line arguments
      Using Batch Parameters
      %{argument_no}
      Using modifiers with batch parameters
      echo %~f0
      How to change the position of batch parameter?
      Using SHIFT /N command
      SHIFT /2
      would shift %3 to %2 and so on, and leave %0 and %1 unaffected.
      %* Reference to all the arguments, not including %0
      Expands %0 to a fully qualified path name.
    • More Information About Commands
      Call