#!/usr/bin/perl
#
#	A wrapper for the Notify Java application.
#
#	The PIRL_JAVA_HOME enviroment variable, if it is set, will be
#	prepended to the java runtime classpath. The value of PIRL_JAVA_HOME
#	may be a directory pathname where the PIRL subdirectory and all its
#	class files is located; or it may be the pathname to a jar file -
#	e.g. PIRL.jar - containing the class files for the PIRL Java
#	Packages.
#
#	N.B.: If the PIRL_JAVA_HOME enviroment variable is not set but the
#	/opt/java/PIRL pathname exists, then /opt/java will be used for the
#	value of PIRL_JAVA_HOME.
#
#	If the CLASSPATH environment variable is set its value is appended to
#	the java runtime classpath.
#
#	The location of the following third party packages are expected to be
#	in the java runtime classpath or provided as the value of an environment
#	variable having the names listed here:
#
#	JAVAMAIL - http://www.oracle.com/technetwork/java/javamail/
#	JAF - http://java.sun.com/products/archive/javabeans/jaf11.html
#
#	The pathnames to the JavaX JavaMail and JavaBeans Activation
#	Framework jar files or the root directory where their class files
#	are located. These packages provide email message sending
#	functionality as used by the Notify class. Note: These packages are
#	only required when Notify must use an "unfriendly" email server.
#	They may not be required at all, in which case a Notify-simple.java
#	implementation is provided that only uses JFC classes and worked
#	fine for many years until a "sophisticated" email server was
#	encountered.
#
#
#	Note: On Apple OS X (Darwin) systems the Java Virtual Machine will
#	automatically include jar files in the ~/Library/Java/Extensions and
#	/Library/Java/Extensions directories, if they exist, in the java
#	runtime classpath.
#
#
#	CVS ID: Notify,v 1.7 2011/10/27 22:55:18 castalia Exp

$CLASSPATH		= $ENV{"CLASSPATH"};

$PIRL_JAVA_HOME	= $ENV{"PIRL_JAVA_HOME"};
$PIRL_JAVA_HOME = "/opt/java"
	if (! $PIRL_JAVA_HOME &&
		-e "/opt/java/PIRL");
Add_to_CLASSPATH ($PIRL_JAVA_HOME);

$JAVAMAIL = "$PIRL_JAVA_HOME/javamail/mail.jar"
	unless $JAVAMAIL = $ENV{"JAVAMAIL"};
Add_to_CLASSPATH ($JAVAMAIL);

$JAF = "$PIRL_JAVA_HOME/jaf/activation.jar"
	unless $JAF = $ENV{"JAF"};
Add_to_CLASSPATH ($JAF);

@Arguments = (java);
push @Arguments, "-cp", $CLASSPATH
	if $CLASSPATH;
push @Arguments, "PIRL.Conductor.Notify", @ARGV;

exec @Arguments;


sub Add_to_CLASSPATH
{
my ($pathname) = @_;

if (-e "$pathname")
	{
	if ($CLASSPATH)
		{
		$CLASSPATH = "$CLASSPATH:$pathname"
			unless "$pathname" =~ /"$pathname"/;
		}
	else
		{
		$CLASSPATH = $pathname;
		}
	}
}
