use Cwd qw(abs_path getcwd);
use File::Path qw(make_path remove_tree);
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$File::Fetch::BLACKLIST = [qw|lwp httptiny httplite|];
$path = abs_path(dirname($exe));
$jarfile_name = "xml-casa-assembly-1.52.jar";
$sakura_release = "libsakura-4.0.2065-01.tar.gz";
open(JAVAVER, "$java -version 2>&1 |");
if ( m|version "?(\d+)\.(\d+)|i ) {
print "found java version ", join('.',@java_version), "\n";
die "cannot run $java" unless scalar(@java_version) > 0;
die "java version 1.8 or greater is required\n"
unless $java_version[0] > 7 || ($java_version[0] == 1 && $java_version[1] >= 8);
$distro_jarfile = $jarfile = "$path/java/$jarfile_name";
$jarfile = "$path/../target/scala-2.12/$jarfile_name";
$jarfile = $distro_jarfile;
### pull from download url
my $jardir = dirname($jarfile);
my $ff = File::Fetch->new(uri => "http://casa.nrao.edu/download/devel/xml-casa/java/$jarfile_name");
my $where = $ff->fetch( to => $jardir );
die "configuration error, cannot find jar file ($jarfile_name)" unless -e $jarfile;
if ( ! -d 'sakura-source/src' ) {
if ( ! -d '.sakura' || ! -f ".sakura/$sakura_release" ) {
### pull from download url
### download from jp times out...
#my $ff = File::Fetch->new(uri => "http://alma-dl.mtk.nao.ac.jp/ftp/sakura/releases/latest_src/$sakura_release");
my $ff = File::Fetch->new(uri => "http://casa.nrao.edu/download/devel/libsakura/$sakura_release");
my $where = $ff->fetch( to => '.sakura' );
unlink(".sakura/$sakura_release") unless -f ".sakura/$sakura_release" && -s ".sakura/$sakura_release" > 354000;