From jbq@anyware-tech.com  Wed Apr 19 15:45:46 2006
Return-Path: <jbq@anyware-tech.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id EA54516A487;
	Wed, 19 Apr 2006 15:45:45 +0000 (UTC)
	(envelope-from jbq@anyware-tech.com)
Received: from caraldi.com (195-13-58-165.oxyd.net [195.13.58.165])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 428C343D5A;
	Wed, 19 Apr 2006 15:45:41 +0000 (GMT)
	(envelope-from jbq@anyware-tech.com)
Received: from vision.anyware (10.21.96-84.rev.gaoland.net [84.96.21.10])
	by caraldi.com (Postfix) with ESMTP id 71816620C;
	Wed, 19 Apr 2006 17:45:40 +0200 (CEST)
Received: by vision.anyware (Postfix, from userid 1021)
	id 1B3686173; Wed, 19 Apr 2006 17:45:42 +0200 (CEST)
Message-Id: <20060419154542.1B3686173@vision.anyware>
Date: Wed, 19 Apr 2006 17:45:42 +0200 (CEST)
From: Jean-Baptiste Quenot <jbq@caraldi.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: java@freebsd.org
Subject: Allow java/javavmwrapper to report the location of the JVM
X-Send-Pr-Version: 3.113
X-GNATS-Notify: hq@FreeBSD.org

>Number:         96050
>Category:       ports
>Synopsis:       Allow java/javavmwrapper to report the location of the JVM
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    glewis
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 19 15:50:15 GMT 2006
>Closed-Date:    Thu Jun 08 18:03:45 GMT 2006
>Last-Modified:  Thu Jun 08 18:03:45 GMT 2006
>Originator:     Jean-Baptiste Quenot
>Release:        FreeBSD 5.5-PRERELEASE i386
>Organization:
>Environment:
System: FreeBSD vision.anyware 5.5-PRERELEASE FreeBSD 5.5-PRERELEASE #1: Thu Mar 9 19:20:53 CET 2006 jbq@vision.anyware:/usr/obj/usr/src/sys/VISION i386
>Description:
Please see discussion at
http://lists.freebsd.org/pipermail/freebsd-java/2006-April/005152.html

The Java ports infrastructure provides ${JAVA_HOME} and ${JAVA} on build-time to
a port's Makefile, but it would be great to set the Java version requirement on
a per-port basis in the rc flags.  This requires to get JAVA_HOME and java
executable path from javavmwrapper at runtime.

The idea is to make javavm recognize two special environment variables:

JAVAVM_PRINT_JAVA_HOME

  When set, find the best suitable JVM and print the corresponding value of
  JAVA_HOME instead of executing the java program


JAVAVM_PRINT_JAVA_PROGRAM

  When set, find the best suitable JVM and print the path of the Java program
  instead of executing it

For this to  work correctly, we need javavm to  stop upon failure.  Until  now,
when  the  java program  cannot  be exec-uted,  javavm issues a warning and goes
on to the next JVM.

Thanks in advance!
>How-To-Repeat:
>Fix:
diff -ru javavmwrapper.orig/src/javavm.1 javavmwrapper/src/javavm.1
--- javavmwrapper.orig/src/javavm.1	Tue Apr 19 00:03:27 2005
+++ javavmwrapper/src/javavm.1	Wed Apr 19 17:32:22 2006
@@ -124,6 +124,12 @@
 .Ql 1.5
 and
 .Ql 1.5+ .
+.It Ev JAVAVM_PRINT_JAVA_HOME
+When set, find the best suitable JVM and print the corresponding value of
+JAVA_HOME instead of executing the java program.
+.It Ev JAVAVM_PRINT_JAVA_PROGRAM
+When set, find the best suitable JVM and print the path of the Java program
+instead of executing it.
 .El
 .Sh FILES
 .Bl -tag -width indent
diff -ru javavmwrapper.orig/src/javavmwrapper.sh javavmwrapper/src/javavmwrapper.sh
--- javavmwrapper.orig/src/javavmwrapper.sh	Fri Nov  4 00:04:40 2005
+++ javavmwrapper/src/javavmwrapper.sh	Wed Apr 19 17:29:22 2006
@@ -6,6 +6,8 @@
 # They can then be selected from based on environment variables and the
 # configuration file.
 #
+# Please have a look at the javavm(1) man page for more information.
+#
 # ----------------------------------------------------------------------------
 # "THE BEER-WARE LICENSE" (Revision 42, (c) Poul-Henning Kamp):
 # Maxim Sobolev <sobomax@FreeBSD.org> wrote this file.  As long as you retain
@@ -43,13 +45,23 @@
 tryJavaCommand () {
     # Check for the command being executable and exec it if so.
     if [ -x "${1}" ]; then
-        if [ ! -z "${SAVE_PATH}" ]; then
-            export PATH=${SAVE_PATH}
+        if [ -z "$JAVAVM_PRINT_JAVA_HOME" -a -z "$JAVAVM_PRINT_JAVA_PROGRAM" ] ; then
+            if [ ! -z "${SAVE_PATH}" ]; then
+                export PATH=${SAVE_PATH}
+            fi
+
+            exec "${@}"
+            echo "${IAM}: error: couldn't run specified Java command - \"${1}\"" >&2
+            exit 1
+        else
+            if [ -n "$JAVAVM_PRINT_JAVA_HOME" ] ; then
+                echo "${JAVA_HOME}"
+            else
+                echo "${@}"
+            fi
+            exit 0
         fi
-        exec "${@}"
     fi
-
-    echo "${IAM}: warning: couldn't run specified Java command - \"${1}\"" >&2
 }
 
 #
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-ports-bugs->glewis 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Wed Apr 19 15:56:08 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=96050 
State-Changed-From-To: open->closed 
State-Changed-By: glewis 
State-Changed-When: Thu Jun 8 18:01:28 UTC 2006 
State-Changed-Why:  
Thanks for the ideas.  I've implemented them in a different way using a 
single variable (JAVAVM_DRYRUN).  You should still be able to get the 
information you need (and more).  An example of extracting it is in the 
javavm manual page. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=96050 
>Unformatted:
