Saturday, October 30, 2004

ANT logging PART II

If you are using ANT for daily EOD build, then you may wish to get a pager or e-mail notification when an error occurs during the build process. Integrating log4j with ANT is fairly straight-forward, as the previous part has explored. But there might be scenarios where using the default log4j configuration may not be desirable.

1. If you have more than one build routines running under the same project, you may not wish to maintain multiple files.

2. If you are deploying an enterprise application, and your EOD build script requires the loading of databases, you may have additional interested parties such as DBAs and network administrators who will monitor your process and potentially make changes. Maintaining a separate properties file for logging may not be acceptable to them. In that case, you may find yourself having to consolidate the file into a properties file configuring the major aspects of your ANT program.

The following code demonstrates how to write a custom ANT task to hook a particular ANT script to log4j, and to read the main ANT properties file for that program for the log4j settings.

Properties props = new Properties();
try {
// ""));
props.load(new FileInputStream(configFile));
Enumeration enum =
String name =
(String) enum.nextElement();
log(name + "=" + props.getProperty(name));
} catch (IOException e) {
project.addBuildListener(new Log4jListener());

After this is done, then there is no mystery in getting log4j to send out e-mail or pager notifications when something goes wrong with your build process. Below is an example log4j configuration that enables the SMTPAppender for e-mails.

# log4j configuration
log4j.rootLogger=INFO, R, mail
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.mail.subject=Build failure,
#log4j.appender.mail.layout.ConversionPattern=%d{ISO8601} %5p [%t] (%F:%L) - %m%n

Friday, October 08, 2004

Dynamic resize of iframe in IE 5.5 with HTML documents formatted with

I did a few google searches, and there doesn't seem to have any ready-made javascript for dynamically resizing an iframe in Internet Explorer 5.5 where the document layout is done using
tags. So here is the script for that:

var dhtml_frame = document.frames(frame_id);
var dhtml_frame_doc = dhtml_frame.document;
while(dhtml_frame_doc.readyState != "complete"){};
var height = 0;
var width = 0;
for(var i = 0; i < tagname ="="> height)
height = dhtml_frame_doc.all[i].offsetHeight;
if(dhtml_frame_doc.all[i].offsetWidth > width)
width = dhtml_frame_doc.all[i].offsetWidth;
} = height + 20; = width + 20;

Tuesday, October 05, 2004

Interim addition on ANT

Before I finish my second part on error-handling/reporting in ANT, I will explore how to deploy ANT in a production environment.

The default distribution of ANT provides platform independent scripts that enable ANT to be deployed to different platforms. However, the default installation instructions pollute the host environment with the ANT_HOME variable. In a production environment, having multiple applications depend on a single ANT instance may create undesired dependencies.

One solution to this problem is to specify only the ANT_HOME and ANT_HOME/lib variables at execution time, so that each application can have a different ANT location.

In Windows, you can wrap around your ANT execution by creating a .bat file with the following commands:

set PATH=%PATH%;%ANT_HOME%/bin
ant ${TargetName}

In Unix, you can create a shell script that duplicates the functionality above:

ant ${TargetName}

One disadvantage of this approach is that the actual command is not platform independent. As of version 1.6.2, ANT allows you to specify the above information in a single line of code which is compatible with both Windows and Unix. You can simply launch the ANT environment by issuing the command:

java -classpath "${ANT_LIB_DIR}/ant-launcher.jar" -Dant.home="${ANT_HOME_DIR} -Dant.Dant.library.dir="${ANT_LIB_DIR}" ${TargetName}