[libinline-java-perl] 217/398: More changes towards 0.40...
Jonas Smedegaard
dr at jones.dk
Thu Feb 26 11:43:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to tag 0.55
in repository libinline-java-perl.
commit 8d426ccebeb29b4af8994200e37e92bf24550ace
Author: patrick_leb <>
Date: Sat Mar 22 04:07:02 2003 +0000
More changes towards 0.40...
---
Java.pm | 156 ++++++++++++++++---------------------
Java.pod | 204 +++++++++++++++----------------------------------
Java/Array.pm | 6 +-
Java/Callback.pm | 8 +-
Java/Class.pm | 15 +---
Java/JNI.pm | 2 +-
Java/JNI.xs | 3 +-
Java/JVM.pm | 30 ++++++--
Java/Object.pm | 16 ++--
Java/Portable.pm | 7 --
Java/Protocol.pm | 63 ++-------------
README | 19 +++--
TODO | 12 ++-
t/01_init.t | 4 +-
t/10_1_shared_alone.t | 4 +-
t/10_2_shared_start.t | 4 +-
t/10_6_shared_sim.t | 4 +-
t/13_end.t | 19 +++++
t/pod_test.pl | 3 -
t/shared_jvm_server.pl | 3 -
20 files changed, 215 insertions(+), 367 deletions(-)
diff --git a/Java.pm b/Java.pm
index ac275ec..a659662 100644
--- a/Java.pm
+++ b/Java.pm
@@ -15,11 +15,9 @@ if (! defined($Inline::Java::DEBUG)){
$Inline::Java::DEBUG = 0 ;
}
-
# Set DEBUG stream
*DEBUG_STREAM = *STDERR ;
-
require Inline ;
use Carp ;
use Config ;
@@ -43,13 +41,11 @@ require File::Spec->catfile('Java', 'DefaultJ2SDK.pl') ;
# This is set when the script is over.
my $DONE = 0 ;
-
# This is set when at least one JVM is loaded.
my $JVM = undef ;
-
-# This hash will store the $o objects...
-my $INLINES = {} ;
+# This list will store the $o objects...
+my @INLINES = () ;
# This stuff is to control the termination of the Java Interpreter
@@ -57,7 +53,6 @@ sub done {
my $signal = shift ;
# To preserve the passed exit code...
- # Thanks Maria
my $ec = $? ;
$DONE = 1 ;
@@ -113,12 +108,13 @@ sub validate {
Inline::Java::debug(1, "Starting validate.") ;
my $jdk = Inline::Java::get_default_j2sdk() ;
+ my $dbg = $Inline::Java::DEBUG ;
my %opts = @_ ;
- $o->set_option('DEBUG', 0, 'i', 1, \%opts) ;
+ $o->set_option('DEBUG', $dbg, 'i', 1, \%opts) ;
$o->set_option('J2SDK', $jdk, 's', 1, \%opts) ;
$o->set_option('CLASSPATH', '', 's', 1, \%opts) ;
- $o->set_option('PORT', 7890, 'i', 1, \%opts) ;
+ $o->set_option('PORT', -1, 'i', 1, \%opts) ;
$o->set_option('STARTUP_DELAY', 15, 'i', 1, \%opts) ;
$o->set_option('SHARED_JVM', 0, 'b', 1, \%opts) ;
$o->set_option('JNI', 0, 'b', 1, \%opts) ;
@@ -141,6 +137,15 @@ sub validate {
$o->set_java_config('JNI', 1) ;
}
+ if ($o->get_java_config('PORT') == -1){
+ if ($o->get_java_config('SHARED_JVM')){
+ $o->set_java_config('PORT') = 7891 ;
+ }
+ else{
+ $o->set_java_config('PORT') = 7890 ;
+ }
+ }
+
if (($o->get_java_config('JNI'))&&($o->get_java_config('SHARED_JVM'))){
croak("You can't use the 'SHARED_JVM' option in 'JNI' mode") ;
}
@@ -274,13 +279,21 @@ sub build {
"javac" . portable("EXE_EXTENSION")) ;
my $redir = portable("IO_REDIR") ;
+ # We need to add all the previous install dirs to the classpath because
+ # they can access each other.
+ my @prev_install_dirs = () ;
+ foreach my $in (@INLINES){
+ push @prev_install_dirs, File::Spec->catdir($in->get_api('install_lib'),
+ 'auto', $in->get_api('modpname')) ;
+ }
+
my $cp = $ENV{CLASSPATH} || '' ;
- $ENV{CLASSPATH} = make_classpath($o->get_java_config('CLASSPATH'), get_server_jar()) ;
+ $ENV{CLASSPATH} = make_classpath($o->get_java_config('CLASSPATH'), get_server_jar(), @prev_install_dirs) ;
my $cmd = "\"$javac\" -d \"$install_dir\" $source > cmd.out $redir" ;
if ($o->get_config('UNTAINT')){
($cmd) = $cmd =~ /(.*)/ ;
}
- Inline::Java::debug(2, "$cmd") ;
+ Inline::Java::debug(1, "$cmd") ;
my $res = system($cmd) ;
$res and do {
croak $o->compile_error_msg($cmd) ;
@@ -305,8 +318,6 @@ sub build {
}
}
}
- my $modfname = $o->get_api('modfname') ;
- my $suffix = $o->get_api('suffix') ;
# Touch the .jdat file.
my $jdat = File::Spec->catfile($install_dir, $o->get_api('modfname') . '.' . $o->get_api('suffix')) ;
@@ -367,7 +378,6 @@ sub load {
Inline::Java::debug(1, "Starting load.") ;
- my $modfname = $o->get_api('modfname') ;
my $install_dir = File::Spec->catdir($o->get_api('install_lib'),
'auto', $o->get_api('modpname')) ;
@@ -395,25 +405,14 @@ sub load {
$pc->AddClassPath($install_dir) ;
}
- my $study_module_classes = 1 ;
- my $prev_o = $INLINES->{$modfname} ;
- if (defined($prev_o)){
- Inline::Java::debug(2, "module '$modfname' was already loaded, importing binding into new instance") ;
- if (! defined($o->{ILSM}->{data})){
- $o->{ILSM}->{data} = [] ;
- }
- push @{$o->{ILSM}->{data}}, @{$prev_o->{ILSM}->{data}} ;
- $study_module_classes = 0 ;
- }
-
# Add our Inline object to the list.
- $INLINES->{$modfname} = $o ;
+ push @INLINES, $o ;
my $classes = [] ;
if ((defined($o->get_java_config('STUDY')))&&(scalar($o->get_java_config('STUDY')))){
$classes = $o->get_java_config('STUDY') ;
}
- $o->_study($classes, $study_module_classes) ;
+ $o->_study($classes, 1) ;
$o->set_java_config('loaded', 1) ;
Inline::Java::debug(1, "load done.") ;
@@ -427,9 +426,35 @@ sub _study {
my $classes = shift ;
my $study_module = shift ;
+ my $install_dir = File::Spec->catdir($o->get_api('install_lib'),
+ 'auto', $o->get_api('modpname')) ;
+
+ if ($study_module){
+ # We need to add the classes that are in the directory or under...
+ my @cl = Inline::Java::Portable::find_classes_in_dir($install_dir) ;
+ foreach my $class (@cl){
+ if ($class =~ s/([\w\$]+)\.class$/$1/){
+ my $f = $1 ;
+ push @{$classes}, $f ;
+ }
+ }
+ }
+
+ my @new_classes = () ;
+ foreach my $class (@{$classes}){
+ $class = Inline::Java::Class::ValidateClass($class) ;
+ if (! Inline::Java::known_to_perl($o->get_api('pkg'), $class)){
+ push @new_classes, $class ;
+ }
+ }
+
+ if (! scalar(@new_classes)){
+ return ;
+ }
+
# Then we ask it to give us the public symbols from the classes
# that we got.
- my @lines = $o->report($classes, $study_module) ;
+ my @lines = $o->report(\@new_classes, $study_module) ;
# Now we read up the symbols and bind them to Perl.
$o->bind_jdat($o->load_jdat(@lines)) ;
@@ -466,32 +491,10 @@ sub report {
}
}
- if ($study_module){
- # We need to add the classes that are in the directory or under...
- my @cl = Inline::Java::Portable::find_classes_in_dir($install_dir) ;
- foreach my $class (@cl){
- if ($class =~ s/([\w\$]+)\.class$/$1/){
- my $f = $1 ;
- push @{$classes}, $f ;
- }
- }
- }
-
- my @new_classes = () ;
- foreach my $class (@{$classes}){
- $class = Inline::Java::Class::ValidateClass($class) ;
- if (! Inline::Java::known_to_perl($o->get_api('pkg'), $class)){
- push @new_classes, $class ;
- }
- }
- if (! scalar(@new_classes)){
- return () ;
- }
-
# Ok, there are some classes in there that we don't know about.
# Ask for the info on the classes
my $pc = new Inline::Java::Protocol(undef, $o) ;
- my $resp = $pc->Report(join(" ", @new_classes)) ;
+ my $resp = $pc->Report(join(" ", @{$classes})) ;
if (($study_module)&&($o->get_java_config('built'))){
# Update the cache.
@@ -601,12 +604,12 @@ sub bind_jdat {
my $d = shift ;
my $idx = shift ;
- my $modfname = $o->get_api('modfname') ;
-
if (! defined($d->{classes})){
return ;
}
+ my $inline_idx = scalar(@INLINES) - 1 ;
+
my %classes = %{$d->{classes}} ;
foreach my $class (sort keys %classes) {
my $class_name = $class ;
@@ -619,15 +622,14 @@ sub bind_jdat {
my $code = <<CODE;
package $class ;
-use vars qw(\@ISA \$EXISTS \$JAVA_CLASS \$DUMMY_OBJECT) ;
+use vars qw(\@ISA \$INLINE \$EXISTS \$JAVA_CLASS \$DUMMY_OBJECT) ;
\@ISA = qw(Inline::Java::Object) ;
+\$INLINE = \$INLINES[$inline_idx] ;
\$EXISTS = 1 ;
\$JAVA_CLASS = '$java_class' ;
\$DUMMY_OBJECT = $class$dash>__new(
- \$JAVA_CLASS,
- Inline::Java::get_INLINE('$modfname'),
- 0) ;
+ \$JAVA_CLASS, \$INLINE, 0) ;
use Carp ;
@@ -658,7 +660,7 @@ sub new {
my \$class = shift ;
my \@args = \@_ ;
- my \$o = Inline::Java::get_INLINE('$modfname') ;
+ my \$o = \$INLINE ;
my \$d = \$o->{ILSM}->{data}->[$idx] ;
my \$signatures = \$d->{classes}->{'$class'}->{constructors} ;
my (\$proto, \$new_args, \$static) = \$class->__validate_prototype('new', [\@args], \$signatures, \$o) ;
@@ -702,15 +704,15 @@ sub bind_method {
my $method = shift ;
my $static = shift ;
- my $modfname = $o->get_api('modfname') ;
-
+ my $inline_idx = scalar(@INLINES) - 1 ;
+
my $code = <<CODE;
sub $method {
my \$this = shift ;
my \@args = \@_ ;
- my \$o = Inline::Java::get_INLINE('$modfname') ;
+ my \$o = \$INLINE ;
my \$d = \$o->{ILSM}->{data}->[$idx] ;
my \$signatures = \$d->{classes}->{'$class'}->{methods}->{'$method'} ;
my (\$proto, \$new_args, \$static) = \$this->__validate_prototype('$method', [\@args], \$signatures, \$o) ;
@@ -850,7 +852,7 @@ sub capture_JVM {
sub i_am_JVM_owner {
if ($JVM){
- $JVM->am_owner() ;
+ return $JVM->am_owner() ;
}
}
@@ -862,23 +864,6 @@ sub release_JVM {
}
-sub get_INLINE {
- my $module = shift ;
-
- return $INLINES->{$module} ;
-}
-
-
-sub get_INLINE_nb {
- return scalar(keys %{$INLINES}) ;
-}
-
-
-sub get_INLINE_modules {
- return keys %{$INLINES} ;
-}
-
-
sub get_DEBUG {
return $Inline::Java::DEBUG ;
}
@@ -983,18 +968,11 @@ sub study_classes {
Inline::Java::debug(2, "selecting random module to house studied classes...") ;
- # Select a random Inline object to be responsible for these
- # classes
- my @modules = keys %{$INLINES} ;
+ # Select a random Inline object to be responsible for these classes
srand() ;
- my $idx = int rand @modules ;
- my $module = $modules[$idx] ;
-
- Inline::Java::debug(2, "selected $module") ;
-
- my $o = Inline::Java::get_INLINE($module) ;
+ my $o = @INLINES[int(rand(@INLINES))] ;
- return $o->_study($classes) ;
+ return $o->_study($classes, 0) ;
}
diff --git a/Java.pod b/Java.pod
index bc26ff0..f557e05 100644
--- a/Java.pod
+++ b/Java.pod
@@ -27,6 +27,14 @@ Inline::Java - Write Perl classes in Java.
=for comment
+=head1 WARNING
+
+THIS IS ALPHA SOFTWARE. It is incomplete and possibly unreliable.
+It is also possible that some elements of the interface (API) will
+change in future releases.
+ Z<>
+
+
=head1 DESCRIPTION
The C<Inline::Java> module allows you to put Java source code
@@ -74,13 +82,15 @@ reference (array contains lines of source code). This information
is detailed in 'perldoc Inline'.
In order for C<Inline::Java> to function properly, it needs to know
-where to find the Java compiler (javac) and the Java Runtime (java)
-on your machine. This is done using one of the following techniques:
+where to find a Java 2 SDK on your machine. This is done using one
+of the following techniques:
+
+ - set the J2SDK configuration option to the correct directory
+ - set the PERL_INLINE_JAVA_J2SDK environment variable to the
+ correct directory
- - set the BIN configuration option to the correct directory
- - set the PERL_INLINE_JAVA_BIN environment variable to the correct
- directory
- - put the correct directory in your PATH environment variable
+If none of these are specified, C<Inline::Java> will use the Java
+2 SDK that was specified a install time.
=head1 CONFIGURATION OPTIONS
@@ -88,13 +98,12 @@ on your machine. This is done using one of the following techniques:
There are a number of configuration options that dictate the
behavior of C<Inline::Java>:
- BIN:
- Specifies the path to your Java binaries.
- Ex: BIN => 'my/java/bin/path'
+ J2SDK:
+ Specifies the path to your Java 2 SDK.
+ Ex: BIN => 'my/java/2/sdk/path'
Note: This configuration option only has an effect on the first
'use Inline Java' call inside a Perl script, since all other calls
- make use of the same JVM. However, you can use it if you want to
- change which 'javac' executable is used for subsequent calls.
+ make use of the same JVM.
PORT:
Specifies the starting port number for the server. If many
@@ -186,25 +195,22 @@ behavior of C<Inline::Java>:
=head1 ENVIRONMENT VARIABLES
- PERL_INLINE_JAVA_BIN:
- Same as the BIN option.
-
- PERL_INLINE_JAVA_JNI:
- Same as the JNI option.
+Every configuration option listed above, with the exception of STUDY,
+can be specified using an environment variable named using the
+following convention:
- PERL_INLINE_JAVA_EMBEDDED_JNI:
- Same as the EMBEDDED_JNI option.
+ PERL_INLINE_JAVA_<option name>
- PERL_INLINE_SHARED_JVM:
- Same as the SHARED_JVM option.
+For example, your can specified the JNI option usng the
+PERL_INLINE_JAVA_JNI environment variable.
- PERL_INLINE_JAVA_DEBUG:
- Same as the DEBUG option.
+Note that environment variables take precedence over options specified
+in the script itself.
- PERL_INLINE_JAVA_COMMAND_COM:
- If set to a true value, tells Inline::Java that you are using
- the command.com shell. Inline::Java should normally be able
- to determine this on its own.
+Under Win32, you can also use set the PERL_INLINE_JAVA_COMMAND_COM
+environment variable to a true value to indicate that you are using
+the command.com shell. However, C<Inline::Java> should normally be
+able to determine this on its own.
=head1 CLASSES AND OBJECTS
@@ -577,18 +583,18 @@ $@ is reset by the next eval.
=head1 CALLBACKS
You can now (as of 0.31), call Perl functions from Java. To do this you
-need to create an InlinePerlJavaCaller object. You can then use the
-CallPerl method to call your Perl function. You pass the parameters using
-an array of java.lang.Object. The method will return the result in a
-java.lang.Object, which you must then cast to as a java.lang.String
-(if your Perl method returns a Perl scalar), or anything else if your Perl
-function returns an "Inline::Java" object. Here is a example of a typical
-use:
+need to create an org.perl.inline.java.InlinePerlJavaCaller object. You
+can then use the CallPerl method to call your Perl function. You pass the
+parameters using an array of Objects. The method will return the result in
+an Object, which you must then cast to as a String (if your Perl method
+returns a Perl scalar), or anything else if your Perl function returns
+an "Inline::Java" object. Here is a example of a typical use:
=for comment
use Inline Java => <<'END' ;
import java.util.* ;
+ import org.perl.inline.java.* ;
class Pod_regexp extends InlineJavaPerlCaller {
public Pod_regexp(){
@@ -604,7 +610,7 @@ use:
return true ;
}
}
- catch (PerlException pe){
+ catch (InlineJavaPerlException pe){
// $@ is in pe.GetObject()
}
@@ -627,15 +633,15 @@ use:
=for comment
-The CallPerl method can throw 2 types of exceptions, both of which are inner
-classes of InlineJavaPerlCaller: InlineJavaException and PerlException. The
-former, which designates an internal C<Inline::Java> error, should never be
-dealt with and should be thrown back all the way up to the function that was
-initially called by Perl. The latter indicates that the Perl callback threw
-an exception (die() or croak()). The value of $@ (this can be a scalar or
-any valid "Inline::Java" object) can be retreived using the GetObject method
-of the PerlException object (if you are sure that $@ was a Perl scalar, you
-can use the GetString method).
+The CallPerl method can throw 2 types of exceptions: InlineJavaException and
+InlineJavaPerlException (both of these belong to the org.perl.inline.java
+package). The former, which designates an internal C<Inline::Java> error,
+should never be dealt with and should be thrown back all the way up to the
+function that was initially called by Perl. The latter indicates that the
+Perl callback threw an exception (die() or croak()). The value of $@ (this can
+be a scalar or any valid "Inline::Java" object) can be retreived using the
+GetObject method of the InlineJavaPerlException object (if you are certain
+that $@ was a Perl scalar, you can use the GetString method).
Z<>
@@ -697,51 +703,6 @@ the java::lang::HashMap class is available to use through Perl.
Z<>
-=head1 USING MULTIPLE SECTIONS
-
-If you wish to use more than one C<Inline::Java> section in your Perl script,
-you will need to use the Inline NAME option to name your modules. You can then
-use a special syntax in your CLASSPATH (either the environment variable or the
-configuration option) to tell what Inline::Java modules it will need to load
-at runtime:
-
-=for comment
-
- package Pod_Foo ;
- use Inline (
- Java => <<'END_Pod_Foo',
- class Pod_Foo {
- public Pod_Foo(){
- }
- }
- END_Pod_Foo
- NAME => "Pod_Foo",
- CLASSPATH => "[PERL_INLINE_JAVA=Pod_Foo, Pod_Bar]",
- ) ;
-
- package Pod_Bar ;
- use Inline (
- Java => <<'END_Pod_Bar',
- class Pod_Bar {
- public Pod_Bar() {
- }
- }
- END_Pod_Bar
- NAME => "Pod_Bar",
- ) ;
-
- package main ;
- my $f = new Pod_Foo::Pod_Foo() ;
- my $b = new Pod_Bar::Pod_Bar() ;
-
-=for comment
-
-If you set the CLASSPATH via the configuration option, remember to do so in the
-first Inline::Java section. Also remember that you can't use Java packages with
-Inline::Java. Your classes must be in the unnamed package.
- Z<>
-
-
=head1 JNI vs CLIENT/SERVER MODES
Starting in version 0.20, it is possible to use the JNI (Java Native
@@ -766,11 +727,11 @@ See README.JNI for more information about the JNI extension.
=head1 SHARED_JVM
Starting with version 0.30, the C<Inline::Java> JVM can now be shared between
-multiple processes. The first process to start the JVM is considered the JVM
-owner and will shutdown the JVM on exit. All other processes can connect as
-needed to the JVM. If any of these other processes where created by forking
-the parent process, the Inline::Java->reconnect_JVM() function must be called
-in the child to get a fresh connection to the JVM. Ex:
+multiple processes. The first process to start creates the JVM but does not
+shut it down on exit. All other processes can then connect as needed to the JVM.
+If any of these other processes where created by forking the parent process,
+the Inline::Java->reconnect_JVM() function must be called in the child to get
+a fresh connection to the JVM. Ex:
=for comment
@@ -805,11 +766,7 @@ Once this code was run, each of the 6 processes will have created a different
instance of the 't' class. Data can be shared between the processes by using
static members in the Java code.
-If processes not forked off the parent are connecting to the shared JVM, the
-parent's CLASSPATH must be set properly or else the parent will not see these
-classes. See USING MULTIPLE SECTIONS for more details.
-
-Note: The Java System.out stream is closed int SHARED_JVM mode.
+Note: The Java System.out stream is closed in SHARED_JVM mode.
Z<>
@@ -833,8 +790,6 @@ If you want to use C<Inline::Java> in a CGI script, do the following:
DIRECTORY => '/somewhere/your/web/server/can/write',
) ;
- Inline::Java::release_JVM() ;
-
my $c = new Pod_counter() ;
my $q = new CGI() ;
print
@@ -844,11 +799,9 @@ If you want to use C<Inline::Java> in a CGI script, do the following:
=for comment
-The release_JVM() function simply tells the CGI script that it is no
-longer responsible for shutting down the JVM. What this does is that
-the first CGI to execute will start the JVM, but by releasing it the JVM
-will never be shutdown. Subsequent CGI, since they have the SHARED_JVM
-option enabled, will try to connect to an already existing JVM before
+In this scenario, the first CGI to execute will start the JVM, but does
+not shut it down on exit. Subsequent CGI, since they have the SHARED_JVM
+option enabled, will try to connect to the already existing JVM before
trying to start a new one. Therefore if the JVM happens to crash or is
killed, the next CGI that runs will start a new one. The JVM will be
killed when Apache is shut down.
@@ -873,7 +826,6 @@ Here is an example of how to use C<Inline::Java> under mod_perl:
DIRECTORY => '/somewhere/your/web/server/can/write',
) ;
- Inline::Java::release_JVM() ;
my $c = new Pod_counter() ;
sub handler {
@@ -888,28 +840,7 @@ Here is an example of how to use C<Inline::Java> under mod_perl:
return Apache::Constants::OK() ;
}
-See USING Inline::Java UNDER MOD_PERL for more details about
-the release_JVM() function.
- Z<>
-
-
-=head1 SUPPORTED PLATFORMS
-
-This is an ALPHA release of C<Inline::Java>. Further testing and
-expanded support for other operating systems and platforms will be a
-focus for future releases. It has been tested on:
-
- - Solaris 2.8 + Perl 5.6.1 + Java SDK 1.2.2
- - Solaris 2.8 + Perl 5.6.1 + Java SDK 1.3.1
- - Linux Redhat 7.1 Intel + Perl 5.6 + Java SDK 1.2.2
- - Linux Redhat 7.1 Intel + Perl 5.6 + Java SDK 1.3.1
- - Linux Redhat 7.1 Intel + Perl 5.6 + Java SDK 1.4.0
- - Windows 2000 + Perl 5.6 + Java SDK 1.2.2
- - Windows 2000 + Perl 5.6 + Java SDK 1.3.0
- - Windows 95 + Perl 5.6 + Java SDK 1.3.1
- - Windows 95 + Perl 5.6 + Java SDK 1.2.2
-
-It likely will work with many other configurations.
+See USING Inline::Java IN A CGI for more details.
Z<>
@@ -959,24 +890,11 @@ Here are some things to watch out for:
=item 1
-You can't use the "package" Java directive when using C<Inline::Java>.
-
-=item 2
-
-You can't create public classes when using Inline::Java. This is due
-to the fact that Java requires that public classes be defined in a
-.java file of the same name (C<Inline::Java> can't work this way).
-
-=item 3
-
-You shouldn't name any of your classes starting "InlineJavaServer" or
-"InlineJavaPerl". Those are reserved for C<Inline::Java>'s own Java
-classes. Also do not name your classes 'B', 'S', 'I', 'J', 'F', 'D',
+You shouldn't name any of your classes 'B', 'S', 'I', 'J', 'F', 'D',
'C', 'Z' or 'L'. These classes seem to be used internally by Java to
represent the primitive types.
-
-=item 4
+=item 2
If you upgrade C<Inline::Java> from a previous version, be sure to delete
your Inline directory so that C<Inline::Java>'s own Java classes get
diff --git a/Java/Array.pm b/Java/Array.pm
index 81f3f78..18232c7 100644
--- a/Java/Array.pm
+++ b/Java/Array.pm
@@ -1,11 +1,7 @@
package Inline::Java::Array ;
@Inline::Java::Array::ISA = qw(Inline::Java::Array::Tie) ;
-
use strict ;
-
-$Inline::Java::Array::VERSION = '0.40' ;
-
use Carp ;
@@ -122,7 +118,7 @@ sub __set_element {
my $ret = undef ;
eval {
- my ($new_args, $score) = Inline::Java::Class::CastArguments([$s], [$elem_class], $obj->__get_private()->{module}) ;
+ my ($new_args, $score) = Inline::Java::Class::CastArguments([$s], [$elem_class], $obj->__get_private()->{inline}) ;
$ret = $obj->__get_private()->{proto}->SetJavaMember($idx, [$elem_class], $new_args) ;
} ;
croak $@ if $@ ;
diff --git a/Java/Callback.pm b/Java/Callback.pm
index 90936b8..5fe4778 100644
--- a/Java/Callback.pm
+++ b/Java/Callback.pm
@@ -1,14 +1,8 @@
package Inline::Java::Callback ;
-
use strict ;
-
-$Inline::Java::Callback::VERSION = '0.40' ;
-
-
use Carp ;
-
$Inline::Java::Callback::OBJECT_HOOK = undef ;
@@ -71,7 +65,7 @@ sub ProcessCallback {
$ret = Inline::Java::cast($proto, $ret, $cast_return) ;
}
- ($ret) = Inline::Java::Class::CastArgument($ret, $proto, $inline->get_api('modfname')) ;
+ ($ret) = Inline::Java::Class::CastArgument($ret, $proto, $inline) ;
# Here we must keep a reference to $ret or else it gets deleted
# before the id is returned to Java...
diff --git a/Java/Class.pm b/Java/Class.pm
index ee7a19b..684b99c 100644
--- a/Java/Class.pm
+++ b/Java/Class.pm
@@ -1,15 +1,9 @@
package Inline::Java::Class ;
-
use strict ;
-
-$Inline::Java::Class::VERSION = '0.40' ;
-
-$Inline::Java::Class::MAX_SCORE = 10 ;
-
-
use Carp ;
+$Inline::Java::Class::MAX_SCORE = 10 ;
my $INT_RE = '^[+-]?\d+$' ;
my $FLOAT_RE = '^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$' ;
@@ -94,7 +88,7 @@ sub ValidateClassSplit {
sub CastArguments {
my $args = shift ;
my $proto = shift ;
- my $module = shift ;
+ my $inline = shift ;
Inline::Java::debug_obj($args) ;
Inline::Java::debug_obj($proto) ;
@@ -108,7 +102,7 @@ sub CastArguments {
for (my $i = 0 ; $i < scalar(@{$args}) ; $i++){
my $arg = $args->[$i] ;
my $pro = $proto->[$i] ;
- my @r = CastArgument($arg, $pro, $module) ;
+ my @r = CastArgument($arg, $pro, $inline) ;
$ret->[$i] = $r[0] ;
$score += $r[1] ;
@@ -121,7 +115,7 @@ sub CastArguments {
sub CastArgument {
my $arg = shift ;
my $proto = shift ;
- my $module = shift ;
+ my $inline = shift ;
ValidateClass($proto) ;
@@ -149,7 +143,6 @@ sub CastArgument {
my $an = Inline::Java::Array::Normalizer->new($array_type || $proto, $arg) ;
$array_score = $an->{score} ;
my $flat = $an->FlattenArray() ;
- my $inline = Inline::Java::get_INLINE($module) ;
# We need to create the array on the Java side, and then grab
# the returned object.
diff --git a/Java/JNI.pm b/Java/JNI.pm
index 121dba4..b232cb1 100644
--- a/Java/JNI.pm
+++ b/Java/JNI.pm
@@ -4,7 +4,7 @@ package Inline::Java::JNI ;
use strict ;
-$Inline::Java::JNI::VERSION = '0.31' ;
+$Inline::Java::JNI::VERSION = '0.40' ;
use DynaLoader ;
use Carp ;
diff --git a/Java/JNI.xs b/Java/JNI.xs
index 076168c..521ac64 100644
--- a/Java/JNI.xs
+++ b/Java/JNI.xs
@@ -22,7 +22,7 @@ typedef struct {
void shutdown_JVM(InlineJavaJNIVM *this){
- if (! this->destroyed){
+ if ((! this->embedded)&&(! this->destroyed)){
(*(this->jvm))->DestroyJavaVM(this->jvm) ;
this->destroyed = 1 ;
}
@@ -166,7 +166,6 @@ new(CLASS, classpath, embedded, debug)
}
env = get_env(RETVAL) ;
- RETVAL->destroyed = 1 ; /* do not shutdown, we did not create it */
}
else {
/* Create the Java VM */
diff --git a/Java/JVM.pm b/Java/JVM.pm
index f6f7f12..405165f 100644
--- a/Java/JVM.pm
+++ b/Java/JVM.pm
@@ -2,9 +2,6 @@ package Inline::Java::JVM ;
use strict ;
-
-$Inline::Java::JVM::VERSION = '0.31' ;
-
use Carp ;
use IPC::Open3 ;
use IO::File ;
@@ -31,18 +28,23 @@ sub new {
$this->{socket} = undef ;
$this->{JNI} = undef ;
-
+ $this->{embedded} = $o->get_java_config('EMBEDDED_JNI') ;
+ $this->{owner} = 1 ;
$this->{destroyed} = 0 ;
- Inline::Java::debug(1, "starting JVM...") ;
+ if ($this->{embedded}){
+ Inline::Java::debug(1, "using embedded JVM...") ;
+ }
+ else{
+ Inline::Java::debug(1, "starting JVM...") ;
+ }
- $this->{owner} = 1 ;
if ($o->get_java_config('JNI')){
Inline::Java::debug(1, "JNI mode") ;
my $jni = new Inline::Java::JNI(
$ENV{CLASSPATH} || '',
- $o->get_java_config('EMBEDDED_JNI'),
+ $this->{embedded},
Inline::Java::get_DEBUG(),
) ;
$jni->create_ijs() ;
@@ -68,7 +70,6 @@ sub new {
return $this ;
}
}
- $this->capture(1) ;
my $java = File::Spec->catfile($o->get_java_config('J2SDK'), 'bin',
"java" . Inline::Java::portable("EXE_EXTENSION")) ;
@@ -86,6 +87,14 @@ sub new {
} ;
croak "Can't exec JVM: $@" if $@ ;
+ if ($this->{shared}){
+ # As of 0.40, we release by default.
+ $this->release() ;
+ }
+ else{
+ $this->capture() ;
+ }
+
$this->{pid} = $pid ;
$this->{socket} = $this->setup_socket(
$this->{host},
@@ -138,6 +147,11 @@ sub DESTROY {
sub shutdown {
my $this = shift ;
+ if ($this->{embedded}){
+ Inline::Java::debug(1, "embedded JVM, skipping shutdown.") ;
+ return ;
+ }
+
if (! $this->{destroyed}){
if ($this->am_owner()){
Inline::Java::debug(1, "JVM owner exiting...") ;
diff --git a/Java/Object.pm b/Java/Object.pm
index 80d01b0..0b5edc6 100644
--- a/Java/Object.pm
+++ b/Java/Object.pm
@@ -2,13 +2,9 @@ package Inline::Java::Object ;
@Inline::Java::Object::ISA = qw(Inline::Java::Object::Tie) ;
use strict ;
-
-$Inline::Java::Object::VERSION = '0.31' ;
-
use Inline::Java::Protocol ;
use Carp ;
-
# Here we store as keys the knots and as values our blessed private objects
my $PRIVATES = {} ;
@@ -100,7 +96,7 @@ sub __validate_prototype {
Inline::Java::debug(3, "matching arguments to $method$sig") ;
eval {
- ($new_args, $score) = Inline::Java::Class::CastArguments($args, $proto, $inline->get_api('modfname')) ;
+ ($new_args, $score) = Inline::Java::Class::CastArguments($args, $proto, $inline) ;
} ;
if ($@){
if ($nb_proto == 1){
@@ -239,7 +235,7 @@ sub __get_member {
Inline::Java::debug(3, "fetching member variable '$key'") ;
- my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
+ my $inline = $this->__get_private()->{inline} ;
my $fields = $inline->get_fields($this->__get_private()->{class}) ;
my $types = $fields->{$key} ;
@@ -276,7 +272,7 @@ sub __set_member {
croak "Can't set member '$key' for an object that is not bound to Perl" ;
}
- my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
+ my $inline = $this->__get_private()->{inline} ;
my $fields = $inline->get_fields($this->__get_private()->{class}) ;
my $types = $fields->{$key} ;
@@ -294,7 +290,7 @@ sub __set_member {
my $new_args = undef ;
my $score = undef ;
- ($new_args, $score) = Inline::Java::Class::CastArguments([$value], [$proto], $this->__get_private()->{module}) ;
+ ($new_args, $score) = Inline::Java::Class::CastArguments([$value], [$proto], $this->__get_private()->{inline}) ;
$this->__get_private()->{proto}->SetJavaMember($key, [$proto], $new_args) ;
}
else{
@@ -437,7 +433,7 @@ sub EXISTS {
my $this = shift ;
my $key = shift ;
- my $inline = Inline::Java::get_INLINE($this->__get_private()->{module}) ;
+ my $inline = $this->__get_private()->{inline} ;
my $fields = $inline->get_fields($this->__get_private()->{class}) ;
if ($fields->{$key}){
@@ -531,7 +527,7 @@ sub new {
my $this = {} ;
$this->{class} = $obj_class ;
$this->{java_class} = $java_class ;
- $this->{module} = $inline->get_api('modfname') ;
+ $this->{inline} = $inline ;
$this->{proto} = new Inline::Java::Protocol($this, $inline) ;
bless($this, $class) ;
diff --git a/Java/Portable.pm b/Java/Portable.pm
index 425783d..1750a41 100644
--- a/Java/Portable.pm
+++ b/Java/Portable.pm
@@ -3,12 +3,7 @@ package Inline::Java::Portable ;
@EXPORT = qw(portable make_classpath get_server_jar get_user_jar) ;
-
use strict ;
-
-$Inline::Java::Portable::VERSION = '0.40' ;
-
-
use Exporter ;
use Carp ;
use Config ;
@@ -16,7 +11,6 @@ use Cwd ;
use File::Find ;
use File::Spec ;
-
# Here is some code to figure out if we are running on command.com
# shell under Windows.
my $COMMAND_COM =
@@ -33,7 +27,6 @@ my $COMMAND_COM =
) || 0 ;
-
sub debug {
if (Inline::Java->can("debug")){
return Inline::Java::debug(@_) ;
diff --git a/Java/Protocol.pm b/Java/Protocol.pm
index ee9c660..a318c6b 100644
--- a/Java/Protocol.pm
+++ b/Java/Protocol.pm
@@ -1,10 +1,6 @@
package Inline::Java::Protocol ;
-
use strict ;
-
-$Inline::Java::Protocol::VERSION = '0.40' ;
-
use Inline::Java::Object ;
use Inline::Java::Array ;
use Carp ;
@@ -19,7 +15,7 @@ sub new {
my $this = {} ;
$this->{obj_priv} = $obj || {} ;
- $this->{module} = $inline->get_api('modfname') ;
+ $this->{inline} = $inline ;
bless($this, $class) ;
return $this ;
@@ -300,9 +296,7 @@ sub Send {
my $data = shift ;
my $const = shift ;
- my $inline = Inline::Java::get_INLINE($this->{module}) ;
- my $resp = Inline::Java::__get_JVM()->process_command($inline, $data) ;
-
+ my $resp = Inline::Java::__get_JVM()->process_command($this->{inline}, $data) ;
if ($resp =~ /^error scalar:([\d.-]*)$/){
my $msg = decode($1) ;
Inline::Java::debug(3, "packet recv error: $msg") ;
@@ -346,8 +340,7 @@ sub DeserializeObject {
return undef ;
}
else{
- my $inline = Inline::Java::get_INLINE($this->{module}) ;
- my $pkg = $inline->get_api('pkg') ;
+ my $pkg = $this->{inline}->get_api('pkg') ;
my $obj = undef ;
my $elem_class = $class ;
@@ -365,8 +358,8 @@ sub DeserializeObject {
$perl_class = Inline::Java::java2perl($pkg, $elem_class) ;
if (Inline::Java::Class::ClassIsReference($elem_class)){
if (! Inline::Java::known_to_perl($pkg, $elem_class)){
- if (($thrown)||($inline->get_java_config('AUTOSTUDY'))){
- $inline->_study([$elem_class], 0) ;
+ if (($thrown)||($this->{inline}->get_java_config('AUTOSTUDY'))){
+ $this->{inline}->_study([$elem_class], 0) ;
}
else{
# Object is not known to Perl, it lives as a
@@ -384,12 +377,12 @@ sub DeserializeObject {
if (Inline::Java::Class::ClassIsArray($class)){
Inline::Java::debug(3, "creating array object...") ;
- $obj = Inline::Java::Object->__new($class, $inline, $id) ;
+ $obj = Inline::Java::Object->__new($class, $this->{inline}, $id) ;
$obj = new Inline::Java::Array($obj) ;
Inline::Java::debug(3, "array object created...") ;
}
else{
- $obj = $perl_class->__new($class, $inline, $id) ;
+ $obj = $perl_class->__new($class, $this->{inline}, $id) ;
}
if ($thrown){
@@ -435,44 +428,4 @@ sub DESTROY {
}
-
-1 ;
-
-
-
-__END__
-
-
-RCS file: /cvsroot/inline-java/Inline-Java/Java/Protocol.pm,v
-retrieving revision 1.29
-diff -r1.29 Protocol.pm
-37a38,51
-> sub AddClassPath {
-> my $this = shift ;
-> my @paths = @_ ;
->
-> Inline::Java::debug(3, "adding to class path (" .
-> join(", ", map {"'" . $_ . "'"} @paths) . ")") ;
->
-> my $data = "add_classpath " . join(" ", map {encode($_)} @paths) ;
->
-> return $this->Send($data, 1) ;
-> }
->
->
->
-460a475,477
-> else if (c.equals("add_classpath")){
-> AddClassPath(st) ;
-> }
-553a571,580
-> }
->
->
-> void AddClassPath(StringTokenizer st) throws InlineJavaException {
-> while (st.hasMoreTokens()){
-> String path = decode(st.nextToken()) ;
-> InlineJavaServer.instance.AddClassPath(path) ;
-> }
->
-> SetResponse(null) ;
+1 ;
\ No newline at end of file
diff --git a/README b/README
index 10216b6..2fae358 100644
--- a/README
+++ b/README
@@ -43,7 +43,8 @@ To install Inline::Java do this:
perl Makefile.PL
make (see Note 1)
-make test (see Note 2, 3, 4)
+make java
+make test (see Note 2, 3)
make install
You have to 'make install' before you can run it successfully.
@@ -51,16 +52,11 @@ You have to 'make install' before you can run it successfully.
Note 1: Use nmake on Windows systems.
-Note 2: In order for 'make test' to run properly, you should put the
-directory to your Java binaries in either your PATH environment variable
-or in the PERL_INLINE_JAVA_BIN environment variable. 'make test' will remind
-you if you don't do this.
-
-Note 3: If you have built the JNI extension and want the test suite to use
+Note 2: If you have built the JNI extension and want the test suite to use
it, you will need to set the PERL_INLINE_JAVA_JNI environment variable to 1
BEFORE running 'make test'.
-Note 4: When testing Inline::Java, it's always a good idea to run 'make test'
+Note 3: When testing Inline::Java, it's always a good idea to run 'make test'
twice. The first time you test the building and loading of a module, the
second time you test loading of an already built module.
@@ -68,10 +64,13 @@ second time you test loading of an already built module.
-------------------------------------------------------------------------------
FEATURES:
-Inline::Java version 0.34 is a minor upgrade that includes:
+WARNING: THIS IS ALPHA SOFTWARE. It is incomplete and possibly unreliable.
+ It is also possible that some elements of the interface (API) will
+ change in future releases.
+
+Inline::Java version 0.40 is a major upgrade that includes:
+ Patch by Doug MacEachern to allow running under servlet engines
+ Other minor bug fixes and documentation corrections
-+ Moved to Beta status
Inline::Java version 0.33 is a minor upgrade that includes:
+ Improved and more flexible debug output
diff --git a/TODO b/TODO
index 0922b1c..bb4b04e 100644
--- a/TODO
+++ b/TODO
@@ -1,12 +1,16 @@
CODE:
-- Implement AddClassPath
-- Change BIN to J2SDK
-- Fix makfile.PL to build at install time, create jar and config file
-- Fix environment variables
+- Parse source code for "public class \w+" and use this for file name.
+- Fix install and compilation of jars.
+- Fix installation script for JNI.
+- Write a test for a public class in a package.
+- Retest all the small test stuff under Linux.
+- Restore Alpha status
TEST:
- Alpha
- Cygwin
DOCUMENTATION:
+- Recheck all and complete.
+- Comment new code.
diff --git a/t/01_init.t b/t/01_init.t
index 6c0a978..458d31f 100644
--- a/t/01_init.t
+++ b/t/01_init.t
@@ -13,8 +13,8 @@ use Inline (
Java => 'DATA'
) ;
-my $mod = (Inline::Java::get_INLINE_modules())[0] ;
-my $ij = Inline::Java::get_INLINE($mod) ;
+my $ij = $types1::INLINE ;
+$ij = $types1::INLINE ; # Stupid warning...
my $jdk = $ij->get_java_config("J2SDK") ;
my $ver = types1->version() ;
print STDERR "\nInline version is $Inline::VERSION\n" ;
diff --git a/t/10_1_shared_alone.t b/t/10_1_shared_alone.t
index b8bc973..69e83b7 100755
--- a/t/10_1_shared_alone.t
+++ b/t/10_1_shared_alone.t
@@ -8,7 +8,7 @@ BEGIN {
exit ;
}
else{
- plan(tests => 3) ;
+ plan(tests => 4) ;
}
}
@@ -26,6 +26,8 @@ my $t = new t10() ;
{
ok($t->{i}, 5) ;
+ ok(! Inline::Java::i_am_JVM_owner()) ;
+ Inline::Java::capture_JVM() ;
ok(Inline::Java::i_am_JVM_owner()) ;
}
diff --git a/t/10_2_shared_start.t b/t/10_2_shared_start.t
index 74a5f2d..7b77ced 100755
--- a/t/10_2_shared_start.t
+++ b/t/10_2_shared_start.t
@@ -15,7 +15,7 @@ BEGIN {
exit ;
}
else{
- plan(tests => 4) ;
+ plan(tests => 3) ;
}
}
@@ -33,8 +33,6 @@ use Inline (
my $t = new t10::t10() ;
{
ok($t->{i}++, 5) ;
- ok(Inline::Java::i_am_JVM_owner()) ;
- Inline::Java::release_JVM() ;
ok(! Inline::Java::i_am_JVM_owner()) ;
}
diff --git a/t/10_6_shared_sim.t b/t/10_6_shared_sim.t
index 35ae62c..3166008 100644
--- a/t/10_6_shared_sim.t
+++ b/t/10_6_shared_sim.t
@@ -14,7 +14,7 @@ BEGIN {
exit ;
}
else{
- plan(tests => 8) ;
+ plan(tests => 7) ;
}
}
@@ -28,8 +28,6 @@ Inline->bind(
{
my $t = new t10::t10() ;
ok($t->{i}++, 5) ;
- ok(Inline::Java::i_am_JVM_owner()) ;
- Inline::Java::release_JVM() ;
ok(! Inline::Java::i_am_JVM_owner()) ;
}
my $JVM1 = Inline::Java::__get_JVM() ;
diff --git a/t/13_end.t b/t/13_end.t
new file mode 100644
index 0000000..c081a42
--- /dev/null
+++ b/t/13_end.t
@@ -0,0 +1,19 @@
+use strict ;
+use Test ;
+
+
+BEGIN {
+ plan(tests => 1) ;
+}
+
+
+use Inline Config =>
+ DIRECTORY => './_Inline_test' ;
+
+use Inline (
+ Java => 'STUDY',
+) ;
+
+Inline::Java::capture_JVM() ;
+ok(Inline::Java::i_am_JVM_owner()) ;
+
diff --git a/t/pod_test.pl b/t/pod_test.pl
index a66d4c5..a64a444 100644
--- a/t/pod_test.pl
+++ b/t/pod_test.pl
@@ -29,9 +29,6 @@ my $del = "\n=for comment\n" ;
my @code_blocks = ($pod =~ m/$del(.*?)$del/gs) ;
-my $ps = Inline::Java::portable("ENV_VAR_PATH_SEP_CP") ;
-$ENV{CLASSPATH} .= "$ps" . "[PERL_INLINE_JAVA=Pod_Foo,Pod_Bar]" ;
-
my $skip_to = $opts{s} || 0 ;
my $cnt = -1 ;
diff --git a/t/shared_jvm_server.pl b/t/shared_jvm_server.pl
index dba75d0..1964852 100644
--- a/t/shared_jvm_server.pl
+++ b/t/shared_jvm_server.pl
@@ -4,7 +4,6 @@ use blib ;
BEGIN {
- $ENV{CLASSPATH} .= ":[PERL_INLINE_JAVA=shared_jvm_test]" ;
mkdir('./_Inline_test', 0777) unless -e './_Inline_test';
}
@@ -18,8 +17,6 @@ use Inline(
SHARED_JVM => 1,
) ;
-print "CLASSPATH should be preset for the server to work\n" ;
-print "CLASSPATH = $ENV{CLASSPATH}\n" ;
print "Shared JVM server started\n" ;
while (1){
sleep(60) ;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libinline-java-perl.git
More information about the Pkg-perl-cvs-commits
mailing list