Wednesday, December 31, 2008

Continuous Build Integration

In the Agile Software Development practice we would need to build and test the application frequently. For example we might need to build many times in a day. We could automate this process and have a cron job that builds and generates reports for the development team to consume.
There are tools that help us in this process of building and testing the application at frequent pre-defined intervals, such as Cruisecontrol, Hudson, Bamboo etc., Refer to this link for the feature matrix comparison of these Continuous Integration Tools.
As an example we shall look at Cruisecontrol which is a Java based, open source CI tool - released with BSD style licence.

How CruiseControl works
  • Developer checks work into version control

  • CC polls version control

  • CC triggers a build

  • CC captures logs and build artifacts

    • Examples: jar, war, javadoc, unit test report, code coverage report, code quality metrics

  • CC publishes results

    • Examples: send email, send instant message


We have a config.xml file through which we could configure the tool.
We would specify the version control information(such as CVS host and credentials), the project details, the scheduling information(such as when to build the app), where to log the builds and save the artifacts and whom to inform when the build completes etc., in this config file.
Since plugins are available for cruisecontrol there is a lot of options that we can configure in this config.xml file.

Here's a sample config.xml file:
<cruisecontrol>
  <project name="connectfour">

<listeners>
<currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
</listeners>

<bootstrappers>
<svnbootstrapper localWorkingCopy="projects/${project.name}" />
</bootstrappers>

<modificationset quietperiod="30">
<svn localWorkingCopy="projects/${project.name}"/>
</modificationset>

<schedule interval="300">
<ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
</schedule>

<log>
<merge dir="projects/${project.name}/target/test-results"/>
</log>

<publishers>
<onsuccess>
<artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/target/${project.name}.jar"/>
</onsuccess>
</publishers>

</project>
</cruisecontrol>
There is a cruisecontrol dashboard through which we can access the history of artifacts and build results and manage those.
Here is a sample Dashboard of cruisecontrol.




Monday, November 10, 2008

CSS and JS compression

A web project has lots CSS and JS files associated with it and lots of these files does affect the page load time based on the internet speed, its size etc.

It would be a wise option to compress the CSS and JS files to make download of these on the fly much faster.
1) GZIP compression
2) Remove unwanted space, line feed characters in JS.
3) Use smaller variable names
4) Remove comments

For (1) - Most of the application servers come with option of enabling compression for HTTP and HTTPS. For example in Tomcat you can do it by setting in the server.xml
...
<connector acceptcount="100" connectiontimeout="60000" disableuploadtimeout="true"
port="9014" redirectport="8944" scheme="https" proxyport="443" compression="on"
compressablemimetype="text/html,text/xml,text/plain,text/css,text/javascript">
...
Having 2, 3 and 4 done on the code base will make it ugly and not readable. There are lots of open source tool which can help as they does all these during build time when creating the achieves.

For example one such tool would be Yahoo UI compressor - it has a easy maven plugin as well - click here for more details on usage.