+ All Categories
Home > Education > CodeIgniter Ant Scripting

CodeIgniter Ant Scripting

Date post: 12-Nov-2014
Category:
Upload: albert-rosa
View: 2,874 times
Download: 0 times
Share this document with a friend
Description:
 
23
CodeIgniter Ant Scripting
Transcript
Page 1: CodeIgniter Ant Scripting

CodeIgniter

Ant Scripting

Page 2: CodeIgniter Ant Scripting

Topic

• What is Ant?• Why use Ant?• How can we use Ant?• How to stream development with Ant?

Page 3: CodeIgniter Ant Scripting
Page 4: CodeIgniter Ant Scripting

What Is Ant?

• Ant is a Java-based build tool. In theory, it is kind of like make, without make's wrinkles.

• Ant is different. Instead of a model where it is extended with shell-based commands, Ant is extended using Java classes. Instead of writing shell commands, the configuration files are XML-based, calling out a target tree where various tasks get executed. Each task is run by an object that implements a particular Task interface.

Page 5: CodeIgniter Ant Scripting

So If Ant is Java why do we want to use it for PHP

• Well Ideally Ant was used to stream line build and compilation with Java in response to Make.

• With the way Ant is, it can be used in any automation we want as long as all the requirements used in the automation are already installed– We can’t use something we don’t have ;-)

Page 6: CodeIgniter Ant Scripting

Installing Ant

• Ant can be downloaded from: http://ant.apache.org

• Most Current IDE come with Ant Pre-installed– My Personal Preference NETBEANS IDE– Other’s like Eclipse …. (WHY????)

• MAC OS ant is pre-installed, UBUNTU also, but always update ;-) …

Page 7: CodeIgniter Ant Scripting

Ant Task… huh?

• Ant has a ton of task both built in and downloadable.

• Ant Task are “actions” to be done in the Ant Script.

Page 8: CodeIgniter Ant Scripting

Ant Task Buckets:

Archive TasksAudit/Coverage TasksCompile TasksDeployment TasksDocumentation TasksEJB TasksExecution TasksFile TasksJava2 Extensions Tasks

Logging TasksMail TasksMiscellaneous TasksPre-process TasksProperty TasksRemote TasksSCM TasksTesting Tasks

Page 9: CodeIgniter Ant Scripting

The Ant Build File

<!-- this is an ant script to build the project and information -->

<project name=”Demo" default="freshBuild" basedir=".">

<description> This is the ant script to build demo this has the

ability to clean the build, create a Code Report, Run Unit Tests and Build Documentation

</description>

Page 10: CodeIgniter Ant Scripting

Ant Properties…• <property name="docs" location="docs" />• <property name="applicationDocs" location="${docs}/application"/>• <property name="libraryDocs" location="${docs}/library" />• <property name="reports" location="reports"/>• <property name="sniffer" location="${reports}/sniffer" />• <property name="applicationReports" location="${reports}/application" />• <property name="libraryReports" location="${reports}/library" />• <property name="build" location="build" />• <property name="tests" location="tests" />

Page 11: CodeIgniter Ant Scripting

Ant Cleaning…• <!-- this will create a clean working environment -->• <target name="clean">• <echo message="Clearing the folders"/>• <delete dir="${applicationDocs}"/>• <delete dir="${libraryDocs}" />• <delete dir="${reports}" />• <delete dir="${build}" />

• <echo message="Creating the folders" />• <mkdir dir="${applicationDocs}" />• <mkdir dir="${libraryDocs}" />• <mkdir dir="${reports}" />• <mkdir dir="${sniffer}" />• <mkdir dir="${applicationReports}" />• <mkdir dir="${libraryReports}" />• <mkdir dir="${build}" />• </target>

Page 12: CodeIgniter Ant Scripting

Ant Clean Cont….

• <target name="cleanProject">• <echo message="Clearing the folders"/>• <delete dir="${applicationDocs}"/>• <delete dir="${libraryDocs}" />• <delete dir="${reports}" />• <delete dir="${build}" />• </target>

Page 13: CodeIgniter Ant Scripting

Ant Code Sniffing…• <!-- code sniffer -->• <target name="codeSniff">• <echo message="Started Sniffing code" />

• <echo message="Sniffing Library" />• <exec executable="phpcs" output="${sniffer}/library.sniffer.txt">• <arg value="${NoteLib}"/>• <arg value="--standard=ZEND"/>• <arg value="--report=full" />• <arg value="-n"/>• </exec>

• <echo message="Sniffing Application" />• <exec executable="phpcs" output="${sniffer}/application.sniffer.txt">• <arg value="${application}" />• <arg value="--standard=ZEND" />• <arg value="--report=full" />• <arg value="-n" />• </exec>

• <echo message="Finished Sniffing the Code" />• </target>

Page 14: CodeIgniter Ant Scripting

Ant Documenting …• <!-- PHP DOCUMENTATION -->• <target name="document">• <echo message="Started Documenting the code" />

• <echo message="Documenting the Application" />• <exec executable="phpdoc" output="${docs}/application.doc.result.txt">• <arg line="• --target ${applicationDocs}• --directory ${application}• --title 'Note In A Bottle Application Documentation'• --undocumentedelements on• -i *.phtml• --defaultpackagename 'NoteInBottleApp'• "/>• </exec>

Page 15: CodeIgniter Ant Scripting

Ant Documenting cont…• <echo message="Documenting the Application's Library" />• <exec executable="phpdoc" output="${docs}/application.doc.result.txt">• <arg line="• --target ${libraryDocs}• --directory ${NoteLib}• --title 'Note In A Bottle Library Documentation'• --undocumentedelements on• --defaultpackagename 'NoteInBottle'• "/>• </exec>

• <echo message="Finished Documenting the code" />• </target>

Page 16: CodeIgniter Ant Scripting

Ant Fresh Build….

• <target name="freshBuild" depends="clean, codeSniff, unitTesting, document”>

• </target>

Page 17: CodeIgniter Ant Scripting

Ant Copy to Server…

• <target name="copyToTestServer">• <exec executable="cp" output="${docs}/cp.result.txt">• <arg line="• -R• /Users/albertrosa/Sites/Demo/

/Volumes/www/Demo/• "/>• </exec>

• <echo message="copied"/>• </target>

Page 18: CodeIgniter Ant Scripting

UMMM…. Ok but how does it work…

• So you see how the ant xml file looks, you know the buckets that are included with Ant and you have an idea of how you want your build to go …. SO how do you use it?

• Simple… in your Terminal / command prompt / console navigate to the build file ohh wait I didn’t tell you where the build file should go huh…. Well I always place it at the root of the site so all my paths are relative to that root.

Page 19: CodeIgniter Ant Scripting

But really now how to build it….

• Once you have navigated to the desired location all that is left to do is run the command as follows

ant <target name>

Yep that’s all … so each target is an “task” you can do. But recall the freshBuild target .. That had depends as an attribute. Well those depends are all ran when you execute “ant freshBuild”

Page 20: CodeIgniter Ant Scripting

Basic errors most commonly found

• Ant depends orders – if some targets need something to happen first that should happen before that task is executed

• You are using a ant task that isn’t installed• You action is producing an error and causes

the execution to terminate• You run out of memory :-D rare but possible

on many large scale projects.

Page 21: CodeIgniter Ant Scripting

THANKS

• Thanks go to ROKKAN for providing us with the Conference space.

Page 22: CodeIgniter Ant Scripting

General Info

• My Email: [email protected]• AIM: albertrosa2000• Meetup: www.meetup.com/codeigniter/• Rokkan: www.rokkan.com

Page 23: CodeIgniter Ant Scripting

Sources

• http://ant.apache.org/


Recommended