1--perl 2use strict; 3use lib "lib/"; 4use My::Exec; 5use My::Platform; 6 7## 8## run_java.inc - include script to run Java 9## 10## Parameters 11## $MTR_JAVA: Java which should be used 12## $JAVA_CLASS: Class file to run 13## $JAVA_CLASSPATH: Class path to use when running test 14## $JAVA_JVM_OPTS: Optional parameters to the JVM 15## 16## 17## Usage: 18## 19## --source suite/ndb/include/have_java.inc 20## 21## let JAVA_CLASSPATH=-classpath .:/some/path; 22## let JAVA_JVM_OPTS=-Dsome.setting=123 -ea -Xcheck:jni; 23## 24## let JAVA_CLASS=test/SomeTest.class; 25## --source suite/ndb/include/run_java.inc 26## 27## let JAVA_CLASS=test/SomeOtherTest.class; 28## --source suite/ndb/include/run_java.inc 29## 30 31# Check parameters 32my $java = $ENV{MTR_JAVA} || die "ERROR: Java not found, set MTR_JAVA"; 33my $java_classpath = $ENV{JAVA_CLASSPATH} || die "ERROR: Java classpath not set, please set JAVA_CLASSPATH"; 34my $java_class = $ENV{JAVA_CLASS} || die "ERROR: Java class to run not set, please set JAVA_CLASS"; 35my $java_args = $ENV{MTR_JAVA_ARGS} || ''; 36my $jvm_opts = $ENV{JAVA_JVM_OPTS} || ''; 37my $class_args = $ENV{JAVA_ARGUMENTS} || ''; 38my $vardir = $ENV{MYSQLTEST_VARDIR} || die "Need MYSQLTEST_VARDIR"; 39 40my $sep = ":"; 41if(IS_WINDOWS) 42{ 43 $sep = ";"; 44} 45 46 47# The length of the variables that can be passed in environment variables are limited 48# (around 1024 characters) - this trick lets you plit the classpath in several variables to 49# be avle to pass longer classpaths 50for my $i (1..9) 51{ 52 my $env = $ENV{"JAVA_CLASSPATH_$i"} || ''; 53 if ($env) 54 { 55 $java_classpath .= "$sep$env"; 56 } 57 my $jvm = $ENV{"JAVA_JVM_OPTS_$i"} || ''; 58 if ($jvm) 59 { 60 $jvm_opts .= " $jvm"; 61 } 62} 63 64# Tell the vm to put temporary files in $MYSQLTEST_VARDIR/tmp 65$jvm_opts .= " -Djava.io.tmpdir=$vardir/tmp"; 66 67if ($ENV{MTR_CLASSPATH}) 68{ 69 $java_classpath .= "$sep$ENV{MTR_CLASSPATH}" 70} 71 72my $cmd = "\"$java\" $java_args $jvm_opts -classpath \"$java_classpath\" $java_class $class_args"; 73my $res = exec_print_on_error($cmd); 74 75my $F = IO::File->new("$vardir/tmp/run_java.result", "w") || die "Couldn't open varfile for writing"; 76if ($res) 77{ 78 print $F "# Success\n"; 79} 80else 81{ 82 print $F "die \'$cmd\' run failed;\n"; 83} 84$F->close(); 85 86EOF 87--source $MYSQLTEST_VARDIR/tmp/run_java.result 88