package Cpanel::Easy::OptLib::jdk;

# cpanel - jdk.pm                                 Copyright(c) 2012 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited

my $version_major = 6;
my $version_minor = 37;

sub path_installed {
    my ($easy_obj)  = @_;
    my $jdk_version = "1.$version_major.0_$version_minor";
    my $base_path   = '/usr/local/';
    my $jdk_install_bin = "jdk-${version_major}u${version_minor}-linux-" . ( $easy_obj->{'cpu_bits'} eq '64' ? 'x64' : 'i586' ) . '.bin';

    # Touch /usr/local/jdk/keepmine to skip our JDK installation entirely and use whatever is in /usr/local/jdk

    return {
        'name'         => 'JDK',
        'install_path' => $base_path . 'jdk',
        'itis_up2date' => sub {
            return 1 if ( -e '/usr/local/jdk/keepmine' );
            return 0 if ( !-e '/usr/local/jdk/bin/java' );
            my $java_version = `/usr/local/jdk/bin/java -XX:PermSize=16M -Xms8m -Xmx48m -version 2>&1`;
            return 1 if ( $java_version =~ /\Q${jdk_version}\E/ms );
            return 0;
        },
        'working_path' => 'jdk_dot_bins',
        'command_list' => [
            ["chmod 700 ${jdk_install_bin}"], ["rm -rf ${base_path}jdk ${base_path}jdk${jdk_version}"],
            ["pushd ${base_path} ; echo 'yes' | `dirs +1`/${jdk_install_bin} -noregister ; popd"], ["ln -s ${base_path}jdk${jdk_version} ${base_path}/jdk"]
        ],
    };
}

1;
