########################################################################
# Copyright (C) 2008 ERG Limited, All rights reserved
#
# Module name   : buildtool
# Module type   : build system
# Compiler(s)   : n/a
# Environment(s): jats
#
# Description   : A simple program to invoke the escrow tool
#
# Usage         : jats eprog gen_escrow <bom_id>
#
#
#......................................................................#

require 5.006_001;
use strict;
use warnings;

use JatsError;                                  # Common error reporting
use JatsEnv;
use JatsSystem;

#
#   Globals
#
our $GBE_DM_LOCATION;
our $GBE_DM_USERNAME;
our $GBE_DM_PASSWORD;

my $prog = 'escrowD.jar';


#
#   Expecting one user argument so lets parse it
#
help() unless ( $ARGV[0] );

#
#   Ensure that essential environment variables are set
#
EnvImport('GBE_DM_LOCATION');
EnvImport('GBE_DM_USERNAME');
EnvImport('GBE_DM_PASSWORD');

#
#   Ensure that the required jar is in the same directory
#   It cannot be run from another directory
#
unless ( -f $prog )
{
    Error ("The program $prog is not in the current directory");
}

#
#   Run the program
#
my $rv = JatsCmd( '-java=1.6',
                    'eprog', $prog,
                    '-c', $GBE_DM_LOCATION,
                    '-u', $GBE_DM_USERNAME,
                    '-p', $GBE_DM_PASSWORD,
                    '-b', @ARGV );

exit $rv;

#-------------------------------------------------------------------------------
# Function        : help
#
# Description     : Simple help
#
# Inputs          : 
#
# Returns         : 
#
sub help
{
    print   "Usage: jats eprog gen_escrow <bom_id>\n".
            "Where:\n".
            "    bom_id        - An SBOM Identifier(number)\n"
            ;

    exit 1;
}
