Installing ANT on Ubuntu

Hi All,

Installing ANT on Ubuntu is fairly very simple. All We have to do is to open the terminal window. And simply run the below command.

sudo apt-get -u install ant

Once you run the command You will be prompted for the admin password and the installation begin.. Once Done simply type ANT in the terminal..

Hope this Helps.


R Vashi

Advertisements

Use main ant build file call sub build file

Hi All,

In this article I will explain how to call the sub build.xml files. Whenever we have bigger project code base then it is always very much required to have small build script files. For example for Code review reports we can go for separate build script files, and we can invoke this script file from the main build script file. This will give ease in maintaining the build scripts and ease to read.

To invoke a sub build script file simply make the below call.

<target name="startBuild" description="Build the project" depends="someOtherRequiredStepTask">
<!-- Here we will call the sub build script file -->
<!-- If you want to pass on the same environment(properties) to the sub file set inheritall="true" -->

<antfile="/module1/build.xml" inheritall="false">
</target>

H T H.


Thanks
R Vashi

Timestamp using ANT

Hi All,

In this article I will show how to create a Timestamp using ANT script, Timestamps are very helpful when we are creating daily code review reports, war/ear files, as we can simply append the timestamp with file name which gives us the ease of identifying the file creation date & time.

When we execute <tstamp/>, it generates the local ANT macros ${TSTAMP} and ${DSTAMP}. These are the time and date as numeric strings. They can then be used to dynamically generate timestamp strings.

The below is an example of using time stamp on Jar file creation:

<jar jarfile=”${jar}-${DSTAMP}${TSTAMP}.jar” compress=”true”> …. </jar>

TSTAMP – sets the DSTAMP, TSTAMP, and TODAY properties in the current project.

[NOTE]  By default, the DSTAMP property is in the format “yyyyMMdd”, TSTAMP is in the format “hhmm”, and TODAY is in the format “MMMM dd yyyy”.

Hope this helps.


Thanks,
R Vashi

Jar scanner for finding jars

Hi All,

I am very happy to share a tool written by me, I have named it Archive Scanner, As the name suggest this tool will help to search for Java classes jar names. Sometime we spend lots of time searching for a jar name, and looking here and there. I can understand this pain as I have faced so many times. So it is a sort of tool I have gifted to myself and all you out there.

This tool(jar) is self executable, only things is that you need to set up a java environment to use that.
It works on JDK.1.5 or later. Please download from the below file.

Tool DownLoad:
archive scanner

Steps to Use:
– First of all save the Jar it to some location. e.g c:\myTool
– Open command Console and change the directory to the location where Jar has been saved
– Set Java Home (ignore if already defined)

– Run the below java command
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName Classwriter.class
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName Classwriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com/bea/objectweb/asm/ClassWriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com.bea.objectweb.asm.ClassWriter
or
– java -jar <<Name of jar>> –searchType DSF –dirName C:\\bea\\modules\\ –fileName com.bea.objectweb.asm.ClassWriter.class

Hope this help, Please give your suggestions or your experience with this tool, this would help me to apply any sort of improvements further.

Happy learning.


Thanks
R Vashi

Using Flex PMD for Flex Code Review using ANT

Hi All,

Adobe Technical Services launched FlexPMD – a tool to audit  ActionScript source code and detect common problems (anti patterns, unused code, badly written Flex components ). The tool started as an internal project in Adobe and now it has been made open source.

I can say that using this tool is a must for any complex Flex projects, because it enables you to detect common problems at an early phase. For the moment it can be invoked from Maven/Ant and Mac OS X automaton, in the future it will probably also be available as a Flash Builder plugin.

Below I will detailed out how to use this with ANT script, to get a report.

Step 1: Download the required jars.
http://opensource.adobe.com/wiki/display/flexpmd/Downloads

Step 2: Copy the jars in Lib folder e.g  c:\myproject\lib

Step 3: Write an ant script and add those jars into Classpath.

Flex PMD example
<mkdir dir=”${basedir}/flex/” />
<mkdir dir=”${basedir}/bin1/” />
<property name=”src.dir” value=”${basedir}/flex/” />
bin1/” />

<property name=”flexpmd.version” value=”1.1″ />
<property name=”flexpmd.dir” value=”jars/flex-pmd-ant-task-1.1/” />

<!–****************************************************
FlexPMD
*****************************************************–>

<taskdef name=”flexPmd”
classname=”com.adobe.ac.pmd.ant.FlexPmdAntTask”
classpath=”${flexpmd.dir}/flex-pmd-ant-task-1.1.jar”>
<classpath>
<pathelement location=”${flexpmd.dir}/flex-pmd-ruleset-api-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-ruleset-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-core-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/as3-plugin-utils-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/as3-parser-api-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/pmd-4.2.5.jar”/>
<pathelement location=”${flexpmd.dir}/commons-lang-2.4.jar”/>
<pathelement location=”${flexpmd.dir}/flex-pmd-files-1.1.jar”/>
<pathelement location=”${flexpmd.dir}/plexus-utils-1.0.2.jar”/>
</classpath>
</taskdef>

<target name=”flexPmdWithCustomRuleset”>
<flexPmd
sourceDirectory=”${src.dir}”
outputDirectory=”${bin.dir}”
ruleSet=”${flexpmd.dir}/pmd.xml”/>
</target>

flexPmdWithDefaultRuleset”>
<flexPmd
sourceDirectory=”${src.dir}”
outputDirectory=”${bin.dir}”/>
</target>

Step 4: Run the ant scripts  e.g  >ant flexPmdWithDefaultRuleset

Step 5: After running the ant task, you will see the task output details on the Console.

flexPmdWithDefaultRuleset:
[flexPmd] 01-Jun-2010 20:34:09 com.adobe.ac.pmd.engines.AbstractFlexPmdEngine loadRuleset
[flexPmd] INFO: Ruleset: c:\DOCUME~1\603\LOCALS~1\Temp\default_flex5303689465491432723.xml
[flexPmd] 01-Jun-2010 20:34:09 com.adobe.ac.pmd.engines.AbstractFlexPmdEngine loadRuleset
[flexPmd] INFO: Rules number in the ruleSet: 90
[flexPmd] 01-Jun-2010 20:35:01 com.adobe.ac.pmd.engines.AbstractFlexPmdEngine computeViolations
[flexPmd] INFO: It took 51497ms to compute violations
[flexPmd] 01-Jun-2010 20:35:01 com.adobe.ac.pmd.engines.AbstractFlexPmdEngine computeViolationNumber
[flexPmd] INFO: Violations number found: 3256
[flexPmd] 01-Jun-2010 20:35:01 com.adobe.ac.pmd.engines.FlexPmdXmlEngine writeReport
[flexPmd] INFO: Creating report in
[flexPmd] 01-Jun-2010 20:35:01 com.adobe.ac.pmd.engines.AbstractFlexPmdEngine writeAnyReport
[flexPmd] INFO: It took 390ms to write the Xml report
BUILD SUCCESSFUL

The main things is that it works well on MXML files. Covers all the action script code written.

Also we can easily transform it to some HTML Report by using XSL. Simply give the path of generated report and path of XSL and the location of HTML report.

<xslt in=”${bin.dir}/pmd.xml” style=”pmd-nicerhtml.xsl” out=”bin1/pmd.html” />
Tip: XSL can be found inside pmd-4.2.5.jar, etc folder


Thanks
R Vashi

java.lang.OutOfMemoryError: PermGen space

Hi All,

Few days back I was reading one of the article of my all time favorite guru(Jaysen sharma), So I would like to share that in this article.

In case of OutOfMemoryError in PermGen Sapace …increasing only the Heap Size will not solve anything…

Formula:

(OS Level)Process Size = Java Heap Native Space (2-3% OS related Memory)

PermSize : It’s a Native Memory Area Outside of the Heap, Where ClassLoading kind of things happens…. In an operating System like Windows Default Process Size is 2GB (2048MB) default (It doesn’t matter How much RAM do u have 2GB or 4GB or more)…until we don’t change it by setting OS level parameter to increase the process size..Usually in OS like Solaris/Linux we get 4GB process size as well.

Now Lets take the default Process Size=2GB (Windows), Now if you have set the -Xmx512M, we can assume that rest of the memory 1536 Mb is available for Native codes.

(ProcessSize (-) HeapSize) = Native (+) (2-3% OS related Memory)

2048 MB (-) 512 MB = 1536 MB

THUMB RULES:

MaxPermSize = (Xmx/3) —- Very Special Cases (One Third of maximum Heap Size)

MaxPermSize = (Xmx/4) —- Recommended (One Fourth Of maximum Heap Size)

So finally you need to increase the PermGen Size… like -Xmx1024m -Xms1024m -XX:MaxPermSize256m

But again these are not the Final values … It depends on ther Environments

Thanks

R Vashi.

Using Checkstyle with ANT for JAVA Code review

Hi All,

Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

Step 1: Download Checkstyle jar from  http://checkstyle.sourceforge.net/index.htm

Step 2: Place the checkstyle jars into the Lib directory of your project.

Step 3: Write a build script and add the below ANT Task for running Checkstyle code reviews. Initially Checkstyle generates a XML report for code reviews. So we can use XSL Stylesheet to transform that in HTML format.(see inside the task)

<target name=”runCodeReview”>

config = “${basedir}/lib/checkstyle_allchecks.xml” classpathref=”build.classpath”  failOnViolation=”false” >
<fileset dir=”${basedir}/src” includes=”**/*.java”/>
<!– fromatter is used to generate a XML file –>
</cs:checkstyle>

<xslt in=”${basedir}/reports/code-cs.xml” out=”${basedir}/reports/java_checkstyle_report.html”     style=”${basedir}/checkstyle.xsl”/>
<!– we can use XSL stylesheet to transform the XML reports into HTML format –>
</target>

NOTE: Sometime it is not feasible to use all the JLS coding standards, due to project coding standards requirement, For this we can easily customize few rules in checkstyle_allchecks.xml.


Thanks
R Vashi

sending emails from ANT

Hi All,

This is perhaps the most hottest feature of ANT to send emails from build script. By this task we can achieve email notifications about build creation, Send code metrics, code reviews reports etc.

Note you need to configure SMTP port, before using that.

<mail mailhost=”smtp.myisp.com” mailport=”1025″ subject=”Test build”>
<from address=”config@myisp.com”/>
<replyto address=”me@myisp.com”/>
<to address=”all@xyz.com”/>
The ${buildname} nightly build has completed
<attachments>
<fileset dir=”dist”>
<include name=”**/*.zip”/>
</fileset>
</attachments>
</mail>


Thanks
R Vashi

Using ANT to compile Flex files

Hi All,

The below example will show how to use ANT to compile Flex files to generate .SWF files.

Step 1: Install FLEX SDK3.1   e.g   c:/flex3.1

Step 2: Create a build.xml    e.g. build.xml

Step 3: Add the below ant task defination  in the Build.xml
<taskdef resource=”flexTasks.tasks” classpath=”c:/flex3.1/ant/lib/flexTasks.jar”/>

Step 4: Crate an Ant Task
<target name=”compileFlex”>
<mxmlc file=”/flex/src/Index.mxml”
incremental=”true”
debug=”false”
optimize=”true”
warnings=”false”
services=”flex/services-config.xml”
output=”build/project/view/index.swf”
classpath=”c:/flex3.1/ant/lib/flexTasks.jar”>
<load-config filename=”c:/flex3.1/frameworks/flex-config.xml”/>
<compiler.library-path dir=”lib/swc” append=”true”>
<include name=”*.swc” />
</compiler.library-path>

</mxmlc>

</target>

Thanks

R Vashi.

Using a separate property file in Ant Script

Hi,

The below example will demonstarte usage of a separate property file in Ant Script

Step1: Define a property file.
File: build.properties
——————————
server.name=localhost
server.port=8080
server.scheme=http
——————————–

Step 2: Write ANT Script
File: build.xml
—————————————
<?xml version=”1.0″?>
<project name=”MyProject”basedir=”.”>
<target name=”properties.localfile”>
<property file=”build.properties”/> <!– Loads the property file –>
<echo message=”Server URL: ${server.url}”/>
<echo message=”Server Port: ${server.port}”/>
<echo message=”Server Scheme: ${server.url}”/>
</target>
</project>
————————————-

Thanks
R Vashis