Posts Tagged ‘Tools’

Ant-Custom Tasks and Built-In Tasks.html

Wednesday, January 5th, 2011
In my previous post we have seen how to configure ant and how to use with IDE’s like eclipse. In this post we’ll look into some of the Built-In ant tasks and Custom Tasks. Ant provides lots of built-in tasks. Those task can be categorized as follows
  • Archive Tasks - Has list of all the archiving tools like JAR,WAR,EAR,TAR,ZIP and etc…
  • Audit/Coverage Tasks - Has a single task under this group which is an Code Coverage tool for Design Quality Metrics.
  • Compile Tasks - Includes the task for Code Compilation.
  • Deployment Tasks - Hot deployment task for J2EE Servers.
  • Documentation Tasks - Has JavaDoc task in this category.
  • EJB Tasks - Couple EJB related task specific to App servers.
  • Execution Tasks
  • File Tasks
  • Java2 Extensions Tasks
  • Logging Tasks
  • Mail Tasks
  • Miscellaneous Tasks
  • Pre-process Tasks
  • Property Tasks
  • Remote Tasks - Task like FTP, SCP and etc.
  • SCM Tasks - Includes few popular SCM tasks like ClearCase,CVS and VSS.
  • Testing Tasks - Supports jUnit tasks.
We’ll take few tasks like Mail tasks, Remote tasks and SCM Tasks and try to run a task from each group.
Mail Task
While running the build in an environment where a team is using SCM to commit their changes, this task will be very useful if the build is broke. By using this we can send a mail to the team along with the build errors. Since the MAIL task supports attachment also, it’ll be a very good idea to log all the errors and send it in the mail, so that the team can correct their code base and commit to SCM. The below build script has an example task which shows a simple steps to send a mail using mail task.
		<?xml version="1.0" encoding="UTF-8"?>
		<project name="AntDemo" default="sendMail">
			<target name="sendMail">
				<mail mailhost="smtp.xx.com" subject="Build Broken"  user="kumarasamy@xx.com" password="XXXXXXX">
					  <from name='Build Admin' address="buildadmin@yourcompany.com"/>
					  <to address="usersDL@domain.com"/>
					  <message>The Build has been Completed.</message>
				</mail>
			</target>
		</project>
		
Remote Task - FTP
When we run the build sometimes we use a different machine only for build and finally we’ll copy to the remote machine to deploy it on application servers, for that we can use this ftp task.The below example will show how to use the FTP
		<?xml version="1.0" encoding="UTF-8"?>
		<project name="AntDemo" default="uploadFile">
			<target name="uploadFile">
				<ftp server="ftp.xx.com"
						userid="username"
						password="password">
					<fileset dir="dist">
						<include name="*.war"/>
					</fileset>
				</ftp>
			</target>
		</project>
		
The above FTP task has very simple example, which just uploads your WAR file to your FTP server.
SCM Task - ClearCase
Clearcase is one of the widely used SCM in the industry, sometimes automating the build process is important and we can have these ant tasks provided in ant and perform few SCM tasks in ClearCase. The first step in check-in and checkout process is locking the current stream we use it for building the code base. In the same manner when these check-in and checkout process are completed we’ll have to unlock the stream we have locked it. For this Clearcase provides an command line tool called cleartool, by using this we can achieve these task in command line, Let’s see how we can use it ant by using the ClearCase ant task. Before that we’ll have the following assumptions, We’ll consider the branch name as “BuildFortheFixX.X”.
		<?xml version="1.0" encoding="UTF-8"?>
		<project name="AntDemo" default="lockStream">
			<target name="lockStream">
				<cclock objsel="brtype:BuildFortheFixX.X" />
			</target>
			<target name="unlockStream">
				<ccunlock objsel="brtype:BuildFortheFixX.X" />
			</target>
		</project>
		
The above CC tasks are equal to the following cleartool commands,

			cleartool lock brtype:project_int

			cleartool unlock brtype:project_int
		
Custom Task - ClientGen
Ant provides a way to write our own tasks, the best example will be clientgen task from weblogic which is used to generate the webservice clients from WSDL file. First We’ll we how to use this clientgen task to generate the Service Clients, then we’ll look at how to write an simple custom ant task and call it from the build script. If you are using WL8.1, We have the task defined weblogic.ant.taskdefs.webservices.clientgen.ClientGenTask in webservices.jar. We can use this task to generate the client JAR. The following example will show how to generate the Service Client JAR from a WSDL.
		<?xml version="1.0" encoding="UTF-8"?>
		<project name="AntDemo" default="buildClientJar">
		  <taskdef name="clientgen" classname="weblogic.ant.taskdefs.webservices.clientgen.ClientGenTask" />
			<target name="buildClientJar">
				<clientgen	wsdl="http://myapplication/services/MyAppWebService?wsdl"
										clientjar="dist/MyApprClient.jar"
										packageName="com.techmaddy.client"
										serviceName="MyAppWebService" />
			</target>
		</project>
		
If we look at the taskdef, it points to class ClientGenTask, As we explained earlier every ant task is associated with individual java class. If we write an custom ant task, that should extend a Class org.apache.tools.ant.Task. This is the first and foremost thing we should be doing this. Then it should be overriding the execute() from Task. These two are the important thing we have to notice while writing the custom AntTask. After this we can package this class into a JAR and use it like “clientgen” from Weblogic, by making use of taskdef.
Custom Task - MySimpleTask
In this example we’ll look into how to create our own task and call it from a build script. As i mentioned earlier we need to have class with extends Task and overriding the execute() method. Look at the below example
			package com.techmaddy.ant.taskdefs;

			import org.apache.tools.ant.Project;
			import org.apache.tools.ant.Task;

			public class MySimpleTask extends Task  {
				public void execute() {
					  log("My Simple Task", Project.MSG_INFO);
					  System.out.println("Demo MySimpleTask");
				   }
			}
		
I have used the log method from Task, to place the logs to exact place where the logs from ant is getting added, using SOP is not recommended. Complie this class and package into a JAR and use it your build script. The below is the example for the Build Script which makes a call to MySimpleTask.
			<?xml version="1.0" encoding="UTF-8"?>
			<project name="AntDemo" default="myOwnCustomTask">

				<taskdef name="mysimpletask" classname="com.techmaddy.ant.taskdefs.MySimpleTask" />

				<target name="myOwnCustomTask">
					<mysimpletask/>
				</target>

			</project>
		
The below image shows the output.
Ant-Custom Task
Library Dependencies
1. For Mail task you need to have mail.jar and activation.jar.
2. For FTP task you need to have commons-net.x.x.jar and jakarta-oro-x.x.jar.
3. For Clientgen task you need to have weblogic.jar, webservice.jar and tools.jar.
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Online Artwork Approval

Wednesday, October 27th, 2010

We are a promotional product company which sells pens, mugs, bags, rulers etc printed with our customer’s message / logo on. Currently our designer designs the product makes amendments and then sends the customer a PDF proof for them to check spellings position content etc and then sign and fax it back to us before we send the item into production. We basically want to streamline this process and let the customer digitally sign the proof off.

The Features we would be looking for are as follows:

When a job is booked in we would enter the customer’s details if not already in the online database, and open up a new job under a job number. We then can send an email template to the customer asking for artwork for the order, the status of the order would initially be set as awaiting artwork. If we the status has not been changed to awaiting mock-up then an automatic artwork reminder email is sent after a specified number of days. Under the customer information they will have a unique customer number and then each order will have a unique job number.

Once we have received the artwork the designer would set this status to awaiting mock-up
Once the mock-up is uploaded the customer is automatically emailed and the status changes to waiting for amendments or approval.

Once the approval is uploaded there will be a box with a deadline of approval this will have a default number of days in it (e.g. 5days), but if the designer requires the approval more urgently he can overtype it to a specified number of days. If the approval is needed the same day he can type in 0 which stops any chase emails but puts it to the top of priority list.

Once the artwork is uploaded and an email is automatically sent to the customer if they do not approve or make amendments within a set number of days they will get an automatic reminder email after 2 days (template 1) and again after 4 days (template 2) an email is also sent to the designer to let him know the customer is close to the deadline. If they go over the number of days specified then an overdue email is sent (template 3).

The customer will receive an email with a link, where they will be taken to the artwork page of that specific order. If the customer is happy with the design then they can click a few tick boxes saying they have checked spelling, layout, colors etc and put their name and then click a button to approve. A confirmation box will be displayed to make sure they do want to approve the artwork – this feature needs to be date and time stamped in the database as well as taking a note of their IP address. An email will be sent both to the customer and to the designer saying that the artwork has been approved; also the status of the job will be changed to approved.

If the customer is not happy with the design then they can click amendment which will bring up a text box, in which the customer can type what they want changing and click send. This will then send an email to our designer with the amendment information. If the customer asks for an amendment this will automatically open a new page amendment 1 (job number-1) where the designer needs to upload the changed artwork and the status would change to awaiting amendment. The whole process of approval will then start again until the customer is happy with the design.

An overview page will be available to the designer with all the jobs on the go that are awaiting artwork, approval or amendments (probably colour coded whether we are waiting on the customer or the designer) and in order of priority (days left to approve).

A customer online portal will be available where they can login under their email address and password (customer number); there would be a list of jobs with the ones that have not been approved at the top in date order. The customer will have the ability to go through the history of their artwork approvals and amendments.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Product Comparision Tool

Friday, October 8th, 2010
I was going through the site, Carwale.com, And i was impresed with thier design on comparing cars. Every reseller has this option used by their customer who visits thier site. Let it be an popular algorithm/logic/interface, i just wanted to try myself to create that kind of interface and let’s see how can we improve further on this.
There are few points i have considered in my mind, one among them is the data should be picked dynamically, so that it doesn’t need any code change to add something new. After spending 80mins to finalize the DB design, i came to the following design.
ER-Diagram
Based on this, now i’ll proceed to code, lets see…How can i improve further, i know i’ll get many changes ;)
Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)
Get Adobe Flash player